]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.18.5-201502052352.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.5-201502052352.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238 index a311db8..415b28c 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index f4c71d4..66811b1 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1182,6 +1182,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2260,6 +2264,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 @@ -2552,6 +2560,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 6276fca..e21ed81 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -298,7 +298,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377 HOSTCC = gcc
378 HOSTCXX = g++
379 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
380 -HOSTCXXFLAGS = -O2
381 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -std=gnu89 -fno-delete-null-pointer-checks
382 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
383 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
384
385 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
386 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
387 @@ -445,8 +447,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
388 # Rules shared between *config targets and build targets
389
390 # Basic helpers built in scripts/
391 -PHONY += scripts_basic
392 -scripts_basic:
393 +PHONY += scripts_basic gcc-plugins
394 +scripts_basic: gcc-plugins
395 $(Q)$(MAKE) $(build)=scripts/basic
396 $(Q)rm -f .tmp_quiet_recordmcount
397
398 @@ -620,6 +622,72 @@ endif
399 # Tell gcc to never replace conditional load with a non-conditional one
400 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
401
402 +ifndef DISABLE_PAX_PLUGINS
403 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
404 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
405 +else
406 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
407 +endif
408 +ifneq ($(PLUGINCC),)
409 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
410 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
411 +endif
412 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
413 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
414 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
415 +endif
416 +ifdef CONFIG_KALLOCSTAT_PLUGIN
417 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
418 +endif
419 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
420 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
421 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
422 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
423 +endif
424 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
425 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
426 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
427 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
428 +endif
429 +endif
430 +ifdef CONFIG_CHECKER_PLUGIN
431 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
432 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
433 +endif
434 +endif
435 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
436 +ifdef CONFIG_PAX_SIZE_OVERFLOW
437 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
438 +endif
439 +ifdef CONFIG_PAX_LATENT_ENTROPY
440 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
441 +endif
442 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
443 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
444 +endif
445 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
446 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
450 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
451 +ifeq ($(KBUILD_EXTMOD),)
452 +gcc-plugins:
453 + $(Q)$(MAKE) $(build)=tools/gcc
454 +else
455 +gcc-plugins: ;
456 +endif
457 +else
458 +gcc-plugins:
459 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
460 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
461 +else
462 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
463 +endif
464 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
465 +endif
466 +endif
467 +
468 ifdef CONFIG_READABLE_ASM
469 # Disable optimizations that make assembler listings hard to read.
470 # reorder blocks reorders the control in the function
471 @@ -712,7 +780,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
472 else
473 KBUILD_CFLAGS += -g
474 endif
475 -KBUILD_AFLAGS += -Wa,-gdwarf-2
476 +KBUILD_AFLAGS += -Wa,--gdwarf-2
477 endif
478 ifdef CONFIG_DEBUG_INFO_DWARF4
479 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
480 @@ -877,7 +945,7 @@ export mod_sign_cmd
481
482
483 ifeq ($(KBUILD_EXTMOD),)
484 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
485 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
486
487 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
488 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
489 @@ -924,6 +992,8 @@ endif
490
491 # The actual objects are generated when descending,
492 # make sure no implicit rule kicks in
493 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
496
497 # Handle descending into subdirectories listed in $(vmlinux-dirs)
498 @@ -933,7 +1003,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
499 # Error messages still appears in the original language
500
501 PHONY += $(vmlinux-dirs)
502 -$(vmlinux-dirs): prepare scripts
503 +$(vmlinux-dirs): gcc-plugins prepare scripts
504 $(Q)$(MAKE) $(build)=$@
505
506 define filechk_kernel.release
507 @@ -976,10 +1046,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
508
509 archprepare: archheaders archscripts prepare1 scripts_basic
510
511 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
512 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
513 prepare0: archprepare FORCE
514 $(Q)$(MAKE) $(build)=.
515
516 # All the preparing..
517 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
518 prepare: prepare0
519
520 # Generate some files
521 @@ -1094,6 +1167,8 @@ all: modules
522 # using awk while concatenating to the final file.
523
524 PHONY += modules
525 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
526 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
527 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
528 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
529 @$(kecho) ' Building modules, stage 2.';
530 @@ -1109,7 +1184,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
531
532 # Target to prepare building external modules
533 PHONY += modules_prepare
534 -modules_prepare: prepare scripts
535 +modules_prepare: gcc-plugins prepare scripts
536
537 # Target to install modules
538 PHONY += modules_install
539 @@ -1175,7 +1250,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
540 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
541 signing_key.priv signing_key.x509 x509.genkey \
542 extra_certificates signing_key.x509.keyid \
543 - signing_key.x509.signer include/linux/version.h
544 + signing_key.x509.signer include/linux/version.h \
545 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
547 + tools/gcc/randomize_layout_seed.h
548
549 # clean - Delete most, but leave enough to build external modules
550 #
551 @@ -1214,7 +1292,7 @@ distclean: mrproper
552 @find $(srctree) $(RCS_FIND_IGNORE) \
553 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
554 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
555 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
556 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
557 -type f -print | xargs rm -f
558
559
560 @@ -1380,6 +1458,8 @@ PHONY += $(module-dirs) modules
561 $(module-dirs): crmodverdir $(objtree)/Module.symvers
562 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
563
564 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
565 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
566 modules: $(module-dirs)
567 @$(kecho) ' Building modules, stage 2.';
568 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
569 @@ -1520,17 +1600,21 @@ else
570 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
571 endif
572
573 -%.s: %.c prepare scripts FORCE
574 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
575 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
576 +%.s: %.c gcc-plugins prepare scripts FORCE
577 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
578 %.i: %.c prepare scripts FORCE
579 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
580 -%.o: %.c prepare scripts FORCE
581 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
582 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
583 +%.o: %.c gcc-plugins prepare scripts FORCE
584 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
585 %.lst: %.c prepare scripts FORCE
586 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
587 -%.s: %.S prepare scripts FORCE
588 +%.s: %.S gcc-plugins prepare scripts FORCE
589 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
590 -%.o: %.S prepare scripts FORCE
591 +%.o: %.S gcc-plugins prepare scripts FORCE
592 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
593 %.symtypes: %.c prepare scripts FORCE
594 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
595 @@ -1542,11 +1626,15 @@ endif
596 $(build)=$(build-dir)
597 # Make sure the latest headers are built for Documentation
598 Documentation/: headers_install
599 -%/: prepare scripts FORCE
600 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
601 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
602 +%/: gcc-plugins prepare scripts FORCE
603 $(cmd_crmodverdir)
604 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
605 $(build)=$(build-dir)
606 -%.ko: prepare scripts FORCE
607 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
608 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
609 +%.ko: gcc-plugins prepare scripts FORCE
610 $(cmd_crmodverdir)
611 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
612 $(build)=$(build-dir) $(@:.ko=.o)
613 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
614 index 8f8eafb..3405f46 100644
615 --- a/arch/alpha/include/asm/atomic.h
616 +++ b/arch/alpha/include/asm/atomic.h
617 @@ -239,4 +239,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
618 #define atomic_dec(v) atomic_sub(1,(v))
619 #define atomic64_dec(v) atomic64_sub(1,(v))
620
621 +#define atomic64_read_unchecked(v) atomic64_read(v)
622 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
623 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
624 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
625 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
626 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
627 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
628 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
629 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
630 +
631 #endif /* _ALPHA_ATOMIC_H */
632 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
633 index ad368a9..fbe0f25 100644
634 --- a/arch/alpha/include/asm/cache.h
635 +++ b/arch/alpha/include/asm/cache.h
636 @@ -4,19 +4,19 @@
637 #ifndef __ARCH_ALPHA_CACHE_H
638 #define __ARCH_ALPHA_CACHE_H
639
640 +#include <linux/const.h>
641
642 /* Bytes per L1 (data) cache line. */
643 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
644 -# define L1_CACHE_BYTES 64
645 # define L1_CACHE_SHIFT 6
646 #else
647 /* Both EV4 and EV5 are write-through, read-allocate,
648 direct-mapped, physical.
649 */
650 -# define L1_CACHE_BYTES 32
651 # define L1_CACHE_SHIFT 5
652 #endif
653
654 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
655 #define SMP_CACHE_BYTES L1_CACHE_BYTES
656
657 #endif
658 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
659 index 968d999..d36b2df 100644
660 --- a/arch/alpha/include/asm/elf.h
661 +++ b/arch/alpha/include/asm/elf.h
662 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
663
664 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
665
666 +#ifdef CONFIG_PAX_ASLR
667 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
668 +
669 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
670 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
671 +#endif
672 +
673 /* $0 is set by ld.so to a pointer to a function which might be
674 registered using atexit. This provides a mean for the dynamic
675 linker to call DT_FINI functions for shared libraries that have
676 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
677 index aab14a0..b4fa3e7 100644
678 --- a/arch/alpha/include/asm/pgalloc.h
679 +++ b/arch/alpha/include/asm/pgalloc.h
680 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
681 pgd_set(pgd, pmd);
682 }
683
684 +static inline void
685 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
686 +{
687 + pgd_populate(mm, pgd, pmd);
688 +}
689 +
690 extern pgd_t *pgd_alloc(struct mm_struct *mm);
691
692 static inline void
693 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
694 index d8f9b7e..f6222fa 100644
695 --- a/arch/alpha/include/asm/pgtable.h
696 +++ b/arch/alpha/include/asm/pgtable.h
697 @@ -102,6 +102,17 @@ struct vm_area_struct;
698 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
699 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
700 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 +
702 +#ifdef CONFIG_PAX_PAGEEXEC
703 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
704 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
705 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +#else
707 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
708 +# define PAGE_COPY_NOEXEC PAGE_COPY
709 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
710 +#endif
711 +
712 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
713
714 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
715 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
716 index 2fd00b7..cfd5069 100644
717 --- a/arch/alpha/kernel/module.c
718 +++ b/arch/alpha/kernel/module.c
719 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
720
721 /* The small sections were sorted to the end of the segment.
722 The following should definitely cover them. */
723 - gp = (u64)me->module_core + me->core_size - 0x8000;
724 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
725 got = sechdrs[me->arch.gotsecindex].sh_addr;
726
727 for (i = 0; i < n; i++) {
728 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
729 index f9c732e..78fbb0f 100644
730 --- a/arch/alpha/kernel/osf_sys.c
731 +++ b/arch/alpha/kernel/osf_sys.c
732 @@ -1295,10 +1295,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
733 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
734
735 static unsigned long
736 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
737 - unsigned long limit)
738 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
739 + unsigned long limit, unsigned long flags)
740 {
741 struct vm_unmapped_area_info info;
742 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
743
744 info.flags = 0;
745 info.length = len;
746 @@ -1306,6 +1307,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
747 info.high_limit = limit;
748 info.align_mask = 0;
749 info.align_offset = 0;
750 + info.threadstack_offset = offset;
751 return vm_unmapped_area(&info);
752 }
753
754 @@ -1338,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
755 merely specific addresses, but regions of memory -- perhaps
756 this feature should be incorporated into all ports? */
757
758 +#ifdef CONFIG_PAX_RANDMMAP
759 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
760 +#endif
761 +
762 if (addr) {
763 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
764 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
765 if (addr != (unsigned long) -ENOMEM)
766 return addr;
767 }
768
769 /* Next, try allocating at TASK_UNMAPPED_BASE. */
770 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
771 - len, limit);
772 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
773 +
774 if (addr != (unsigned long) -ENOMEM)
775 return addr;
776
777 /* Finally, try allocating in low memory. */
778 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
779 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
780
781 return addr;
782 }
783 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
784 index 98838a0..b304fb4 100644
785 --- a/arch/alpha/mm/fault.c
786 +++ b/arch/alpha/mm/fault.c
787 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
788 __reload_thread(pcb);
789 }
790
791 +#ifdef CONFIG_PAX_PAGEEXEC
792 +/*
793 + * PaX: decide what to do with offenders (regs->pc = fault address)
794 + *
795 + * returns 1 when task should be killed
796 + * 2 when patched PLT trampoline was detected
797 + * 3 when unpatched PLT trampoline was detected
798 + */
799 +static int pax_handle_fetch_fault(struct pt_regs *regs)
800 +{
801 +
802 +#ifdef CONFIG_PAX_EMUPLT
803 + int err;
804 +
805 + do { /* PaX: patched PLT emulation #1 */
806 + unsigned int ldah, ldq, jmp;
807 +
808 + err = get_user(ldah, (unsigned int *)regs->pc);
809 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
810 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
811 +
812 + if (err)
813 + break;
814 +
815 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
816 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
817 + jmp == 0x6BFB0000U)
818 + {
819 + unsigned long r27, addr;
820 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
821 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
822 +
823 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
824 + err = get_user(r27, (unsigned long *)addr);
825 + if (err)
826 + break;
827 +
828 + regs->r27 = r27;
829 + regs->pc = r27;
830 + return 2;
831 + }
832 + } while (0);
833 +
834 + do { /* PaX: patched PLT emulation #2 */
835 + unsigned int ldah, lda, br;
836 +
837 + err = get_user(ldah, (unsigned int *)regs->pc);
838 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
839 + err |= get_user(br, (unsigned int *)(regs->pc+8));
840 +
841 + if (err)
842 + break;
843 +
844 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
845 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
846 + (br & 0xFFE00000U) == 0xC3E00000U)
847 + {
848 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
849 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
850 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
851 +
852 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
853 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
854 + return 2;
855 + }
856 + } while (0);
857 +
858 + do { /* PaX: unpatched PLT emulation */
859 + unsigned int br;
860 +
861 + err = get_user(br, (unsigned int *)regs->pc);
862 +
863 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
864 + unsigned int br2, ldq, nop, jmp;
865 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
866 +
867 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
868 + err = get_user(br2, (unsigned int *)addr);
869 + err |= get_user(ldq, (unsigned int *)(addr+4));
870 + err |= get_user(nop, (unsigned int *)(addr+8));
871 + err |= get_user(jmp, (unsigned int *)(addr+12));
872 + err |= get_user(resolver, (unsigned long *)(addr+16));
873 +
874 + if (err)
875 + break;
876 +
877 + if (br2 == 0xC3600000U &&
878 + ldq == 0xA77B000CU &&
879 + nop == 0x47FF041FU &&
880 + jmp == 0x6B7B0000U)
881 + {
882 + regs->r28 = regs->pc+4;
883 + regs->r27 = addr+16;
884 + regs->pc = resolver;
885 + return 3;
886 + }
887 + }
888 + } while (0);
889 +#endif
890 +
891 + return 1;
892 +}
893 +
894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
895 +{
896 + unsigned long i;
897 +
898 + printk(KERN_ERR "PAX: bytes at PC: ");
899 + for (i = 0; i < 5; i++) {
900 + unsigned int c;
901 + if (get_user(c, (unsigned int *)pc+i))
902 + printk(KERN_CONT "???????? ");
903 + else
904 + printk(KERN_CONT "%08x ", c);
905 + }
906 + printk("\n");
907 +}
908 +#endif
909
910 /*
911 * This routine handles page faults. It determines the address,
912 @@ -133,8 +251,29 @@ retry:
913 good_area:
914 si_code = SEGV_ACCERR;
915 if (cause < 0) {
916 - if (!(vma->vm_flags & VM_EXEC))
917 + if (!(vma->vm_flags & VM_EXEC)) {
918 +
919 +#ifdef CONFIG_PAX_PAGEEXEC
920 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
921 + goto bad_area;
922 +
923 + up_read(&mm->mmap_sem);
924 + switch (pax_handle_fetch_fault(regs)) {
925 +
926 +#ifdef CONFIG_PAX_EMUPLT
927 + case 2:
928 + case 3:
929 + return;
930 +#endif
931 +
932 + }
933 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
934 + do_group_exit(SIGKILL);
935 +#else
936 goto bad_area;
937 +#endif
938 +
939 + }
940 } else if (!cause) {
941 /* Allow reads even for write-only mappings */
942 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
943 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
944 index 89c4b5c..847a7be 100644
945 --- a/arch/arm/Kconfig
946 +++ b/arch/arm/Kconfig
947 @@ -1740,7 +1740,7 @@ config ALIGNMENT_TRAP
948
949 config UACCESS_WITH_MEMCPY
950 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
951 - depends on MMU
952 + depends on MMU && !PAX_MEMORY_UDEREF
953 default y if CPU_FEROCEON
954 help
955 Implement faster copy_to_user and clear_user methods for CPU
956 @@ -2004,6 +2004,7 @@ config XIP_PHYS_ADDR
957 config KEXEC
958 bool "Kexec system call (EXPERIMENTAL)"
959 depends on (!SMP || PM_SLEEP_SMP)
960 + depends on !GRKERNSEC_KMEM
961 help
962 kexec is a system call that implements the ability to shutdown your
963 current kernel, and to start another kernel. It is like a reboot
964 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
965 index e22c119..eaa807d 100644
966 --- a/arch/arm/include/asm/atomic.h
967 +++ b/arch/arm/include/asm/atomic.h
968 @@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972 +#ifdef CONFIG_GENERIC_ATOMIC64
973 +#include <asm-generic/atomic64.h>
974 +#endif
975 +
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980 +#ifdef CONFIG_THUMB2_KERNEL
981 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982 +#else
983 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984 +#endif
985 +
986 +#define _ASM_EXTABLE(from, to) \
987 +" .pushsection __ex_table,\"a\"\n"\
988 +" .align 3\n" \
989 +" .long " #from ", " #to"\n" \
990 +" .popsection"
991 +
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999 +{
1000 + return ACCESS_ONCE(v->counter);
1001 +}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004 +{
1005 + v->counter = i;
1006 +}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010 @@ -38,26 +62,50 @@
1011 * to ensure that the update happens.
1012 */
1013
1014 -#define ATOMIC_OP(op, c_op, asm_op) \
1015 -static inline void atomic_##op(int i, atomic_t *v) \
1016 +#ifdef CONFIG_PAX_REFCOUNT
1017 +#define __OVERFLOW_POST \
1018 + " bvc 3f\n" \
1019 + "2: " REFCOUNT_TRAP_INSN "\n"\
1020 + "3:\n"
1021 +#define __OVERFLOW_POST_RETURN \
1022 + " bvc 3f\n" \
1023 +" mov %0, %1\n" \
1024 + "2: " REFCOUNT_TRAP_INSN "\n"\
1025 + "3:\n"
1026 +#define __OVERFLOW_EXTABLE \
1027 + "4:\n" \
1028 + _ASM_EXTABLE(2b, 4b)
1029 +#else
1030 +#define __OVERFLOW_POST
1031 +#define __OVERFLOW_POST_RETURN
1032 +#define __OVERFLOW_EXTABLE
1033 +#endif
1034 +
1035 +#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1036 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1037 { \
1038 unsigned long tmp; \
1039 int result; \
1040 \
1041 prefetchw(&v->counter); \
1042 - __asm__ __volatile__("@ atomic_" #op "\n" \
1043 + __asm__ __volatile__("@ atomic_" #op #suffix "\n" \
1044 "1: ldrex %0, [%3]\n" \
1045 " " #asm_op " %0, %0, %4\n" \
1046 + post_op \
1047 " strex %1, %0, [%3]\n" \
1048 " teq %1, #0\n" \
1049 -" bne 1b" \
1050 +" bne 1b\n" \
1051 + extable \
1052 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1053 : "r" (&v->counter), "Ir" (i) \
1054 : "cc"); \
1055 } \
1056
1057 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1058 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1059 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1060 + __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1061 +
1062 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1063 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1064 { \
1065 unsigned long tmp; \
1066 int result; \
1067 @@ -65,12 +113,14 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1068 smp_mb(); \
1069 prefetchw(&v->counter); \
1070 \
1071 - __asm__ __volatile__("@ atomic_" #op "_return\n" \
1072 + __asm__ __volatile__("@ atomic_" #op "_return" #suffix "\n" \
1073 "1: ldrex %0, [%3]\n" \
1074 " " #asm_op " %0, %0, %4\n" \
1075 + post_op \
1076 " strex %1, %0, [%3]\n" \
1077 " teq %1, #0\n" \
1078 -" bne 1b" \
1079 +" bne 1b\n" \
1080 + extable \
1081 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1082 : "r" (&v->counter), "Ir" (i) \
1083 : "cc"); \
1084 @@ -80,6 +130,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1085 return result; \
1086 }
1087
1088 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1089 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1090 +
1091 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1092 {
1093 int oldval;
1094 @@ -115,12 +168,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 __asm__ __volatile__ ("@ atomic_add_unless\n"
1096 "1: ldrex %0, [%4]\n"
1097 " teq %0, %5\n"
1098 -" beq 2f\n"
1099 -" add %1, %0, %6\n"
1100 +" beq 4f\n"
1101 +" adds %1, %0, %6\n"
1102 +
1103 +#ifdef CONFIG_PAX_REFCOUNT
1104 +" bvc 3f\n"
1105 +"2: " REFCOUNT_TRAP_INSN "\n"
1106 +"3:\n"
1107 +#endif
1108 +
1109 " strex %2, %1, [%4]\n"
1110 " teq %2, #0\n"
1111 " bne 1b\n"
1112 -"2:"
1113 +"4:"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1120 : "r" (&v->counter), "r" (u), "r" (a)
1121 : "cc");
1122 @@ -131,14 +196,36 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 return oldval;
1124 }
1125
1126 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1127 +{
1128 + unsigned long oldval, res;
1129 +
1130 + smp_mb();
1131 +
1132 + do {
1133 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1134 + "ldrex %1, [%3]\n"
1135 + "mov %0, #0\n"
1136 + "teq %1, %4\n"
1137 + "strexeq %0, %5, [%3]\n"
1138 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1139 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1140 + : "cc");
1141 + } while (res);
1142 +
1143 + smp_mb();
1144 +
1145 + return oldval;
1146 +}
1147 +
1148 #else /* ARM_ARCH_6 */
1149
1150 #ifdef CONFIG_SMP
1151 #error SMP not supported on pre-ARMv6 CPUs
1152 #endif
1153
1154 -#define ATOMIC_OP(op, c_op, asm_op) \
1155 -static inline void atomic_##op(int i, atomic_t *v) \
1156 +#define __ATOMIC_OP(op, suffix, c_op, asm_op) \
1157 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1158 { \
1159 unsigned long flags; \
1160 \
1161 @@ -147,8 +234,11 @@ static inline void atomic_##op(int i, atomic_t *v) \
1162 raw_local_irq_restore(flags); \
1163 } \
1164
1165 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1166 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1167 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op) \
1168 + __ATOMIC_OP(op, _unchecked, c_op, asm_op)
1169 +
1170 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op) \
1171 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1172 { \
1173 unsigned long flags; \
1174 int val; \
1175 @@ -161,6 +251,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1176 return val; \
1177 }
1178
1179 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op)\
1180 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op)
1181 +
1182 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1183 {
1184 int ret;
1185 @@ -175,6 +268,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1186 return ret;
1187 }
1188
1189 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1190 +{
1191 + return atomic_cmpxchg((atomic_t *)v, old, new);
1192 +}
1193 +
1194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1195 {
1196 int c, old;
1197 @@ -196,16 +294,38 @@ ATOMIC_OPS(sub, -=, sub)
1198
1199 #undef ATOMIC_OPS
1200 #undef ATOMIC_OP_RETURN
1201 +#undef __ATOMIC_OP_RETURN
1202 #undef ATOMIC_OP
1203 +#undef __ATOMIC_OP
1204
1205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1206 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1207 +{
1208 + return xchg(&v->counter, new);
1209 +}
1210
1211 #define atomic_inc(v) atomic_add(1, v)
1212 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1213 +{
1214 + atomic_add_unchecked(1, v);
1215 +}
1216 #define atomic_dec(v) atomic_sub(1, v)
1217 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1218 +{
1219 + atomic_sub_unchecked(1, v);
1220 +}
1221
1222 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1223 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1224 +{
1225 + return atomic_add_return_unchecked(1, v) == 0;
1226 +}
1227 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1228 #define atomic_inc_return(v) (atomic_add_return(1, v))
1229 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1230 +{
1231 + return atomic_add_return_unchecked(1, v);
1232 +}
1233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1234 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1235
1236 @@ -216,6 +336,14 @@ typedef struct {
1237 long long counter;
1238 } atomic64_t;
1239
1240 +#ifdef CONFIG_PAX_REFCOUNT
1241 +typedef struct {
1242 + long long counter;
1243 +} atomic64_unchecked_t;
1244 +#else
1245 +typedef atomic64_t atomic64_unchecked_t;
1246 +#endif
1247 +
1248 #define ATOMIC64_INIT(i) { (i) }
1249
1250 #ifdef CONFIG_ARM_LPAE
1251 @@ -232,6 +360,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1252 return result;
1253 }
1254
1255 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1256 +{
1257 + long long result;
1258 +
1259 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1260 +" ldrd %0, %H0, [%1]"
1261 + : "=&r" (result)
1262 + : "r" (&v->counter), "Qo" (v->counter)
1263 + );
1264 +
1265 + return result;
1266 +}
1267 +
1268 static inline void atomic64_set(atomic64_t *v, long long i)
1269 {
1270 __asm__ __volatile__("@ atomic64_set\n"
1271 @@ -240,6 +381,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1272 : "r" (&v->counter), "r" (i)
1273 );
1274 }
1275 +
1276 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1277 +{
1278 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1279 +" strd %2, %H2, [%1]"
1280 + : "=Qo" (v->counter)
1281 + : "r" (&v->counter), "r" (i)
1282 + );
1283 +}
1284 #else
1285 static inline long long atomic64_read(const atomic64_t *v)
1286 {
1287 @@ -254,6 +404,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1288 return result;
1289 }
1290
1291 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1292 +{
1293 + long long result;
1294 +
1295 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1296 +" ldrexd %0, %H0, [%1]"
1297 + : "=&r" (result)
1298 + : "r" (&v->counter), "Qo" (v->counter)
1299 + );
1300 +
1301 + return result;
1302 +}
1303 +
1304 static inline void atomic64_set(atomic64_t *v, long long i)
1305 {
1306 long long tmp;
1307 @@ -268,29 +431,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1308 : "r" (&v->counter), "r" (i)
1309 : "cc");
1310 }
1311 +
1312 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1313 +{
1314 + long long tmp;
1315 +
1316 + prefetchw(&v->counter);
1317 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1318 +"1: ldrexd %0, %H0, [%2]\n"
1319 +" strexd %0, %3, %H3, [%2]\n"
1320 +" teq %0, #0\n"
1321 +" bne 1b"
1322 + : "=&r" (tmp), "=Qo" (v->counter)
1323 + : "r" (&v->counter), "r" (i)
1324 + : "cc");
1325 +}
1326 #endif
1327
1328 -#define ATOMIC64_OP(op, op1, op2) \
1329 -static inline void atomic64_##op(long long i, atomic64_t *v) \
1330 +#undef __OVERFLOW_POST_RETURN
1331 +#define __OVERFLOW_POST_RETURN \
1332 + " bvc 3f\n" \
1333 +" mov %0, %1\n" \
1334 +" mov %H0, %H1\n" \
1335 + "2: " REFCOUNT_TRAP_INSN "\n"\
1336 + "3:\n"
1337 +
1338 +#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1339 +static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1340 { \
1341 long long result; \
1342 unsigned long tmp; \
1343 \
1344 prefetchw(&v->counter); \
1345 - __asm__ __volatile__("@ atomic64_" #op "\n" \
1346 + __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1347 "1: ldrexd %0, %H0, [%3]\n" \
1348 " " #op1 " %Q0, %Q0, %Q4\n" \
1349 " " #op2 " %R0, %R0, %R4\n" \
1350 + post_op \
1351 " strexd %1, %0, %H0, [%3]\n" \
1352 " teq %1, #0\n" \
1353 -" bne 1b" \
1354 +" bne 1b\n" \
1355 + extable \
1356 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1357 : "r" (&v->counter), "r" (i) \
1358 : "cc"); \
1359 } \
1360
1361 -#define ATOMIC64_OP_RETURN(op, op1, op2) \
1362 -static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1363 +#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1364 + __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1365 +
1366 +#define __ATOMIC64_OP_RETURN(op, suffix, op1, op2, post_op, extable) \
1367 +static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1368 { \
1369 long long result; \
1370 unsigned long tmp; \
1371 @@ -298,13 +489,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1372 smp_mb(); \
1373 prefetchw(&v->counter); \
1374 \
1375 - __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1376 + __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1377 "1: ldrexd %0, %H0, [%3]\n" \
1378 " " #op1 " %Q0, %Q0, %Q4\n" \
1379 " " #op2 " %R0, %R0, %R4\n" \
1380 + post_op \
1381 " strexd %1, %0, %H0, [%3]\n" \
1382 " teq %1, #0\n" \
1383 -" bne 1b" \
1384 +" bne 1b\n" \
1385 + extable \
1386 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1387 : "r" (&v->counter), "r" (i) \
1388 : "cc"); \
1389 @@ -314,6 +507,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1390 return result; \
1391 }
1392
1393 +#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1394 + __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1395 +
1396 #define ATOMIC64_OPS(op, op1, op2) \
1397 ATOMIC64_OP(op, op1, op2) \
1398 ATOMIC64_OP_RETURN(op, op1, op2)
1399 @@ -323,7 +519,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1400
1401 #undef ATOMIC64_OPS
1402 #undef ATOMIC64_OP_RETURN
1403 +#undef __ATOMIC64_OP_RETURN
1404 #undef ATOMIC64_OP
1405 +#undef __ATOMIC64_OP
1406 +#undef __OVERFLOW_EXTABLE
1407 +#undef __OVERFLOW_POST_RETURN
1408 +#undef __OVERFLOW_POST
1409
1410 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1411 long long new)
1412 @@ -351,6 +552,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417 + long long new)
1418 +{
1419 + long long oldval;
1420 + unsigned long res;
1421 +
1422 + smp_mb();
1423 +
1424 + do {
1425 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426 + "ldrexd %1, %H1, [%3]\n"
1427 + "mov %0, #0\n"
1428 + "teq %1, %4\n"
1429 + "teqeq %H1, %H4\n"
1430 + "strexdeq %0, %5, %H5, [%3]"
1431 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432 + : "r" (&ptr->counter), "r" (old), "r" (new)
1433 + : "cc");
1434 + } while (res);
1435 +
1436 + smp_mb();
1437 +
1438 + return oldval;
1439 +}
1440 +
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444 @@ -376,21 +602,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448 - unsigned long tmp;
1449 + u64 tmp;
1450
1451 smp_mb();
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1455 -"1: ldrexd %0, %H0, [%3]\n"
1456 -" subs %Q0, %Q0, #1\n"
1457 -" sbc %R0, %R0, #0\n"
1458 +"1: ldrexd %1, %H1, [%3]\n"
1459 +" subs %Q0, %Q1, #1\n"
1460 +" sbcs %R0, %R1, #0\n"
1461 +
1462 +#ifdef CONFIG_PAX_REFCOUNT
1463 +" bvc 3f\n"
1464 +" mov %Q0, %Q1\n"
1465 +" mov %R0, %R1\n"
1466 +"2: " REFCOUNT_TRAP_INSN "\n"
1467 +"3:\n"
1468 +#endif
1469 +
1470 " teq %R0, #0\n"
1471 -" bmi 2f\n"
1472 +" bmi 4f\n"
1473 " strexd %1, %0, %H0, [%3]\n"
1474 " teq %1, #0\n"
1475 " bne 1b\n"
1476 -"2:"
1477 +"4:\n"
1478 +
1479 +#ifdef CONFIG_PAX_REFCOUNT
1480 + _ASM_EXTABLE(2b, 4b)
1481 +#endif
1482 +
1483 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 : "r" (&v->counter)
1485 : "cc");
1486 @@ -414,13 +654,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1487 " teq %0, %5\n"
1488 " teqeq %H0, %H5\n"
1489 " moveq %1, #0\n"
1490 -" beq 2f\n"
1491 +" beq 4f\n"
1492 " adds %Q0, %Q0, %Q6\n"
1493 -" adc %R0, %R0, %R6\n"
1494 +" adcs %R0, %R0, %R6\n"
1495 +
1496 +#ifdef CONFIG_PAX_REFCOUNT
1497 +" bvc 3f\n"
1498 +"2: " REFCOUNT_TRAP_INSN "\n"
1499 +"3:\n"
1500 +#endif
1501 +
1502 " strexd %2, %0, %H0, [%4]\n"
1503 " teq %2, #0\n"
1504 " bne 1b\n"
1505 -"2:"
1506 +"4:\n"
1507 +
1508 +#ifdef CONFIG_PAX_REFCOUNT
1509 + _ASM_EXTABLE(2b, 4b)
1510 +#endif
1511 +
1512 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1513 : "r" (&v->counter), "r" (u), "r" (a)
1514 : "cc");
1515 @@ -433,10 +685,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1516
1517 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1518 #define atomic64_inc(v) atomic64_add(1LL, (v))
1519 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1520 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1521 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1523 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1524 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1525 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1526 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1527 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1528 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1529 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1530 index c6a3e73..35cca85 100644
1531 --- a/arch/arm/include/asm/barrier.h
1532 +++ b/arch/arm/include/asm/barrier.h
1533 @@ -63,7 +63,7 @@
1534 do { \
1535 compiletime_assert_atomic_type(*p); \
1536 smp_mb(); \
1537 - ACCESS_ONCE(*p) = (v); \
1538 + ACCESS_ONCE_RW(*p) = (v); \
1539 } while (0)
1540
1541 #define smp_load_acquire(p) \
1542 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1543 index 75fe66b..ba3dee4 100644
1544 --- a/arch/arm/include/asm/cache.h
1545 +++ b/arch/arm/include/asm/cache.h
1546 @@ -4,8 +4,10 @@
1547 #ifndef __ASMARM_CACHE_H
1548 #define __ASMARM_CACHE_H
1549
1550 +#include <linux/const.h>
1551 +
1552 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1553 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1555
1556 /*
1557 * Memory returned by kmalloc() may be used for DMA, so we must make
1558 @@ -24,5 +26,6 @@
1559 #endif
1560
1561 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1562 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1563
1564 #endif
1565 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1566 index 10e78d0..dc8505d 100644
1567 --- a/arch/arm/include/asm/cacheflush.h
1568 +++ b/arch/arm/include/asm/cacheflush.h
1569 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1570 void (*dma_unmap_area)(const void *, size_t, int);
1571
1572 void (*dma_flush_range)(const void *, const void *);
1573 -};
1574 +} __no_const;
1575
1576 /*
1577 * Select the calling method
1578 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1579 index 5233151..87a71fa 100644
1580 --- a/arch/arm/include/asm/checksum.h
1581 +++ b/arch/arm/include/asm/checksum.h
1582 @@ -37,7 +37,19 @@ __wsum
1583 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1584
1585 __wsum
1586 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1588 +
1589 +static inline __wsum
1590 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1591 +{
1592 + __wsum ret;
1593 + pax_open_userland();
1594 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1595 + pax_close_userland();
1596 + return ret;
1597 +}
1598 +
1599 +
1600
1601 /*
1602 * Fold a partial checksum without adding pseudo headers
1603 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1604 index abb2c37..96db950 100644
1605 --- a/arch/arm/include/asm/cmpxchg.h
1606 +++ b/arch/arm/include/asm/cmpxchg.h
1607 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1608
1609 #define xchg(ptr,x) \
1610 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1611 +#define xchg_unchecked(ptr,x) \
1612 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1613
1614 #include <asm-generic/cmpxchg-local.h>
1615
1616 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1617 index 6ddbe44..b5e38b1 100644
1618 --- a/arch/arm/include/asm/domain.h
1619 +++ b/arch/arm/include/asm/domain.h
1620 @@ -48,18 +48,37 @@
1621 * Domain types
1622 */
1623 #define DOMAIN_NOACCESS 0
1624 -#define DOMAIN_CLIENT 1
1625 #ifdef CONFIG_CPU_USE_DOMAINS
1626 +#define DOMAIN_USERCLIENT 1
1627 +#define DOMAIN_KERNELCLIENT 1
1628 #define DOMAIN_MANAGER 3
1629 +#define DOMAIN_VECTORS DOMAIN_USER
1630 #else
1631 +
1632 +#ifdef CONFIG_PAX_KERNEXEC
1633 #define DOMAIN_MANAGER 1
1634 +#define DOMAIN_KERNEXEC 3
1635 +#else
1636 +#define DOMAIN_MANAGER 1
1637 +#endif
1638 +
1639 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1640 +#define DOMAIN_USERCLIENT 0
1641 +#define DOMAIN_UDEREF 1
1642 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1643 +#else
1644 +#define DOMAIN_USERCLIENT 1
1645 +#define DOMAIN_VECTORS DOMAIN_USER
1646 +#endif
1647 +#define DOMAIN_KERNELCLIENT 1
1648 +
1649 #endif
1650
1651 #define domain_val(dom,type) ((type) << (2*(dom)))
1652
1653 #ifndef __ASSEMBLY__
1654
1655 -#ifdef CONFIG_CPU_USE_DOMAINS
1656 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1657 static inline void set_domain(unsigned val)
1658 {
1659 asm volatile(
1660 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1661 isb();
1662 }
1663
1664 -#define modify_domain(dom,type) \
1665 - do { \
1666 - struct thread_info *thread = current_thread_info(); \
1667 - unsigned int domain = thread->cpu_domain; \
1668 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1669 - thread->cpu_domain = domain | domain_val(dom, type); \
1670 - set_domain(thread->cpu_domain); \
1671 - } while (0)
1672 -
1673 +extern void modify_domain(unsigned int dom, unsigned int type);
1674 #else
1675 static inline void set_domain(unsigned val) { }
1676 static inline void modify_domain(unsigned dom, unsigned type) { }
1677 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1678 index afb9caf..9a0bac0 100644
1679 --- a/arch/arm/include/asm/elf.h
1680 +++ b/arch/arm/include/asm/elf.h
1681 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1682 the loader. We need to make sure that it is out of the way of the program
1683 that it will "exec", and that there is sufficient room for the brk. */
1684
1685 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1686 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1687 +
1688 +#ifdef CONFIG_PAX_ASLR
1689 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1690 +
1691 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1693 +#endif
1694
1695 /* When the program starts, a1 contains a pointer to a function to be
1696 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1697 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1698 extern void elf_set_personality(const struct elf32_hdr *);
1699 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1700
1701 -struct mm_struct;
1702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1703 -#define arch_randomize_brk arch_randomize_brk
1704 -
1705 #ifdef CONFIG_MMU
1706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1707 struct linux_binprm;
1708 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1709 index de53547..52b9a28 100644
1710 --- a/arch/arm/include/asm/fncpy.h
1711 +++ b/arch/arm/include/asm/fncpy.h
1712 @@ -81,7 +81,9 @@
1713 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1714 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1715 \
1716 + pax_open_kernel(); \
1717 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1718 + pax_close_kernel(); \
1719 flush_icache_range((unsigned long)(dest_buf), \
1720 (unsigned long)(dest_buf) + (size)); \
1721 \
1722 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1723 index 53e69da..3fdc896 100644
1724 --- a/arch/arm/include/asm/futex.h
1725 +++ b/arch/arm/include/asm/futex.h
1726 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1727 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1728 return -EFAULT;
1729
1730 + pax_open_userland();
1731 +
1732 smp_mb();
1733 /* Prefetching cannot fault */
1734 prefetchw(uaddr);
1735 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 : "cc", "memory");
1737 smp_mb();
1738
1739 + pax_close_userland();
1740 +
1741 *uval = val;
1742 return ret;
1743 }
1744 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1746 return -EFAULT;
1747
1748 + pax_open_userland();
1749 +
1750 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1751 "1: " TUSER(ldr) " %1, [%4]\n"
1752 " teq %1, %2\n"
1753 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1755 : "cc", "memory");
1756
1757 + pax_close_userland();
1758 +
1759 *uval = val;
1760 return ret;
1761 }
1762 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1763 return -EFAULT;
1764
1765 pagefault_disable(); /* implies preempt_disable() */
1766 + pax_open_userland();
1767
1768 switch (op) {
1769 case FUTEX_OP_SET:
1770 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 ret = -ENOSYS;
1772 }
1773
1774 + pax_close_userland();
1775 pagefault_enable(); /* subsumes preempt_enable() */
1776
1777 if (!ret) {
1778 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1779 index 83eb2f7..ed77159 100644
1780 --- a/arch/arm/include/asm/kmap_types.h
1781 +++ b/arch/arm/include/asm/kmap_types.h
1782 @@ -4,6 +4,6 @@
1783 /*
1784 * This is the "bare minimum". AIO seems to require this.
1785 */
1786 -#define KM_TYPE_NR 16
1787 +#define KM_TYPE_NR 17
1788
1789 #endif
1790 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1791 index 9e614a1..3302cca 100644
1792 --- a/arch/arm/include/asm/mach/dma.h
1793 +++ b/arch/arm/include/asm/mach/dma.h
1794 @@ -22,7 +22,7 @@ struct dma_ops {
1795 int (*residue)(unsigned int, dma_t *); /* optional */
1796 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1797 const char *type;
1798 -};
1799 +} __do_const;
1800
1801 struct dma_struct {
1802 void *addr; /* single DMA address */
1803 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1804 index f98c7f3..e5c626d 100644
1805 --- a/arch/arm/include/asm/mach/map.h
1806 +++ b/arch/arm/include/asm/mach/map.h
1807 @@ -23,17 +23,19 @@ struct map_desc {
1808
1809 /* types 0-3 are defined in asm/io.h */
1810 enum {
1811 - MT_UNCACHED = 4,
1812 - MT_CACHECLEAN,
1813 - MT_MINICLEAN,
1814 + MT_UNCACHED_RW = 4,
1815 + MT_CACHECLEAN_RO,
1816 + MT_MINICLEAN_RO,
1817 MT_LOW_VECTORS,
1818 MT_HIGH_VECTORS,
1819 - MT_MEMORY_RWX,
1820 + __MT_MEMORY_RWX,
1821 MT_MEMORY_RW,
1822 - MT_ROM,
1823 - MT_MEMORY_RWX_NONCACHED,
1824 + MT_MEMORY_RX,
1825 + MT_ROM_RX,
1826 + MT_MEMORY_RW_NONCACHED,
1827 + MT_MEMORY_RX_NONCACHED,
1828 MT_MEMORY_RW_DTCM,
1829 - MT_MEMORY_RWX_ITCM,
1830 + MT_MEMORY_RX_ITCM,
1831 MT_MEMORY_RW_SO,
1832 MT_MEMORY_DMA_READY,
1833 };
1834 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835 index 891a56b..48f337e 100644
1836 --- a/arch/arm/include/asm/outercache.h
1837 +++ b/arch/arm/include/asm/outercache.h
1838 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1839
1840 /* This is an ARM L2C thing */
1841 void (*write_sec)(unsigned long, unsigned);
1842 -};
1843 +} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848 index 4355f0e..cd9168e 100644
1849 --- a/arch/arm/include/asm/page.h
1850 +++ b/arch/arm/include/asm/page.h
1851 @@ -23,6 +23,7 @@
1852
1853 #else
1854
1855 +#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863 -};
1864 +} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869 index 78a7793..e3dc06c 100644
1870 --- a/arch/arm/include/asm/pgalloc.h
1871 +++ b/arch/arm/include/asm/pgalloc.h
1872 @@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876 +#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885 +{
1886 + pud_populate(mm, pud, pmd);
1887 +}
1888 +
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905 +{
1906 +#ifdef CONFIG_ARM_LPAE
1907 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908 +#else
1909 + if (addr & SECTION_SIZE)
1910 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911 + else
1912 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913 +#endif
1914 + flush_pmd_entry(pmdp);
1915 +}
1916 +
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930 index 5cfba15..f415e1a 100644
1931 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933 @@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941 +
1942 /*
1943 * - section
1944 */
1945 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949 @@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957 @@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966 index f027941..f36ce30 100644
1967 --- a/arch/arm/include/asm/pgtable-2level.h
1968 +++ b/arch/arm/include/asm/pgtable-2level.h
1969 @@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974 +#define L_PTE_PXN (_AT(pteval_t, 0))
1975 +
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980 index 9fd61c7..f8f1cff 100644
1981 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983 @@ -76,6 +76,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992 index a31ecdad..95e98d4 100644
1993 --- a/arch/arm/include/asm/pgtable-3level.h
1994 +++ b/arch/arm/include/asm/pgtable-3level.h
1995 @@ -81,6 +81,7 @@
1996 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2003 @@ -92,10 +93,12 @@
2004 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2005 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2006 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2007 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2008
2009 /*
2010 * To be used in assembly code with the upper page attributes.
2011 */
2012 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2013 #define L_PTE_XN_HIGH (1 << (54 - 32))
2014 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2015
2016 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2017 index 3b30062..01a5f9d 100644
2018 --- a/arch/arm/include/asm/pgtable.h
2019 +++ b/arch/arm/include/asm/pgtable.h
2020 @@ -33,6 +33,9 @@
2021 #include <asm/pgtable-2level.h>
2022 #endif
2023
2024 +#define ktla_ktva(addr) (addr)
2025 +#define ktva_ktla(addr) (addr)
2026 +
2027 /*
2028 * Just any arbitrary offset to the start of the vmalloc VM area: the
2029 * current 8MB value just means that there will be a 8MB "hole" after the
2030 @@ -48,6 +51,9 @@
2031 #define LIBRARY_TEXT_START 0x0c000000
2032
2033 #ifndef __ASSEMBLY__
2034 +extern pteval_t __supported_pte_mask;
2035 +extern pmdval_t __supported_pmd_mask;
2036 +
2037 extern void __pte_error(const char *file, int line, pte_t);
2038 extern void __pmd_error(const char *file, int line, pmd_t);
2039 extern void __pgd_error(const char *file, int line, pgd_t);
2040 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2041 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2042 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2043
2044 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2045 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2046 +
2047 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2048 +#include <asm/domain.h>
2049 +#include <linux/thread_info.h>
2050 +#include <linux/preempt.h>
2051 +
2052 +static inline int test_domain(int domain, int domaintype)
2053 +{
2054 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2055 +}
2056 +#endif
2057 +
2058 +#ifdef CONFIG_PAX_KERNEXEC
2059 +static inline unsigned long pax_open_kernel(void) {
2060 +#ifdef CONFIG_ARM_LPAE
2061 + /* TODO */
2062 +#else
2063 + preempt_disable();
2064 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2065 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2066 +#endif
2067 + return 0;
2068 +}
2069 +
2070 +static inline unsigned long pax_close_kernel(void) {
2071 +#ifdef CONFIG_ARM_LPAE
2072 + /* TODO */
2073 +#else
2074 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2075 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2076 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2077 + preempt_enable_no_resched();
2078 +#endif
2079 + return 0;
2080 +}
2081 +#else
2082 +static inline unsigned long pax_open_kernel(void) { return 0; }
2083 +static inline unsigned long pax_close_kernel(void) { return 0; }
2084 +#endif
2085 +
2086 /*
2087 * This is the lowest virtual address we can permit any user space
2088 * mapping to be mapped at. This is particularly important for
2089 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2090 /*
2091 * The pgprot_* and protection_map entries will be fixed up in runtime
2092 * to include the cachable and bufferable bits based on memory policy,
2093 - * as well as any architecture dependent bits like global/ASID and SMP
2094 - * shared mapping bits.
2095 + * as well as any architecture dependent bits like global/ASID, PXN,
2096 + * and SMP shared mapping bits.
2097 */
2098 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2099
2100 @@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2101 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2102 {
2103 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2104 - L_PTE_NONE | L_PTE_VALID;
2105 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2106 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2107 return pte;
2108 }
2109 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2110 index c25ef3e..735f14b 100644
2111 --- a/arch/arm/include/asm/psci.h
2112 +++ b/arch/arm/include/asm/psci.h
2113 @@ -32,7 +32,7 @@ struct psci_operations {
2114 int (*affinity_info)(unsigned long target_affinity,
2115 unsigned long lowest_affinity_level);
2116 int (*migrate_info_type)(void);
2117 -};
2118 +} __no_const;
2119
2120 extern struct psci_operations psci_ops;
2121 extern struct smp_operations psci_smp_ops;
2122 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2123 index 18f5a55..5072a40 100644
2124 --- a/arch/arm/include/asm/smp.h
2125 +++ b/arch/arm/include/asm/smp.h
2126 @@ -107,7 +107,7 @@ struct smp_operations {
2127 int (*cpu_disable)(unsigned int cpu);
2128 #endif
2129 #endif
2130 -};
2131 +} __no_const;
2132
2133 struct of_cpu_method {
2134 const char *method;
2135 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2136 index ce73ab6..7310f8a 100644
2137 --- a/arch/arm/include/asm/thread_info.h
2138 +++ b/arch/arm/include/asm/thread_info.h
2139 @@ -78,9 +78,9 @@ struct thread_info {
2140 .flags = 0, \
2141 .preempt_count = INIT_PREEMPT_COUNT, \
2142 .addr_limit = KERNEL_DS, \
2143 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2144 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2145 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2146 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2147 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2148 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2149 .restart_block = { \
2150 .fn = do_no_restart_syscall, \
2151 }, \
2152 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2153 #define TIF_SYSCALL_AUDIT 9
2154 #define TIF_SYSCALL_TRACEPOINT 10
2155 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2156 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2157 +/* within 8 bits of TIF_SYSCALL_TRACE
2158 + * to meet flexible second operand requirements
2159 + */
2160 +#define TIF_GRSEC_SETXID 12
2161 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2162 #define TIF_USING_IWMMXT 17
2163 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2164 #define TIF_RESTORE_SIGMASK 20
2165 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2166 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2167 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2168 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2169 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2170
2171 /* Checks for any syscall work in entry-common.S */
2172 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2173 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2174 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2175
2176 /*
2177 * Change these and you break ASM code in entry-common.S
2178 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2179 index 5f833f7..76e6644 100644
2180 --- a/arch/arm/include/asm/tls.h
2181 +++ b/arch/arm/include/asm/tls.h
2182 @@ -3,6 +3,7 @@
2183
2184 #include <linux/compiler.h>
2185 #include <asm/thread_info.h>
2186 +#include <asm/pgtable.h>
2187
2188 #ifdef __ASSEMBLY__
2189 #include <asm/asm-offsets.h>
2190 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2191 * at 0xffff0fe0 must be used instead. (see
2192 * entry-armv.S for details)
2193 */
2194 + pax_open_kernel();
2195 *((unsigned int *)0xffff0ff0) = val;
2196 + pax_close_kernel();
2197 #endif
2198 }
2199
2200 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201 index 4767eb9..bf00668 100644
2202 --- a/arch/arm/include/asm/uaccess.h
2203 +++ b/arch/arm/include/asm/uaccess.h
2204 @@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208 +#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224 +
2225 +static inline void pax_open_userland(void)
2226 +{
2227 +
2228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2229 + if (segment_eq(get_fs(), USER_DS)) {
2230 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232 + }
2233 +#endif
2234 +
2235 +}
2236 +
2237 +static inline void pax_close_userland(void)
2238 +{
2239 +
2240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2241 + if (segment_eq(get_fs(), USER_DS)) {
2242 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244 + }
2245 +#endif
2246 +
2247 +}
2248 +
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256 + int __e; \
2257 might_fault(); \
2258 - __get_user_check(x,p); \
2259 + pax_open_userland(); \
2260 + __e = __get_user_check(x,p); \
2261 + pax_close_userland(); \
2262 + __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270 + int __e; \
2271 might_fault(); \
2272 - __put_user_check(x,p); \
2273 + pax_open_userland(); \
2274 + __e = __put_user_check(x,p); \
2275 + pax_close_userland(); \
2276 + __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292 + pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294 + pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300 + pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302 + pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306 @@ -368,13 +409,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310 + pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312 + pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318 + pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320 + pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324 @@ -474,11 +519,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 +
2337 + check_object_size(to, n, false);
2338 + pax_open_userland();
2339 + ret = ___copy_from_user(to, from, n);
2340 + pax_close_userland();
2341 + return ret;
2342 +}
2343 +
2344 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345 +{
2346 + unsigned long ret;
2347 +
2348 + check_object_size(from, n, true);
2349 + pax_open_userland();
2350 + ret = ___copy_to_user(to, from, n);
2351 + pax_close_userland();
2352 + return ret;
2353 +}
2354 +
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359 +
2360 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361 +{
2362 + unsigned long ret;
2363 + pax_open_userland();
2364 + ret = ___clear_user(addr, n);
2365 + pax_close_userland();
2366 + return ret;
2367 +}
2368 +
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376 + if ((long)n < 0)
2377 + return n;
2378 +
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386 + if ((long)n < 0)
2387 + return n;
2388 +
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393 index 5af0ed1..cea83883 100644
2394 --- a/arch/arm/include/uapi/asm/ptrace.h
2395 +++ b/arch/arm/include/uapi/asm/ptrace.h
2396 @@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406 index a88671c..1cc895e 100644
2407 --- a/arch/arm/kernel/armksyms.c
2408 +++ b/arch/arm/kernel/armksyms.c
2409 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2414 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422 -EXPORT_SYMBOL(__copy_from_user);
2423 -EXPORT_SYMBOL(__copy_to_user);
2424 -EXPORT_SYMBOL(__clear_user);
2425 +EXPORT_SYMBOL(___copy_from_user);
2426 +EXPORT_SYMBOL(___copy_to_user);
2427 +EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432 index 2f5555d..d493c91 100644
2433 --- a/arch/arm/kernel/entry-armv.S
2434 +++ b/arch/arm/kernel/entry-armv.S
2435 @@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439 + .macro pax_enter_kernel
2440 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441 + @ make aligned space for saved DACR
2442 + sub sp, sp, #8
2443 + @ save regs
2444 + stmdb sp!, {r1, r2}
2445 + @ read DACR from cpu_domain into r1
2446 + mov r2, sp
2447 + @ assume 8K pages, since we have to split the immediate in two
2448 + bic r2, r2, #(0x1fc0)
2449 + bic r2, r2, #(0x3f)
2450 + ldr r1, [r2, #TI_CPU_DOMAIN]
2451 + @ store old DACR on stack
2452 + str r1, [sp, #8]
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457 +#endif
2458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2459 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461 +#endif
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r2, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r1, r2}
2470 +#endif
2471 + .endm
2472 +
2473 + .macro pax_open_userland
2474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2475 + @ save regs
2476 + stmdb sp!, {r0, r1}
2477 + @ read DACR from cpu_domain into r1
2478 + mov r0, sp
2479 + @ assume 8K pages, since we have to split the immediate in two
2480 + bic r0, r0, #(0x1fc0)
2481 + bic r0, r0, #(0x3f)
2482 + ldr r1, [r0, #TI_CPU_DOMAIN]
2483 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2484 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486 + @ write r1 to current_thread_info()->cpu_domain
2487 + str r1, [r0, #TI_CPU_DOMAIN]
2488 + @ write r1 to DACR
2489 + mcr p15, 0, r1, c3, c0, 0
2490 + @ instruction sync
2491 + instr_sync
2492 + @ restore regs
2493 + ldmia sp!, {r0, r1}
2494 +#endif
2495 + .endm
2496 +
2497 + .macro pax_close_userland
2498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2499 + @ save regs
2500 + stmdb sp!, {r0, r1}
2501 + @ read DACR from cpu_domain into r1
2502 + mov r0, sp
2503 + @ assume 8K pages, since we have to split the immediate in two
2504 + bic r0, r0, #(0x1fc0)
2505 + bic r0, r0, #(0x3f)
2506 + ldr r1, [r0, #TI_CPU_DOMAIN]
2507 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509 + @ write r1 to current_thread_info()->cpu_domain
2510 + str r1, [r0, #TI_CPU_DOMAIN]
2511 + @ write r1 to DACR
2512 + mcr p15, 0, r1, c3, c0, 0
2513 + @ instruction sync
2514 + instr_sync
2515 + @ restore regs
2516 + ldmia sp!, {r0, r1}
2517 +#endif
2518 + .endm
2519 +
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523 @@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527 +
2528 + pax_enter_kernel
2529 +
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535 +
2536 mov r1, #\reason
2537 .endm
2538
2539 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0, trace=1
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543 +
2544 + pax_enter_kernel
2545 +
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547 +
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556 + @ offset sp by 8 as done in pax_enter_kernel
2557 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558 +#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560 +#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564 @@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2565 .macro usr_entry, trace=1
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568 +
2569 + pax_enter_kernel_user
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574 @@ -478,7 +575,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578 + pax_open_userland
2579 1: ldrt r0, [r4]
2580 + pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584 @@ -512,11 +611,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588 + pax_open_userland
2589 2: ldrht r5, [r4]
2590 + pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594 + pax_open_userland
2595 3: ldrht r0, [r2]
2596 + pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600 @@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604 -4: str r4, [sp, #S_PC] @ retry current instruction
2605 +4: pax_close_userland
2606 + str r4, [sp, #S_PC] @ retry current instruction
2607 ret r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610 @@ -766,7 +870,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614 -#ifdef CONFIG_CPU_USE_DOMAINS
2615 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619 @@ -775,7 +879,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623 -#ifdef CONFIG_CPU_USE_DOMAINS
2624 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629 index 6bb09d4..113e875 100644
2630 --- a/arch/arm/kernel/entry-common.S
2631 +++ b/arch/arm/kernel/entry-common.S
2632 @@ -11,18 +11,46 @@
2633 #include <asm/assembler.h>
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636 +#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639 +#include "entry-header.S"
2640 +
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646 + @ save regs
2647 + stmdb sp!, {r1, r2}
2648 + @ read DACR from cpu_domain into r1
2649 + mov r2, sp
2650 + @ assume 8K pages, since we have to split the immediate in two
2651 + bic r2, r2, #(0x1fc0)
2652 + bic r2, r2, #(0x3f)
2653 + ldr r1, [r2, #TI_CPU_DOMAIN]
2654 +#ifdef CONFIG_PAX_KERNEXEC
2655 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658 +#endif
2659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2660 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2661 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663 +#endif
2664 + @ write r1 to current_thread_info()->cpu_domain
2665 + str r1, [r2, #TI_CPU_DOMAIN]
2666 + @ write r1 to DACR
2667 + mcr p15, 0, r1, c3, c0, 0
2668 + @ instruction sync
2669 + instr_sync
2670 + @ restore regs
2671 + ldmia sp!, {r1, r2}
2672 +#endif
2673 .endm
2674 #endif
2675
2676 -#include "entry-header.S"
2677 -
2678 -
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686 + /*
2687 + * do this here to avoid a performance hit of wrapping the code above
2688 + * that directly dereferences userland to parse the SWI instruction
2689 + */
2690 + pax_enter_kernel_user
2691 +
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696 index 4176df7..a901f8d 100644
2697 --- a/arch/arm/kernel/entry-header.S
2698 +++ b/arch/arm/kernel/entry-header.S
2699 @@ -196,6 +196,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703 + .macro pax_enter_kernel_user
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read DACR from cpu_domain into r1
2708 + mov r0, sp
2709 + @ assume 8K pages, since we have to split the immediate in two
2710 + bic r0, r0, #(0x1fc0)
2711 + bic r0, r0, #(0x3f)
2712 + ldr r1, [r0, #TI_CPU_DOMAIN]
2713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2714 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716 +#endif
2717 +#ifdef CONFIG_PAX_KERNEXEC
2718 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721 +#endif
2722 + @ write r1 to current_thread_info()->cpu_domain
2723 + str r1, [r0, #TI_CPU_DOMAIN]
2724 + @ write r1 to DACR
2725 + mcr p15, 0, r1, c3, c0, 0
2726 + @ instruction sync
2727 + instr_sync
2728 + @ restore regs
2729 + ldmia sp!, {r0, r1}
2730 +#endif
2731 + .endm
2732 +
2733 + .macro pax_exit_kernel
2734 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735 + @ save regs
2736 + stmdb sp!, {r0, r1}
2737 + @ read old DACR from stack into r1
2738 + ldr r1, [sp, #(8 + S_SP)]
2739 + sub r1, r1, #8
2740 + ldr r1, [r1]
2741 +
2742 + @ write r1 to current_thread_info()->cpu_domain
2743 + mov r0, sp
2744 + @ assume 8K pages, since we have to split the immediate in two
2745 + bic r0, r0, #(0x1fc0)
2746 + bic r0, r0, #(0x3f)
2747 + str r1, [r0, #TI_CPU_DOMAIN]
2748 + @ write r1 to DACR
2749 + mcr p15, 0, r1, c3, c0, 0
2750 + @ instruction sync
2751 + instr_sync
2752 + @ restore regs
2753 + ldmia sp!, {r0, r1}
2754 +#endif
2755 + .endm
2756 +
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760 @@ -215,6 +269,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764 +
2765 + pax_exit_kernel
2766 +
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2769 @ We must avoid clrex due to Cortex-A15 erratum #830321
2770 @@ -290,6 +347,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774 +
2775 + pax_exit_kernel
2776 +
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779
2780 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781 index b37752a..ff5cb72 100644
2782 --- a/arch/arm/kernel/fiq.c
2783 +++ b/arch/arm/kernel/fiq.c
2784 @@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788 + pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790 + pax_close_kernel();
2791 +
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796 index 664eee8..f470938 100644
2797 --- a/arch/arm/kernel/head.S
2798 +++ b/arch/arm/kernel/head.S
2799 @@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809 index 6a4dffe..4a86a70 100644
2810 --- a/arch/arm/kernel/module.c
2811 +++ b/arch/arm/kernel/module.c
2812 @@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816 -void *module_alloc(unsigned long size)
2817 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820 + return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823 + GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826 +
2827 +void *module_alloc(unsigned long size)
2828 +{
2829 +
2830 +#ifdef CONFIG_PAX_KERNEXEC
2831 + return __module_alloc(size, PAGE_KERNEL);
2832 +#else
2833 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2834 +#endif
2835 +
2836 +}
2837 +
2838 +#ifdef CONFIG_PAX_KERNEXEC
2839 +void module_free_exec(struct module *mod, void *module_region)
2840 +{
2841 + module_free(mod, module_region);
2842 +}
2843 +EXPORT_SYMBOL(module_free_exec);
2844 +
2845 +void *module_alloc_exec(unsigned long size)
2846 +{
2847 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2848 +}
2849 +EXPORT_SYMBOL(module_alloc_exec);
2850 +#endif
2851 #endif
2852
2853 int
2854 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855 index 07314af..c46655c 100644
2856 --- a/arch/arm/kernel/patch.c
2857 +++ b/arch/arm/kernel/patch.c
2858 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862 + pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870 + pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875 index fe972a2..a772d83 100644
2876 --- a/arch/arm/kernel/process.c
2877 +++ b/arch/arm/kernel/process.c
2878 @@ -207,6 +207,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882 + BUG();
2883 }
2884
2885 /*
2886 @@ -220,7 +221,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890 -void machine_restart(char *cmd)
2891 +__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895 @@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2900 - print_symbol("LR is at %s\n", regs->ARM_lr);
2901 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906 @@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2911 -{
2912 - unsigned long range_end = mm->brk + 0x02000000;
2913 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914 -}
2915 -
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919 @@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928 @@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2929 return is_gate_vma(vma) ? "[vectors]" : NULL;
2930 }
2931
2932 -/* If possible, provide a placement hint at a random offset from the
2933 - * stack for the signal page.
2934 - */
2935 -static unsigned long sigpage_addr(const struct mm_struct *mm,
2936 - unsigned int npages)
2937 -{
2938 - unsigned long offset;
2939 - unsigned long first;
2940 - unsigned long last;
2941 - unsigned long addr;
2942 - unsigned int slots;
2943 -
2944 - first = PAGE_ALIGN(mm->start_stack);
2945 -
2946 - last = TASK_SIZE - (npages << PAGE_SHIFT);
2947 -
2948 - /* No room after stack? */
2949 - if (first > last)
2950 - return 0;
2951 -
2952 - /* Just enough room? */
2953 - if (first == last)
2954 - return first;
2955 -
2956 - slots = ((last - first) >> PAGE_SHIFT) + 1;
2957 -
2958 - offset = get_random_int() % slots;
2959 -
2960 - addr = first + (offset << PAGE_SHIFT);
2961 -
2962 - return addr;
2963 -}
2964 -
2965 -static struct page *signal_page;
2966 -extern struct page *get_signal_page(void);
2967 -
2968 -static const struct vm_special_mapping sigpage_mapping = {
2969 - .name = "[sigpage]",
2970 - .pages = &signal_page,
2971 -};
2972 -
2973 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2974 {
2975 struct mm_struct *mm = current->mm;
2976 - struct vm_area_struct *vma;
2977 - unsigned long addr;
2978 - unsigned long hint;
2979 - int ret = 0;
2980 -
2981 - if (!signal_page)
2982 - signal_page = get_signal_page();
2983 - if (!signal_page)
2984 - return -ENOMEM;
2985
2986 down_write(&mm->mmap_sem);
2987 - hint = sigpage_addr(mm, 1);
2988 - addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2989 - if (IS_ERR_VALUE(addr)) {
2990 - ret = addr;
2991 - goto up_fail;
2992 - }
2993 -
2994 - vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2995 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2996 - &sigpage_mapping);
2997 -
2998 - if (IS_ERR(vma)) {
2999 - ret = PTR_ERR(vma);
3000 - goto up_fail;
3001 - }
3002 -
3003 - mm->context.sigpage = addr;
3004 -
3005 - up_fail:
3006 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3007 up_write(&mm->mmap_sem);
3008 - return ret;
3009 + return 0;
3010 }
3011 #endif
3012 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3013 index f73891b..cf3004e 100644
3014 --- a/arch/arm/kernel/psci.c
3015 +++ b/arch/arm/kernel/psci.c
3016 @@ -28,7 +28,7 @@
3017 #include <asm/psci.h>
3018 #include <asm/system_misc.h>
3019
3020 -struct psci_operations psci_ops;
3021 +struct psci_operations psci_ops __read_only;
3022
3023 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3024 typedef int (*psci_initcall_t)(const struct device_node *);
3025 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3026 index ef9119f..31995a3 100644
3027 --- a/arch/arm/kernel/ptrace.c
3028 +++ b/arch/arm/kernel/ptrace.c
3029 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3030 regs->ARM_ip = ip;
3031 }
3032
3033 +#ifdef CONFIG_GRKERNSEC_SETXID
3034 +extern void gr_delayed_cred_worker(void);
3035 +#endif
3036 +
3037 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3038 {
3039 current_thread_info()->syscall = scno;
3040
3041 +#ifdef CONFIG_GRKERNSEC_SETXID
3042 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3043 + gr_delayed_cred_worker();
3044 +#endif
3045 +
3046 /* Do the secure computing check first; failures should be fast. */
3047 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3048 if (secure_computing() == -1)
3049 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3050 index 306e1ac..1b477ed 100644
3051 --- a/arch/arm/kernel/setup.c
3052 +++ b/arch/arm/kernel/setup.c
3053 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3054 unsigned int elf_hwcap2 __read_mostly;
3055 EXPORT_SYMBOL(elf_hwcap2);
3056
3057 +pteval_t __supported_pte_mask __read_only;
3058 +pmdval_t __supported_pmd_mask __read_only;
3059
3060 #ifdef MULTI_CPU
3061 -struct processor processor __read_mostly;
3062 +struct processor processor __read_only;
3063 #endif
3064 #ifdef MULTI_TLB
3065 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3066 +struct cpu_tlb_fns cpu_tlb __read_only;
3067 #endif
3068 #ifdef MULTI_USER
3069 -struct cpu_user_fns cpu_user __read_mostly;
3070 +struct cpu_user_fns cpu_user __read_only;
3071 #endif
3072 #ifdef MULTI_CACHE
3073 -struct cpu_cache_fns cpu_cache __read_mostly;
3074 +struct cpu_cache_fns cpu_cache __read_only;
3075 #endif
3076 #ifdef CONFIG_OUTER_CACHE
3077 -struct outer_cache_fns outer_cache __read_mostly;
3078 +struct outer_cache_fns outer_cache __read_only;
3079 EXPORT_SYMBOL(outer_cache);
3080 #endif
3081
3082 @@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3083 asm("mrc p15, 0, %0, c0, c1, 4"
3084 : "=r" (mmfr0));
3085 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3086 - (mmfr0 & 0x000000f0) >= 0x00000030)
3087 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3088 cpu_arch = CPU_ARCH_ARMv7;
3089 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3090 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3091 + __supported_pte_mask |= L_PTE_PXN;
3092 + __supported_pmd_mask |= PMD_PXNTABLE;
3093 + }
3094 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3095 (mmfr0 & 0x000000f0) == 0x00000020)
3096 cpu_arch = CPU_ARCH_ARMv6;
3097 else
3098 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3099 index bd19834..e4d8c66 100644
3100 --- a/arch/arm/kernel/signal.c
3101 +++ b/arch/arm/kernel/signal.c
3102 @@ -24,8 +24,6 @@
3103
3104 extern const unsigned long sigreturn_codes[7];
3105
3106 -static unsigned long signal_return_offset;
3107 -
3108 #ifdef CONFIG_CRUNCH
3109 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3110 {
3111 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3112 * except when the MPU has protected the vectors
3113 * page from PL0
3114 */
3115 - retcode = mm->context.sigpage + signal_return_offset +
3116 - (idx << 2) + thumb;
3117 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3118 } else
3119 #endif
3120 {
3121 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3122 } while (thread_flags & _TIF_WORK_MASK);
3123 return 0;
3124 }
3125 -
3126 -struct page *get_signal_page(void)
3127 -{
3128 - unsigned long ptr;
3129 - unsigned offset;
3130 - struct page *page;
3131 - void *addr;
3132 -
3133 - page = alloc_pages(GFP_KERNEL, 0);
3134 -
3135 - if (!page)
3136 - return NULL;
3137 -
3138 - addr = page_address(page);
3139 -
3140 - /* Give the signal return code some randomness */
3141 - offset = 0x200 + (get_random_int() & 0x7fc);
3142 - signal_return_offset = offset;
3143 -
3144 - /*
3145 - * Copy signal return handlers into the vector page, and
3146 - * set sigreturn to be a pointer to these.
3147 - */
3148 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3149 -
3150 - ptr = (unsigned long)addr + offset;
3151 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3152 -
3153 - return page;
3154 -}
3155 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3156 index a8e32aa..b2f7198 100644
3157 --- a/arch/arm/kernel/smp.c
3158 +++ b/arch/arm/kernel/smp.c
3159 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3160
3161 static DECLARE_COMPLETION(cpu_running);
3162
3163 -static struct smp_operations smp_ops;
3164 +static struct smp_operations smp_ops __read_only;
3165
3166 void __init smp_set_ops(struct smp_operations *ops)
3167 {
3168 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3169 index 7a3be1d..b00c7de 100644
3170 --- a/arch/arm/kernel/tcm.c
3171 +++ b/arch/arm/kernel/tcm.c
3172 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3173 .virtual = ITCM_OFFSET,
3174 .pfn = __phys_to_pfn(ITCM_OFFSET),
3175 .length = 0,
3176 - .type = MT_MEMORY_RWX_ITCM,
3177 + .type = MT_MEMORY_RX_ITCM,
3178 }
3179 };
3180
3181 @@ -267,7 +267,9 @@ no_dtcm:
3182 start = &__sitcm_text;
3183 end = &__eitcm_text;
3184 ram = &__itcm_start;
3185 + pax_open_kernel();
3186 memcpy(start, ram, itcm_code_sz);
3187 + pax_close_kernel();
3188 pr_debug("CPU ITCM: copied code from %p - %p\n",
3189 start, end);
3190 itcm_present = true;
3191 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3192 index 9f5d818..e013427 100644
3193 --- a/arch/arm/kernel/traps.c
3194 +++ b/arch/arm/kernel/traps.c
3195 @@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3196 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3197 {
3198 #ifdef CONFIG_KALLSYMS
3199 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3200 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3201 #else
3202 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3203 #endif
3204 @@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3205 static int die_owner = -1;
3206 static unsigned int die_nest_count;
3207
3208 +extern void gr_handle_kernel_exploit(void);
3209 +
3210 static unsigned long oops_begin(void)
3211 {
3212 int cpu;
3213 @@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3214 panic("Fatal exception in interrupt");
3215 if (panic_on_oops)
3216 panic("Fatal exception");
3217 +
3218 + gr_handle_kernel_exploit();
3219 +
3220 if (signr)
3221 do_exit(signr);
3222 }
3223 @@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3224 kuser_init(vectors_base);
3225
3226 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3227 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3228 +
3229 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3230 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3231 +#endif
3232 +
3233 #else /* ifndef CONFIG_CPU_V7M */
3234 /*
3235 * on V7-M there is no need to copy the vector table to a dedicated
3236 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3237 index 8e95aa4..595dfc8 100644
3238 --- a/arch/arm/kernel/vmlinux.lds.S
3239 +++ b/arch/arm/kernel/vmlinux.lds.S
3240 @@ -8,7 +8,11 @@
3241 #include <asm/thread_info.h>
3242 #include <asm/memory.h>
3243 #include <asm/page.h>
3244 -
3245 +
3246 +#ifdef CONFIG_PAX_KERNEXEC
3247 +#include <asm/pgtable.h>
3248 +#endif
3249 +
3250 #define PROC_INFO \
3251 . = ALIGN(4); \
3252 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3253 @@ -34,7 +38,7 @@
3254 #endif
3255
3256 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3257 - defined(CONFIG_GENERIC_BUG)
3258 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3259 #define ARM_EXIT_KEEP(x) x
3260 #define ARM_EXIT_DISCARD(x)
3261 #else
3262 @@ -90,6 +94,11 @@ SECTIONS
3263 _text = .;
3264 HEAD_TEXT
3265 }
3266 +
3267 +#ifdef CONFIG_PAX_KERNEXEC
3268 + . = ALIGN(1<<SECTION_SHIFT);
3269 +#endif
3270 +
3271 .text : { /* Real text segment */
3272 _stext = .; /* Text and read-only data */
3273 __exception_text_start = .;
3274 @@ -112,6 +121,8 @@ SECTIONS
3275 ARM_CPU_KEEP(PROC_INFO)
3276 }
3277
3278 + _etext = .; /* End of text section */
3279 +
3280 RO_DATA(PAGE_SIZE)
3281
3282 . = ALIGN(4);
3283 @@ -142,7 +153,9 @@ SECTIONS
3284
3285 NOTES
3286
3287 - _etext = .; /* End of text and rodata section */
3288 +#ifdef CONFIG_PAX_KERNEXEC
3289 + . = ALIGN(1<<SECTION_SHIFT);
3290 +#endif
3291
3292 #ifndef CONFIG_XIP_KERNEL
3293 . = ALIGN(PAGE_SIZE);
3294 @@ -221,6 +234,11 @@ SECTIONS
3295 #else
3296 . = ALIGN(THREAD_SIZE);
3297 __init_end = .;
3298 +
3299 +#ifdef CONFIG_PAX_KERNEXEC
3300 + . = ALIGN(1<<SECTION_SHIFT);
3301 +#endif
3302 +
3303 __data_loc = .;
3304 #endif
3305
3306 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3307 index 9e193c8..3560fe6 100644
3308 --- a/arch/arm/kvm/arm.c
3309 +++ b/arch/arm/kvm/arm.c
3310 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3311 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3312
3313 /* The VMID used in the VTTBR */
3314 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3315 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3316 static u8 kvm_next_vmid;
3317 static DEFINE_SPINLOCK(kvm_vmid_lock);
3318
3319 @@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3320 */
3321 static bool need_new_vmid_gen(struct kvm *kvm)
3322 {
3323 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3324 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3325 }
3326
3327 /**
3328 @@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3329
3330 /* First user of a new VMID generation? */
3331 if (unlikely(kvm_next_vmid == 0)) {
3332 - atomic64_inc(&kvm_vmid_gen);
3333 + atomic64_inc_unchecked(&kvm_vmid_gen);
3334 kvm_next_vmid = 1;
3335
3336 /*
3337 @@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3338 kvm_call_hyp(__kvm_flush_vm_context);
3339 }
3340
3341 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3342 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3343 kvm->arch.vmid = kvm_next_vmid;
3344 kvm_next_vmid++;
3345
3346 @@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3347 /**
3348 * Initialize Hyp-mode and memory mappings on all CPUs.
3349 */
3350 -int kvm_arch_init(void *opaque)
3351 +int kvm_arch_init(const void *opaque)
3352 {
3353 int err;
3354 int ret, cpu;
3355 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3356 index 14a0d98..7771a7d 100644
3357 --- a/arch/arm/lib/clear_user.S
3358 +++ b/arch/arm/lib/clear_user.S
3359 @@ -12,14 +12,14 @@
3360
3361 .text
3362
3363 -/* Prototype: int __clear_user(void *addr, size_t sz)
3364 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3365 * Purpose : clear some user memory
3366 * Params : addr - user memory address to clear
3367 * : sz - number of bytes to clear
3368 * Returns : number of bytes NOT cleared
3369 */
3370 ENTRY(__clear_user_std)
3371 -WEAK(__clear_user)
3372 +WEAK(___clear_user)
3373 stmfd sp!, {r1, lr}
3374 mov r2, #0
3375 cmp r1, #4
3376 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3377 USER( strnebt r2, [r0])
3378 mov r0, #0
3379 ldmfd sp!, {r1, pc}
3380 -ENDPROC(__clear_user)
3381 +ENDPROC(___clear_user)
3382 ENDPROC(__clear_user_std)
3383
3384 .pushsection .fixup,"ax"
3385 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3386 index 66a477a..bee61d3 100644
3387 --- a/arch/arm/lib/copy_from_user.S
3388 +++ b/arch/arm/lib/copy_from_user.S
3389 @@ -16,7 +16,7 @@
3390 /*
3391 * Prototype:
3392 *
3393 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3394 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3395 *
3396 * Purpose:
3397 *
3398 @@ -84,11 +84,11 @@
3399
3400 .text
3401
3402 -ENTRY(__copy_from_user)
3403 +ENTRY(___copy_from_user)
3404
3405 #include "copy_template.S"
3406
3407 -ENDPROC(__copy_from_user)
3408 +ENDPROC(___copy_from_user)
3409
3410 .pushsection .fixup,"ax"
3411 .align 0
3412 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3413 index 6ee2f67..d1cce76 100644
3414 --- a/arch/arm/lib/copy_page.S
3415 +++ b/arch/arm/lib/copy_page.S
3416 @@ -10,6 +10,7 @@
3417 * ASM optimised string functions
3418 */
3419 #include <linux/linkage.h>
3420 +#include <linux/const.h>
3421 #include <asm/assembler.h>
3422 #include <asm/asm-offsets.h>
3423 #include <asm/cache.h>
3424 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3425 index d066df6..df28194 100644
3426 --- a/arch/arm/lib/copy_to_user.S
3427 +++ b/arch/arm/lib/copy_to_user.S
3428 @@ -16,7 +16,7 @@
3429 /*
3430 * Prototype:
3431 *
3432 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3433 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3434 *
3435 * Purpose:
3436 *
3437 @@ -88,11 +88,11 @@
3438 .text
3439
3440 ENTRY(__copy_to_user_std)
3441 -WEAK(__copy_to_user)
3442 +WEAK(___copy_to_user)
3443
3444 #include "copy_template.S"
3445
3446 -ENDPROC(__copy_to_user)
3447 +ENDPROC(___copy_to_user)
3448 ENDPROC(__copy_to_user_std)
3449
3450 .pushsection .fixup,"ax"
3451 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3452 index 7d08b43..f7ca7ea 100644
3453 --- a/arch/arm/lib/csumpartialcopyuser.S
3454 +++ b/arch/arm/lib/csumpartialcopyuser.S
3455 @@ -57,8 +57,8 @@
3456 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3457 */
3458
3459 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3460 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3461 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3462 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3463
3464 #include "csumpartialcopygeneric.S"
3465
3466 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3467 index 312d43e..21d2322 100644
3468 --- a/arch/arm/lib/delay.c
3469 +++ b/arch/arm/lib/delay.c
3470 @@ -29,7 +29,7 @@
3471 /*
3472 * Default to the loop-based delay implementation.
3473 */
3474 -struct arm_delay_ops arm_delay_ops = {
3475 +struct arm_delay_ops arm_delay_ops __read_only = {
3476 .delay = __loop_delay,
3477 .const_udelay = __loop_const_udelay,
3478 .udelay = __loop_udelay,
3479 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3480 index 3e58d71..029817c 100644
3481 --- a/arch/arm/lib/uaccess_with_memcpy.c
3482 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3483 @@ -136,7 +136,7 @@ out:
3484 }
3485
3486 unsigned long
3487 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3488 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3489 {
3490 /*
3491 * This test is stubbed out of the main function above to keep
3492 @@ -190,7 +190,7 @@ out:
3493 return n;
3494 }
3495
3496 -unsigned long __clear_user(void __user *addr, unsigned long n)
3497 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3498 {
3499 /* See rational for this in __copy_to_user() above. */
3500 if (n < 64)
3501 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3502 index 9610792..4dfb851 100644
3503 --- a/arch/arm/mach-at91/setup.c
3504 +++ b/arch/arm/mach-at91/setup.c
3505 @@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3506
3507 desc->pfn = __phys_to_pfn(base);
3508 desc->length = length;
3509 - desc->type = MT_MEMORY_RWX_NONCACHED;
3510 + desc->type = MT_MEMORY_RW_NONCACHED;
3511
3512 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3513 base, length, desc->virtual);
3514 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3515 index 7f352de..6dc0929 100644
3516 --- a/arch/arm/mach-keystone/keystone.c
3517 +++ b/arch/arm/mach-keystone/keystone.c
3518 @@ -27,7 +27,7 @@
3519
3520 #include "keystone.h"
3521
3522 -static struct notifier_block platform_nb;
3523 +static notifier_block_no_const platform_nb;
3524 static unsigned long keystone_dma_pfn_offset __read_mostly;
3525
3526 static int keystone_platform_notifier(struct notifier_block *nb,
3527 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3528 index 1163a3e..424adbf 100644
3529 --- a/arch/arm/mach-mvebu/coherency.c
3530 +++ b/arch/arm/mach-mvebu/coherency.c
3531 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3532
3533 /*
3534 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3535 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3536 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3537 * is needed as a workaround for a deadlock issue between the PCIe
3538 * interface and the cache controller.
3539 */
3540 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3541 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3542
3543 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3544 - mtype = MT_UNCACHED;
3545 + mtype = MT_UNCACHED_RW;
3546
3547 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3548 }
3549 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3550 index 97767a2..9233746 100644
3551 --- a/arch/arm/mach-omap2/board-n8x0.c
3552 +++ b/arch/arm/mach-omap2/board-n8x0.c
3553 @@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3554 }
3555 #endif
3556
3557 -struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3558 +struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3559 .late_init = n8x0_menelaus_late_init,
3560 };
3561
3562 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3563 index 5fa3755..1e8c247 100644
3564 --- a/arch/arm/mach-omap2/gpmc.c
3565 +++ b/arch/arm/mach-omap2/gpmc.c
3566 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3567 };
3568
3569 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3570 -static struct irq_chip gpmc_irq_chip;
3571 static int gpmc_irq_start;
3572
3573 static struct resource gpmc_mem_root;
3574 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3575
3576 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3577
3578 +static struct irq_chip gpmc_irq_chip = {
3579 + .name = "gpmc",
3580 + .irq_startup = gpmc_irq_noop_ret,
3581 + .irq_enable = gpmc_irq_enable,
3582 + .irq_disable = gpmc_irq_disable,
3583 + .irq_shutdown = gpmc_irq_noop,
3584 + .irq_ack = gpmc_irq_noop,
3585 + .irq_mask = gpmc_irq_noop,
3586 + .irq_unmask = gpmc_irq_noop,
3587 +
3588 +};
3589 +
3590 static int gpmc_setup_irq(void)
3591 {
3592 int i;
3593 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3594 return gpmc_irq_start;
3595 }
3596
3597 - gpmc_irq_chip.name = "gpmc";
3598 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3599 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3600 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3601 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3602 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3603 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3604 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3605 -
3606 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3607 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3608
3609 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610 index 6944ae3..bc587ca 100644
3611 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3612 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3613 @@ -86,7 +86,7 @@ struct cpu_pm_ops {
3614 void (*resume)(void);
3615 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3616 void (*hotplug_restart)(void);
3617 -};
3618 +} __no_const;
3619
3620 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3621 static struct powerdomain *mpuss_pd;
3622 @@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3623 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3624 {}
3625
3626 -struct cpu_pm_ops omap_pm_ops = {
3627 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3628 .finish_suspend = default_finish_suspend,
3629 .resume = dummy_cpu_resume,
3630 .scu_prepare = dummy_scu_prepare,
3631 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3632 index f961c46..4a453dc 100644
3633 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3634 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3635 @@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3636 return NOTIFY_OK;
3637 }
3638
3639 -static struct notifier_block __refdata irq_hotplug_notifier = {
3640 +static struct notifier_block irq_hotplug_notifier = {
3641 .notifier_call = irq_cpu_hotplug_notify,
3642 };
3643
3644 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3645 index 8c58b71..95b655f 100644
3646 --- a/arch/arm/mach-omap2/omap_device.c
3647 +++ b/arch/arm/mach-omap2/omap_device.c
3648 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3649 struct platform_device __init *omap_device_build(const char *pdev_name,
3650 int pdev_id,
3651 struct omap_hwmod *oh,
3652 - void *pdata, int pdata_len)
3653 + const void *pdata, int pdata_len)
3654 {
3655 struct omap_hwmod *ohs[] = { oh };
3656
3657 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3658 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3659 int pdev_id,
3660 struct omap_hwmod **ohs,
3661 - int oh_cnt, void *pdata,
3662 + int oh_cnt, const void *pdata,
3663 int pdata_len)
3664 {
3665 int ret = -ENOMEM;
3666 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3667 index 78c02b3..c94109a 100644
3668 --- a/arch/arm/mach-omap2/omap_device.h
3669 +++ b/arch/arm/mach-omap2/omap_device.h
3670 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3671 /* Core code interface */
3672
3673 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3674 - struct omap_hwmod *oh, void *pdata,
3675 + struct omap_hwmod *oh, const void *pdata,
3676 int pdata_len);
3677
3678 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3679 struct omap_hwmod **oh, int oh_cnt,
3680 - void *pdata, int pdata_len);
3681 + const void *pdata, int pdata_len);
3682
3683 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3684 struct omap_hwmod **ohs, int oh_cnt);
3685 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3686 index 716247e..8df346d 100644
3687 --- a/arch/arm/mach-omap2/omap_hwmod.c
3688 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3689 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3690 int (*init_clkdm)(struct omap_hwmod *oh);
3691 void (*update_context_lost)(struct omap_hwmod *oh);
3692 int (*get_context_lost)(struct omap_hwmod *oh);
3693 -};
3694 +} __no_const;
3695
3696 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3697 -static struct omap_hwmod_soc_ops soc_ops;
3698 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3699
3700 /* omap_hwmod_list contains all registered struct omap_hwmods */
3701 static LIST_HEAD(omap_hwmod_list);
3702 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3703 index 95fee54..cfa9cf1 100644
3704 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3705 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3706 @@ -10,6 +10,7 @@
3707
3708 #include <linux/kernel.h>
3709 #include <linux/init.h>
3710 +#include <asm/pgtable.h>
3711
3712 #include "powerdomain.h"
3713
3714 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3715
3716 void __init am43xx_powerdomains_init(void)
3717 {
3718 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719 + pax_open_kernel();
3720 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3721 + pax_close_kernel();
3722 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3723 pwrdm_register_pwrdms(powerdomains_am43xx);
3724 pwrdm_complete_init();
3725 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3726 index ff0a68c..b312aa0 100644
3727 --- a/arch/arm/mach-omap2/wd_timer.c
3728 +++ b/arch/arm/mach-omap2/wd_timer.c
3729 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3730 struct omap_hwmod *oh;
3731 char *oh_name = "wd_timer2";
3732 char *dev_name = "omap_wdt";
3733 - struct omap_wd_timer_platform_data pdata;
3734 + static struct omap_wd_timer_platform_data pdata = {
3735 + .read_reset_sources = prm_read_reset_sources
3736 + };
3737
3738 if (!cpu_class_is_omap2() || of_have_populated_dt())
3739 return 0;
3740 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3741 return -EINVAL;
3742 }
3743
3744 - pdata.read_reset_sources = prm_read_reset_sources;
3745 -
3746 pdev = omap_device_build(dev_name, id, oh, &pdata,
3747 sizeof(struct omap_wd_timer_platform_data));
3748 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3749 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3750 index b30bf5c..d0825bf 100644
3751 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3752 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3753 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3754 bool entered_lp2 = false;
3755
3756 if (tegra_pending_sgi())
3757 - ACCESS_ONCE(abort_flag) = true;
3758 + ACCESS_ONCE_RW(abort_flag) = true;
3759
3760 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3761
3762 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3763 index 2dea8b5..6499da2 100644
3764 --- a/arch/arm/mach-ux500/setup.h
3765 +++ b/arch/arm/mach-ux500/setup.h
3766 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3767 .type = MT_DEVICE, \
3768 }
3769
3770 -#define __MEM_DEV_DESC(x, sz) { \
3771 - .virtual = IO_ADDRESS(x), \
3772 - .pfn = __phys_to_pfn(x), \
3773 - .length = sz, \
3774 - .type = MT_MEMORY_RWX, \
3775 -}
3776 -
3777 extern struct smp_operations ux500_smp_ops;
3778 extern void ux500_cpu_die(unsigned int cpu);
3779
3780 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3781 index 7eb94e6..799ad3e 100644
3782 --- a/arch/arm/mm/Kconfig
3783 +++ b/arch/arm/mm/Kconfig
3784 @@ -446,6 +446,7 @@ config CPU_32v5
3785
3786 config CPU_32v6
3787 bool
3788 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3789 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3790
3791 config CPU_32v6K
3792 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3793
3794 config CPU_USE_DOMAINS
3795 bool
3796 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3797 help
3798 This option enables or disables the use of domain switching
3799 via the set_fs() function.
3800 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3801
3802 config KUSER_HELPERS
3803 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3804 - depends on MMU
3805 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3806 default y
3807 help
3808 Warning: disabling this option may break user programs.
3809 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3810 See Documentation/arm/kernel_user_helpers.txt for details.
3811
3812 However, the fixed address nature of these helpers can be used
3813 - by ROP (return orientated programming) authors when creating
3814 + by ROP (Return Oriented Programming) authors when creating
3815 exploits.
3816
3817 If all of the binaries and libraries which run on your platform
3818 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3819 index 83792f4..c25d36b 100644
3820 --- a/arch/arm/mm/alignment.c
3821 +++ b/arch/arm/mm/alignment.c
3822 @@ -216,10 +216,12 @@ union offset_union {
3823 #define __get16_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v, a = addr; \
3826 + pax_open_userland(); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 val = v << ((BE) ? 8 : 0); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 8); \
3831 + pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835 @@ -233,6 +235,7 @@ union offset_union {
3836 #define __get32_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v, a = addr; \
3839 + pax_open_userland(); \
3840 __get8_unaligned_check(ins,v,a,err); \
3841 val = v << ((BE) ? 24 : 0); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843 @@ -241,6 +244,7 @@ union offset_union {
3844 val |= v << ((BE) ? 8 : 16); \
3845 __get8_unaligned_check(ins,v,a,err); \
3846 val |= v << ((BE) ? 0 : 24); \
3847 + pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851 @@ -254,6 +258,7 @@ union offset_union {
3852 #define __put16_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855 + pax_open_userland(); \
3856 __asm__( FIRST_BYTE_16 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859 @@ -273,6 +278,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863 + pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867 @@ -286,6 +292,7 @@ union offset_union {
3868 #define __put32_unaligned_check(ins,val,addr) \
3869 do { \
3870 unsigned int err = 0, v = val, a = addr; \
3871 + pax_open_userland(); \
3872 __asm__( FIRST_BYTE_32 \
3873 ARM( "1: "ins" %1, [%2], #1\n" ) \
3874 THUMB( "1: "ins" %1, [%2]\n" ) \
3875 @@ -315,6 +322,7 @@ union offset_union {
3876 " .popsection\n" \
3877 : "=r" (err), "=&r" (v), "=&r" (a) \
3878 : "0" (err), "1" (v), "2" (a)); \
3879 + pax_close_userland(); \
3880 if (err) \
3881 goto fault; \
3882 } while (0)
3883 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3884 index 5e65ca8..879e7b3 100644
3885 --- a/arch/arm/mm/cache-l2x0.c
3886 +++ b/arch/arm/mm/cache-l2x0.c
3887 @@ -42,7 +42,7 @@ struct l2c_init_data {
3888 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3889 void (*save)(void __iomem *);
3890 struct outer_cache_fns outer_cache;
3891 -};
3892 +} __do_const;
3893
3894 #define CACHE_LINE_SIZE 32
3895
3896 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3897 index 6eb97b3..e77848e 100644
3898 --- a/arch/arm/mm/context.c
3899 +++ b/arch/arm/mm/context.c
3900 @@ -43,7 +43,7 @@
3901 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3902
3903 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3904 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3905 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3906 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3907
3908 static DEFINE_PER_CPU(atomic64_t, active_asids);
3909 @@ -144,21 +144,17 @@ static void flush_context(unsigned int cpu)
3910 /* Update the list of reserved ASIDs and the ASID bitmap. */
3911 bitmap_clear(asid_map, 0, NUM_USER_ASIDS);
3912 for_each_possible_cpu(i) {
3913 - if (i == cpu) {
3914 - asid = 0;
3915 - } else {
3916 - asid = atomic64_xchg(&per_cpu(active_asids, i), 0);
3917 - /*
3918 - * If this CPU has already been through a
3919 - * rollover, but hasn't run another task in
3920 - * the meantime, we must preserve its reserved
3921 - * ASID, as this is the only trace we have of
3922 - * the process it is still running.
3923 - */
3924 - if (asid == 0)
3925 - asid = per_cpu(reserved_asids, i);
3926 - __set_bit(asid & ~ASID_MASK, asid_map);
3927 - }
3928 + asid = atomic64_xchg(&per_cpu(active_asids, i), 0);
3929 + /*
3930 + * If this CPU has already been through a
3931 + * rollover, but hasn't run another task in
3932 + * the meantime, we must preserve its reserved
3933 + * ASID, as this is the only trace we have of
3934 + * the process it is still running.
3935 + */
3936 + if (asid == 0)
3937 + asid = per_cpu(reserved_asids, i);
3938 + __set_bit(asid & ~ASID_MASK, asid_map);
3939 per_cpu(reserved_asids, i) = asid;
3940 }
3941
3942 @@ -182,7 +178,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3943 {
3944 static u32 cur_idx = 1;
3945 u64 asid = atomic64_read(&mm->context.id);
3946 - u64 generation = atomic64_read(&asid_generation);
3947 + u64 generation = atomic64_read_unchecked(&asid_generation);
3948
3949 if (asid != 0 && is_reserved_asid(asid)) {
3950 /*
3951 @@ -203,7 +199,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3952 */
3953 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3954 if (asid == NUM_USER_ASIDS) {
3955 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3956 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3957 &asid_generation);
3958 flush_context(cpu);
3959 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3960 @@ -234,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3961 cpu_set_reserved_ttbr0();
3962
3963 asid = atomic64_read(&mm->context.id);
3964 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3965 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3966 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3967 goto switch_mm_fastpath;
3968
3969 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3970 /* Check that our ASID belongs to the current generation. */
3971 asid = atomic64_read(&mm->context.id);
3972 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3973 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3974 asid = new_context(mm, cpu);
3975 atomic64_set(&mm->context.id, asid);
3976 }
3977 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3978 index eb8830a..e8ff52e 100644
3979 --- a/arch/arm/mm/fault.c
3980 +++ b/arch/arm/mm/fault.c
3981 @@ -25,6 +25,7 @@
3982 #include <asm/system_misc.h>
3983 #include <asm/system_info.h>
3984 #include <asm/tlbflush.h>
3985 +#include <asm/sections.h>
3986
3987 #include "fault.h"
3988
3989 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3990 if (fixup_exception(regs))
3991 return;
3992
3993 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3994 + if (addr < TASK_SIZE) {
3995 + if (current->signal->curr_ip)
3996 + 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),
3997 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3998 + else
3999 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4000 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4001 + }
4002 +#endif
4003 +
4004 +#ifdef CONFIG_PAX_KERNEXEC
4005 + if ((fsr & FSR_WRITE) &&
4006 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4007 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4008 + {
4009 + if (current->signal->curr_ip)
4010 + 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),
4011 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4012 + else
4013 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4014 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4015 + }
4016 +#endif
4017 +
4018 /*
4019 * No handler, we'll have to terminate things with extreme prejudice.
4020 */
4021 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4022 }
4023 #endif
4024
4025 +#ifdef CONFIG_PAX_PAGEEXEC
4026 + if (fsr & FSR_LNX_PF) {
4027 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4028 + do_group_exit(SIGKILL);
4029 + }
4030 +#endif
4031 +
4032 tsk->thread.address = addr;
4033 tsk->thread.error_code = fsr;
4034 tsk->thread.trap_no = 14;
4035 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4036 }
4037 #endif /* CONFIG_MMU */
4038
4039 +#ifdef CONFIG_PAX_PAGEEXEC
4040 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4041 +{
4042 + long i;
4043 +
4044 + printk(KERN_ERR "PAX: bytes at PC: ");
4045 + for (i = 0; i < 20; i++) {
4046 + unsigned char c;
4047 + if (get_user(c, (__force unsigned char __user *)pc+i))
4048 + printk(KERN_CONT "?? ");
4049 + else
4050 + printk(KERN_CONT "%02x ", c);
4051 + }
4052 + printk("\n");
4053 +
4054 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4055 + for (i = -1; i < 20; i++) {
4056 + unsigned long c;
4057 + if (get_user(c, (__force unsigned long __user *)sp+i))
4058 + printk(KERN_CONT "???????? ");
4059 + else
4060 + printk(KERN_CONT "%08lx ", c);
4061 + }
4062 + printk("\n");
4063 +}
4064 +#endif
4065 +
4066 /*
4067 * First Level Translation Fault Handler
4068 *
4069 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4070 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4071 struct siginfo info;
4072
4073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4074 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4075 + if (current->signal->curr_ip)
4076 + 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),
4077 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4078 + else
4079 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4080 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4081 + goto die;
4082 + }
4083 +#endif
4084 +
4085 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4086 return;
4087
4088 +die:
4089 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4090 inf->name, fsr, addr);
4091
4092 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4093 ifsr_info[nr].name = name;
4094 }
4095
4096 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4097 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4098 +
4099 asmlinkage void __exception
4100 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4101 {
4102 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4103 struct siginfo info;
4104 + unsigned long pc = instruction_pointer(regs);
4105 +
4106 + if (user_mode(regs)) {
4107 + unsigned long sigpage = current->mm->context.sigpage;
4108 +
4109 + if (sigpage <= pc && pc < sigpage + 7*4) {
4110 + if (pc < sigpage + 3*4)
4111 + sys_sigreturn(regs);
4112 + else
4113 + sys_rt_sigreturn(regs);
4114 + return;
4115 + }
4116 + if (pc == 0xffff0f60UL) {
4117 + /*
4118 + * PaX: __kuser_cmpxchg64 emulation
4119 + */
4120 + // TODO
4121 + //regs->ARM_pc = regs->ARM_lr;
4122 + //return;
4123 + }
4124 + if (pc == 0xffff0fa0UL) {
4125 + /*
4126 + * PaX: __kuser_memory_barrier emulation
4127 + */
4128 + // dmb(); implied by the exception
4129 + regs->ARM_pc = regs->ARM_lr;
4130 + return;
4131 + }
4132 + if (pc == 0xffff0fc0UL) {
4133 + /*
4134 + * PaX: __kuser_cmpxchg emulation
4135 + */
4136 + // TODO
4137 + //long new;
4138 + //int op;
4139 +
4140 + //op = FUTEX_OP_SET << 28;
4141 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4142 + //regs->ARM_r0 = old != new;
4143 + //regs->ARM_pc = regs->ARM_lr;
4144 + //return;
4145 + }
4146 + if (pc == 0xffff0fe0UL) {
4147 + /*
4148 + * PaX: __kuser_get_tls emulation
4149 + */
4150 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4151 + regs->ARM_pc = regs->ARM_lr;
4152 + return;
4153 + }
4154 + }
4155 +
4156 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4157 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4158 + if (current->signal->curr_ip)
4159 + 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),
4160 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4161 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4162 + else
4163 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4164 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4165 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4166 + goto die;
4167 + }
4168 +#endif
4169 +
4170 +#ifdef CONFIG_PAX_REFCOUNT
4171 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4172 +#ifdef CONFIG_THUMB2_KERNEL
4173 + unsigned short bkpt;
4174 +
4175 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4176 +#else
4177 + unsigned int bkpt;
4178 +
4179 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4180 +#endif
4181 + current->thread.error_code = ifsr;
4182 + current->thread.trap_no = 0;
4183 + pax_report_refcount_overflow(regs);
4184 + fixup_exception(regs);
4185 + return;
4186 + }
4187 + }
4188 +#endif
4189
4190 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4191 return;
4192
4193 +die:
4194 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4195 inf->name, ifsr, addr);
4196
4197 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4198 index cf08bdf..772656c 100644
4199 --- a/arch/arm/mm/fault.h
4200 +++ b/arch/arm/mm/fault.h
4201 @@ -3,6 +3,7 @@
4202
4203 /*
4204 * Fault status register encodings. We steal bit 31 for our own purposes.
4205 + * Set when the FSR value is from an instruction fault.
4206 */
4207 #define FSR_LNX_PF (1 << 31)
4208 #define FSR_WRITE (1 << 11)
4209 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4210 }
4211 #endif
4212
4213 +/* valid for LPAE and !LPAE */
4214 +static inline int is_xn_fault(unsigned int fsr)
4215 +{
4216 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4217 +}
4218 +
4219 +static inline int is_domain_fault(unsigned int fsr)
4220 +{
4221 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4222 +}
4223 +
4224 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4225 unsigned long search_exception_table(unsigned long addr);
4226
4227 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4228 index 9481f85..6dae261 100644
4229 --- a/arch/arm/mm/init.c
4230 +++ b/arch/arm/mm/init.c
4231 @@ -31,6 +31,8 @@
4232 #include <asm/setup.h>
4233 #include <asm/tlb.h>
4234 #include <asm/fixmap.h>
4235 +#include <asm/system_info.h>
4236 +#include <asm/cp15.h>
4237
4238 #include <asm/mach/arch.h>
4239 #include <asm/mach/map.h>
4240 @@ -619,7 +621,46 @@ void free_initmem(void)
4241 {
4242 #ifdef CONFIG_HAVE_TCM
4243 extern char __tcm_start, __tcm_end;
4244 +#endif
4245
4246 +#ifdef CONFIG_PAX_KERNEXEC
4247 + unsigned long addr;
4248 + pgd_t *pgd;
4249 + pud_t *pud;
4250 + pmd_t *pmd;
4251 + int cpu_arch = cpu_architecture();
4252 + unsigned int cr = get_cr();
4253 +
4254 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4255 + /* make pages tables, etc before .text NX */
4256 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4257 + pgd = pgd_offset_k(addr);
4258 + pud = pud_offset(pgd, addr);
4259 + pmd = pmd_offset(pud, addr);
4260 + __section_update(pmd, addr, PMD_SECT_XN);
4261 + }
4262 + /* make init NX */
4263 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4264 + pgd = pgd_offset_k(addr);
4265 + pud = pud_offset(pgd, addr);
4266 + pmd = pmd_offset(pud, addr);
4267 + __section_update(pmd, addr, PMD_SECT_XN);
4268 + }
4269 + /* make kernel code/rodata RX */
4270 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4271 + pgd = pgd_offset_k(addr);
4272 + pud = pud_offset(pgd, addr);
4273 + pmd = pmd_offset(pud, addr);
4274 +#ifdef CONFIG_ARM_LPAE
4275 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4276 +#else
4277 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4278 +#endif
4279 + }
4280 + }
4281 +#endif
4282 +
4283 +#ifdef CONFIG_HAVE_TCM
4284 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4285 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4286 #endif
4287 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4288 index d1e5ad7..84dcbf2 100644
4289 --- a/arch/arm/mm/ioremap.c
4290 +++ b/arch/arm/mm/ioremap.c
4291 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4292 unsigned int mtype;
4293
4294 if (cached)
4295 - mtype = MT_MEMORY_RWX;
4296 + mtype = MT_MEMORY_RX;
4297 else
4298 - mtype = MT_MEMORY_RWX_NONCACHED;
4299 + mtype = MT_MEMORY_RX_NONCACHED;
4300
4301 return __arm_ioremap_caller(phys_addr, size, mtype,
4302 __builtin_return_address(0));
4303 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4304 index 5e85ed3..b10a7ed 100644
4305 --- a/arch/arm/mm/mmap.c
4306 +++ b/arch/arm/mm/mmap.c
4307 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4308 struct vm_area_struct *vma;
4309 int do_align = 0;
4310 int aliasing = cache_is_vipt_aliasing();
4311 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4312 struct vm_unmapped_area_info info;
4313
4314 /*
4315 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4316 if (len > TASK_SIZE)
4317 return -ENOMEM;
4318
4319 +#ifdef CONFIG_PAX_RANDMMAP
4320 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4321 +#endif
4322 +
4323 if (addr) {
4324 if (do_align)
4325 addr = COLOUR_ALIGN(addr, pgoff);
4326 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4327 addr = PAGE_ALIGN(addr);
4328
4329 vma = find_vma(mm, addr);
4330 - if (TASK_SIZE - len >= addr &&
4331 - (!vma || addr + len <= vma->vm_start))
4332 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4333 return addr;
4334 }
4335
4336 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4337 info.high_limit = TASK_SIZE;
4338 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4339 info.align_offset = pgoff << PAGE_SHIFT;
4340 + info.threadstack_offset = offset;
4341 return vm_unmapped_area(&info);
4342 }
4343
4344 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4345 unsigned long addr = addr0;
4346 int do_align = 0;
4347 int aliasing = cache_is_vipt_aliasing();
4348 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4349 struct vm_unmapped_area_info info;
4350
4351 /*
4352 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4353 return addr;
4354 }
4355
4356 +#ifdef CONFIG_PAX_RANDMMAP
4357 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4358 +#endif
4359 +
4360 /* requesting a specific address */
4361 if (addr) {
4362 if (do_align)
4363 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4364 else
4365 addr = PAGE_ALIGN(addr);
4366 vma = find_vma(mm, addr);
4367 - if (TASK_SIZE - len >= addr &&
4368 - (!vma || addr + len <= vma->vm_start))
4369 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4370 return addr;
4371 }
4372
4373 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4374 info.high_limit = mm->mmap_base;
4375 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4376 info.align_offset = pgoff << PAGE_SHIFT;
4377 + info.threadstack_offset = offset;
4378 addr = vm_unmapped_area(&info);
4379
4380 /*
4381 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4382 {
4383 unsigned long random_factor = 0UL;
4384
4385 +#ifdef CONFIG_PAX_RANDMMAP
4386 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4387 +#endif
4388 +
4389 /* 8 bits of randomness in 20 address space bits */
4390 if ((current->flags & PF_RANDOMIZE) &&
4391 !(current->personality & ADDR_NO_RANDOMIZE))
4392 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4393
4394 if (mmap_is_legacy()) {
4395 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4396 +
4397 +#ifdef CONFIG_PAX_RANDMMAP
4398 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4399 + mm->mmap_base += mm->delta_mmap;
4400 +#endif
4401 +
4402 mm->get_unmapped_area = arch_get_unmapped_area;
4403 } else {
4404 mm->mmap_base = mmap_base(random_factor);
4405 +
4406 +#ifdef CONFIG_PAX_RANDMMAP
4407 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4408 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4409 +#endif
4410 +
4411 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4412 }
4413 }
4414 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4415 index 9f98cec..115fcb6 100644
4416 --- a/arch/arm/mm/mmu.c
4417 +++ b/arch/arm/mm/mmu.c
4418 @@ -40,6 +40,22 @@
4419 #include "mm.h"
4420 #include "tcm.h"
4421
4422 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4423 +void modify_domain(unsigned int dom, unsigned int type)
4424 +{
4425 + struct thread_info *thread = current_thread_info();
4426 + unsigned int domain = thread->cpu_domain;
4427 + /*
4428 + * DOMAIN_MANAGER might be defined to some other value,
4429 + * use the arch-defined constant
4430 + */
4431 + domain &= ~domain_val(dom, 3);
4432 + thread->cpu_domain = domain | domain_val(dom, type);
4433 + set_domain(thread->cpu_domain);
4434 +}
4435 +EXPORT_SYMBOL(modify_domain);
4436 +#endif
4437 +
4438 /*
4439 * empty_zero_page is a special page that is used for
4440 * zero-initialized data and COW.
4441 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4442 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4443 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4444
4445 -static struct mem_type mem_types[] = {
4446 +#ifdef CONFIG_PAX_KERNEXEC
4447 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4448 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4449 +#else
4450 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4451 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4452 +#endif
4453 +
4454 +static struct mem_type mem_types[] __read_only = {
4455 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4456 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4457 L_PTE_SHARED,
4458 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4459 .prot_sect = PROT_SECT_DEVICE,
4460 .domain = DOMAIN_IO,
4461 },
4462 - [MT_UNCACHED] = {
4463 + [MT_UNCACHED_RW] = {
4464 .prot_pte = PROT_PTE_DEVICE,
4465 .prot_l1 = PMD_TYPE_TABLE,
4466 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4467 .domain = DOMAIN_IO,
4468 },
4469 - [MT_CACHECLEAN] = {
4470 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4471 + [MT_CACHECLEAN_RO] = {
4472 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4473 .domain = DOMAIN_KERNEL,
4474 },
4475 #ifndef CONFIG_ARM_LPAE
4476 - [MT_MINICLEAN] = {
4477 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4478 + [MT_MINICLEAN_RO] = {
4479 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4480 .domain = DOMAIN_KERNEL,
4481 },
4482 #endif
4483 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4484 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4485 L_PTE_RDONLY,
4486 .prot_l1 = PMD_TYPE_TABLE,
4487 - .domain = DOMAIN_USER,
4488 + .domain = DOMAIN_VECTORS,
4489 },
4490 [MT_HIGH_VECTORS] = {
4491 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4492 L_PTE_USER | L_PTE_RDONLY,
4493 .prot_l1 = PMD_TYPE_TABLE,
4494 - .domain = DOMAIN_USER,
4495 + .domain = DOMAIN_VECTORS,
4496 },
4497 - [MT_MEMORY_RWX] = {
4498 + [__MT_MEMORY_RWX] = {
4499 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4500 .prot_l1 = PMD_TYPE_TABLE,
4501 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4502 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4503 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4504 .domain = DOMAIN_KERNEL,
4505 },
4506 - [MT_ROM] = {
4507 - .prot_sect = PMD_TYPE_SECT,
4508 + [MT_MEMORY_RX] = {
4509 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4510 + .prot_l1 = PMD_TYPE_TABLE,
4511 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4512 + .domain = DOMAIN_KERNEL,
4513 + },
4514 + [MT_ROM_RX] = {
4515 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4516 .domain = DOMAIN_KERNEL,
4517 },
4518 - [MT_MEMORY_RWX_NONCACHED] = {
4519 + [MT_MEMORY_RW_NONCACHED] = {
4520 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4521 L_PTE_MT_BUFFERABLE,
4522 .prot_l1 = PMD_TYPE_TABLE,
4523 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4524 .domain = DOMAIN_KERNEL,
4525 },
4526 + [MT_MEMORY_RX_NONCACHED] = {
4527 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4528 + L_PTE_MT_BUFFERABLE,
4529 + .prot_l1 = PMD_TYPE_TABLE,
4530 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4531 + .domain = DOMAIN_KERNEL,
4532 + },
4533 [MT_MEMORY_RW_DTCM] = {
4534 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4535 L_PTE_XN,
4536 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4537 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4538 .domain = DOMAIN_KERNEL,
4539 },
4540 - [MT_MEMORY_RWX_ITCM] = {
4541 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4542 + [MT_MEMORY_RX_ITCM] = {
4543 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4544 .prot_l1 = PMD_TYPE_TABLE,
4545 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4546 .domain = DOMAIN_KERNEL,
4547 },
4548 [MT_MEMORY_RW_SO] = {
4549 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4550 * Mark cache clean areas and XIP ROM read only
4551 * from SVC mode and no access from userspace.
4552 */
4553 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4554 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4555 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4556 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4557 +#ifdef CONFIG_PAX_KERNEXEC
4558 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4559 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4560 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4561 +#endif
4562 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4563 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4564 #endif
4565
4566 /*
4567 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4568 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4569 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4570 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4571 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4572 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4573 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4574 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4575 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4576 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4577 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4578 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4579 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4580 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4581 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4582 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4583 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4584 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4585 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4586 }
4587 }
4588
4589 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4590 if (cpu_arch >= CPU_ARCH_ARMv6) {
4591 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4592 /* Non-cacheable Normal is XCB = 001 */
4593 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4594 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4595 + PMD_SECT_BUFFERED;
4596 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4597 PMD_SECT_BUFFERED;
4598 } else {
4599 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4600 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4601 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4602 + PMD_SECT_TEX(1);
4603 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4604 PMD_SECT_TEX(1);
4605 }
4606 } else {
4607 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4608 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4609 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4610 }
4611
4612 #ifdef CONFIG_ARM_LPAE
4613 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4614 vecs_pgprot |= PTE_EXT_AF;
4615 #endif
4616
4617 + user_pgprot |= __supported_pte_mask;
4618 +
4619 for (i = 0; i < 16; i++) {
4620 pteval_t v = pgprot_val(protection_map[i]);
4621 protection_map[i] = __pgprot(v | user_pgprot);
4622 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4623
4624 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4625 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4626 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4627 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4628 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4629 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4630 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4631 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4632 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4633 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4634 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4635 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4636 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4637 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4638 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4639 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4640
4641 switch (cp->pmd) {
4642 case PMD_SECT_WT:
4643 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4644 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4645 break;
4646 case PMD_SECT_WB:
4647 case PMD_SECT_WBWA:
4648 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4649 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4650 break;
4651 }
4652 pr_info("Memory policy: %sData cache %s\n",
4653 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4654 return;
4655 }
4656
4657 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4658 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4659 md->virtual >= PAGE_OFFSET &&
4660 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4661 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4662 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4663 * called function. This means you can't use any function or debugging
4664 * method which may touch any device, otherwise the kernel _will_ crash.
4665 */
4666 +
4667 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4668 +
4669 static void __init devicemaps_init(const struct machine_desc *mdesc)
4670 {
4671 struct map_desc map;
4672 unsigned long addr;
4673 - void *vectors;
4674
4675 - /*
4676 - * Allocate the vector page early.
4677 - */
4678 - vectors = early_alloc(PAGE_SIZE * 2);
4679 -
4680 - early_trap_init(vectors);
4681 + early_trap_init(&vectors);
4682
4683 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4684 pmd_clear(pmd_off_k(addr));
4685 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4686 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4687 map.virtual = MODULES_VADDR;
4688 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4689 - map.type = MT_ROM;
4690 + map.type = MT_ROM_RX;
4691 create_mapping(&map);
4692 #endif
4693
4694 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4695 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4696 map.virtual = FLUSH_BASE;
4697 map.length = SZ_1M;
4698 - map.type = MT_CACHECLEAN;
4699 + map.type = MT_CACHECLEAN_RO;
4700 create_mapping(&map);
4701 #endif
4702 #ifdef FLUSH_BASE_MINICACHE
4703 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4704 map.virtual = FLUSH_BASE_MINICACHE;
4705 map.length = SZ_1M;
4706 - map.type = MT_MINICLEAN;
4707 + map.type = MT_MINICLEAN_RO;
4708 create_mapping(&map);
4709 #endif
4710
4711 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4712 * location (0xffff0000). If we aren't using high-vectors, also
4713 * create a mapping at the low-vectors virtual address.
4714 */
4715 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4716 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4717 map.virtual = 0xffff0000;
4718 map.length = PAGE_SIZE;
4719 #ifdef CONFIG_KUSER_HELPERS
4720 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4721 static void __init map_lowmem(void)
4722 {
4723 struct memblock_region *reg;
4724 +#ifndef CONFIG_PAX_KERNEXEC
4725 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4726 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4727 +#endif
4728
4729 /* Map all the lowmem memory banks. */
4730 for_each_memblock(memory, reg) {
4731 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4732 if (start >= end)
4733 break;
4734
4735 +#ifdef CONFIG_PAX_KERNEXEC
4736 + map.pfn = __phys_to_pfn(start);
4737 + map.virtual = __phys_to_virt(start);
4738 + map.length = end - start;
4739 +
4740 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4741 + struct map_desc kernel;
4742 + struct map_desc initmap;
4743 +
4744 + /* when freeing initmem we will make this RW */
4745 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4746 + initmap.virtual = (unsigned long)__init_begin;
4747 + initmap.length = _sdata - __init_begin;
4748 + initmap.type = __MT_MEMORY_RWX;
4749 + create_mapping(&initmap);
4750 +
4751 + /* when freeing initmem we will make this RX */
4752 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4753 + kernel.virtual = (unsigned long)_stext;
4754 + kernel.length = __init_begin - _stext;
4755 + kernel.type = __MT_MEMORY_RWX;
4756 + create_mapping(&kernel);
4757 +
4758 + if (map.virtual < (unsigned long)_stext) {
4759 + map.length = (unsigned long)_stext - map.virtual;
4760 + map.type = __MT_MEMORY_RWX;
4761 + create_mapping(&map);
4762 + }
4763 +
4764 + map.pfn = __phys_to_pfn(__pa(_sdata));
4765 + map.virtual = (unsigned long)_sdata;
4766 + map.length = end - __pa(_sdata);
4767 + }
4768 +
4769 + map.type = MT_MEMORY_RW;
4770 + create_mapping(&map);
4771 +#else
4772 if (end < kernel_x_start || start >= kernel_x_end) {
4773 map.pfn = __phys_to_pfn(start);
4774 map.virtual = __phys_to_virt(start);
4775 map.length = end - start;
4776 - map.type = MT_MEMORY_RWX;
4777 + map.type = __MT_MEMORY_RWX;
4778
4779 create_mapping(&map);
4780 } else {
4781 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4782 map.pfn = __phys_to_pfn(kernel_x_start);
4783 map.virtual = __phys_to_virt(kernel_x_start);
4784 map.length = kernel_x_end - kernel_x_start;
4785 - map.type = MT_MEMORY_RWX;
4786 + map.type = __MT_MEMORY_RWX;
4787
4788 create_mapping(&map);
4789
4790 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4791 create_mapping(&map);
4792 }
4793 }
4794 +#endif
4795 }
4796 }
4797
4798 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4799 index e1268f9..a9755a7 100644
4800 --- a/arch/arm/net/bpf_jit_32.c
4801 +++ b/arch/arm/net/bpf_jit_32.c
4802 @@ -20,6 +20,7 @@
4803 #include <asm/cacheflush.h>
4804 #include <asm/hwcap.h>
4805 #include <asm/opcodes.h>
4806 +#include <asm/pgtable.h>
4807
4808 #include "bpf_jit_32.h"
4809
4810 @@ -71,7 +72,11 @@ struct jit_ctx {
4811 #endif
4812 };
4813
4814 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4815 +int bpf_jit_enable __read_only;
4816 +#else
4817 int bpf_jit_enable __read_mostly;
4818 +#endif
4819
4820 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4821 {
4822 @@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4823 {
4824 u32 *ptr;
4825 /* We are guaranteed to have aligned memory. */
4826 + pax_open_kernel();
4827 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4828 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4829 + pax_close_kernel();
4830 }
4831
4832 static void build_prologue(struct jit_ctx *ctx)
4833 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4834 index 5b217f4..c23f40e 100644
4835 --- a/arch/arm/plat-iop/setup.c
4836 +++ b/arch/arm/plat-iop/setup.c
4837 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4838 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4839 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4840 .length = IOP3XX_PERIPHERAL_SIZE,
4841 - .type = MT_UNCACHED,
4842 + .type = MT_UNCACHED_RW,
4843 },
4844 };
4845
4846 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4847 index a5bc92d..0bb4730 100644
4848 --- a/arch/arm/plat-omap/sram.c
4849 +++ b/arch/arm/plat-omap/sram.c
4850 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4851 * Looks like we need to preserve some bootloader code at the
4852 * beginning of SRAM for jumping to flash for reboot to work...
4853 */
4854 + pax_open_kernel();
4855 memset_io(omap_sram_base + omap_sram_skip, 0,
4856 omap_sram_size - omap_sram_skip);
4857 + pax_close_kernel();
4858 }
4859 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4860 index ce6d763..cfea917 100644
4861 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4862 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4863 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4864 int (*started)(unsigned ch);
4865 int (*flush)(unsigned ch);
4866 int (*stop)(unsigned ch);
4867 -};
4868 +} __no_const;
4869
4870 extern void *samsung_dmadev_get_ops(void);
4871 extern void *s3c_dma_get_ops(void);
4872 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4873 index 6389d60..b5d3bdd 100644
4874 --- a/arch/arm64/include/asm/barrier.h
4875 +++ b/arch/arm64/include/asm/barrier.h
4876 @@ -41,7 +41,7 @@
4877 do { \
4878 compiletime_assert_atomic_type(*p); \
4879 barrier(); \
4880 - ACCESS_ONCE(*p) = (v); \
4881 + ACCESS_ONCE_RW(*p) = (v); \
4882 } while (0)
4883
4884 #define smp_load_acquire(p) \
4885 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4886 index 3bf8f4e..5dd5491 100644
4887 --- a/arch/arm64/include/asm/uaccess.h
4888 +++ b/arch/arm64/include/asm/uaccess.h
4889 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4890 flag; \
4891 })
4892
4893 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4894 #define access_ok(type, addr, size) __range_ok(addr, size)
4895 #define user_addr_max get_fs
4896
4897 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4898 index c3a58a1..78fbf54 100644
4899 --- a/arch/avr32/include/asm/cache.h
4900 +++ b/arch/avr32/include/asm/cache.h
4901 @@ -1,8 +1,10 @@
4902 #ifndef __ASM_AVR32_CACHE_H
4903 #define __ASM_AVR32_CACHE_H
4904
4905 +#include <linux/const.h>
4906 +
4907 #define L1_CACHE_SHIFT 5
4908 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4909 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4910
4911 /*
4912 * Memory returned by kmalloc() may be used for DMA, so we must make
4913 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4914 index d232888..87c8df1 100644
4915 --- a/arch/avr32/include/asm/elf.h
4916 +++ b/arch/avr32/include/asm/elf.h
4917 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4918 the loader. We need to make sure that it is out of the way of the program
4919 that it will "exec", and that there is sufficient room for the brk. */
4920
4921 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4922 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4923
4924 +#ifdef CONFIG_PAX_ASLR
4925 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4926 +
4927 +#define PAX_DELTA_MMAP_LEN 15
4928 +#define PAX_DELTA_STACK_LEN 15
4929 +#endif
4930
4931 /* This yields a mask that user programs can use to figure out what
4932 instruction set this CPU supports. This could be done in user space,
4933 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4934 index 479330b..53717a8 100644
4935 --- a/arch/avr32/include/asm/kmap_types.h
4936 +++ b/arch/avr32/include/asm/kmap_types.h
4937 @@ -2,9 +2,9 @@
4938 #define __ASM_AVR32_KMAP_TYPES_H
4939
4940 #ifdef CONFIG_DEBUG_HIGHMEM
4941 -# define KM_TYPE_NR 29
4942 +# define KM_TYPE_NR 30
4943 #else
4944 -# define KM_TYPE_NR 14
4945 +# define KM_TYPE_NR 15
4946 #endif
4947
4948 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4949 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4950 index 0eca933..eb78c7b 100644
4951 --- a/arch/avr32/mm/fault.c
4952 +++ b/arch/avr32/mm/fault.c
4953 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4954
4955 int exception_trace = 1;
4956
4957 +#ifdef CONFIG_PAX_PAGEEXEC
4958 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4959 +{
4960 + unsigned long i;
4961 +
4962 + printk(KERN_ERR "PAX: bytes at PC: ");
4963 + for (i = 0; i < 20; i++) {
4964 + unsigned char c;
4965 + if (get_user(c, (unsigned char *)pc+i))
4966 + printk(KERN_CONT "???????? ");
4967 + else
4968 + printk(KERN_CONT "%02x ", c);
4969 + }
4970 + printk("\n");
4971 +}
4972 +#endif
4973 +
4974 /*
4975 * This routine handles page faults. It determines the address and the
4976 * problem, and then passes it off to one of the appropriate routines.
4977 @@ -176,6 +193,16 @@ bad_area:
4978 up_read(&mm->mmap_sem);
4979
4980 if (user_mode(regs)) {
4981 +
4982 +#ifdef CONFIG_PAX_PAGEEXEC
4983 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4984 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4985 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4986 + do_group_exit(SIGKILL);
4987 + }
4988 + }
4989 +#endif
4990 +
4991 if (exception_trace && printk_ratelimit())
4992 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4993 "sp %08lx ecr %lu\n",
4994 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4995 index 568885a..f8008df 100644
4996 --- a/arch/blackfin/include/asm/cache.h
4997 +++ b/arch/blackfin/include/asm/cache.h
4998 @@ -7,6 +7,7 @@
4999 #ifndef __ARCH_BLACKFIN_CACHE_H
5000 #define __ARCH_BLACKFIN_CACHE_H
5001
5002 +#include <linux/const.h>
5003 #include <linux/linkage.h> /* for asmlinkage */
5004
5005 /*
5006 @@ -14,7 +15,7 @@
5007 * Blackfin loads 32 bytes for cache
5008 */
5009 #define L1_CACHE_SHIFT 5
5010 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5011 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5012 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5013
5014 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5015 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5016 index aea2718..3639a60 100644
5017 --- a/arch/cris/include/arch-v10/arch/cache.h
5018 +++ b/arch/cris/include/arch-v10/arch/cache.h
5019 @@ -1,8 +1,9 @@
5020 #ifndef _ASM_ARCH_CACHE_H
5021 #define _ASM_ARCH_CACHE_H
5022
5023 +#include <linux/const.h>
5024 /* Etrax 100LX have 32-byte cache-lines. */
5025 -#define L1_CACHE_BYTES 32
5026 #define L1_CACHE_SHIFT 5
5027 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5028
5029 #endif /* _ASM_ARCH_CACHE_H */
5030 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5031 index 7caf25d..ee65ac5 100644
5032 --- a/arch/cris/include/arch-v32/arch/cache.h
5033 +++ b/arch/cris/include/arch-v32/arch/cache.h
5034 @@ -1,11 +1,12 @@
5035 #ifndef _ASM_CRIS_ARCH_CACHE_H
5036 #define _ASM_CRIS_ARCH_CACHE_H
5037
5038 +#include <linux/const.h>
5039 #include <arch/hwregs/dma.h>
5040
5041 /* A cache-line is 32 bytes. */
5042 -#define L1_CACHE_BYTES 32
5043 #define L1_CACHE_SHIFT 5
5044 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5045
5046 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5047
5048 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5049 index 102190a..5334cea 100644
5050 --- a/arch/frv/include/asm/atomic.h
5051 +++ b/arch/frv/include/asm/atomic.h
5052 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5053 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5054 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5055
5056 +#define atomic64_read_unchecked(v) atomic64_read(v)
5057 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5058 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5059 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5060 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5061 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5062 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5063 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5064 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5065 +
5066 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5067 {
5068 int c, old;
5069 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5070 index 2797163..c2a401df9 100644
5071 --- a/arch/frv/include/asm/cache.h
5072 +++ b/arch/frv/include/asm/cache.h
5073 @@ -12,10 +12,11 @@
5074 #ifndef __ASM_CACHE_H
5075 #define __ASM_CACHE_H
5076
5077 +#include <linux/const.h>
5078
5079 /* bytes per L1 cache line */
5080 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5081 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5082 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5083
5084 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5085 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5086 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5087 index 43901f2..0d8b865 100644
5088 --- a/arch/frv/include/asm/kmap_types.h
5089 +++ b/arch/frv/include/asm/kmap_types.h
5090 @@ -2,6 +2,6 @@
5091 #ifndef _ASM_KMAP_TYPES_H
5092 #define _ASM_KMAP_TYPES_H
5093
5094 -#define KM_TYPE_NR 17
5095 +#define KM_TYPE_NR 18
5096
5097 #endif
5098 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5099 index 836f147..4cf23f5 100644
5100 --- a/arch/frv/mm/elf-fdpic.c
5101 +++ b/arch/frv/mm/elf-fdpic.c
5102 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5103 {
5104 struct vm_area_struct *vma;
5105 struct vm_unmapped_area_info info;
5106 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5107
5108 if (len > TASK_SIZE)
5109 return -ENOMEM;
5110 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5111 if (addr) {
5112 addr = PAGE_ALIGN(addr);
5113 vma = find_vma(current->mm, addr);
5114 - if (TASK_SIZE - len >= addr &&
5115 - (!vma || addr + len <= vma->vm_start))
5116 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5117 goto success;
5118 }
5119
5120 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5121 info.high_limit = (current->mm->start_stack - 0x00200000);
5122 info.align_mask = 0;
5123 info.align_offset = 0;
5124 + info.threadstack_offset = offset;
5125 addr = vm_unmapped_area(&info);
5126 if (!(addr & ~PAGE_MASK))
5127 goto success;
5128 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5129 index 2635117..fa223cb 100644
5130 --- a/arch/hexagon/include/asm/cache.h
5131 +++ b/arch/hexagon/include/asm/cache.h
5132 @@ -21,9 +21,11 @@
5133 #ifndef __ASM_CACHE_H
5134 #define __ASM_CACHE_H
5135
5136 +#include <linux/const.h>
5137 +
5138 /* Bytes per L1 cache line */
5139 -#define L1_CACHE_SHIFT (5)
5140 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5141 +#define L1_CACHE_SHIFT 5
5142 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5143
5144 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5145 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5146 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5147 index c84c88b..2a6e1ba 100644
5148 --- a/arch/ia64/Kconfig
5149 +++ b/arch/ia64/Kconfig
5150 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5151 config KEXEC
5152 bool "kexec system call"
5153 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5154 + depends on !GRKERNSEC_KMEM
5155 help
5156 kexec is a system call that implements the ability to shutdown your
5157 current kernel, and to start another kernel. It is like a reboot
5158 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5159 index 5441b14..039a446 100644
5160 --- a/arch/ia64/Makefile
5161 +++ b/arch/ia64/Makefile
5162 @@ -99,5 +99,6 @@ endef
5163 archprepare: make_nr_irqs_h FORCE
5164 PHONY += make_nr_irqs_h FORCE
5165
5166 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5167 make_nr_irqs_h: FORCE
5168 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5169 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5170 index 0bf0350..2ad1957 100644
5171 --- a/arch/ia64/include/asm/atomic.h
5172 +++ b/arch/ia64/include/asm/atomic.h
5173 @@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5174 #define atomic64_inc(v) atomic64_add(1, (v))
5175 #define atomic64_dec(v) atomic64_sub(1, (v))
5176
5177 +#define atomic64_read_unchecked(v) atomic64_read(v)
5178 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5179 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5180 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5181 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5182 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5183 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5184 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5185 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5186 +
5187 #endif /* _ASM_IA64_ATOMIC_H */
5188 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5189 index a48957c..e097b56 100644
5190 --- a/arch/ia64/include/asm/barrier.h
5191 +++ b/arch/ia64/include/asm/barrier.h
5192 @@ -67,7 +67,7 @@
5193 do { \
5194 compiletime_assert_atomic_type(*p); \
5195 barrier(); \
5196 - ACCESS_ONCE(*p) = (v); \
5197 + ACCESS_ONCE_RW(*p) = (v); \
5198 } while (0)
5199
5200 #define smp_load_acquire(p) \
5201 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5202 index 988254a..e1ee885 100644
5203 --- a/arch/ia64/include/asm/cache.h
5204 +++ b/arch/ia64/include/asm/cache.h
5205 @@ -1,6 +1,7 @@
5206 #ifndef _ASM_IA64_CACHE_H
5207 #define _ASM_IA64_CACHE_H
5208
5209 +#include <linux/const.h>
5210
5211 /*
5212 * Copyright (C) 1998-2000 Hewlett-Packard Co
5213 @@ -9,7 +10,7 @@
5214
5215 /* Bytes per L1 (data) cache line. */
5216 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5217 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5218 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5219
5220 #ifdef CONFIG_SMP
5221 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5222 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5223 index 5a83c5c..4d7f553 100644
5224 --- a/arch/ia64/include/asm/elf.h
5225 +++ b/arch/ia64/include/asm/elf.h
5226 @@ -42,6 +42,13 @@
5227 */
5228 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5229
5230 +#ifdef CONFIG_PAX_ASLR
5231 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5232 +
5233 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5234 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5235 +#endif
5236 +
5237 #define PT_IA_64_UNWIND 0x70000001
5238
5239 /* IA-64 relocations: */
5240 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5241 index 5767cdf..7462574 100644
5242 --- a/arch/ia64/include/asm/pgalloc.h
5243 +++ b/arch/ia64/include/asm/pgalloc.h
5244 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5245 pgd_val(*pgd_entry) = __pa(pud);
5246 }
5247
5248 +static inline void
5249 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5250 +{
5251 + pgd_populate(mm, pgd_entry, pud);
5252 +}
5253 +
5254 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5255 {
5256 return quicklist_alloc(0, GFP_KERNEL, NULL);
5257 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5258 pud_val(*pud_entry) = __pa(pmd);
5259 }
5260
5261 +static inline void
5262 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5263 +{
5264 + pud_populate(mm, pud_entry, pmd);
5265 +}
5266 +
5267 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5268 {
5269 return quicklist_alloc(0, GFP_KERNEL, NULL);
5270 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5271 index 7935115..c0eca6a 100644
5272 --- a/arch/ia64/include/asm/pgtable.h
5273 +++ b/arch/ia64/include/asm/pgtable.h
5274 @@ -12,7 +12,7 @@
5275 * David Mosberger-Tang <davidm@hpl.hp.com>
5276 */
5277
5278 -
5279 +#include <linux/const.h>
5280 #include <asm/mman.h>
5281 #include <asm/page.h>
5282 #include <asm/processor.h>
5283 @@ -142,6 +142,17 @@
5284 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5285 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5286 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5287 +
5288 +#ifdef CONFIG_PAX_PAGEEXEC
5289 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5290 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5291 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5292 +#else
5293 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5294 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5295 +# define PAGE_COPY_NOEXEC PAGE_COPY
5296 +#endif
5297 +
5298 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5299 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5300 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5301 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5302 index 45698cd..e8e2dbc 100644
5303 --- a/arch/ia64/include/asm/spinlock.h
5304 +++ b/arch/ia64/include/asm/spinlock.h
5305 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5306 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5307
5308 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5309 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5310 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5311 }
5312
5313 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5314 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5315 index 449c8c0..3d4b1e9 100644
5316 --- a/arch/ia64/include/asm/uaccess.h
5317 +++ b/arch/ia64/include/asm/uaccess.h
5318 @@ -70,6 +70,7 @@
5319 && ((segment).seg == KERNEL_DS.seg \
5320 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5321 })
5322 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5323 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5324
5325 /*
5326 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5327 static inline unsigned long
5328 __copy_to_user (void __user *to, const void *from, unsigned long count)
5329 {
5330 + if (count > INT_MAX)
5331 + return count;
5332 +
5333 + if (!__builtin_constant_p(count))
5334 + check_object_size(from, count, true);
5335 +
5336 return __copy_user(to, (__force void __user *) from, count);
5337 }
5338
5339 static inline unsigned long
5340 __copy_from_user (void *to, const void __user *from, unsigned long count)
5341 {
5342 + if (count > INT_MAX)
5343 + return count;
5344 +
5345 + if (!__builtin_constant_p(count))
5346 + check_object_size(to, count, false);
5347 +
5348 return __copy_user((__force void __user *) to, from, count);
5349 }
5350
5351 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5352 ({ \
5353 void __user *__cu_to = (to); \
5354 const void *__cu_from = (from); \
5355 - long __cu_len = (n); \
5356 + unsigned long __cu_len = (n); \
5357 \
5358 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5359 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5360 + if (!__builtin_constant_p(n)) \
5361 + check_object_size(__cu_from, __cu_len, true); \
5362 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5363 + } \
5364 __cu_len; \
5365 })
5366
5367 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5368 ({ \
5369 void *__cu_to = (to); \
5370 const void __user *__cu_from = (from); \
5371 - long __cu_len = (n); \
5372 + unsigned long __cu_len = (n); \
5373 \
5374 __chk_user_ptr(__cu_from); \
5375 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5376 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5377 + if (!__builtin_constant_p(n)) \
5378 + check_object_size(__cu_to, __cu_len, false); \
5379 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5380 + } \
5381 __cu_len; \
5382 })
5383
5384 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5385 index 24603be..948052d 100644
5386 --- a/arch/ia64/kernel/module.c
5387 +++ b/arch/ia64/kernel/module.c
5388 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5389 void
5390 module_free (struct module *mod, void *module_region)
5391 {
5392 - if (mod && mod->arch.init_unw_table &&
5393 - module_region == mod->module_init) {
5394 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5395 unw_remove_unwind_table(mod->arch.init_unw_table);
5396 mod->arch.init_unw_table = NULL;
5397 }
5398 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5399 }
5400
5401 static inline int
5402 +in_init_rx (const struct module *mod, uint64_t addr)
5403 +{
5404 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5405 +}
5406 +
5407 +static inline int
5408 +in_init_rw (const struct module *mod, uint64_t addr)
5409 +{
5410 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5411 +}
5412 +
5413 +static inline int
5414 in_init (const struct module *mod, uint64_t addr)
5415 {
5416 - return addr - (uint64_t) mod->module_init < mod->init_size;
5417 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5418 +}
5419 +
5420 +static inline int
5421 +in_core_rx (const struct module *mod, uint64_t addr)
5422 +{
5423 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5424 +}
5425 +
5426 +static inline int
5427 +in_core_rw (const struct module *mod, uint64_t addr)
5428 +{
5429 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5430 }
5431
5432 static inline int
5433 in_core (const struct module *mod, uint64_t addr)
5434 {
5435 - return addr - (uint64_t) mod->module_core < mod->core_size;
5436 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5437 }
5438
5439 static inline int
5440 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5441 break;
5442
5443 case RV_BDREL:
5444 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5445 + if (in_init_rx(mod, val))
5446 + val -= (uint64_t) mod->module_init_rx;
5447 + else if (in_init_rw(mod, val))
5448 + val -= (uint64_t) mod->module_init_rw;
5449 + else if (in_core_rx(mod, val))
5450 + val -= (uint64_t) mod->module_core_rx;
5451 + else if (in_core_rw(mod, val))
5452 + val -= (uint64_t) mod->module_core_rw;
5453 break;
5454
5455 case RV_LTV:
5456 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5457 * addresses have been selected...
5458 */
5459 uint64_t gp;
5460 - if (mod->core_size > MAX_LTOFF)
5461 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5462 /*
5463 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5464 * at the end of the module.
5465 */
5466 - gp = mod->core_size - MAX_LTOFF / 2;
5467 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5468 else
5469 - gp = mod->core_size / 2;
5470 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5471 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5472 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5473 mod->arch.gp = gp;
5474 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5475 }
5476 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5477 index c39c3cd..3c77738 100644
5478 --- a/arch/ia64/kernel/palinfo.c
5479 +++ b/arch/ia64/kernel/palinfo.c
5480 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5481 return NOTIFY_OK;
5482 }
5483
5484 -static struct notifier_block __refdata palinfo_cpu_notifier =
5485 +static struct notifier_block palinfo_cpu_notifier =
5486 {
5487 .notifier_call = palinfo_cpu_callback,
5488 .priority = 0,
5489 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5490 index 41e33f8..65180b2a 100644
5491 --- a/arch/ia64/kernel/sys_ia64.c
5492 +++ b/arch/ia64/kernel/sys_ia64.c
5493 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5494 unsigned long align_mask = 0;
5495 struct mm_struct *mm = current->mm;
5496 struct vm_unmapped_area_info info;
5497 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5498
5499 if (len > RGN_MAP_LIMIT)
5500 return -ENOMEM;
5501 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5502 if (REGION_NUMBER(addr) == RGN_HPAGE)
5503 addr = 0;
5504 #endif
5505 +
5506 +#ifdef CONFIG_PAX_RANDMMAP
5507 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5508 + addr = mm->free_area_cache;
5509 + else
5510 +#endif
5511 +
5512 if (!addr)
5513 addr = TASK_UNMAPPED_BASE;
5514
5515 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5516 info.high_limit = TASK_SIZE;
5517 info.align_mask = align_mask;
5518 info.align_offset = 0;
5519 + info.threadstack_offset = offset;
5520 return vm_unmapped_area(&info);
5521 }
5522
5523 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5524 index 84f8a52..7c76178 100644
5525 --- a/arch/ia64/kernel/vmlinux.lds.S
5526 +++ b/arch/ia64/kernel/vmlinux.lds.S
5527 @@ -192,7 +192,7 @@ SECTIONS {
5528 /* Per-cpu data: */
5529 . = ALIGN(PERCPU_PAGE_SIZE);
5530 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5531 - __phys_per_cpu_start = __per_cpu_load;
5532 + __phys_per_cpu_start = per_cpu_load;
5533 /*
5534 * ensure percpu data fits
5535 * into percpu page size
5536 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5537 index 7225dad..2a7c8256 100644
5538 --- a/arch/ia64/mm/fault.c
5539 +++ b/arch/ia64/mm/fault.c
5540 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5541 return pte_present(pte);
5542 }
5543
5544 +#ifdef CONFIG_PAX_PAGEEXEC
5545 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5546 +{
5547 + unsigned long i;
5548 +
5549 + printk(KERN_ERR "PAX: bytes at PC: ");
5550 + for (i = 0; i < 8; i++) {
5551 + unsigned int c;
5552 + if (get_user(c, (unsigned int *)pc+i))
5553 + printk(KERN_CONT "???????? ");
5554 + else
5555 + printk(KERN_CONT "%08x ", c);
5556 + }
5557 + printk("\n");
5558 +}
5559 +#endif
5560 +
5561 # define VM_READ_BIT 0
5562 # define VM_WRITE_BIT 1
5563 # define VM_EXEC_BIT 2
5564 @@ -151,8 +168,21 @@ retry:
5565 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5566 goto bad_area;
5567
5568 - if ((vma->vm_flags & mask) != mask)
5569 + if ((vma->vm_flags & mask) != mask) {
5570 +
5571 +#ifdef CONFIG_PAX_PAGEEXEC
5572 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5573 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5574 + goto bad_area;
5575 +
5576 + up_read(&mm->mmap_sem);
5577 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5578 + do_group_exit(SIGKILL);
5579 + }
5580 +#endif
5581 +
5582 goto bad_area;
5583 + }
5584
5585 /*
5586 * If for any reason at all we couldn't handle the fault, make
5587 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5588 index 76069c1..c2aa816 100644
5589 --- a/arch/ia64/mm/hugetlbpage.c
5590 +++ b/arch/ia64/mm/hugetlbpage.c
5591 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5592 unsigned long pgoff, unsigned long flags)
5593 {
5594 struct vm_unmapped_area_info info;
5595 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5596
5597 if (len > RGN_MAP_LIMIT)
5598 return -ENOMEM;
5599 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5600 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5601 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5602 info.align_offset = 0;
5603 + info.threadstack_offset = offset;
5604 return vm_unmapped_area(&info);
5605 }
5606
5607 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5608 index 6b33457..88b5124 100644
5609 --- a/arch/ia64/mm/init.c
5610 +++ b/arch/ia64/mm/init.c
5611 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5612 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5613 vma->vm_end = vma->vm_start + PAGE_SIZE;
5614 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5615 +
5616 +#ifdef CONFIG_PAX_PAGEEXEC
5617 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5618 + vma->vm_flags &= ~VM_EXEC;
5619 +
5620 +#ifdef CONFIG_PAX_MPROTECT
5621 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5622 + vma->vm_flags &= ~VM_MAYEXEC;
5623 +#endif
5624 +
5625 + }
5626 +#endif
5627 +
5628 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5629 down_write(&current->mm->mmap_sem);
5630 if (insert_vm_struct(current->mm, vma)) {
5631 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5632 gate_vma.vm_start = FIXADDR_USER_START;
5633 gate_vma.vm_end = FIXADDR_USER_END;
5634 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5635 - gate_vma.vm_page_prot = __P101;
5636 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5637
5638 return 0;
5639 }
5640 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5641 index 40b3ee9..8c2c112 100644
5642 --- a/arch/m32r/include/asm/cache.h
5643 +++ b/arch/m32r/include/asm/cache.h
5644 @@ -1,8 +1,10 @@
5645 #ifndef _ASM_M32R_CACHE_H
5646 #define _ASM_M32R_CACHE_H
5647
5648 +#include <linux/const.h>
5649 +
5650 /* L1 cache line size */
5651 #define L1_CACHE_SHIFT 4
5652 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5653 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5654
5655 #endif /* _ASM_M32R_CACHE_H */
5656 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5657 index 82abd15..d95ae5d 100644
5658 --- a/arch/m32r/lib/usercopy.c
5659 +++ b/arch/m32r/lib/usercopy.c
5660 @@ -14,6 +14,9 @@
5661 unsigned long
5662 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5663 {
5664 + if ((long)n < 0)
5665 + return n;
5666 +
5667 prefetch(from);
5668 if (access_ok(VERIFY_WRITE, to, n))
5669 __copy_user(to,from,n);
5670 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5671 unsigned long
5672 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5673 {
5674 + if ((long)n < 0)
5675 + return n;
5676 +
5677 prefetchw(to);
5678 if (access_ok(VERIFY_READ, from, n))
5679 __copy_user_zeroing(to,from,n);
5680 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5681 index 0395c51..5f26031 100644
5682 --- a/arch/m68k/include/asm/cache.h
5683 +++ b/arch/m68k/include/asm/cache.h
5684 @@ -4,9 +4,11 @@
5685 #ifndef __ARCH_M68K_CACHE_H
5686 #define __ARCH_M68K_CACHE_H
5687
5688 +#include <linux/const.h>
5689 +
5690 /* bytes per L1 cache line */
5691 #define L1_CACHE_SHIFT 4
5692 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5693 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5694
5695 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5696
5697 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5698 index c7591e8..ecef036 100644
5699 --- a/arch/metag/include/asm/barrier.h
5700 +++ b/arch/metag/include/asm/barrier.h
5701 @@ -89,7 +89,7 @@ static inline void fence(void)
5702 do { \
5703 compiletime_assert_atomic_type(*p); \
5704 smp_mb(); \
5705 - ACCESS_ONCE(*p) = (v); \
5706 + ACCESS_ONCE_RW(*p) = (v); \
5707 } while (0)
5708
5709 #define smp_load_acquire(p) \
5710 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5711 index 3c32075..ae0ae75 100644
5712 --- a/arch/metag/mm/hugetlbpage.c
5713 +++ b/arch/metag/mm/hugetlbpage.c
5714 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5715 info.high_limit = TASK_SIZE;
5716 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5717 info.align_offset = 0;
5718 + info.threadstack_offset = 0;
5719 return vm_unmapped_area(&info);
5720 }
5721
5722 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5723 index 4efe96a..60e8699 100644
5724 --- a/arch/microblaze/include/asm/cache.h
5725 +++ b/arch/microblaze/include/asm/cache.h
5726 @@ -13,11 +13,12 @@
5727 #ifndef _ASM_MICROBLAZE_CACHE_H
5728 #define _ASM_MICROBLAZE_CACHE_H
5729
5730 +#include <linux/const.h>
5731 #include <asm/registers.h>
5732
5733 #define L1_CACHE_SHIFT 5
5734 /* word-granular cache in microblaze */
5735 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5736 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5737
5738 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5739
5740 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5741 index 9536ef9..9333776 100644
5742 --- a/arch/mips/Kconfig
5743 +++ b/arch/mips/Kconfig
5744 @@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5745
5746 config KEXEC
5747 bool "Kexec system call"
5748 + depends on !GRKERNSEC_KMEM
5749 help
5750 kexec is a system call that implements the ability to shutdown your
5751 current kernel, and to start another kernel. It is like a reboot
5752 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5753 index 02f2444..506969c 100644
5754 --- a/arch/mips/cavium-octeon/dma-octeon.c
5755 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5756 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5757 if (dma_release_from_coherent(dev, order, vaddr))
5758 return;
5759
5760 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5761 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5762 }
5763
5764 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5765 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5766 index 6dd6bfc..903b0d6 100644
5767 --- a/arch/mips/include/asm/atomic.h
5768 +++ b/arch/mips/include/asm/atomic.h
5769 @@ -21,15 +21,39 @@
5770 #include <asm/cmpxchg.h>
5771 #include <asm/war.h>
5772
5773 +#ifdef CONFIG_GENERIC_ATOMIC64
5774 +#include <asm-generic/atomic64.h>
5775 +#endif
5776 +
5777 #define ATOMIC_INIT(i) { (i) }
5778
5779 +#ifdef CONFIG_64BIT
5780 +#define _ASM_EXTABLE(from, to) \
5781 +" .section __ex_table,\"a\"\n" \
5782 +" .dword " #from ", " #to"\n" \
5783 +" .previous\n"
5784 +#else
5785 +#define _ASM_EXTABLE(from, to) \
5786 +" .section __ex_table,\"a\"\n" \
5787 +" .word " #from ", " #to"\n" \
5788 +" .previous\n"
5789 +#endif
5790 +
5791 /*
5792 * atomic_read - read atomic variable
5793 * @v: pointer of type atomic_t
5794 *
5795 * Atomically reads the value of @v.
5796 */
5797 -#define atomic_read(v) ACCESS_ONCE((v)->counter)
5798 +static inline int atomic_read(const atomic_t *v)
5799 +{
5800 + return ACCESS_ONCE(v->counter);
5801 +}
5802 +
5803 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5804 +{
5805 + return ACCESS_ONCE(v->counter);
5806 +}
5807
5808 /*
5809 * atomic_set - set atomic variable
5810 @@ -38,47 +62,77 @@
5811 *
5812 * Atomically sets the value of @v to @i.
5813 */
5814 -#define atomic_set(v, i) ((v)->counter = (i))
5815 +static inline void atomic_set(atomic_t *v, int i)
5816 +{
5817 + v->counter = i;
5818 +}
5819
5820 -#define ATOMIC_OP(op, c_op, asm_op) \
5821 -static __inline__ void atomic_##op(int i, atomic_t * v) \
5822 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5823 +{
5824 + v->counter = i;
5825 +}
5826 +
5827 +#ifdef CONFIG_PAX_REFCOUNT
5828 +#define __OVERFLOW_POST \
5829 + " b 4f \n" \
5830 + " .set noreorder \n" \
5831 + "3: b 5f \n" \
5832 + " move %0, %1 \n" \
5833 + " .set reorder \n"
5834 +#define __OVERFLOW_EXTABLE \
5835 + "3:\n" \
5836 + _ASM_EXTABLE(2b, 3b)
5837 +#else
5838 +#define __OVERFLOW_POST
5839 +#define __OVERFLOW_EXTABLE
5840 +#endif
5841 +
5842 +#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5843 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5844 { \
5845 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5846 int temp; \
5847 \
5848 __asm__ __volatile__( \
5849 - " .set arch=r4000 \n" \
5850 - "1: ll %0, %1 # atomic_" #op " \n" \
5851 - " " #asm_op " %0, %2 \n" \
5852 + " .set mips3 \n" \
5853 + "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5854 + "2: " #asm_op " %0, %2 \n" \
5855 " sc %0, %1 \n" \
5856 " beqzl %0, 1b \n" \
5857 + extable \
5858 " .set mips0 \n" \
5859 : "=&r" (temp), "+m" (v->counter) \
5860 : "Ir" (i)); \
5861 } else if (kernel_uses_llsc) { \
5862 int temp; \
5863 \
5864 - do { \
5865 - __asm__ __volatile__( \
5866 - " .set arch=r4000 \n" \
5867 - " ll %0, %1 # atomic_" #op "\n" \
5868 - " " #asm_op " %0, %2 \n" \
5869 - " sc %0, %1 \n" \
5870 - " .set mips0 \n" \
5871 - : "=&r" (temp), "+m" (v->counter) \
5872 - : "Ir" (i)); \
5873 - } while (unlikely(!temp)); \
5874 + __asm__ __volatile__( \
5875 + " .set mips3 \n" \
5876 + " ll %0, %1 # atomic_" #op #suffix "\n" \
5877 + "2: " #asm_op " %0, %2 \n" \
5878 + " sc %0, %1 \n" \
5879 + " beqz %0, 1b \n" \
5880 + extable \
5881 + " .set mips0 \n" \
5882 + : "=&r" (temp), "+m" (v->counter) \
5883 + : "Ir" (i)); \
5884 } else { \
5885 unsigned long flags; \
5886 \
5887 raw_local_irq_save(flags); \
5888 - v->counter c_op i; \
5889 + __asm__ __volatile__( \
5890 + "2: " #asm_op " %0, %1 \n" \
5891 + extable \
5892 + : "+r" (v->counter) : "Ir" (i)); \
5893 raw_local_irq_restore(flags); \
5894 } \
5895 } \
5896
5897 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5898 -static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5899 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5900 + __ATOMIC_OP(op, _unchecked, asm_op)
5901 +
5902 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5903 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5904 { \
5905 int result; \
5906 \
5907 @@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5908 int temp; \
5909 \
5910 __asm__ __volatile__( \
5911 - " .set arch=r4000 \n" \
5912 - "1: ll %1, %2 # atomic_" #op "_return \n" \
5913 - " " #asm_op " %0, %1, %3 \n" \
5914 + " .set mips3 \n" \
5915 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5916 + "2: " #asm_op " %0, %1, %3 \n" \
5917 " sc %0, %2 \n" \
5918 " beqzl %0, 1b \n" \
5919 - " " #asm_op " %0, %1, %3 \n" \
5920 + post_op \
5921 + extable \
5922 + "4: " #asm_op " %0, %1, %3 \n" \
5923 + "5: \n" \
5924 " .set mips0 \n" \
5925 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5926 : "Ir" (i)); \
5927 } else if (kernel_uses_llsc) { \
5928 int temp; \
5929 \
5930 - do { \
5931 - __asm__ __volatile__( \
5932 - " .set arch=r4000 \n" \
5933 - " ll %1, %2 # atomic_" #op "_return \n" \
5934 - " " #asm_op " %0, %1, %3 \n" \
5935 - " sc %0, %2 \n" \
5936 - " .set mips0 \n" \
5937 - : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5938 - : "Ir" (i)); \
5939 - } while (unlikely(!result)); \
5940 + __asm__ __volatile__( \
5941 + " .set mips3 \n" \
5942 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5943 + "2: " #asm_op " %0, %1, %3 \n" \
5944 + " sc %0, %2 \n" \
5945 + " beqz %0, 1b \n" \
5946 + post_op \
5947 + extable \
5948 + "4: " #asm_op " %0, %1, %3 \n" \
5949 + "5: \n" \
5950 + " .set mips0 \n" \
5951 + : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5952 + : "Ir" (i)); \
5953 \
5954 result = temp; result c_op i; \
5955 } else { \
5956 unsigned long flags; \
5957 \
5958 raw_local_irq_save(flags); \
5959 - result = v->counter; \
5960 - result c_op i; \
5961 - v->counter = result; \
5962 + __asm__ __volatile__( \
5963 + " lw %0, %1 \n" \
5964 + "2: " #asm_op " %0, %1, %2 \n" \
5965 + " sw %0, %1 \n" \
5966 + "3: \n" \
5967 + extable \
5968 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5969 raw_local_irq_restore(flags); \
5970 } \
5971 \
5972 @@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5973 return result; \
5974 }
5975
5976 -#define ATOMIC_OPS(op, c_op, asm_op) \
5977 - ATOMIC_OP(op, c_op, asm_op) \
5978 - ATOMIC_OP_RETURN(op, c_op, asm_op)
5979 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5980 + __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5981
5982 -ATOMIC_OPS(add, +=, addu)
5983 -ATOMIC_OPS(sub, -=, subu)
5984 +#define ATOMIC_OPS(op, asm_op) \
5985 + ATOMIC_OP(op, asm_op) \
5986 + ATOMIC_OP_RETURN(op, asm_op)
5987 +
5988 +ATOMIC_OPS(add, add)
5989 +ATOMIC_OPS(sub, sub)
5990
5991 #undef ATOMIC_OPS
5992 #undef ATOMIC_OP_RETURN
5993 +#undef __ATOMIC_OP_RETURN
5994 #undef ATOMIC_OP
5995 +#undef __ATOMIC_OP
5996
5997 /*
5998 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5999 @@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
6000 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6001 * The function returns the old value of @v minus @i.
6002 */
6003 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6004 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6005 {
6006 int result;
6007
6008 @@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6009 return result;
6010 }
6011
6012 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6013 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6014 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6015 +{
6016 + return cmpxchg(&v->counter, old, new);
6017 +}
6018 +
6019 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6020 + int new)
6021 +{
6022 + return cmpxchg(&(v->counter), old, new);
6023 +}
6024 +
6025 +static inline int atomic_xchg(atomic_t *v, int new)
6026 +{
6027 + return xchg(&v->counter, new);
6028 +}
6029 +
6030 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6031 +{
6032 + return xchg(&(v->counter), new);
6033 +}
6034
6035 /**
6036 * __atomic_add_unless - add unless the number is a given value
6037 @@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6038
6039 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6040 #define atomic_inc_return(v) atomic_add_return(1, (v))
6041 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6042 +{
6043 + return atomic_add_return_unchecked(1, v);
6044 +}
6045
6046 /*
6047 * atomic_sub_and_test - subtract value from variable and test result
6048 @@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6049 * other cases.
6050 */
6051 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6052 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6053 +{
6054 + return atomic_add_return_unchecked(1, v) == 0;
6055 +}
6056
6057 /*
6058 * atomic_dec_and_test - decrement by 1 and test
6059 @@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6060 * Atomically increments @v by 1.
6061 */
6062 #define atomic_inc(v) atomic_add(1, (v))
6063 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6064 +{
6065 + atomic_add_unchecked(1, v);
6066 +}
6067
6068 /*
6069 * atomic_dec - decrement and test
6070 @@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6071 * Atomically decrements @v by 1.
6072 */
6073 #define atomic_dec(v) atomic_sub(1, (v))
6074 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6075 +{
6076 + atomic_sub_unchecked(1, v);
6077 +}
6078
6079 /*
6080 * atomic_add_negative - add and test if negative
6081 @@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6082 * @v: pointer of type atomic64_t
6083 *
6084 */
6085 -#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6086 +static inline long atomic64_read(const atomic64_t *v)
6087 +{
6088 + return ACCESS_ONCE(v->counter);
6089 +}
6090 +
6091 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6092 +{
6093 + return ACCESS_ONCE(v->counter);
6094 +}
6095
6096 /*
6097 * atomic64_set - set atomic variable
6098 * @v: pointer of type atomic64_t
6099 * @i: required value
6100 */
6101 -#define atomic64_set(v, i) ((v)->counter = (i))
6102 +static inline void atomic64_set(atomic64_t *v, long i)
6103 +{
6104 + v->counter = i;
6105 +}
6106
6107 -#define ATOMIC64_OP(op, c_op, asm_op) \
6108 -static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6109 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6110 +{
6111 + v->counter = i;
6112 +}
6113 +
6114 +#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6115 +static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6116 { \
6117 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6118 long temp; \
6119 \
6120 __asm__ __volatile__( \
6121 - " .set arch=r4000 \n" \
6122 - "1: lld %0, %1 # atomic64_" #op " \n" \
6123 - " " #asm_op " %0, %2 \n" \
6124 + " .set mips3 \n" \
6125 + "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6126 + "2: " #asm_op " %0, %2 \n" \
6127 " scd %0, %1 \n" \
6128 " beqzl %0, 1b \n" \
6129 + extable \
6130 " .set mips0 \n" \
6131 : "=&r" (temp), "+m" (v->counter) \
6132 : "Ir" (i)); \
6133 } else if (kernel_uses_llsc) { \
6134 long temp; \
6135 \
6136 - do { \
6137 - __asm__ __volatile__( \
6138 - " .set arch=r4000 \n" \
6139 - " lld %0, %1 # atomic64_" #op "\n" \
6140 - " " #asm_op " %0, %2 \n" \
6141 - " scd %0, %1 \n" \
6142 - " .set mips0 \n" \
6143 - : "=&r" (temp), "+m" (v->counter) \
6144 - : "Ir" (i)); \
6145 - } while (unlikely(!temp)); \
6146 + __asm__ __volatile__( \
6147 + " .set mips3 \n" \
6148 + " lld %0, %1 # atomic64_" #op #suffix "\n" \
6149 + "2: " #asm_op " %0, %2 \n" \
6150 + " scd %0, %1 \n" \
6151 + " beqz %0, 1b \n" \
6152 + extable \
6153 + " .set mips0 \n" \
6154 + : "=&r" (temp), "+m" (v->counter) \
6155 + : "Ir" (i)); \
6156 } else { \
6157 unsigned long flags; \
6158 \
6159 raw_local_irq_save(flags); \
6160 - v->counter c_op i; \
6161 + __asm__ __volatile__( \
6162 + "2: " #asm_op " %0, %1 \n" \
6163 + extable \
6164 + : "+r" (v->counter) : "Ir" (i)); \
6165 raw_local_irq_restore(flags); \
6166 } \
6167 } \
6168
6169 -#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6170 -static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6171 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6172 + __ATOMIC64_OP(op, _unchecked, asm_op)
6173 +
6174 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6175 +static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6176 { \
6177 long result; \
6178 \
6179 @@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6180 long temp; \
6181 \
6182 __asm__ __volatile__( \
6183 - " .set arch=r4000 \n" \
6184 + " .set mips3 \n" \
6185 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6186 - " " #asm_op " %0, %1, %3 \n" \
6187 + "2: " #asm_op " %0, %1, %3 \n" \
6188 " scd %0, %2 \n" \
6189 " beqzl %0, 1b \n" \
6190 - " " #asm_op " %0, %1, %3 \n" \
6191 + post_op \
6192 + extable \
6193 + "4: " #asm_op " %0, %1, %3 \n" \
6194 + "5: \n" \
6195 " .set mips0 \n" \
6196 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6197 : "Ir" (i)); \
6198 } else if (kernel_uses_llsc) { \
6199 long temp; \
6200 \
6201 - do { \
6202 - __asm__ __volatile__( \
6203 - " .set arch=r4000 \n" \
6204 - " lld %1, %2 # atomic64_" #op "_return\n" \
6205 - " " #asm_op " %0, %1, %3 \n" \
6206 - " scd %0, %2 \n" \
6207 - " .set mips0 \n" \
6208 - : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6209 - : "Ir" (i), "m" (v->counter) \
6210 - : "memory"); \
6211 - } while (unlikely(!result)); \
6212 + __asm__ __volatile__( \
6213 + " .set mips3 \n" \
6214 + "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6215 + "2: " #asm_op " %0, %1, %3 \n" \
6216 + " scd %0, %2 \n" \
6217 + " beqz %0, 1b \n" \
6218 + post_op \
6219 + extable \
6220 + "4: " #asm_op " %0, %1, %3 \n" \
6221 + "5: \n" \
6222 + " .set mips0 \n" \
6223 + : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6224 + : "Ir" (i), "m" (v->counter) \
6225 + : "memory"); \
6226 \
6227 result = temp; result c_op i; \
6228 } else { \
6229 unsigned long flags; \
6230 \
6231 raw_local_irq_save(flags); \
6232 - result = v->counter; \
6233 - result c_op i; \
6234 - v->counter = result; \
6235 + __asm__ __volatile__( \
6236 + " ld %0, %1 \n" \
6237 + "2: " #asm_op " %0, %1, %2 \n" \
6238 + " sd %0, %1 \n" \
6239 + "3: \n" \
6240 + extable \
6241 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6242 raw_local_irq_restore(flags); \
6243 } \
6244 \
6245 @@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6246 return result; \
6247 }
6248
6249 -#define ATOMIC64_OPS(op, c_op, asm_op) \
6250 - ATOMIC64_OP(op, c_op, asm_op) \
6251 - ATOMIC64_OP_RETURN(op, c_op, asm_op)
6252 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6253 + __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6254
6255 -ATOMIC64_OPS(add, +=, daddu)
6256 -ATOMIC64_OPS(sub, -=, dsubu)
6257 +#define ATOMIC64_OPS(op, asm_op) \
6258 + ATOMIC64_OP(op, asm_op) \
6259 + ATOMIC64_OP_RETURN(op, asm_op)
6260 +
6261 +ATOMIC64_OPS(add, dadd)
6262 +ATOMIC64_OPS(sub, dsub)
6263
6264 #undef ATOMIC64_OPS
6265 #undef ATOMIC64_OP_RETURN
6266 +#undef __ATOMIC64_OP_RETURN
6267 #undef ATOMIC64_OP
6268 +#undef __ATOMIC64_OP
6269 +#undef __OVERFLOW_EXTABLE
6270 +#undef __OVERFLOW_POST
6271
6272 /*
6273 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6274 @@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6275 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6276 * The function returns the old value of @v minus @i.
6277 */
6278 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6279 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6280 {
6281 long result;
6282
6283 @@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6284 return result;
6285 }
6286
6287 -#define atomic64_cmpxchg(v, o, n) \
6288 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6289 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6290 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6291 +{
6292 + return cmpxchg(&v->counter, old, new);
6293 +}
6294 +
6295 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6296 + long new)
6297 +{
6298 + return cmpxchg(&(v->counter), old, new);
6299 +}
6300 +
6301 +static inline long atomic64_xchg(atomic64_t *v, long new)
6302 +{
6303 + return xchg(&v->counter, new);
6304 +}
6305 +
6306 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6307 +{
6308 + return xchg(&(v->counter), new);
6309 +}
6310
6311 /**
6312 * atomic64_add_unless - add unless the number is a given value
6313 @@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6314
6315 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6316 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6317 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6318
6319 /*
6320 * atomic64_sub_and_test - subtract value from variable and test result
6321 @@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6322 * other cases.
6323 */
6324 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6325 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6326
6327 /*
6328 * atomic64_dec_and_test - decrement by 1 and test
6329 @@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6330 * Atomically increments @v by 1.
6331 */
6332 #define atomic64_inc(v) atomic64_add(1, (v))
6333 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6334
6335 /*
6336 * atomic64_dec - decrement and test
6337 @@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6338 * Atomically decrements @v by 1.
6339 */
6340 #define atomic64_dec(v) atomic64_sub(1, (v))
6341 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6342
6343 /*
6344 * atomic64_add_negative - add and test if negative
6345 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6346 index d0101dd..266982c 100644
6347 --- a/arch/mips/include/asm/barrier.h
6348 +++ b/arch/mips/include/asm/barrier.h
6349 @@ -184,7 +184,7 @@
6350 do { \
6351 compiletime_assert_atomic_type(*p); \
6352 smp_mb(); \
6353 - ACCESS_ONCE(*p) = (v); \
6354 + ACCESS_ONCE_RW(*p) = (v); \
6355 } while (0)
6356
6357 #define smp_load_acquire(p) \
6358 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6359 index b4db69f..8f3b093 100644
6360 --- a/arch/mips/include/asm/cache.h
6361 +++ b/arch/mips/include/asm/cache.h
6362 @@ -9,10 +9,11 @@
6363 #ifndef _ASM_CACHE_H
6364 #define _ASM_CACHE_H
6365
6366 +#include <linux/const.h>
6367 #include <kmalloc.h>
6368
6369 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6370 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6371 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6372
6373 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6374 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6375 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6376 index 1d38fe0..9beabc9 100644
6377 --- a/arch/mips/include/asm/elf.h
6378 +++ b/arch/mips/include/asm/elf.h
6379 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6380 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6381 #endif
6382
6383 +#ifdef CONFIG_PAX_ASLR
6384 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6385 +
6386 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6387 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6388 +#endif
6389 +
6390 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6391 struct linux_binprm;
6392 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6393 int uses_interp);
6394
6395 -struct mm_struct;
6396 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6397 -#define arch_randomize_brk arch_randomize_brk
6398 -
6399 #endif /* _ASM_ELF_H */
6400 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6401 index c1f6afa..38cc6e9 100644
6402 --- a/arch/mips/include/asm/exec.h
6403 +++ b/arch/mips/include/asm/exec.h
6404 @@ -12,6 +12,6 @@
6405 #ifndef _ASM_EXEC_H
6406 #define _ASM_EXEC_H
6407
6408 -extern unsigned long arch_align_stack(unsigned long sp);
6409 +#define arch_align_stack(x) ((x) & ~0xfUL)
6410
6411 #endif /* _ASM_EXEC_H */
6412 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6413 index 9e8ef59..1139d6b 100644
6414 --- a/arch/mips/include/asm/hw_irq.h
6415 +++ b/arch/mips/include/asm/hw_irq.h
6416 @@ -10,7 +10,7 @@
6417
6418 #include <linux/atomic.h>
6419
6420 -extern atomic_t irq_err_count;
6421 +extern atomic_unchecked_t irq_err_count;
6422
6423 /*
6424 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6425 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6426 index 46dfc3c..a16b13a 100644
6427 --- a/arch/mips/include/asm/local.h
6428 +++ b/arch/mips/include/asm/local.h
6429 @@ -12,15 +12,25 @@ typedef struct
6430 atomic_long_t a;
6431 } local_t;
6432
6433 +typedef struct {
6434 + atomic_long_unchecked_t a;
6435 +} local_unchecked_t;
6436 +
6437 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6438
6439 #define local_read(l) atomic_long_read(&(l)->a)
6440 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6441 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6442 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6443
6444 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6445 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6446 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6447 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6448 #define local_inc(l) atomic_long_inc(&(l)->a)
6449 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6450 #define local_dec(l) atomic_long_dec(&(l)->a)
6451 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6452
6453 /*
6454 * Same as above, but return the result value
6455 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6456 return result;
6457 }
6458
6459 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6460 +{
6461 + unsigned long result;
6462 +
6463 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6464 + unsigned long temp;
6465 +
6466 + __asm__ __volatile__(
6467 + " .set mips3 \n"
6468 + "1:" __LL "%1, %2 # local_add_return \n"
6469 + " addu %0, %1, %3 \n"
6470 + __SC "%0, %2 \n"
6471 + " beqzl %0, 1b \n"
6472 + " addu %0, %1, %3 \n"
6473 + " .set mips0 \n"
6474 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6475 + : "Ir" (i), "m" (l->a.counter)
6476 + : "memory");
6477 + } else if (kernel_uses_llsc) {
6478 + unsigned long temp;
6479 +
6480 + __asm__ __volatile__(
6481 + " .set mips3 \n"
6482 + "1:" __LL "%1, %2 # local_add_return \n"
6483 + " addu %0, %1, %3 \n"
6484 + __SC "%0, %2 \n"
6485 + " beqz %0, 1b \n"
6486 + " addu %0, %1, %3 \n"
6487 + " .set mips0 \n"
6488 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6489 + : "Ir" (i), "m" (l->a.counter)
6490 + : "memory");
6491 + } else {
6492 + unsigned long flags;
6493 +
6494 + local_irq_save(flags);
6495 + result = l->a.counter;
6496 + result += i;
6497 + l->a.counter = result;
6498 + local_irq_restore(flags);
6499 + }
6500 +
6501 + return result;
6502 +}
6503 +
6504 static __inline__ long local_sub_return(long i, local_t * l)
6505 {
6506 unsigned long result;
6507 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6508
6509 #define local_cmpxchg(l, o, n) \
6510 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6511 +#define local_cmpxchg_unchecked(l, o, n) \
6512 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6513 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6514
6515 /**
6516 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6517 index 3be8180..c4798d5 100644
6518 --- a/arch/mips/include/asm/page.h
6519 +++ b/arch/mips/include/asm/page.h
6520 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6521 #ifdef CONFIG_CPU_MIPS32
6522 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6523 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6524 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6525 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6526 #else
6527 typedef struct { unsigned long long pte; } pte_t;
6528 #define pte_val(x) ((x).pte)
6529 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6530 index b336037..5b874cc 100644
6531 --- a/arch/mips/include/asm/pgalloc.h
6532 +++ b/arch/mips/include/asm/pgalloc.h
6533 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6534 {
6535 set_pud(pud, __pud((unsigned long)pmd));
6536 }
6537 +
6538 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6539 +{
6540 + pud_populate(mm, pud, pmd);
6541 +}
6542 #endif
6543
6544 /*
6545 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6546 index d6d1928..ce4f822 100644
6547 --- a/arch/mips/include/asm/pgtable.h
6548 +++ b/arch/mips/include/asm/pgtable.h
6549 @@ -20,6 +20,9 @@
6550 #include <asm/io.h>
6551 #include <asm/pgtable-bits.h>
6552
6553 +#define ktla_ktva(addr) (addr)
6554 +#define ktva_ktla(addr) (addr)
6555 +
6556 struct mm_struct;
6557 struct vm_area_struct;
6558
6559 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6560 index 7de8658..c109224 100644
6561 --- a/arch/mips/include/asm/thread_info.h
6562 +++ b/arch/mips/include/asm/thread_info.h
6563 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6564 #define TIF_SECCOMP 4 /* secure computing */
6565 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6566 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6567 +/* li takes a 32bit immediate */
6568 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6569 +
6570 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6571 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6572 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6573 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6574 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6575 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6576 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6577 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6578
6579 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6580 _TIF_SYSCALL_AUDIT | \
6581 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6582 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6583 + _TIF_GRSEC_SETXID)
6584
6585 /* work to do in syscall_trace_leave() */
6586 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6587 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6588 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6589
6590 /* work to do on interrupt/exception return */
6591 #define _TIF_WORK_MASK \
6592 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6593 /* work to do on any return to u-space */
6594 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6595 _TIF_WORK_SYSCALL_EXIT | \
6596 - _TIF_SYSCALL_TRACEPOINT)
6597 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6598
6599 /*
6600 * We stash processor id into a COP0 register to retrieve it fast
6601 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6602 index 22a5624..7c96295 100644
6603 --- a/arch/mips/include/asm/uaccess.h
6604 +++ b/arch/mips/include/asm/uaccess.h
6605 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6606 __ok == 0; \
6607 })
6608
6609 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6610 #define access_ok(type, addr, size) \
6611 likely(__access_ok((addr), (size), __access_mask))
6612
6613 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6614 index 1188e00..41cf144 100644
6615 --- a/arch/mips/kernel/binfmt_elfn32.c
6616 +++ b/arch/mips/kernel/binfmt_elfn32.c
6617 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6618 #undef ELF_ET_DYN_BASE
6619 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6620
6621 +#ifdef CONFIG_PAX_ASLR
6622 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6623 +
6624 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6625 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6626 +#endif
6627 +
6628 #include <asm/processor.h>
6629 #include <linux/module.h>
6630 #include <linux/elfcore.h>
6631 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6632 index 9287678..f870e47 100644
6633 --- a/arch/mips/kernel/binfmt_elfo32.c
6634 +++ b/arch/mips/kernel/binfmt_elfo32.c
6635 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6636 #undef ELF_ET_DYN_BASE
6637 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6638
6639 +#ifdef CONFIG_PAX_ASLR
6640 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6641 +
6642 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6643 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6644 +#endif
6645 +
6646 #include <asm/processor.h>
6647
6648 #include <linux/module.h>
6649 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6650 index 50b3648..c2f3cec 100644
6651 --- a/arch/mips/kernel/i8259.c
6652 +++ b/arch/mips/kernel/i8259.c
6653 @@ -201,7 +201,7 @@ spurious_8259A_irq:
6654 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6655 spurious_irq_mask |= irqmask;
6656 }
6657 - atomic_inc(&irq_err_count);
6658 + atomic_inc_unchecked(&irq_err_count);
6659 /*
6660 * Theoretically we do not have to handle this IRQ,
6661 * but in Linux this does not cause problems and is
6662 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6663 index 44a1f79..2bd6aa3 100644
6664 --- a/arch/mips/kernel/irq-gt641xx.c
6665 +++ b/arch/mips/kernel/irq-gt641xx.c
6666 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6667 }
6668 }
6669
6670 - atomic_inc(&irq_err_count);
6671 + atomic_inc_unchecked(&irq_err_count);
6672 }
6673
6674 void __init gt641xx_irq_init(void)
6675 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6676 index d2bfbc2..a8eacd2 100644
6677 --- a/arch/mips/kernel/irq.c
6678 +++ b/arch/mips/kernel/irq.c
6679 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6680 printk("unexpected IRQ # %d\n", irq);
6681 }
6682
6683 -atomic_t irq_err_count;
6684 +atomic_unchecked_t irq_err_count;
6685
6686 int arch_show_interrupts(struct seq_file *p, int prec)
6687 {
6688 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6689 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6690 return 0;
6691 }
6692
6693 asmlinkage void spurious_interrupt(void)
6694 {
6695 - atomic_inc(&irq_err_count);
6696 + atomic_inc_unchecked(&irq_err_count);
6697 }
6698
6699 void __init init_IRQ(void)
6700 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
6701 #endif
6702 }
6703
6704 +
6705 #ifdef DEBUG_STACKOVERFLOW
6706 +extern void gr_handle_kernel_exploit(void);
6707 +
6708 static inline void check_stack_overflow(void)
6709 {
6710 unsigned long sp;
6711 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6712 printk("do_IRQ: stack overflow: %ld\n",
6713 sp - sizeof(struct thread_info));
6714 dump_stack();
6715 + gr_handle_kernel_exploit();
6716 }
6717 }
6718 #else
6719 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6720 index 0614717..002fa43 100644
6721 --- a/arch/mips/kernel/pm-cps.c
6722 +++ b/arch/mips/kernel/pm-cps.c
6723 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6724 nc_core_ready_count = nc_addr;
6725
6726 /* Ensure ready_count is zero-initialised before the assembly runs */
6727 - ACCESS_ONCE(*nc_core_ready_count) = 0;
6728 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6729 coupled_barrier(&per_cpu(pm_barrier, core), online);
6730
6731 /* Run the generated entry code */
6732 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6733 index 636b074..8fbb91f 100644
6734 --- a/arch/mips/kernel/process.c
6735 +++ b/arch/mips/kernel/process.c
6736 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6737 out:
6738 return pc;
6739 }
6740 -
6741 -/*
6742 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6743 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6744 - */
6745 -unsigned long arch_align_stack(unsigned long sp)
6746 -{
6747 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6748 - sp -= get_random_int() & ~PAGE_MASK;
6749 -
6750 - return sp & ALMASK;
6751 -}
6752 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6753 index 9d1487d..10c5da5 100644
6754 --- a/arch/mips/kernel/ptrace.c
6755 +++ b/arch/mips/kernel/ptrace.c
6756 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6757 return ret;
6758 }
6759
6760 +#ifdef CONFIG_GRKERNSEC_SETXID
6761 +extern void gr_delayed_cred_worker(void);
6762 +#endif
6763 +
6764 /*
6765 * Notification of system call entry/exit
6766 * - triggered by current->work.syscall_trace
6767 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6768 tracehook_report_syscall_entry(regs))
6769 ret = -1;
6770
6771 +#ifdef CONFIG_GRKERNSEC_SETXID
6772 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6773 + gr_delayed_cred_worker();
6774 +#endif
6775 +
6776 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6777 trace_sys_enter(regs, regs->regs[2]);
6778
6779 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6780 index 07fc524..b9d7f28 100644
6781 --- a/arch/mips/kernel/reset.c
6782 +++ b/arch/mips/kernel/reset.c
6783 @@ -13,6 +13,7 @@
6784 #include <linux/reboot.h>
6785
6786 #include <asm/reboot.h>
6787 +#include <asm/bug.h>
6788
6789 /*
6790 * Urgs ... Too many MIPS machines to handle this in a generic way.
6791 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6792 {
6793 if (_machine_restart)
6794 _machine_restart(command);
6795 + BUG();
6796 }
6797
6798 void machine_halt(void)
6799 {
6800 if (_machine_halt)
6801 _machine_halt();
6802 + BUG();
6803 }
6804
6805 void machine_power_off(void)
6806 {
6807 if (pm_power_off)
6808 pm_power_off();
6809 + BUG();
6810 }
6811 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6812 index 2242bdd..b284048 100644
6813 --- a/arch/mips/kernel/sync-r4k.c
6814 +++ b/arch/mips/kernel/sync-r4k.c
6815 @@ -18,8 +18,8 @@
6816 #include <asm/mipsregs.h>
6817
6818 static atomic_t count_start_flag = ATOMIC_INIT(0);
6819 -static atomic_t count_count_start = ATOMIC_INIT(0);
6820 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6821 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6822 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6823 static atomic_t count_reference = ATOMIC_INIT(0);
6824
6825 #define COUNTON 100
6826 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6827
6828 for (i = 0; i < NR_LOOPS; i++) {
6829 /* slaves loop on '!= 2' */
6830 - while (atomic_read(&count_count_start) != 1)
6831 + while (atomic_read_unchecked(&count_count_start) != 1)
6832 mb();
6833 - atomic_set(&count_count_stop, 0);
6834 + atomic_set_unchecked(&count_count_stop, 0);
6835 smp_wmb();
6836
6837 /* this lets the slaves write their count register */
6838 - atomic_inc(&count_count_start);
6839 + atomic_inc_unchecked(&count_count_start);
6840
6841 /*
6842 * Everyone initialises count in the last loop:
6843 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6844 /*
6845 * Wait for all slaves to leave the synchronization point:
6846 */
6847 - while (atomic_read(&count_count_stop) != 1)
6848 + while (atomic_read_unchecked(&count_count_stop) != 1)
6849 mb();
6850 - atomic_set(&count_count_start, 0);
6851 + atomic_set_unchecked(&count_count_start, 0);
6852 smp_wmb();
6853 - atomic_inc(&count_count_stop);
6854 + atomic_inc_unchecked(&count_count_stop);
6855 }
6856 /* Arrange for an interrupt in a short while */
6857 write_c0_compare(read_c0_count() + COUNTON);
6858 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6859 initcount = atomic_read(&count_reference);
6860
6861 for (i = 0; i < NR_LOOPS; i++) {
6862 - atomic_inc(&count_count_start);
6863 - while (atomic_read(&count_count_start) != 2)
6864 + atomic_inc_unchecked(&count_count_start);
6865 + while (atomic_read_unchecked(&count_count_start) != 2)
6866 mb();
6867
6868 /*
6869 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6870 if (i == NR_LOOPS-1)
6871 write_c0_count(initcount);
6872
6873 - atomic_inc(&count_count_stop);
6874 - while (atomic_read(&count_count_stop) != 2)
6875 + atomic_inc_unchecked(&count_count_stop);
6876 + while (atomic_read_unchecked(&count_count_stop) != 2)
6877 mb();
6878 }
6879 /* Arrange for an interrupt in a short while */
6880 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6881 index 22b19c2..c5cc8c4 100644
6882 --- a/arch/mips/kernel/traps.c
6883 +++ b/arch/mips/kernel/traps.c
6884 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6885 siginfo_t info;
6886
6887 prev_state = exception_enter();
6888 - die_if_kernel("Integer overflow", regs);
6889 + if (unlikely(!user_mode(regs))) {
6890 +
6891 +#ifdef CONFIG_PAX_REFCOUNT
6892 + if (fixup_exception(regs)) {
6893 + pax_report_refcount_overflow(regs);
6894 + exception_exit(prev_state);
6895 + return;
6896 + }
6897 +#endif
6898 +
6899 + die("Integer overflow", regs);
6900 + }
6901
6902 info.si_code = FPE_INTOVF;
6903 info.si_signo = SIGFPE;
6904 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6905 index e3b21e5..ea5ff7c 100644
6906 --- a/arch/mips/kvm/mips.c
6907 +++ b/arch/mips/kvm/mips.c
6908 @@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6909 return r;
6910 }
6911
6912 -int kvm_arch_init(void *opaque)
6913 +int kvm_arch_init(const void *opaque)
6914 {
6915 if (kvm_mips_callbacks) {
6916 kvm_err("kvm: module already exists\n");
6917 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6918 index becc42b..9e43d4b 100644
6919 --- a/arch/mips/mm/fault.c
6920 +++ b/arch/mips/mm/fault.c
6921 @@ -28,6 +28,23 @@
6922 #include <asm/highmem.h> /* For VMALLOC_END */
6923 #include <linux/kdebug.h>
6924
6925 +#ifdef CONFIG_PAX_PAGEEXEC
6926 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6927 +{
6928 + unsigned long i;
6929 +
6930 + printk(KERN_ERR "PAX: bytes at PC: ");
6931 + for (i = 0; i < 5; i++) {
6932 + unsigned int c;
6933 + if (get_user(c, (unsigned int *)pc+i))
6934 + printk(KERN_CONT "???????? ");
6935 + else
6936 + printk(KERN_CONT "%08x ", c);
6937 + }
6938 + printk("\n");
6939 +}
6940 +#endif
6941 +
6942 /*
6943 * This routine handles page faults. It determines the address,
6944 * and the problem, and then passes it off to one of the appropriate
6945 @@ -199,6 +216,14 @@ bad_area:
6946 bad_area_nosemaphore:
6947 /* User mode accesses just cause a SIGSEGV */
6948 if (user_mode(regs)) {
6949 +
6950 +#ifdef CONFIG_PAX_PAGEEXEC
6951 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6952 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6953 + do_group_exit(SIGKILL);
6954 + }
6955 +#endif
6956 +
6957 tsk->thread.cp0_badvaddr = address;
6958 tsk->thread.error_code = write;
6959 #if 0
6960 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6961 index f1baadd..5472dca 100644
6962 --- a/arch/mips/mm/mmap.c
6963 +++ b/arch/mips/mm/mmap.c
6964 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6965 struct vm_area_struct *vma;
6966 unsigned long addr = addr0;
6967 int do_color_align;
6968 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6969 struct vm_unmapped_area_info info;
6970
6971 if (unlikely(len > TASK_SIZE))
6972 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6973 do_color_align = 1;
6974
6975 /* requesting a specific address */
6976 +
6977 +#ifdef CONFIG_PAX_RANDMMAP
6978 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6979 +#endif
6980 +
6981 if (addr) {
6982 if (do_color_align)
6983 addr = COLOUR_ALIGN(addr, pgoff);
6984 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6985 addr = PAGE_ALIGN(addr);
6986
6987 vma = find_vma(mm, addr);
6988 - if (TASK_SIZE - len >= addr &&
6989 - (!vma || addr + len <= vma->vm_start))
6990 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6991 return addr;
6992 }
6993
6994 info.length = len;
6995 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6996 info.align_offset = pgoff << PAGE_SHIFT;
6997 + info.threadstack_offset = offset;
6998
6999 if (dir == DOWN) {
7000 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7001 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7002 {
7003 unsigned long random_factor = 0UL;
7004
7005 +#ifdef CONFIG_PAX_RANDMMAP
7006 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7007 +#endif
7008 +
7009 if (current->flags & PF_RANDOMIZE) {
7010 random_factor = get_random_int();
7011 random_factor = random_factor << PAGE_SHIFT;
7012 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7013
7014 if (mmap_is_legacy()) {
7015 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7016 +
7017 +#ifdef CONFIG_PAX_RANDMMAP
7018 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7019 + mm->mmap_base += mm->delta_mmap;
7020 +#endif
7021 +
7022 mm->get_unmapped_area = arch_get_unmapped_area;
7023 } else {
7024 mm->mmap_base = mmap_base(random_factor);
7025 +
7026 +#ifdef CONFIG_PAX_RANDMMAP
7027 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7028 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7029 +#endif
7030 +
7031 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7032 }
7033 }
7034
7035 -static inline unsigned long brk_rnd(void)
7036 -{
7037 - unsigned long rnd = get_random_int();
7038 -
7039 - rnd = rnd << PAGE_SHIFT;
7040 - /* 8MB for 32bit, 256MB for 64bit */
7041 - if (TASK_IS_32BIT_ADDR)
7042 - rnd = rnd & 0x7ffffful;
7043 - else
7044 - rnd = rnd & 0xffffffful;
7045 -
7046 - return rnd;
7047 -}
7048 -
7049 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7050 -{
7051 - unsigned long base = mm->brk;
7052 - unsigned long ret;
7053 -
7054 - ret = PAGE_ALIGN(base + brk_rnd());
7055 -
7056 - if (ret < mm->brk)
7057 - return mm->brk;
7058 -
7059 - return ret;
7060 -}
7061 -
7062 int __virt_addr_valid(const volatile void *kaddr)
7063 {
7064 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7065 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7066 index 59cccd9..f39ac2f 100644
7067 --- a/arch/mips/pci/pci-octeon.c
7068 +++ b/arch/mips/pci/pci-octeon.c
7069 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7070
7071
7072 static struct pci_ops octeon_pci_ops = {
7073 - octeon_read_config,
7074 - octeon_write_config,
7075 + .read = octeon_read_config,
7076 + .write = octeon_write_config,
7077 };
7078
7079 static struct resource octeon_pci_mem_resource = {
7080 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7081 index 5e36c33..eb4a17b 100644
7082 --- a/arch/mips/pci/pcie-octeon.c
7083 +++ b/arch/mips/pci/pcie-octeon.c
7084 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7085 }
7086
7087 static struct pci_ops octeon_pcie0_ops = {
7088 - octeon_pcie0_read_config,
7089 - octeon_pcie0_write_config,
7090 + .read = octeon_pcie0_read_config,
7091 + .write = octeon_pcie0_write_config,
7092 };
7093
7094 static struct resource octeon_pcie0_mem_resource = {
7095 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7096 };
7097
7098 static struct pci_ops octeon_pcie1_ops = {
7099 - octeon_pcie1_read_config,
7100 - octeon_pcie1_write_config,
7101 + .read = octeon_pcie1_read_config,
7102 + .write = octeon_pcie1_write_config,
7103 };
7104
7105 static struct resource octeon_pcie1_mem_resource = {
7106 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7107 };
7108
7109 static struct pci_ops octeon_dummy_ops = {
7110 - octeon_dummy_read_config,
7111 - octeon_dummy_write_config,
7112 + .read = octeon_dummy_read_config,
7113 + .write = octeon_dummy_write_config,
7114 };
7115
7116 static struct resource octeon_dummy_mem_resource = {
7117 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7118 index a2358b4..7cead4f 100644
7119 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7120 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7121 @@ -187,9 +187,9 @@ void
7122 cont_nmi_dump(void)
7123 {
7124 #ifndef REAL_NMI_SIGNAL
7125 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7126 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7127
7128 - atomic_inc(&nmied_cpus);
7129 + atomic_inc_unchecked(&nmied_cpus);
7130 #endif
7131 /*
7132 * Only allow 1 cpu to proceed
7133 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7134 udelay(10000);
7135 }
7136 #else
7137 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7138 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7139 #endif
7140
7141 /*
7142 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7143 index a046b30..6799527 100644
7144 --- a/arch/mips/sni/rm200.c
7145 +++ b/arch/mips/sni/rm200.c
7146 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7147 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7148 spurious_irq_mask |= irqmask;
7149 }
7150 - atomic_inc(&irq_err_count);
7151 + atomic_inc_unchecked(&irq_err_count);
7152 /*
7153 * Theoretically we do not have to handle this IRQ,
7154 * but in Linux this does not cause problems and is
7155 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7156 index 41e873b..34d33a7 100644
7157 --- a/arch/mips/vr41xx/common/icu.c
7158 +++ b/arch/mips/vr41xx/common/icu.c
7159 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7160
7161 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7162
7163 - atomic_inc(&irq_err_count);
7164 + atomic_inc_unchecked(&irq_err_count);
7165
7166 return -1;
7167 }
7168 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7169 index ae0e4ee..e8f0692 100644
7170 --- a/arch/mips/vr41xx/common/irq.c
7171 +++ b/arch/mips/vr41xx/common/irq.c
7172 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7173 irq_cascade_t *cascade;
7174
7175 if (irq >= NR_IRQS) {
7176 - atomic_inc(&irq_err_count);
7177 + atomic_inc_unchecked(&irq_err_count);
7178 return;
7179 }
7180
7181 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7182 ret = cascade->get_irq(irq);
7183 irq = ret;
7184 if (ret < 0)
7185 - atomic_inc(&irq_err_count);
7186 + atomic_inc_unchecked(&irq_err_count);
7187 else
7188 irq_dispatch(irq);
7189 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7190 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7191 index 967d144..db12197 100644
7192 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7193 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7194 @@ -11,12 +11,14 @@
7195 #ifndef _ASM_PROC_CACHE_H
7196 #define _ASM_PROC_CACHE_H
7197
7198 +#include <linux/const.h>
7199 +
7200 /* L1 cache */
7201
7202 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7203 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7204 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7205 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7206 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7207 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7208
7209 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7210 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7211 index bcb5df2..84fabd2 100644
7212 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7213 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7214 @@ -16,13 +16,15 @@
7215 #ifndef _ASM_PROC_CACHE_H
7216 #define _ASM_PROC_CACHE_H
7217
7218 +#include <linux/const.h>
7219 +
7220 /*
7221 * L1 cache
7222 */
7223 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7224 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7225 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7226 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7227 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7228 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7229
7230 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7231 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7232 index 4ce7a01..449202a 100644
7233 --- a/arch/openrisc/include/asm/cache.h
7234 +++ b/arch/openrisc/include/asm/cache.h
7235 @@ -19,11 +19,13 @@
7236 #ifndef __ASM_OPENRISC_CACHE_H
7237 #define __ASM_OPENRISC_CACHE_H
7238
7239 +#include <linux/const.h>
7240 +
7241 /* FIXME: How can we replace these with values from the CPU...
7242 * they shouldn't be hard-coded!
7243 */
7244
7245 -#define L1_CACHE_BYTES 16
7246 #define L1_CACHE_SHIFT 4
7247 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7248
7249 #endif /* __ASM_OPENRISC_CACHE_H */
7250 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7251 index 226f8ca..9d9b87d 100644
7252 --- a/arch/parisc/include/asm/atomic.h
7253 +++ b/arch/parisc/include/asm/atomic.h
7254 @@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7255 return dec;
7256 }
7257
7258 +#define atomic64_read_unchecked(v) atomic64_read(v)
7259 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7260 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7261 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7262 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7263 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7264 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7265 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7266 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7267 +
7268 #endif /* !CONFIG_64BIT */
7269
7270
7271 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7272 index 47f11c7..3420df2 100644
7273 --- a/arch/parisc/include/asm/cache.h
7274 +++ b/arch/parisc/include/asm/cache.h
7275 @@ -5,6 +5,7 @@
7276 #ifndef __ARCH_PARISC_CACHE_H
7277 #define __ARCH_PARISC_CACHE_H
7278
7279 +#include <linux/const.h>
7280
7281 /*
7282 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7283 @@ -15,13 +16,13 @@
7284 * just ruin performance.
7285 */
7286 #ifdef CONFIG_PA20
7287 -#define L1_CACHE_BYTES 64
7288 #define L1_CACHE_SHIFT 6
7289 #else
7290 -#define L1_CACHE_BYTES 32
7291 #define L1_CACHE_SHIFT 5
7292 #endif
7293
7294 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7295 +
7296 #ifndef __ASSEMBLY__
7297
7298 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7299 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7300 index 3391d06..c23a2cc 100644
7301 --- a/arch/parisc/include/asm/elf.h
7302 +++ b/arch/parisc/include/asm/elf.h
7303 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7304
7305 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7306
7307 +#ifdef CONFIG_PAX_ASLR
7308 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7309 +
7310 +#define PAX_DELTA_MMAP_LEN 16
7311 +#define PAX_DELTA_STACK_LEN 16
7312 +#endif
7313 +
7314 /* This yields a mask that user programs can use to figure out what
7315 instruction set this CPU supports. This could be done in user space,
7316 but it's not easy, and we've already done it here. */
7317 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7318 index f213f5b..0af3e8e 100644
7319 --- a/arch/parisc/include/asm/pgalloc.h
7320 +++ b/arch/parisc/include/asm/pgalloc.h
7321 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7322 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7323 }
7324
7325 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7326 +{
7327 + pgd_populate(mm, pgd, pmd);
7328 +}
7329 +
7330 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7331 {
7332 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7333 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7334 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7335 #define pmd_free(mm, x) do { } while (0)
7336 #define pgd_populate(mm, pmd, pte) BUG()
7337 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7338
7339 #endif
7340
7341 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7342 index 22b89d1..ce34230 100644
7343 --- a/arch/parisc/include/asm/pgtable.h
7344 +++ b/arch/parisc/include/asm/pgtable.h
7345 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7346 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7347 #define PAGE_COPY PAGE_EXECREAD
7348 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7349 +
7350 +#ifdef CONFIG_PAX_PAGEEXEC
7351 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7352 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7353 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7354 +#else
7355 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7356 +# define PAGE_COPY_NOEXEC PAGE_COPY
7357 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7358 +#endif
7359 +
7360 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7361 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7362 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7363 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7364 index a5cb070..8604ddc 100644
7365 --- a/arch/parisc/include/asm/uaccess.h
7366 +++ b/arch/parisc/include/asm/uaccess.h
7367 @@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7368 const void __user *from,
7369 unsigned long n)
7370 {
7371 - int sz = __compiletime_object_size(to);
7372 + size_t sz = __compiletime_object_size(to);
7373 int ret = -EFAULT;
7374
7375 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7376 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7377 ret = __copy_from_user(to, from, n);
7378 else
7379 copy_from_user_overflow();
7380 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7381 index 50dfafc..b9fc230 100644
7382 --- a/arch/parisc/kernel/module.c
7383 +++ b/arch/parisc/kernel/module.c
7384 @@ -98,16 +98,38 @@
7385
7386 /* three functions to determine where in the module core
7387 * or init pieces the location is */
7388 +static inline int in_init_rx(struct module *me, void *loc)
7389 +{
7390 + return (loc >= me->module_init_rx &&
7391 + loc < (me->module_init_rx + me->init_size_rx));
7392 +}
7393 +
7394 +static inline int in_init_rw(struct module *me, void *loc)
7395 +{
7396 + return (loc >= me->module_init_rw &&
7397 + loc < (me->module_init_rw + me->init_size_rw));
7398 +}
7399 +
7400 static inline int in_init(struct module *me, void *loc)
7401 {
7402 - return (loc >= me->module_init &&
7403 - loc <= (me->module_init + me->init_size));
7404 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7405 +}
7406 +
7407 +static inline int in_core_rx(struct module *me, void *loc)
7408 +{
7409 + return (loc >= me->module_core_rx &&
7410 + loc < (me->module_core_rx + me->core_size_rx));
7411 +}
7412 +
7413 +static inline int in_core_rw(struct module *me, void *loc)
7414 +{
7415 + return (loc >= me->module_core_rw &&
7416 + loc < (me->module_core_rw + me->core_size_rw));
7417 }
7418
7419 static inline int in_core(struct module *me, void *loc)
7420 {
7421 - return (loc >= me->module_core &&
7422 - loc <= (me->module_core + me->core_size));
7423 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7424 }
7425
7426 static inline int in_local(struct module *me, void *loc)
7427 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7428 }
7429
7430 /* align things a bit */
7431 - me->core_size = ALIGN(me->core_size, 16);
7432 - me->arch.got_offset = me->core_size;
7433 - me->core_size += gots * sizeof(struct got_entry);
7434 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7435 + me->arch.got_offset = me->core_size_rw;
7436 + me->core_size_rw += gots * sizeof(struct got_entry);
7437
7438 - me->core_size = ALIGN(me->core_size, 16);
7439 - me->arch.fdesc_offset = me->core_size;
7440 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7441 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7442 + me->arch.fdesc_offset = me->core_size_rw;
7443 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7444
7445 me->arch.got_max = gots;
7446 me->arch.fdesc_max = fdescs;
7447 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7448
7449 BUG_ON(value == 0);
7450
7451 - got = me->module_core + me->arch.got_offset;
7452 + got = me->module_core_rw + me->arch.got_offset;
7453 for (i = 0; got[i].addr; i++)
7454 if (got[i].addr == value)
7455 goto out;
7456 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7457 #ifdef CONFIG_64BIT
7458 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7459 {
7460 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7461 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7462
7463 if (!value) {
7464 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7465 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7466
7467 /* Create new one */
7468 fdesc->addr = value;
7469 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7470 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7471 return (Elf_Addr)fdesc;
7472 }
7473 #endif /* CONFIG_64BIT */
7474 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7475
7476 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7477 end = table + sechdrs[me->arch.unwind_section].sh_size;
7478 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7479 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7480
7481 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7482 me->arch.unwind_section, table, end, gp);
7483 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7484 index e1ffea2..46ed66e 100644
7485 --- a/arch/parisc/kernel/sys_parisc.c
7486 +++ b/arch/parisc/kernel/sys_parisc.c
7487 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7488 unsigned long task_size = TASK_SIZE;
7489 int do_color_align, last_mmap;
7490 struct vm_unmapped_area_info info;
7491 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7492
7493 if (len > task_size)
7494 return -ENOMEM;
7495 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7496 goto found_addr;
7497 }
7498
7499 +#ifdef CONFIG_PAX_RANDMMAP
7500 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7501 +#endif
7502 +
7503 if (addr) {
7504 if (do_color_align && last_mmap)
7505 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7506 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7507 info.high_limit = mmap_upper_limit();
7508 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7509 info.align_offset = shared_align_offset(last_mmap, pgoff);
7510 + info.threadstack_offset = offset;
7511 addr = vm_unmapped_area(&info);
7512
7513 found_addr:
7514 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7515 unsigned long addr = addr0;
7516 int do_color_align, last_mmap;
7517 struct vm_unmapped_area_info info;
7518 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7519
7520 #ifdef CONFIG_64BIT
7521 /* This should only ever run for 32-bit processes. */
7522 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7523 }
7524
7525 /* requesting a specific address */
7526 +#ifdef CONFIG_PAX_RANDMMAP
7527 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7528 +#endif
7529 +
7530 if (addr) {
7531 if (do_color_align && last_mmap)
7532 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7533 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7534 info.high_limit = mm->mmap_base;
7535 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7536 info.align_offset = shared_align_offset(last_mmap, pgoff);
7537 + info.threadstack_offset = offset;
7538 addr = vm_unmapped_area(&info);
7539 if (!(addr & ~PAGE_MASK))
7540 goto found_addr;
7541 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7542 mm->mmap_legacy_base = mmap_legacy_base();
7543 mm->mmap_base = mmap_upper_limit();
7544
7545 +#ifdef CONFIG_PAX_RANDMMAP
7546 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7547 + mm->mmap_legacy_base += mm->delta_mmap;
7548 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7549 + }
7550 +#endif
7551 +
7552 if (mmap_is_legacy()) {
7553 mm->mmap_base = mm->mmap_legacy_base;
7554 mm->get_unmapped_area = arch_get_unmapped_area;
7555 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7556 index 47ee620..1107387 100644
7557 --- a/arch/parisc/kernel/traps.c
7558 +++ b/arch/parisc/kernel/traps.c
7559 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7560
7561 down_read(&current->mm->mmap_sem);
7562 vma = find_vma(current->mm,regs->iaoq[0]);
7563 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7564 - && (vma->vm_flags & VM_EXEC)) {
7565 -
7566 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7567 fault_address = regs->iaoq[0];
7568 fault_space = regs->iasq[0];
7569
7570 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7571 index 3ca9c11..d163ef7 100644
7572 --- a/arch/parisc/mm/fault.c
7573 +++ b/arch/parisc/mm/fault.c
7574 @@ -15,6 +15,7 @@
7575 #include <linux/sched.h>
7576 #include <linux/interrupt.h>
7577 #include <linux/module.h>
7578 +#include <linux/unistd.h>
7579
7580 #include <asm/uaccess.h>
7581 #include <asm/traps.h>
7582 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7583 static unsigned long
7584 parisc_acctyp(unsigned long code, unsigned int inst)
7585 {
7586 - if (code == 6 || code == 16)
7587 + if (code == 6 || code == 7 || code == 16)
7588 return VM_EXEC;
7589
7590 switch (inst & 0xf0000000) {
7591 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7592 }
7593 #endif
7594
7595 +#ifdef CONFIG_PAX_PAGEEXEC
7596 +/*
7597 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7598 + *
7599 + * returns 1 when task should be killed
7600 + * 2 when rt_sigreturn trampoline was detected
7601 + * 3 when unpatched PLT trampoline was detected
7602 + */
7603 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7604 +{
7605 +
7606 +#ifdef CONFIG_PAX_EMUPLT
7607 + int err;
7608 +
7609 + do { /* PaX: unpatched PLT emulation */
7610 + unsigned int bl, depwi;
7611 +
7612 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7613 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7614 +
7615 + if (err)
7616 + break;
7617 +
7618 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7619 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7620 +
7621 + err = get_user(ldw, (unsigned int *)addr);
7622 + err |= get_user(bv, (unsigned int *)(addr+4));
7623 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7624 +
7625 + if (err)
7626 + break;
7627 +
7628 + if (ldw == 0x0E801096U &&
7629 + bv == 0xEAC0C000U &&
7630 + ldw2 == 0x0E881095U)
7631 + {
7632 + unsigned int resolver, map;
7633 +
7634 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7635 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7636 + if (err)
7637 + break;
7638 +
7639 + regs->gr[20] = instruction_pointer(regs)+8;
7640 + regs->gr[21] = map;
7641 + regs->gr[22] = resolver;
7642 + regs->iaoq[0] = resolver | 3UL;
7643 + regs->iaoq[1] = regs->iaoq[0] + 4;
7644 + return 3;
7645 + }
7646 + }
7647 + } while (0);
7648 +#endif
7649 +
7650 +#ifdef CONFIG_PAX_EMUTRAMP
7651 +
7652 +#ifndef CONFIG_PAX_EMUSIGRT
7653 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7654 + return 1;
7655 +#endif
7656 +
7657 + do { /* PaX: rt_sigreturn emulation */
7658 + unsigned int ldi1, ldi2, bel, nop;
7659 +
7660 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7661 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7662 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7663 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7664 +
7665 + if (err)
7666 + break;
7667 +
7668 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7669 + ldi2 == 0x3414015AU &&
7670 + bel == 0xE4008200U &&
7671 + nop == 0x08000240U)
7672 + {
7673 + regs->gr[25] = (ldi1 & 2) >> 1;
7674 + regs->gr[20] = __NR_rt_sigreturn;
7675 + regs->gr[31] = regs->iaoq[1] + 16;
7676 + regs->sr[0] = regs->iasq[1];
7677 + regs->iaoq[0] = 0x100UL;
7678 + regs->iaoq[1] = regs->iaoq[0] + 4;
7679 + regs->iasq[0] = regs->sr[2];
7680 + regs->iasq[1] = regs->sr[2];
7681 + return 2;
7682 + }
7683 + } while (0);
7684 +#endif
7685 +
7686 + return 1;
7687 +}
7688 +
7689 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7690 +{
7691 + unsigned long i;
7692 +
7693 + printk(KERN_ERR "PAX: bytes at PC: ");
7694 + for (i = 0; i < 5; i++) {
7695 + unsigned int c;
7696 + if (get_user(c, (unsigned int *)pc+i))
7697 + printk(KERN_CONT "???????? ");
7698 + else
7699 + printk(KERN_CONT "%08x ", c);
7700 + }
7701 + printk("\n");
7702 +}
7703 +#endif
7704 +
7705 int fixup_exception(struct pt_regs *regs)
7706 {
7707 const struct exception_table_entry *fix;
7708 @@ -234,8 +345,33 @@ retry:
7709
7710 good_area:
7711
7712 - if ((vma->vm_flags & acc_type) != acc_type)
7713 + if ((vma->vm_flags & acc_type) != acc_type) {
7714 +
7715 +#ifdef CONFIG_PAX_PAGEEXEC
7716 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7717 + (address & ~3UL) == instruction_pointer(regs))
7718 + {
7719 + up_read(&mm->mmap_sem);
7720 + switch (pax_handle_fetch_fault(regs)) {
7721 +
7722 +#ifdef CONFIG_PAX_EMUPLT
7723 + case 3:
7724 + return;
7725 +#endif
7726 +
7727 +#ifdef CONFIG_PAX_EMUTRAMP
7728 + case 2:
7729 + return;
7730 +#endif
7731 +
7732 + }
7733 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7734 + do_group_exit(SIGKILL);
7735 + }
7736 +#endif
7737 +
7738 goto bad_area;
7739 + }
7740
7741 /*
7742 * If for any reason at all we couldn't handle the fault, make
7743 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7744 index 88eace4..4ba2591 100644
7745 --- a/arch/powerpc/Kconfig
7746 +++ b/arch/powerpc/Kconfig
7747 @@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7748 config KEXEC
7749 bool "kexec system call"
7750 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7751 + depends on !GRKERNSEC_KMEM
7752 help
7753 kexec is a system call that implements the ability to shutdown your
7754 current kernel, and to start another kernel. It is like a reboot
7755 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7756 index 512d278..d31fadd 100644
7757 --- a/arch/powerpc/include/asm/atomic.h
7758 +++ b/arch/powerpc/include/asm/atomic.h
7759 @@ -12,6 +12,11 @@
7760
7761 #define ATOMIC_INIT(i) { (i) }
7762
7763 +#define _ASM_EXTABLE(from, to) \
7764 +" .section __ex_table,\"a\"\n" \
7765 + PPC_LONG" " #from ", " #to"\n" \
7766 +" .previous\n"
7767 +
7768 static __inline__ int atomic_read(const atomic_t *v)
7769 {
7770 int t;
7771 @@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7772 return t;
7773 }
7774
7775 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7776 +{
7777 + int t;
7778 +
7779 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7780 +
7781 + return t;
7782 +}
7783 +
7784 static __inline__ void atomic_set(atomic_t *v, int i)
7785 {
7786 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7787 }
7788
7789 -#define ATOMIC_OP(op, asm_op) \
7790 -static __inline__ void atomic_##op(int a, atomic_t *v) \
7791 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7792 +{
7793 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7794 +}
7795 +
7796 +#ifdef CONFIG_PAX_REFCOUNT
7797 +#define __REFCOUNT_OP(op) op##o.
7798 +#define __OVERFLOW_PRE \
7799 + " mcrxr cr0\n"
7800 +#define __OVERFLOW_POST \
7801 + " bf 4*cr0+so, 3f\n" \
7802 + "2: .long 0x00c00b00\n" \
7803 + "3:\n"
7804 +#define __OVERFLOW_EXTABLE \
7805 + "\n4:\n"
7806 + _ASM_EXTABLE(2b, 4b)
7807 +#else
7808 +#define __REFCOUNT_OP(op) op
7809 +#define __OVERFLOW_PRE
7810 +#define __OVERFLOW_POST
7811 +#define __OVERFLOW_EXTABLE
7812 +#endif
7813 +
7814 +#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7815 +static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7816 { \
7817 int t; \
7818 \
7819 __asm__ __volatile__( \
7820 -"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7821 +"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7822 + pre_op \
7823 #asm_op " %0,%2,%0\n" \
7824 + post_op \
7825 PPC405_ERR77(0,%3) \
7826 " stwcx. %0,0,%3 \n" \
7827 " bne- 1b\n" \
7828 + extable \
7829 : "=&r" (t), "+m" (v->counter) \
7830 : "r" (a), "r" (&v->counter) \
7831 : "cc"); \
7832 } \
7833
7834 -#define ATOMIC_OP_RETURN(op, asm_op) \
7835 -static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7836 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7837 + __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7838 +
7839 +#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7840 +static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7841 { \
7842 int t; \
7843 \
7844 __asm__ __volatile__( \
7845 PPC_ATOMIC_ENTRY_BARRIER \
7846 -"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7847 +"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7848 + pre_op \
7849 #asm_op " %0,%1,%0\n" \
7850 + post_op \
7851 PPC405_ERR77(0,%2) \
7852 " stwcx. %0,0,%2 \n" \
7853 " bne- 1b\n" \
7854 + extable \
7855 PPC_ATOMIC_EXIT_BARRIER \
7856 : "=&r" (t) \
7857 : "r" (a), "r" (&v->counter) \
7858 @@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7859 return t; \
7860 }
7861
7862 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7863 + __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7864 +
7865 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7866
7867 ATOMIC_OPS(add, add)
7868 @@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7869
7870 #undef ATOMIC_OPS
7871 #undef ATOMIC_OP_RETURN
7872 +#undef __ATOMIC_OP_RETURN
7873 #undef ATOMIC_OP
7874 +#undef __ATOMIC_OP
7875
7876 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7877
7878 -static __inline__ void atomic_inc(atomic_t *v)
7879 -{
7880 - int t;
7881 +/*
7882 + * atomic_inc - increment atomic variable
7883 + * @v: pointer of type atomic_t
7884 + *
7885 + * Automatically increments @v by 1
7886 + */
7887 +#define atomic_inc(v) atomic_add(1, (v))
7888 +#define atomic_inc_return(v) atomic_add_return(1, (v))
7889
7890 - __asm__ __volatile__(
7891 -"1: lwarx %0,0,%2 # atomic_inc\n\
7892 - addic %0,%0,1\n"
7893 - PPC405_ERR77(0,%2)
7894 -" stwcx. %0,0,%2 \n\
7895 - bne- 1b"
7896 - : "=&r" (t), "+m" (v->counter)
7897 - : "r" (&v->counter)
7898 - : "cc", "xer");
7899 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7900 +{
7901 + atomic_add_unchecked(1, v);
7902 }
7903
7904 -static __inline__ int atomic_inc_return(atomic_t *v)
7905 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7906 {
7907 - int t;
7908 -
7909 - __asm__ __volatile__(
7910 - PPC_ATOMIC_ENTRY_BARRIER
7911 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
7912 - addic %0,%0,1\n"
7913 - PPC405_ERR77(0,%1)
7914 -" stwcx. %0,0,%1 \n\
7915 - bne- 1b"
7916 - PPC_ATOMIC_EXIT_BARRIER
7917 - : "=&r" (t)
7918 - : "r" (&v->counter)
7919 - : "cc", "xer", "memory");
7920 -
7921 - return t;
7922 + return atomic_add_return_unchecked(1, v);
7923 }
7924
7925 /*
7926 @@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7927 */
7928 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7929
7930 -static __inline__ void atomic_dec(atomic_t *v)
7931 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7932 {
7933 - int t;
7934 -
7935 - __asm__ __volatile__(
7936 -"1: lwarx %0,0,%2 # atomic_dec\n\
7937 - addic %0,%0,-1\n"
7938 - PPC405_ERR77(0,%2)\
7939 -" stwcx. %0,0,%2\n\
7940 - bne- 1b"
7941 - : "=&r" (t), "+m" (v->counter)
7942 - : "r" (&v->counter)
7943 - : "cc", "xer");
7944 + return atomic_add_return_unchecked(1, v) == 0;
7945 }
7946
7947 -static __inline__ int atomic_dec_return(atomic_t *v)
7948 +/*
7949 + * atomic_dec - decrement atomic variable
7950 + * @v: pointer of type atomic_t
7951 + *
7952 + * Atomically decrements @v by 1
7953 + */
7954 +#define atomic_dec(v) atomic_sub(1, (v))
7955 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
7956 +
7957 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7958 {
7959 - int t;
7960 -
7961 - __asm__ __volatile__(
7962 - PPC_ATOMIC_ENTRY_BARRIER
7963 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
7964 - addic %0,%0,-1\n"
7965 - PPC405_ERR77(0,%1)
7966 -" stwcx. %0,0,%1\n\
7967 - bne- 1b"
7968 - PPC_ATOMIC_EXIT_BARRIER
7969 - : "=&r" (t)
7970 - : "r" (&v->counter)
7971 - : "cc", "xer", "memory");
7972 -
7973 - return t;
7974 + atomic_sub_unchecked(1, v);
7975 }
7976
7977 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7978 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7979
7980 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7981 +{
7982 + return cmpxchg(&(v->counter), old, new);
7983 +}
7984 +
7985 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7986 +{
7987 + return xchg(&(v->counter), new);
7988 +}
7989 +
7990 /**
7991 * __atomic_add_unless - add unless the number is a given value
7992 * @v: pointer of type atomic_t
7993 @@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7994 PPC_ATOMIC_ENTRY_BARRIER
7995 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7996 cmpw 0,%0,%3 \n\
7997 - beq- 2f \n\
7998 - add %0,%2,%0 \n"
7999 + beq- 2f \n"
8000 +
8001 +#ifdef CONFIG_PAX_REFCOUNT
8002 +" mcrxr cr0\n"
8003 +" addo. %0,%2,%0\n"
8004 +" bf 4*cr0+so, 4f\n"
8005 +"3:.long " "0x00c00b00""\n"
8006 +"4:\n"
8007 +#else
8008 + "add %0,%2,%0 \n"
8009 +#endif
8010 +
8011 PPC405_ERR77(0,%2)
8012 " stwcx. %0,0,%1 \n\
8013 bne- 1b \n"
8014 +"5:"
8015 +
8016 +#ifdef CONFIG_PAX_REFCOUNT
8017 + _ASM_EXTABLE(3b, 5b)
8018 +#endif
8019 +
8020 PPC_ATOMIC_EXIT_BARRIER
8021 " subf %0,%2,%0 \n\
8022 2:"
8023 @@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8024 }
8025 #define atomic_dec_if_positive atomic_dec_if_positive
8026
8027 +#define smp_mb__before_atomic_dec() smp_mb()
8028 +#define smp_mb__after_atomic_dec() smp_mb()
8029 +#define smp_mb__before_atomic_inc() smp_mb()
8030 +#define smp_mb__after_atomic_inc() smp_mb()
8031 +
8032 #ifdef __powerpc64__
8033
8034 #define ATOMIC64_INIT(i) { (i) }
8035 @@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8036 return t;
8037 }
8038
8039 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8040 +{
8041 + long t;
8042 +
8043 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8044 +
8045 + return t;
8046 +}
8047 +
8048 static __inline__ void atomic64_set(atomic64_t *v, long i)
8049 {
8050 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8051 }
8052
8053 -#define ATOMIC64_OP(op, asm_op) \
8054 -static __inline__ void atomic64_##op(long a, atomic64_t *v) \
8055 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8056 +{
8057 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8058 +}
8059 +
8060 +#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
8061 +static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
8062 { \
8063 long t; \
8064 \
8065 __asm__ __volatile__( \
8066 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
8067 + pre_op \
8068 #asm_op " %0,%2,%0\n" \
8069 + post_op \
8070 " stdcx. %0,0,%3 \n" \
8071 " bne- 1b\n" \
8072 + extable \
8073 : "=&r" (t), "+m" (v->counter) \
8074 : "r" (a), "r" (&v->counter) \
8075 : "cc"); \
8076 }
8077
8078 -#define ATOMIC64_OP_RETURN(op, asm_op) \
8079 -static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8080 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8081 + __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8082 +
8083 +#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8084 +static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8085 { \
8086 long t; \
8087 \
8088 __asm__ __volatile__( \
8089 PPC_ATOMIC_ENTRY_BARRIER \
8090 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8091 + pre_op \
8092 #asm_op " %0,%1,%0\n" \
8093 + post_op \
8094 " stdcx. %0,0,%2 \n" \
8095 " bne- 1b\n" \
8096 + extable \
8097 PPC_ATOMIC_EXIT_BARRIER \
8098 : "=&r" (t) \
8099 : "r" (a), "r" (&v->counter) \
8100 @@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8101 return t; \
8102 }
8103
8104 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8105 + __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8106 +
8107 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8108
8109 ATOMIC64_OPS(add, add)
8110 @@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8111
8112 #undef ATOMIC64_OPS
8113 #undef ATOMIC64_OP_RETURN
8114 +#undef __ATOMIC64_OP_RETURN
8115 #undef ATOMIC64_OP
8116 +#undef __ATOMIC64_OP
8117 +#undef __OVERFLOW_EXTABLE
8118 +#undef __OVERFLOW_POST
8119 +#undef __OVERFLOW_PRE
8120 +#undef __REFCOUNT_OP
8121
8122 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8123
8124 -static __inline__ void atomic64_inc(atomic64_t *v)
8125 -{
8126 - long t;
8127 +/*
8128 + * atomic64_inc - increment atomic variable
8129 + * @v: pointer of type atomic64_t
8130 + *
8131 + * Automatically increments @v by 1
8132 + */
8133 +#define atomic64_inc(v) atomic64_add(1, (v))
8134 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8135
8136 - __asm__ __volatile__(
8137 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8138 - addic %0,%0,1\n\
8139 - stdcx. %0,0,%2 \n\
8140 - bne- 1b"
8141 - : "=&r" (t), "+m" (v->counter)
8142 - : "r" (&v->counter)
8143 - : "cc", "xer");
8144 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8145 +{
8146 + atomic64_add_unchecked(1, v);
8147 }
8148
8149 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8150 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8151 {
8152 - long t;
8153 -
8154 - __asm__ __volatile__(
8155 - PPC_ATOMIC_ENTRY_BARRIER
8156 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8157 - addic %0,%0,1\n\
8158 - stdcx. %0,0,%1 \n\
8159 - bne- 1b"
8160 - PPC_ATOMIC_EXIT_BARRIER
8161 - : "=&r" (t)
8162 - : "r" (&v->counter)
8163 - : "cc", "xer", "memory");
8164 -
8165 - return t;
8166 + return atomic64_add_return_unchecked(1, v);
8167 }
8168
8169 /*
8170 @@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8171 */
8172 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8173
8174 -static __inline__ void atomic64_dec(atomic64_t *v)
8175 +/*
8176 + * atomic64_dec - decrement atomic variable
8177 + * @v: pointer of type atomic64_t
8178 + *
8179 + * Atomically decrements @v by 1
8180 + */
8181 +#define atomic64_dec(v) atomic64_sub(1, (v))
8182 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8183 +
8184 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8185 {
8186 - long t;
8187 -
8188 - __asm__ __volatile__(
8189 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8190 - addic %0,%0,-1\n\
8191 - stdcx. %0,0,%2\n\
8192 - bne- 1b"
8193 - : "=&r" (t), "+m" (v->counter)
8194 - : "r" (&v->counter)
8195 - : "cc", "xer");
8196 -}
8197 -
8198 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8199 -{
8200 - long t;
8201 -
8202 - __asm__ __volatile__(
8203 - PPC_ATOMIC_ENTRY_BARRIER
8204 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8205 - addic %0,%0,-1\n\
8206 - stdcx. %0,0,%1\n\
8207 - bne- 1b"
8208 - PPC_ATOMIC_EXIT_BARRIER
8209 - : "=&r" (t)
8210 - : "r" (&v->counter)
8211 - : "cc", "xer", "memory");
8212 -
8213 - return t;
8214 + atomic64_sub_unchecked(1, v);
8215 }
8216
8217 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8218 @@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8219 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8220 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8221
8222 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8223 +{
8224 + return cmpxchg(&(v->counter), old, new);
8225 +}
8226 +
8227 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8228 +{
8229 + return xchg(&(v->counter), new);
8230 +}
8231 +
8232 /**
8233 * atomic64_add_unless - add unless the number is a given value
8234 * @v: pointer of type atomic64_t
8235 @@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8236
8237 __asm__ __volatile__ (
8238 PPC_ATOMIC_ENTRY_BARRIER
8239 -"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8240 +"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8241 cmpd 0,%0,%3 \n\
8242 - beq- 2f \n\
8243 - add %0,%2,%0 \n"
8244 + beq- 2f \n"
8245 +
8246 +#ifdef CONFIG_PAX_REFCOUNT
8247 +" mcrxr cr0\n"
8248 +" addo. %0,%2,%0\n"
8249 +" bf 4*cr0+so, 4f\n"
8250 +"3:.long " "0x00c00b00""\n"
8251 +"4:\n"
8252 +#else
8253 + "add %0,%2,%0 \n"
8254 +#endif
8255 +
8256 " stdcx. %0,0,%1 \n\
8257 bne- 1b \n"
8258 PPC_ATOMIC_EXIT_BARRIER
8259 +"5:"
8260 +
8261 +#ifdef CONFIG_PAX_REFCOUNT
8262 + _ASM_EXTABLE(3b, 5b)
8263 +#endif
8264 +
8265 " subf %0,%2,%0 \n\
8266 2:"
8267 : "=&r" (t)
8268 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8269 index bab79a1..4a3eabc 100644
8270 --- a/arch/powerpc/include/asm/barrier.h
8271 +++ b/arch/powerpc/include/asm/barrier.h
8272 @@ -73,7 +73,7 @@
8273 do { \
8274 compiletime_assert_atomic_type(*p); \
8275 __lwsync(); \
8276 - ACCESS_ONCE(*p) = (v); \
8277 + ACCESS_ONCE_RW(*p) = (v); \
8278 } while (0)
8279
8280 #define smp_load_acquire(p) \
8281 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8282 index 34a05a1..a1f2c67 100644
8283 --- a/arch/powerpc/include/asm/cache.h
8284 +++ b/arch/powerpc/include/asm/cache.h
8285 @@ -4,6 +4,7 @@
8286 #ifdef __KERNEL__
8287
8288 #include <asm/reg.h>
8289 +#include <linux/const.h>
8290
8291 /* bytes per L1 cache line */
8292 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8293 @@ -23,7 +24,7 @@
8294 #define L1_CACHE_SHIFT 7
8295 #endif
8296
8297 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8298 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8299
8300 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8301
8302 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8303 index 888d8f3..66f581c 100644
8304 --- a/arch/powerpc/include/asm/elf.h
8305 +++ b/arch/powerpc/include/asm/elf.h
8306 @@ -28,8 +28,19 @@
8307 the loader. We need to make sure that it is out of the way of the program
8308 that it will "exec", and that there is sufficient room for the brk. */
8309
8310 -extern unsigned long randomize_et_dyn(unsigned long base);
8311 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8312 +#define ELF_ET_DYN_BASE (0x20000000)
8313 +
8314 +#ifdef CONFIG_PAX_ASLR
8315 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8316 +
8317 +#ifdef __powerpc64__
8318 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8319 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8320 +#else
8321 +#define PAX_DELTA_MMAP_LEN 15
8322 +#define PAX_DELTA_STACK_LEN 15
8323 +#endif
8324 +#endif
8325
8326 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8327
8328 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8329 (0x7ff >> (PAGE_SHIFT - 12)) : \
8330 (0x3ffff >> (PAGE_SHIFT - 12)))
8331
8332 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8333 -#define arch_randomize_brk arch_randomize_brk
8334 -
8335 -
8336 #ifdef CONFIG_SPU_BASE
8337 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8338 #define NT_SPU 1
8339 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8340 index 8196e9c..d83a9f3 100644
8341 --- a/arch/powerpc/include/asm/exec.h
8342 +++ b/arch/powerpc/include/asm/exec.h
8343 @@ -4,6 +4,6 @@
8344 #ifndef _ASM_POWERPC_EXEC_H
8345 #define _ASM_POWERPC_EXEC_H
8346
8347 -extern unsigned long arch_align_stack(unsigned long sp);
8348 +#define arch_align_stack(x) ((x) & ~0xfUL)
8349
8350 #endif /* _ASM_POWERPC_EXEC_H */
8351 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8352 index 5acabbd..7ea14fa 100644
8353 --- a/arch/powerpc/include/asm/kmap_types.h
8354 +++ b/arch/powerpc/include/asm/kmap_types.h
8355 @@ -10,7 +10,7 @@
8356 * 2 of the License, or (at your option) any later version.
8357 */
8358
8359 -#define KM_TYPE_NR 16
8360 +#define KM_TYPE_NR 17
8361
8362 #endif /* __KERNEL__ */
8363 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8364 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8365 index b8da913..c02b593 100644
8366 --- a/arch/powerpc/include/asm/local.h
8367 +++ b/arch/powerpc/include/asm/local.h
8368 @@ -9,21 +9,65 @@ typedef struct
8369 atomic_long_t a;
8370 } local_t;
8371
8372 +typedef struct
8373 +{
8374 + atomic_long_unchecked_t a;
8375 +} local_unchecked_t;
8376 +
8377 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8378
8379 #define local_read(l) atomic_long_read(&(l)->a)
8380 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8381 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8382 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8383
8384 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8385 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8386 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8387 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8388 #define local_inc(l) atomic_long_inc(&(l)->a)
8389 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8390 #define local_dec(l) atomic_long_dec(&(l)->a)
8391 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8392
8393 static __inline__ long local_add_return(long a, local_t *l)
8394 {
8395 long t;
8396
8397 __asm__ __volatile__(
8398 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8399 +
8400 +#ifdef CONFIG_PAX_REFCOUNT
8401 +" mcrxr cr0\n"
8402 +" addo. %0,%1,%0\n"
8403 +" bf 4*cr0+so, 3f\n"
8404 +"2:.long " "0x00c00b00""\n"
8405 +#else
8406 +" add %0,%1,%0\n"
8407 +#endif
8408 +
8409 +"3:\n"
8410 + PPC405_ERR77(0,%2)
8411 + PPC_STLCX "%0,0,%2 \n\
8412 + bne- 1b"
8413 +
8414 +#ifdef CONFIG_PAX_REFCOUNT
8415 +"\n4:\n"
8416 + _ASM_EXTABLE(2b, 4b)
8417 +#endif
8418 +
8419 + : "=&r" (t)
8420 + : "r" (a), "r" (&(l->a.counter))
8421 + : "cc", "memory");
8422 +
8423 + return t;
8424 +}
8425 +
8426 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8427 +{
8428 + long t;
8429 +
8430 + __asm__ __volatile__(
8431 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8432 add %0,%1,%0\n"
8433 PPC405_ERR77(0,%2)
8434 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8435
8436 #define local_cmpxchg(l, o, n) \
8437 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8438 +#define local_cmpxchg_unchecked(l, o, n) \
8439 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8440 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8441
8442 /**
8443 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8444 index 8565c25..2865190 100644
8445 --- a/arch/powerpc/include/asm/mman.h
8446 +++ b/arch/powerpc/include/asm/mman.h
8447 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8448 }
8449 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8450
8451 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8452 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8453 {
8454 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8455 }
8456 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8457 index 26fe1ae..987ffc5 100644
8458 --- a/arch/powerpc/include/asm/page.h
8459 +++ b/arch/powerpc/include/asm/page.h
8460 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8461 * and needs to be executable. This means the whole heap ends
8462 * up being executable.
8463 */
8464 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8465 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8466 +#define VM_DATA_DEFAULT_FLAGS32 \
8467 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8468 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8469
8470 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8471 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8472 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8473 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8474 #endif
8475
8476 +#define ktla_ktva(addr) (addr)
8477 +#define ktva_ktla(addr) (addr)
8478 +
8479 #ifndef CONFIG_PPC_BOOK3S_64
8480 /*
8481 * Use the top bit of the higher-level page table entries to indicate whether
8482 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8483 index d908a46..3753f71 100644
8484 --- a/arch/powerpc/include/asm/page_64.h
8485 +++ b/arch/powerpc/include/asm/page_64.h
8486 @@ -172,15 +172,18 @@ do { \
8487 * stack by default, so in the absence of a PT_GNU_STACK program header
8488 * we turn execute permission off.
8489 */
8490 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8491 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8492 +#define VM_STACK_DEFAULT_FLAGS32 \
8493 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8494 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8495
8496 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8497 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8498
8499 +#ifndef CONFIG_PAX_PAGEEXEC
8500 #define VM_STACK_DEFAULT_FLAGS \
8501 (is_32bit_task() ? \
8502 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8503 +#endif
8504
8505 #include <asm-generic/getorder.h>
8506
8507 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8508 index 4b0be20..c15a27d 100644
8509 --- a/arch/powerpc/include/asm/pgalloc-64.h
8510 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8511 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8512 #ifndef CONFIG_PPC_64K_PAGES
8513
8514 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8515 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8516
8517 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8518 {
8519 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8520 pud_set(pud, (unsigned long)pmd);
8521 }
8522
8523 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8524 +{
8525 + pud_populate(mm, pud, pmd);
8526 +}
8527 +
8528 #define pmd_populate(mm, pmd, pte_page) \
8529 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8530 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8531 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8532 #endif
8533
8534 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8535 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8536
8537 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8538 pte_t *pte)
8539 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8540 index 316f9a5..ba05c77 100644
8541 --- a/arch/powerpc/include/asm/pgtable.h
8542 +++ b/arch/powerpc/include/asm/pgtable.h
8543 @@ -2,6 +2,7 @@
8544 #define _ASM_POWERPC_PGTABLE_H
8545 #ifdef __KERNEL__
8546
8547 +#include <linux/const.h>
8548 #ifndef __ASSEMBLY__
8549 #include <linux/mmdebug.h>
8550 #include <linux/mmzone.h>
8551 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8552 index 4aad413..85d86bf 100644
8553 --- a/arch/powerpc/include/asm/pte-hash32.h
8554 +++ b/arch/powerpc/include/asm/pte-hash32.h
8555 @@ -21,6 +21,7 @@
8556 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8557 #define _PAGE_USER 0x004 /* usermode access allowed */
8558 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8559 +#define _PAGE_EXEC _PAGE_GUARDED
8560 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8561 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8562 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8563 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8564 index a68ee15..552d213 100644
8565 --- a/arch/powerpc/include/asm/reg.h
8566 +++ b/arch/powerpc/include/asm/reg.h
8567 @@ -253,6 +253,7 @@
8568 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8569 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8570 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8571 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8572 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8573 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8574 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8575 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8576 index 5a6614a..d89995d1 100644
8577 --- a/arch/powerpc/include/asm/smp.h
8578 +++ b/arch/powerpc/include/asm/smp.h
8579 @@ -51,7 +51,7 @@ struct smp_ops_t {
8580 int (*cpu_disable)(void);
8581 void (*cpu_die)(unsigned int nr);
8582 int (*cpu_bootable)(unsigned int nr);
8583 -};
8584 +} __no_const;
8585
8586 extern void smp_send_debugger_break(void);
8587 extern void start_secondary_resume(void);
8588 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8589 index 4dbe072..b803275 100644
8590 --- a/arch/powerpc/include/asm/spinlock.h
8591 +++ b/arch/powerpc/include/asm/spinlock.h
8592 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8593 __asm__ __volatile__(
8594 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8595 __DO_SIGN_EXTEND
8596 -" addic. %0,%0,1\n\
8597 - ble- 2f\n"
8598 +
8599 +#ifdef CONFIG_PAX_REFCOUNT
8600 +" mcrxr cr0\n"
8601 +" addico. %0,%0,1\n"
8602 +" bf 4*cr0+so, 3f\n"
8603 +"2:.long " "0x00c00b00""\n"
8604 +#else
8605 +" addic. %0,%0,1\n"
8606 +#endif
8607 +
8608 +"3:\n"
8609 + "ble- 4f\n"
8610 PPC405_ERR77(0,%1)
8611 " stwcx. %0,0,%1\n\
8612 bne- 1b\n"
8613 PPC_ACQUIRE_BARRIER
8614 -"2:" : "=&r" (tmp)
8615 +"4:"
8616 +
8617 +#ifdef CONFIG_PAX_REFCOUNT
8618 + _ASM_EXTABLE(2b,4b)
8619 +#endif
8620 +
8621 + : "=&r" (tmp)
8622 : "r" (&rw->lock)
8623 : "cr0", "xer", "memory");
8624
8625 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8626 __asm__ __volatile__(
8627 "# read_unlock\n\t"
8628 PPC_RELEASE_BARRIER
8629 -"1: lwarx %0,0,%1\n\
8630 - addic %0,%0,-1\n"
8631 +"1: lwarx %0,0,%1\n"
8632 +
8633 +#ifdef CONFIG_PAX_REFCOUNT
8634 +" mcrxr cr0\n"
8635 +" addico. %0,%0,-1\n"
8636 +" bf 4*cr0+so, 3f\n"
8637 +"2:.long " "0x00c00b00""\n"
8638 +#else
8639 +" addic. %0,%0,-1\n"
8640 +#endif
8641 +
8642 +"3:\n"
8643 PPC405_ERR77(0,%1)
8644 " stwcx. %0,0,%1\n\
8645 bne- 1b"
8646 +
8647 +#ifdef CONFIG_PAX_REFCOUNT
8648 +"\n4:\n"
8649 + _ASM_EXTABLE(2b, 4b)
8650 +#endif
8651 +
8652 : "=&r"(tmp)
8653 : "r"(&rw->lock)
8654 : "cr0", "xer", "memory");
8655 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8656 index b034ecd..af7e31f 100644
8657 --- a/arch/powerpc/include/asm/thread_info.h
8658 +++ b/arch/powerpc/include/asm/thread_info.h
8659 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8660 #if defined(CONFIG_PPC64)
8661 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8662 #endif
8663 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8664 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8665
8666 /* as above, but as bit values */
8667 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8668 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8669 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8670 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8671 #define _TIF_NOHZ (1<<TIF_NOHZ)
8672 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8673 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8674 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8675 - _TIF_NOHZ)
8676 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8677
8678 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8679 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8680 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8681 index 9485b43..3bd3c16 100644
8682 --- a/arch/powerpc/include/asm/uaccess.h
8683 +++ b/arch/powerpc/include/asm/uaccess.h
8684 @@ -58,6 +58,7 @@
8685
8686 #endif
8687
8688 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8689 #define access_ok(type, addr, size) \
8690 (__chk_user_ptr(addr), \
8691 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8692 @@ -318,52 +319,6 @@ do { \
8693 extern unsigned long __copy_tofrom_user(void __user *to,
8694 const void __user *from, unsigned long size);
8695
8696 -#ifndef __powerpc64__
8697 -
8698 -static inline unsigned long copy_from_user(void *to,
8699 - const void __user *from, unsigned long n)
8700 -{
8701 - unsigned long over;
8702 -
8703 - if (access_ok(VERIFY_READ, from, n))
8704 - return __copy_tofrom_user((__force void __user *)to, from, n);
8705 - if ((unsigned long)from < TASK_SIZE) {
8706 - over = (unsigned long)from + n - TASK_SIZE;
8707 - return __copy_tofrom_user((__force void __user *)to, from,
8708 - n - over) + over;
8709 - }
8710 - return n;
8711 -}
8712 -
8713 -static inline unsigned long copy_to_user(void __user *to,
8714 - const void *from, unsigned long n)
8715 -{
8716 - unsigned long over;
8717 -
8718 - if (access_ok(VERIFY_WRITE, to, n))
8719 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8720 - if ((unsigned long)to < TASK_SIZE) {
8721 - over = (unsigned long)to + n - TASK_SIZE;
8722 - return __copy_tofrom_user(to, (__force void __user *)from,
8723 - n - over) + over;
8724 - }
8725 - return n;
8726 -}
8727 -
8728 -#else /* __powerpc64__ */
8729 -
8730 -#define __copy_in_user(to, from, size) \
8731 - __copy_tofrom_user((to), (from), (size))
8732 -
8733 -extern unsigned long copy_from_user(void *to, const void __user *from,
8734 - unsigned long n);
8735 -extern unsigned long copy_to_user(void __user *to, const void *from,
8736 - unsigned long n);
8737 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8738 - unsigned long n);
8739 -
8740 -#endif /* __powerpc64__ */
8741 -
8742 static inline unsigned long __copy_from_user_inatomic(void *to,
8743 const void __user *from, unsigned long n)
8744 {
8745 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8746 if (ret == 0)
8747 return 0;
8748 }
8749 +
8750 + if (!__builtin_constant_p(n))
8751 + check_object_size(to, n, false);
8752 +
8753 return __copy_tofrom_user((__force void __user *)to, from, n);
8754 }
8755
8756 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8757 if (ret == 0)
8758 return 0;
8759 }
8760 +
8761 + if (!__builtin_constant_p(n))
8762 + check_object_size(from, n, true);
8763 +
8764 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8765 }
8766
8767 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8768 return __copy_to_user_inatomic(to, from, size);
8769 }
8770
8771 +#ifndef __powerpc64__
8772 +
8773 +static inline unsigned long __must_check copy_from_user(void *to,
8774 + const void __user *from, unsigned long n)
8775 +{
8776 + unsigned long over;
8777 +
8778 + if ((long)n < 0)
8779 + return n;
8780 +
8781 + if (access_ok(VERIFY_READ, from, n)) {
8782 + if (!__builtin_constant_p(n))
8783 + check_object_size(to, n, false);
8784 + return __copy_tofrom_user((__force void __user *)to, from, n);
8785 + }
8786 + if ((unsigned long)from < TASK_SIZE) {
8787 + over = (unsigned long)from + n - TASK_SIZE;
8788 + if (!__builtin_constant_p(n - over))
8789 + check_object_size(to, n - over, false);
8790 + return __copy_tofrom_user((__force void __user *)to, from,
8791 + n - over) + over;
8792 + }
8793 + return n;
8794 +}
8795 +
8796 +static inline unsigned long __must_check copy_to_user(void __user *to,
8797 + const void *from, unsigned long n)
8798 +{
8799 + unsigned long over;
8800 +
8801 + if ((long)n < 0)
8802 + return n;
8803 +
8804 + if (access_ok(VERIFY_WRITE, to, n)) {
8805 + if (!__builtin_constant_p(n))
8806 + check_object_size(from, n, true);
8807 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8808 + }
8809 + if ((unsigned long)to < TASK_SIZE) {
8810 + over = (unsigned long)to + n - TASK_SIZE;
8811 + if (!__builtin_constant_p(n))
8812 + check_object_size(from, n - over, true);
8813 + return __copy_tofrom_user(to, (__force void __user *)from,
8814 + n - over) + over;
8815 + }
8816 + return n;
8817 +}
8818 +
8819 +#else /* __powerpc64__ */
8820 +
8821 +#define __copy_in_user(to, from, size) \
8822 + __copy_tofrom_user((to), (from), (size))
8823 +
8824 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8825 +{
8826 + if ((long)n < 0 || n > INT_MAX)
8827 + return n;
8828 +
8829 + if (!__builtin_constant_p(n))
8830 + check_object_size(to, n, false);
8831 +
8832 + if (likely(access_ok(VERIFY_READ, from, n)))
8833 + n = __copy_from_user(to, from, n);
8834 + else
8835 + memset(to, 0, n);
8836 + return n;
8837 +}
8838 +
8839 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8840 +{
8841 + if ((long)n < 0 || n > INT_MAX)
8842 + return n;
8843 +
8844 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8845 + if (!__builtin_constant_p(n))
8846 + check_object_size(from, n, true);
8847 + n = __copy_to_user(to, from, n);
8848 + }
8849 + return n;
8850 +}
8851 +
8852 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8853 + unsigned long n);
8854 +
8855 +#endif /* __powerpc64__ */
8856 +
8857 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8858
8859 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8860 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8861 index 502cf69..822e63b 100644
8862 --- a/arch/powerpc/kernel/Makefile
8863 +++ b/arch/powerpc/kernel/Makefile
8864 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8865 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8866 endif
8867
8868 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8869 +
8870 obj-y := cputable.o ptrace.o syscalls.o \
8871 irq.o align.o signal_32.o pmc.o vdso.o \
8872 process.o systbl.o idle.o \
8873 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8874 index 3e68d1c..72a5ee6 100644
8875 --- a/arch/powerpc/kernel/exceptions-64e.S
8876 +++ b/arch/powerpc/kernel/exceptions-64e.S
8877 @@ -1010,6 +1010,7 @@ storage_fault_common:
8878 std r14,_DAR(r1)
8879 std r15,_DSISR(r1)
8880 addi r3,r1,STACK_FRAME_OVERHEAD
8881 + bl save_nvgprs
8882 mr r4,r14
8883 mr r5,r15
8884 ld r14,PACA_EXGEN+EX_R14(r13)
8885 @@ -1018,8 +1019,7 @@ storage_fault_common:
8886 cmpdi r3,0
8887 bne- 1f
8888 b ret_from_except_lite
8889 -1: bl save_nvgprs
8890 - mr r5,r3
8891 +1: mr r5,r3
8892 addi r3,r1,STACK_FRAME_OVERHEAD
8893 ld r4,_DAR(r1)
8894 bl bad_page_fault
8895 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8896 index 72e783e..fe058e2 100644
8897 --- a/arch/powerpc/kernel/exceptions-64s.S
8898 +++ b/arch/powerpc/kernel/exceptions-64s.S
8899 @@ -1588,10 +1588,10 @@ handle_page_fault:
8900 11: ld r4,_DAR(r1)
8901 ld r5,_DSISR(r1)
8902 addi r3,r1,STACK_FRAME_OVERHEAD
8903 + bl save_nvgprs
8904 bl do_page_fault
8905 cmpdi r3,0
8906 beq+ 12f
8907 - bl save_nvgprs
8908 mr r5,r3
8909 addi r3,r1,STACK_FRAME_OVERHEAD
8910 lwz r4,_DAR(r1)
8911 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8912 index c143835..5a9697f 100644
8913 --- a/arch/powerpc/kernel/irq.c
8914 +++ b/arch/powerpc/kernel/irq.c
8915 @@ -461,6 +461,8 @@ void migrate_irqs(void)
8916 }
8917 #endif
8918
8919 +extern void gr_handle_kernel_exploit(void);
8920 +
8921 static inline void check_stack_overflow(void)
8922 {
8923 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8924 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8925 pr_err("do_IRQ: stack overflow: %ld\n",
8926 sp - sizeof(struct thread_info));
8927 dump_stack();
8928 + gr_handle_kernel_exploit();
8929 }
8930 #endif
8931 }
8932 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8933 index c94d2e0..992a9ce 100644
8934 --- a/arch/powerpc/kernel/module_32.c
8935 +++ b/arch/powerpc/kernel/module_32.c
8936 @@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8937 me->arch.core_plt_section = i;
8938 }
8939 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8940 - pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8941 + pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8942 return -ENOEXEC;
8943 }
8944
8945 @@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8946
8947 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8948 /* Init, or core PLT? */
8949 - if (location >= mod->module_core
8950 - && location < mod->module_core + mod->core_size)
8951 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8952 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8953 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8954 - else
8955 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8956 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8957 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8958 + else {
8959 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8960 + return ~0UL;
8961 + }
8962
8963 /* Find this entry, or if that fails, the next avail. entry */
8964 while (entry->jump[0]) {
8965 @@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8966 }
8967 #ifdef CONFIG_DYNAMIC_FTRACE
8968 module->arch.tramp =
8969 - do_plt_call(module->module_core,
8970 + do_plt_call(module->module_core_rx,
8971 (unsigned long)ftrace_caller,
8972 sechdrs, module);
8973 #endif
8974 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8975 index 923cd2d..ae782a9 100644
8976 --- a/arch/powerpc/kernel/process.c
8977 +++ b/arch/powerpc/kernel/process.c
8978 @@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8979 * Lookup NIP late so we have the best change of getting the
8980 * above info out without failing
8981 */
8982 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8983 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8984 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8985 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8986 #endif
8987 show_stack(current, (unsigned long *) regs->gpr[1]);
8988 if (!user_mode(regs))
8989 @@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8990 newsp = stack[0];
8991 ip = stack[STACK_FRAME_LR_SAVE];
8992 if (!firstframe || ip != lr) {
8993 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8994 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8995 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8996 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8997 - printk(" (%pS)",
8998 + printk(" (%pA)",
8999 (void *)current->ret_stack[curr_frame].ret);
9000 curr_frame--;
9001 }
9002 @@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9003 struct pt_regs *regs = (struct pt_regs *)
9004 (sp + STACK_FRAME_OVERHEAD);
9005 lr = regs->link;
9006 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9007 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9008 regs->trap, (void *)regs->nip, (void *)lr);
9009 firstframe = 1;
9010 }
9011 @@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
9012 mtspr(SPRN_CTRLT, ctrl);
9013 }
9014 #endif /* CONFIG_PPC64 */
9015 -
9016 -unsigned long arch_align_stack(unsigned long sp)
9017 -{
9018 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9019 - sp -= get_random_int() & ~PAGE_MASK;
9020 - return sp & ~0xf;
9021 -}
9022 -
9023 -static inline unsigned long brk_rnd(void)
9024 -{
9025 - unsigned long rnd = 0;
9026 -
9027 - /* 8MB for 32bit, 1GB for 64bit */
9028 - if (is_32bit_task())
9029 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9030 - else
9031 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9032 -
9033 - return rnd << PAGE_SHIFT;
9034 -}
9035 -
9036 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9037 -{
9038 - unsigned long base = mm->brk;
9039 - unsigned long ret;
9040 -
9041 -#ifdef CONFIG_PPC_STD_MMU_64
9042 - /*
9043 - * If we are using 1TB segments and we are allowed to randomise
9044 - * the heap, we can put it above 1TB so it is backed by a 1TB
9045 - * segment. Otherwise the heap will be in the bottom 1TB
9046 - * which always uses 256MB segments and this may result in a
9047 - * performance penalty.
9048 - */
9049 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9050 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9051 -#endif
9052 -
9053 - ret = PAGE_ALIGN(base + brk_rnd());
9054 -
9055 - if (ret < mm->brk)
9056 - return mm->brk;
9057 -
9058 - return ret;
9059 -}
9060 -
9061 -unsigned long randomize_et_dyn(unsigned long base)
9062 -{
9063 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9064 -
9065 - if (ret < base)
9066 - return base;
9067 -
9068 - return ret;
9069 -}
9070 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9071 index f21897b..28c0428 100644
9072 --- a/arch/powerpc/kernel/ptrace.c
9073 +++ b/arch/powerpc/kernel/ptrace.c
9074 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9075 return ret;
9076 }
9077
9078 +#ifdef CONFIG_GRKERNSEC_SETXID
9079 +extern void gr_delayed_cred_worker(void);
9080 +#endif
9081 +
9082 /*
9083 * We must return the syscall number to actually look up in the table.
9084 * This can be -1L to skip running any syscall at all.
9085 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9086
9087 secure_computing_strict(regs->gpr[0]);
9088
9089 +#ifdef CONFIG_GRKERNSEC_SETXID
9090 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9091 + gr_delayed_cred_worker();
9092 +#endif
9093 +
9094 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9095 tracehook_report_syscall_entry(regs))
9096 /*
9097 @@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9098 {
9099 int step;
9100
9101 +#ifdef CONFIG_GRKERNSEC_SETXID
9102 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9103 + gr_delayed_cred_worker();
9104 +#endif
9105 +
9106 audit_syscall_exit(regs);
9107
9108 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9109 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9110 index b171001..4ac7ac5 100644
9111 --- a/arch/powerpc/kernel/signal_32.c
9112 +++ b/arch/powerpc/kernel/signal_32.c
9113 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9114 /* Save user registers on the stack */
9115 frame = &rt_sf->uc.uc_mcontext;
9116 addr = frame;
9117 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9118 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9119 sigret = 0;
9120 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9121 } else {
9122 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9123 index 2cb0c94..c0c0bc9 100644
9124 --- a/arch/powerpc/kernel/signal_64.c
9125 +++ b/arch/powerpc/kernel/signal_64.c
9126 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9127 current->thread.fp_state.fpscr = 0;
9128
9129 /* Set up to return from userspace. */
9130 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9131 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9132 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9133 } else {
9134 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9135 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9136 index 0dc43f9..a885d33 100644
9137 --- a/arch/powerpc/kernel/traps.c
9138 +++ b/arch/powerpc/kernel/traps.c
9139 @@ -36,6 +36,7 @@
9140 #include <linux/debugfs.h>
9141 #include <linux/ratelimit.h>
9142 #include <linux/context_tracking.h>
9143 +#include <linux/uaccess.h>
9144
9145 #include <asm/emulated_ops.h>
9146 #include <asm/pgtable.h>
9147 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9148 return flags;
9149 }
9150
9151 +extern void gr_handle_kernel_exploit(void);
9152 +
9153 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9154 int signr)
9155 {
9156 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9157 panic("Fatal exception in interrupt");
9158 if (panic_on_oops)
9159 panic("Fatal exception");
9160 +
9161 + gr_handle_kernel_exploit();
9162 +
9163 do_exit(signr);
9164 }
9165
9166 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9167 enum ctx_state prev_state = exception_enter();
9168 unsigned int reason = get_reason(regs);
9169
9170 +#ifdef CONFIG_PAX_REFCOUNT
9171 + unsigned int bkpt;
9172 + const struct exception_table_entry *entry;
9173 +
9174 + if (reason & REASON_ILLEGAL) {
9175 + /* Check if PaX bad instruction */
9176 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9177 + current->thread.trap_nr = 0;
9178 + pax_report_refcount_overflow(regs);
9179 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9180 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9181 + regs->nip = entry->fixup;
9182 + return;
9183 + }
9184 + /* fixup_exception() could not handle */
9185 + goto bail;
9186 + }
9187 + }
9188 +#endif
9189 +
9190 /* We can now get here via a FP Unavailable exception if the core
9191 * has no FPU, in that case the reason flags will be 0 */
9192
9193 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9194 index f174351..5722009 100644
9195 --- a/arch/powerpc/kernel/vdso.c
9196 +++ b/arch/powerpc/kernel/vdso.c
9197 @@ -35,6 +35,7 @@
9198 #include <asm/vdso.h>
9199 #include <asm/vdso_datapage.h>
9200 #include <asm/setup.h>
9201 +#include <asm/mman.h>
9202
9203 #undef DEBUG
9204
9205 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9206 vdso_base = VDSO32_MBASE;
9207 #endif
9208
9209 - current->mm->context.vdso_base = 0;
9210 + current->mm->context.vdso_base = ~0UL;
9211
9212 /* vDSO has a problem and was disabled, just don't "enable" it for the
9213 * process
9214 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9215 vdso_base = get_unmapped_area(NULL, vdso_base,
9216 (vdso_pages << PAGE_SHIFT) +
9217 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9218 - 0, 0);
9219 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9220 if (IS_ERR_VALUE(vdso_base)) {
9221 rc = vdso_base;
9222 goto fail_mmapsem;
9223 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9224 index c1f8f53..71a3b96 100644
9225 --- a/arch/powerpc/kvm/powerpc.c
9226 +++ b/arch/powerpc/kvm/powerpc.c
9227 @@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9228 }
9229 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9230
9231 -int kvm_arch_init(void *opaque)
9232 +int kvm_arch_init(const void *opaque)
9233 {
9234 return 0;
9235 }
9236 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9237 index 5eea6f3..5d10396 100644
9238 --- a/arch/powerpc/lib/usercopy_64.c
9239 +++ b/arch/powerpc/lib/usercopy_64.c
9240 @@ -9,22 +9,6 @@
9241 #include <linux/module.h>
9242 #include <asm/uaccess.h>
9243
9244 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9245 -{
9246 - if (likely(access_ok(VERIFY_READ, from, n)))
9247 - n = __copy_from_user(to, from, n);
9248 - else
9249 - memset(to, 0, n);
9250 - return n;
9251 -}
9252 -
9253 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9254 -{
9255 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9256 - n = __copy_to_user(to, from, n);
9257 - return n;
9258 -}
9259 -
9260 unsigned long copy_in_user(void __user *to, const void __user *from,
9261 unsigned long n)
9262 {
9263 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9264 return n;
9265 }
9266
9267 -EXPORT_SYMBOL(copy_from_user);
9268 -EXPORT_SYMBOL(copy_to_user);
9269 EXPORT_SYMBOL(copy_in_user);
9270
9271 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9272 index 08d659a..ab329f4 100644
9273 --- a/arch/powerpc/mm/fault.c
9274 +++ b/arch/powerpc/mm/fault.c
9275 @@ -33,6 +33,10 @@
9276 #include <linux/ratelimit.h>
9277 #include <linux/context_tracking.h>
9278 #include <linux/hugetlb.h>
9279 +#include <linux/slab.h>
9280 +#include <linux/pagemap.h>
9281 +#include <linux/compiler.h>
9282 +#include <linux/unistd.h>
9283
9284 #include <asm/firmware.h>
9285 #include <asm/page.h>
9286 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9287 }
9288 #endif
9289
9290 +#ifdef CONFIG_PAX_PAGEEXEC
9291 +/*
9292 + * PaX: decide what to do with offenders (regs->nip = fault address)
9293 + *
9294 + * returns 1 when task should be killed
9295 + */
9296 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9297 +{
9298 + return 1;
9299 +}
9300 +
9301 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9302 +{
9303 + unsigned long i;
9304 +
9305 + printk(KERN_ERR "PAX: bytes at PC: ");
9306 + for (i = 0; i < 5; i++) {
9307 + unsigned int c;
9308 + if (get_user(c, (unsigned int __user *)pc+i))
9309 + printk(KERN_CONT "???????? ");
9310 + else
9311 + printk(KERN_CONT "%08x ", c);
9312 + }
9313 + printk("\n");
9314 +}
9315 +#endif
9316 +
9317 /*
9318 * Check whether the instruction at regs->nip is a store using
9319 * an update addressing form which will update r1.
9320 @@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9321 * indicate errors in DSISR but can validly be set in SRR1.
9322 */
9323 if (trap == 0x400)
9324 - error_code &= 0x48200000;
9325 + error_code &= 0x58200000;
9326 else
9327 is_write = error_code & DSISR_ISSTORE;
9328 #else
9329 @@ -390,7 +421,7 @@ good_area:
9330 * "undefined". Of those that can be set, this is the only
9331 * one which seems bad.
9332 */
9333 - if (error_code & 0x10000000)
9334 + if (error_code & DSISR_GUARDED)
9335 /* Guarded storage error. */
9336 goto bad_area;
9337 #endif /* CONFIG_8xx */
9338 @@ -405,7 +436,7 @@ good_area:
9339 * processors use the same I/D cache coherency mechanism
9340 * as embedded.
9341 */
9342 - if (error_code & DSISR_PROTFAULT)
9343 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9344 goto bad_area;
9345 #endif /* CONFIG_PPC_STD_MMU */
9346
9347 @@ -495,6 +526,23 @@ bad_area:
9348 bad_area_nosemaphore:
9349 /* User mode accesses cause a SIGSEGV */
9350 if (user_mode(regs)) {
9351 +
9352 +#ifdef CONFIG_PAX_PAGEEXEC
9353 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9354 +#ifdef CONFIG_PPC_STD_MMU
9355 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9356 +#else
9357 + if (is_exec && regs->nip == address) {
9358 +#endif
9359 + switch (pax_handle_fetch_fault(regs)) {
9360 + }
9361 +
9362 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9363 + do_group_exit(SIGKILL);
9364 + }
9365 + }
9366 +#endif
9367 +
9368 _exception(SIGSEGV, regs, code, address);
9369 goto bail;
9370 }
9371 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9372 index cb8bdbe..cde4bc7 100644
9373 --- a/arch/powerpc/mm/mmap.c
9374 +++ b/arch/powerpc/mm/mmap.c
9375 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9376 return sysctl_legacy_va_layout;
9377 }
9378
9379 -static unsigned long mmap_rnd(void)
9380 +static unsigned long mmap_rnd(struct mm_struct *mm)
9381 {
9382 unsigned long rnd = 0;
9383
9384 +#ifdef CONFIG_PAX_RANDMMAP
9385 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9386 +#endif
9387 +
9388 if (current->flags & PF_RANDOMIZE) {
9389 /* 8MB for 32bit, 1GB for 64bit */
9390 if (is_32bit_task())
9391 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9392 return rnd << PAGE_SHIFT;
9393 }
9394
9395 -static inline unsigned long mmap_base(void)
9396 +static inline unsigned long mmap_base(struct mm_struct *mm)
9397 {
9398 unsigned long gap = rlimit(RLIMIT_STACK);
9399
9400 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9401 else if (gap > MAX_GAP)
9402 gap = MAX_GAP;
9403
9404 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9405 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9406 }
9407
9408 /*
9409 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9410 */
9411 if (mmap_is_legacy()) {
9412 mm->mmap_base = TASK_UNMAPPED_BASE;
9413 +
9414 +#ifdef CONFIG_PAX_RANDMMAP
9415 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9416 + mm->mmap_base += mm->delta_mmap;
9417 +#endif
9418 +
9419 mm->get_unmapped_area = arch_get_unmapped_area;
9420 } else {
9421 - mm->mmap_base = mmap_base();
9422 + mm->mmap_base = mmap_base(mm);
9423 +
9424 +#ifdef CONFIG_PAX_RANDMMAP
9425 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9426 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9427 +#endif
9428 +
9429 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9430 }
9431 }
9432 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9433 index ded0ea1..f213a9b 100644
9434 --- a/arch/powerpc/mm/slice.c
9435 +++ b/arch/powerpc/mm/slice.c
9436 @@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9437 if ((mm->task_size - len) < addr)
9438 return 0;
9439 vma = find_vma(mm, addr);
9440 - return (!vma || (addr + len) <= vma->vm_start);
9441 + return check_heap_stack_gap(vma, addr, len, 0);
9442 }
9443
9444 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9445 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9446 info.align_offset = 0;
9447
9448 addr = TASK_UNMAPPED_BASE;
9449 +
9450 +#ifdef CONFIG_PAX_RANDMMAP
9451 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9452 + addr += mm->delta_mmap;
9453 +#endif
9454 +
9455 while (addr < TASK_SIZE) {
9456 info.low_limit = addr;
9457 if (!slice_scan_available(addr, available, 1, &addr))
9458 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9459 if (fixed && addr > (mm->task_size - len))
9460 return -ENOMEM;
9461
9462 +#ifdef CONFIG_PAX_RANDMMAP
9463 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9464 + addr = 0;
9465 +#endif
9466 +
9467 /* If hint, make sure it matches our alignment restrictions */
9468 if (!fixed && addr) {
9469 addr = _ALIGN_UP(addr, 1ul << pshift);
9470 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9471 index 4278acf..67fd0e6 100644
9472 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9473 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9474 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9475 }
9476
9477 static struct pci_ops scc_pciex_pci_ops = {
9478 - scc_pciex_read_config,
9479 - scc_pciex_write_config,
9480 + .read = scc_pciex_read_config,
9481 + .write = scc_pciex_write_config,
9482 };
9483
9484 static void pciex_clear_intr_all(unsigned int __iomem *base)
9485 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9486 index d966bbe..372124a 100644
9487 --- a/arch/powerpc/platforms/cell/spufs/file.c
9488 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9489 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9490 return VM_FAULT_NOPAGE;
9491 }
9492
9493 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9494 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9495 unsigned long address,
9496 - void *buf, int len, int write)
9497 + void *buf, size_t len, int write)
9498 {
9499 struct spu_context *ctx = vma->vm_file->private_data;
9500 unsigned long offset = address - vma->vm_start;
9501 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9502 index fa934fe..c296056 100644
9503 --- a/arch/s390/include/asm/atomic.h
9504 +++ b/arch/s390/include/asm/atomic.h
9505 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9506 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9507 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9508
9509 +#define atomic64_read_unchecked(v) atomic64_read(v)
9510 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9511 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9512 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9513 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9514 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9515 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9516 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9517 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9518 +
9519 #endif /* __ARCH_S390_ATOMIC__ */
9520 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9521 index b5dce65..8aca09a 100644
9522 --- a/arch/s390/include/asm/barrier.h
9523 +++ b/arch/s390/include/asm/barrier.h
9524 @@ -39,7 +39,7 @@
9525 do { \
9526 compiletime_assert_atomic_type(*p); \
9527 barrier(); \
9528 - ACCESS_ONCE(*p) = (v); \
9529 + ACCESS_ONCE_RW(*p) = (v); \
9530 } while (0)
9531
9532 #define smp_load_acquire(p) \
9533 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9534 index 4d7ccac..d03d0ad 100644
9535 --- a/arch/s390/include/asm/cache.h
9536 +++ b/arch/s390/include/asm/cache.h
9537 @@ -9,8 +9,10 @@
9538 #ifndef __ARCH_S390_CACHE_H
9539 #define __ARCH_S390_CACHE_H
9540
9541 -#define L1_CACHE_BYTES 256
9542 +#include <linux/const.h>
9543 +
9544 #define L1_CACHE_SHIFT 8
9545 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9546 #define NET_SKB_PAD 32
9547
9548 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9549 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9550 index f6e43d3..5f57681 100644
9551 --- a/arch/s390/include/asm/elf.h
9552 +++ b/arch/s390/include/asm/elf.h
9553 @@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9554 the loader. We need to make sure that it is out of the way of the program
9555 that it will "exec", and that there is sufficient room for the brk. */
9556
9557 -extern unsigned long randomize_et_dyn(unsigned long base);
9558 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9559 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9560 +
9561 +#ifdef CONFIG_PAX_ASLR
9562 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9563 +
9564 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9565 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9566 +#endif
9567
9568 /* This yields a mask that user programs can use to figure out what
9569 instruction set this CPU supports. */
9570 @@ -223,9 +229,6 @@ struct linux_binprm;
9571 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9572 int arch_setup_additional_pages(struct linux_binprm *, int);
9573
9574 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9575 -#define arch_randomize_brk arch_randomize_brk
9576 -
9577 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9578
9579 #endif
9580 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9581 index c4a93d6..4d2a9b4 100644
9582 --- a/arch/s390/include/asm/exec.h
9583 +++ b/arch/s390/include/asm/exec.h
9584 @@ -7,6 +7,6 @@
9585 #ifndef __ASM_EXEC_H
9586 #define __ASM_EXEC_H
9587
9588 -extern unsigned long arch_align_stack(unsigned long sp);
9589 +#define arch_align_stack(x) ((x) & ~0xfUL)
9590
9591 #endif /* __ASM_EXEC_H */
9592 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9593 index cd4c68e..6764641 100644
9594 --- a/arch/s390/include/asm/uaccess.h
9595 +++ b/arch/s390/include/asm/uaccess.h
9596 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9597 __range_ok((unsigned long)(addr), (size)); \
9598 })
9599
9600 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9601 #define access_ok(type, addr, size) __access_ok(addr, size)
9602
9603 /*
9604 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9605 copy_to_user(void __user *to, const void *from, unsigned long n)
9606 {
9607 might_fault();
9608 +
9609 + if ((long)n < 0)
9610 + return n;
9611 +
9612 return __copy_to_user(to, from, n);
9613 }
9614
9615 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9616 static inline unsigned long __must_check
9617 copy_from_user(void *to, const void __user *from, unsigned long n)
9618 {
9619 - unsigned int sz = __compiletime_object_size(to);
9620 + size_t sz = __compiletime_object_size(to);
9621
9622 might_fault();
9623 - if (unlikely(sz != -1 && sz < n)) {
9624 +
9625 + if ((long)n < 0)
9626 + return n;
9627 +
9628 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9629 copy_from_user_overflow();
9630 return n;
9631 }
9632 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9633 index b89b591..fd9609d 100644
9634 --- a/arch/s390/kernel/module.c
9635 +++ b/arch/s390/kernel/module.c
9636 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9637
9638 /* Increase core size by size of got & plt and set start
9639 offsets for got and plt. */
9640 - me->core_size = ALIGN(me->core_size, 4);
9641 - me->arch.got_offset = me->core_size;
9642 - me->core_size += me->arch.got_size;
9643 - me->arch.plt_offset = me->core_size;
9644 - me->core_size += me->arch.plt_size;
9645 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9646 + me->arch.got_offset = me->core_size_rw;
9647 + me->core_size_rw += me->arch.got_size;
9648 + me->arch.plt_offset = me->core_size_rx;
9649 + me->core_size_rx += me->arch.plt_size;
9650 return 0;
9651 }
9652
9653 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9654 if (info->got_initialized == 0) {
9655 Elf_Addr *gotent;
9656
9657 - gotent = me->module_core + me->arch.got_offset +
9658 + gotent = me->module_core_rw + me->arch.got_offset +
9659 info->got_offset;
9660 *gotent = val;
9661 info->got_initialized = 1;
9662 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9663 rc = apply_rela_bits(loc, val, 0, 64, 0);
9664 else if (r_type == R_390_GOTENT ||
9665 r_type == R_390_GOTPLTENT) {
9666 - val += (Elf_Addr) me->module_core - loc;
9667 + val += (Elf_Addr) me->module_core_rw - loc;
9668 rc = apply_rela_bits(loc, val, 1, 32, 1);
9669 }
9670 break;
9671 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9672 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9673 if (info->plt_initialized == 0) {
9674 unsigned int *ip;
9675 - ip = me->module_core + me->arch.plt_offset +
9676 + ip = me->module_core_rx + me->arch.plt_offset +
9677 info->plt_offset;
9678 #ifndef CONFIG_64BIT
9679 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9680 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9681 val - loc + 0xffffUL < 0x1ffffeUL) ||
9682 (r_type == R_390_PLT32DBL &&
9683 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9684 - val = (Elf_Addr) me->module_core +
9685 + val = (Elf_Addr) me->module_core_rx +
9686 me->arch.plt_offset +
9687 info->plt_offset;
9688 val += rela->r_addend - loc;
9689 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9690 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9691 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9692 val = val + rela->r_addend -
9693 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9694 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9695 if (r_type == R_390_GOTOFF16)
9696 rc = apply_rela_bits(loc, val, 0, 16, 0);
9697 else if (r_type == R_390_GOTOFF32)
9698 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9699 break;
9700 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9701 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9702 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9703 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9704 rela->r_addend - loc;
9705 if (r_type == R_390_GOTPC)
9706 rc = apply_rela_bits(loc, val, 1, 32, 0);
9707 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9708 index ed84cc2..c05a9d2 100644
9709 --- a/arch/s390/kernel/process.c
9710 +++ b/arch/s390/kernel/process.c
9711 @@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9712 }
9713 return 0;
9714 }
9715 -
9716 -unsigned long arch_align_stack(unsigned long sp)
9717 -{
9718 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9719 - sp -= get_random_int() & ~PAGE_MASK;
9720 - return sp & ~0xf;
9721 -}
9722 -
9723 -static inline unsigned long brk_rnd(void)
9724 -{
9725 - /* 8MB for 32bit, 1GB for 64bit */
9726 - if (is_32bit_task())
9727 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9728 - else
9729 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9730 -}
9731 -
9732 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9733 -{
9734 - unsigned long ret;
9735 -
9736 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9737 - return (ret > mm->brk) ? ret : mm->brk;
9738 -}
9739 -
9740 -unsigned long randomize_et_dyn(unsigned long base)
9741 -{
9742 - unsigned long ret;
9743 -
9744 - if (!(current->flags & PF_RANDOMIZE))
9745 - return base;
9746 - ret = PAGE_ALIGN(base + brk_rnd());
9747 - return (ret > base) ? ret : base;
9748 -}
9749 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9750 index 9b436c2..54fbf0a 100644
9751 --- a/arch/s390/mm/mmap.c
9752 +++ b/arch/s390/mm/mmap.c
9753 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9754 */
9755 if (mmap_is_legacy()) {
9756 mm->mmap_base = mmap_base_legacy();
9757 +
9758 +#ifdef CONFIG_PAX_RANDMMAP
9759 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9760 + mm->mmap_base += mm->delta_mmap;
9761 +#endif
9762 +
9763 mm->get_unmapped_area = arch_get_unmapped_area;
9764 } else {
9765 mm->mmap_base = mmap_base();
9766 +
9767 +#ifdef CONFIG_PAX_RANDMMAP
9768 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9769 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9770 +#endif
9771 +
9772 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9773 }
9774 }
9775 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9776 */
9777 if (mmap_is_legacy()) {
9778 mm->mmap_base = mmap_base_legacy();
9779 +
9780 +#ifdef CONFIG_PAX_RANDMMAP
9781 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9782 + mm->mmap_base += mm->delta_mmap;
9783 +#endif
9784 +
9785 mm->get_unmapped_area = s390_get_unmapped_area;
9786 } else {
9787 mm->mmap_base = mmap_base();
9788 +
9789 +#ifdef CONFIG_PAX_RANDMMAP
9790 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9791 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9792 +#endif
9793 +
9794 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9795 }
9796 }
9797 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9798 index ae3d59f..f65f075 100644
9799 --- a/arch/score/include/asm/cache.h
9800 +++ b/arch/score/include/asm/cache.h
9801 @@ -1,7 +1,9 @@
9802 #ifndef _ASM_SCORE_CACHE_H
9803 #define _ASM_SCORE_CACHE_H
9804
9805 +#include <linux/const.h>
9806 +
9807 #define L1_CACHE_SHIFT 4
9808 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9809 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9810
9811 #endif /* _ASM_SCORE_CACHE_H */
9812 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9813 index f9f3cd5..58ff438 100644
9814 --- a/arch/score/include/asm/exec.h
9815 +++ b/arch/score/include/asm/exec.h
9816 @@ -1,6 +1,6 @@
9817 #ifndef _ASM_SCORE_EXEC_H
9818 #define _ASM_SCORE_EXEC_H
9819
9820 -extern unsigned long arch_align_stack(unsigned long sp);
9821 +#define arch_align_stack(x) (x)
9822
9823 #endif /* _ASM_SCORE_EXEC_H */
9824 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9825 index a1519ad3..e8ac1ff 100644
9826 --- a/arch/score/kernel/process.c
9827 +++ b/arch/score/kernel/process.c
9828 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9829
9830 return task_pt_regs(task)->cp0_epc;
9831 }
9832 -
9833 -unsigned long arch_align_stack(unsigned long sp)
9834 -{
9835 - return sp;
9836 -}
9837 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9838 index ef9e555..331bd29 100644
9839 --- a/arch/sh/include/asm/cache.h
9840 +++ b/arch/sh/include/asm/cache.h
9841 @@ -9,10 +9,11 @@
9842 #define __ASM_SH_CACHE_H
9843 #ifdef __KERNEL__
9844
9845 +#include <linux/const.h>
9846 #include <linux/init.h>
9847 #include <cpu/cache.h>
9848
9849 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9850 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9851
9852 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9853
9854 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9855 index 6777177..cb5e44f 100644
9856 --- a/arch/sh/mm/mmap.c
9857 +++ b/arch/sh/mm/mmap.c
9858 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9859 struct mm_struct *mm = current->mm;
9860 struct vm_area_struct *vma;
9861 int do_colour_align;
9862 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9863 struct vm_unmapped_area_info info;
9864
9865 if (flags & MAP_FIXED) {
9866 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9867 if (filp || (flags & MAP_SHARED))
9868 do_colour_align = 1;
9869
9870 +#ifdef CONFIG_PAX_RANDMMAP
9871 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9872 +#endif
9873 +
9874 if (addr) {
9875 if (do_colour_align)
9876 addr = COLOUR_ALIGN(addr, pgoff);
9877 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9878 addr = PAGE_ALIGN(addr);
9879
9880 vma = find_vma(mm, addr);
9881 - if (TASK_SIZE - len >= addr &&
9882 - (!vma || addr + len <= vma->vm_start))
9883 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9884 return addr;
9885 }
9886
9887 info.flags = 0;
9888 info.length = len;
9889 - info.low_limit = TASK_UNMAPPED_BASE;
9890 + info.low_limit = mm->mmap_base;
9891 info.high_limit = TASK_SIZE;
9892 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9893 info.align_offset = pgoff << PAGE_SHIFT;
9894 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9895 struct mm_struct *mm = current->mm;
9896 unsigned long addr = addr0;
9897 int do_colour_align;
9898 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9899 struct vm_unmapped_area_info info;
9900
9901 if (flags & MAP_FIXED) {
9902 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9903 if (filp || (flags & MAP_SHARED))
9904 do_colour_align = 1;
9905
9906 +#ifdef CONFIG_PAX_RANDMMAP
9907 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9908 +#endif
9909 +
9910 /* requesting a specific address */
9911 if (addr) {
9912 if (do_colour_align)
9913 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9914 addr = PAGE_ALIGN(addr);
9915
9916 vma = find_vma(mm, addr);
9917 - if (TASK_SIZE - len >= addr &&
9918 - (!vma || addr + len <= vma->vm_start))
9919 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9920 return addr;
9921 }
9922
9923 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9924 VM_BUG_ON(addr != -ENOMEM);
9925 info.flags = 0;
9926 info.low_limit = TASK_UNMAPPED_BASE;
9927 +
9928 +#ifdef CONFIG_PAX_RANDMMAP
9929 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9930 + info.low_limit += mm->delta_mmap;
9931 +#endif
9932 +
9933 info.high_limit = TASK_SIZE;
9934 addr = vm_unmapped_area(&info);
9935 }
9936 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9937 index 4082749..fd97781 100644
9938 --- a/arch/sparc/include/asm/atomic_64.h
9939 +++ b/arch/sparc/include/asm/atomic_64.h
9940 @@ -15,18 +15,38 @@
9941 #define ATOMIC64_INIT(i) { (i) }
9942
9943 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9944 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9945 +{
9946 + return ACCESS_ONCE(v->counter);
9947 +}
9948 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9949 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9950 +{
9951 + return ACCESS_ONCE(v->counter);
9952 +}
9953
9954 #define atomic_set(v, i) (((v)->counter) = i)
9955 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9956 +{
9957 + v->counter = i;
9958 +}
9959 #define atomic64_set(v, i) (((v)->counter) = i)
9960 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9961 +{
9962 + v->counter = i;
9963 +}
9964
9965 -#define ATOMIC_OP(op) \
9966 -void atomic_##op(int, atomic_t *); \
9967 -void atomic64_##op(long, atomic64_t *);
9968 +#define __ATOMIC_OP(op, suffix) \
9969 +void atomic_##op##suffix(int, atomic##suffix##_t *); \
9970 +void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9971
9972 -#define ATOMIC_OP_RETURN(op) \
9973 -int atomic_##op##_return(int, atomic_t *); \
9974 -long atomic64_##op##_return(long, atomic64_t *);
9975 +#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9976 +
9977 +#define __ATOMIC_OP_RETURN(op, suffix) \
9978 +int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9979 +long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9980 +
9981 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9982
9983 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9984
9985 @@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9986
9987 #undef ATOMIC_OPS
9988 #undef ATOMIC_OP_RETURN
9989 +#undef __ATOMIC_OP_RETURN
9990 #undef ATOMIC_OP
9991 +#undef __ATOMIC_OP
9992
9993 #define atomic_dec_return(v) atomic_sub_return(1, v)
9994 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9995
9996 #define atomic_inc_return(v) atomic_add_return(1, v)
9997 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9998 +{
9999 + return atomic_add_return_unchecked(1, v);
10000 +}
10001 #define atomic64_inc_return(v) atomic64_add_return(1, v)
10002 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10003 +{
10004 + return atomic64_add_return_unchecked(1, v);
10005 +}
10006
10007 /*
10008 * atomic_inc_and_test - increment and test
10009 @@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
10010 * other cases.
10011 */
10012 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10013 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10014 +{
10015 + return atomic_inc_return_unchecked(v) == 0;
10016 +}
10017 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10018
10019 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
10020 @@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
10021 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
10022
10023 #define atomic_inc(v) atomic_add(1, v)
10024 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10025 +{
10026 + atomic_add_unchecked(1, v);
10027 +}
10028 #define atomic64_inc(v) atomic64_add(1, v)
10029 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10030 +{
10031 + atomic64_add_unchecked(1, v);
10032 +}
10033
10034 #define atomic_dec(v) atomic_sub(1, v)
10035 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10036 +{
10037 + atomic_sub_unchecked(1, v);
10038 +}
10039 #define atomic64_dec(v) atomic64_sub(1, v)
10040 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10041 +{
10042 + atomic64_sub_unchecked(1, v);
10043 +}
10044
10045 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
10046 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
10047
10048 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10049 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10050 +{
10051 + return cmpxchg(&v->counter, old, new);
10052 +}
10053 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10054 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10055 +{
10056 + return xchg(&v->counter, new);
10057 +}
10058
10059 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10060 {
10061 - int c, old;
10062 + int c, old, new;
10063 c = atomic_read(v);
10064 for (;;) {
10065 - if (unlikely(c == (u)))
10066 + if (unlikely(c == u))
10067 break;
10068 - old = atomic_cmpxchg((v), c, c + (a));
10069 +
10070 + asm volatile("addcc %2, %0, %0\n"
10071 +
10072 +#ifdef CONFIG_PAX_REFCOUNT
10073 + "tvs %%icc, 6\n"
10074 +#endif
10075 +
10076 + : "=r" (new)
10077 + : "0" (c), "ir" (a)
10078 + : "cc");
10079 +
10080 + old = atomic_cmpxchg(v, c, new);
10081 if (likely(old == c))
10082 break;
10083 c = old;
10084 @@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10085 #define atomic64_cmpxchg(v, o, n) \
10086 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10087 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10088 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10089 +{
10090 + return xchg(&v->counter, new);
10091 +}
10092
10093 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10094 {
10095 - long c, old;
10096 + long c, old, new;
10097 c = atomic64_read(v);
10098 for (;;) {
10099 - if (unlikely(c == (u)))
10100 + if (unlikely(c == u))
10101 break;
10102 - old = atomic64_cmpxchg((v), c, c + (a));
10103 +
10104 + asm volatile("addcc %2, %0, %0\n"
10105 +
10106 +#ifdef CONFIG_PAX_REFCOUNT
10107 + "tvs %%xcc, 6\n"
10108 +#endif
10109 +
10110 + : "=r" (new)
10111 + : "0" (c), "ir" (a)
10112 + : "cc");
10113 +
10114 + old = atomic64_cmpxchg(v, c, new);
10115 if (likely(old == c))
10116 break;
10117 c = old;
10118 }
10119 - return c != (u);
10120 + return c != u;
10121 }
10122
10123 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10124 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10125 index 305dcc3..7835030 100644
10126 --- a/arch/sparc/include/asm/barrier_64.h
10127 +++ b/arch/sparc/include/asm/barrier_64.h
10128 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10129 do { \
10130 compiletime_assert_atomic_type(*p); \
10131 barrier(); \
10132 - ACCESS_ONCE(*p) = (v); \
10133 + ACCESS_ONCE_RW(*p) = (v); \
10134 } while (0)
10135
10136 #define smp_load_acquire(p) \
10137 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10138 index 5bb6991..5c2132e 100644
10139 --- a/arch/sparc/include/asm/cache.h
10140 +++ b/arch/sparc/include/asm/cache.h
10141 @@ -7,10 +7,12 @@
10142 #ifndef _SPARC_CACHE_H
10143 #define _SPARC_CACHE_H
10144
10145 +#include <linux/const.h>
10146 +
10147 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10148
10149 #define L1_CACHE_SHIFT 5
10150 -#define L1_CACHE_BYTES 32
10151 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10152
10153 #ifdef CONFIG_SPARC32
10154 #define SMP_CACHE_BYTES_SHIFT 5
10155 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10156 index a24e41f..47677ff 100644
10157 --- a/arch/sparc/include/asm/elf_32.h
10158 +++ b/arch/sparc/include/asm/elf_32.h
10159 @@ -114,6 +114,13 @@ typedef struct {
10160
10161 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10162
10163 +#ifdef CONFIG_PAX_ASLR
10164 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10165 +
10166 +#define PAX_DELTA_MMAP_LEN 16
10167 +#define PAX_DELTA_STACK_LEN 16
10168 +#endif
10169 +
10170 /* This yields a mask that user programs can use to figure out what
10171 instruction set this cpu supports. This can NOT be done in userspace
10172 on Sparc. */
10173 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10174 index 370ca1e..d4f4a98 100644
10175 --- a/arch/sparc/include/asm/elf_64.h
10176 +++ b/arch/sparc/include/asm/elf_64.h
10177 @@ -189,6 +189,13 @@ typedef struct {
10178 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10179 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10180
10181 +#ifdef CONFIG_PAX_ASLR
10182 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10183 +
10184 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10185 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10186 +#endif
10187 +
10188 extern unsigned long sparc64_elf_hwcap;
10189 #define ELF_HWCAP sparc64_elf_hwcap
10190
10191 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10192 index a3890da..f6a408e 100644
10193 --- a/arch/sparc/include/asm/pgalloc_32.h
10194 +++ b/arch/sparc/include/asm/pgalloc_32.h
10195 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10196 }
10197
10198 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10199 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10200
10201 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10202 unsigned long address)
10203 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10204 index 5e31871..13469c6 100644
10205 --- a/arch/sparc/include/asm/pgalloc_64.h
10206 +++ b/arch/sparc/include/asm/pgalloc_64.h
10207 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10208 }
10209
10210 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10211 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10212
10213 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10214 {
10215 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10216 }
10217
10218 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10219 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10220
10221 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10222 {
10223 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10224 index 59ba6f6..4518128 100644
10225 --- a/arch/sparc/include/asm/pgtable.h
10226 +++ b/arch/sparc/include/asm/pgtable.h
10227 @@ -5,4 +5,8 @@
10228 #else
10229 #include <asm/pgtable_32.h>
10230 #endif
10231 +
10232 +#define ktla_ktva(addr) (addr)
10233 +#define ktva_ktla(addr) (addr)
10234 +
10235 #endif
10236 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10237 index b9b91ae..950b91e 100644
10238 --- a/arch/sparc/include/asm/pgtable_32.h
10239 +++ b/arch/sparc/include/asm/pgtable_32.h
10240 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10241 #define PAGE_SHARED SRMMU_PAGE_SHARED
10242 #define PAGE_COPY SRMMU_PAGE_COPY
10243 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10244 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10245 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10246 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10247 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10248
10249 /* Top-level page directory - dummy used by init-mm.
10250 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10251
10252 /* xwr */
10253 #define __P000 PAGE_NONE
10254 -#define __P001 PAGE_READONLY
10255 -#define __P010 PAGE_COPY
10256 -#define __P011 PAGE_COPY
10257 +#define __P001 PAGE_READONLY_NOEXEC
10258 +#define __P010 PAGE_COPY_NOEXEC
10259 +#define __P011 PAGE_COPY_NOEXEC
10260 #define __P100 PAGE_READONLY
10261 #define __P101 PAGE_READONLY
10262 #define __P110 PAGE_COPY
10263 #define __P111 PAGE_COPY
10264
10265 #define __S000 PAGE_NONE
10266 -#define __S001 PAGE_READONLY
10267 -#define __S010 PAGE_SHARED
10268 -#define __S011 PAGE_SHARED
10269 +#define __S001 PAGE_READONLY_NOEXEC
10270 +#define __S010 PAGE_SHARED_NOEXEC
10271 +#define __S011 PAGE_SHARED_NOEXEC
10272 #define __S100 PAGE_READONLY
10273 #define __S101 PAGE_READONLY
10274 #define __S110 PAGE_SHARED
10275 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10276 index 79da178..c2eede8 100644
10277 --- a/arch/sparc/include/asm/pgtsrmmu.h
10278 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10279 @@ -115,6 +115,11 @@
10280 SRMMU_EXEC | SRMMU_REF)
10281 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10282 SRMMU_EXEC | SRMMU_REF)
10283 +
10284 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10285 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10286 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10287 +
10288 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10289 SRMMU_DIRTY | SRMMU_REF)
10290
10291 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10292 index 29d64b1..4272fe8 100644
10293 --- a/arch/sparc/include/asm/setup.h
10294 +++ b/arch/sparc/include/asm/setup.h
10295 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10296 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10297
10298 /* init_64.c */
10299 -extern atomic_t dcpage_flushes;
10300 -extern atomic_t dcpage_flushes_xcall;
10301 +extern atomic_unchecked_t dcpage_flushes;
10302 +extern atomic_unchecked_t dcpage_flushes_xcall;
10303
10304 extern int sysctl_tsb_ratio;
10305 #endif
10306 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10307 index 9689176..63c18ea 100644
10308 --- a/arch/sparc/include/asm/spinlock_64.h
10309 +++ b/arch/sparc/include/asm/spinlock_64.h
10310 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10311
10312 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10313
10314 -static void inline arch_read_lock(arch_rwlock_t *lock)
10315 +static inline void arch_read_lock(arch_rwlock_t *lock)
10316 {
10317 unsigned long tmp1, tmp2;
10318
10319 __asm__ __volatile__ (
10320 "1: ldsw [%2], %0\n"
10321 " brlz,pn %0, 2f\n"
10322 -"4: add %0, 1, %1\n"
10323 +"4: addcc %0, 1, %1\n"
10324 +
10325 +#ifdef CONFIG_PAX_REFCOUNT
10326 +" tvs %%icc, 6\n"
10327 +#endif
10328 +
10329 " cas [%2], %0, %1\n"
10330 " cmp %0, %1\n"
10331 " bne,pn %%icc, 1b\n"
10332 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10333 " .previous"
10334 : "=&r" (tmp1), "=&r" (tmp2)
10335 : "r" (lock)
10336 - : "memory");
10337 + : "memory", "cc");
10338 }
10339
10340 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10341 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10342 {
10343 int tmp1, tmp2;
10344
10345 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10346 "1: ldsw [%2], %0\n"
10347 " brlz,a,pn %0, 2f\n"
10348 " mov 0, %0\n"
10349 -" add %0, 1, %1\n"
10350 +" addcc %0, 1, %1\n"
10351 +
10352 +#ifdef CONFIG_PAX_REFCOUNT
10353 +" tvs %%icc, 6\n"
10354 +#endif
10355 +
10356 " cas [%2], %0, %1\n"
10357 " cmp %0, %1\n"
10358 " bne,pn %%icc, 1b\n"
10359 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10360 return tmp1;
10361 }
10362
10363 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10364 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10365 {
10366 unsigned long tmp1, tmp2;
10367
10368 __asm__ __volatile__(
10369 "1: lduw [%2], %0\n"
10370 -" sub %0, 1, %1\n"
10371 +" subcc %0, 1, %1\n"
10372 +
10373 +#ifdef CONFIG_PAX_REFCOUNT
10374 +" tvs %%icc, 6\n"
10375 +#endif
10376 +
10377 " cas [%2], %0, %1\n"
10378 " cmp %0, %1\n"
10379 " bne,pn %%xcc, 1b\n"
10380 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10381 : "memory");
10382 }
10383
10384 -static void inline arch_write_lock(arch_rwlock_t *lock)
10385 +static inline void arch_write_lock(arch_rwlock_t *lock)
10386 {
10387 unsigned long mask, tmp1, tmp2;
10388
10389 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10390 : "memory");
10391 }
10392
10393 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10394 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10395 {
10396 __asm__ __volatile__(
10397 " stw %%g0, [%0]"
10398 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10399 : "memory");
10400 }
10401
10402 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10403 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10404 {
10405 unsigned long mask, tmp1, tmp2, result;
10406
10407 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10408 index 025c984..a216504 100644
10409 --- a/arch/sparc/include/asm/thread_info_32.h
10410 +++ b/arch/sparc/include/asm/thread_info_32.h
10411 @@ -49,6 +49,8 @@ struct thread_info {
10412 unsigned long w_saved;
10413
10414 struct restart_block restart_block;
10415 +
10416 + unsigned long lowest_stack;
10417 };
10418
10419 /*
10420 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10421 index 798f027..b009941 100644
10422 --- a/arch/sparc/include/asm/thread_info_64.h
10423 +++ b/arch/sparc/include/asm/thread_info_64.h
10424 @@ -63,6 +63,8 @@ struct thread_info {
10425 struct pt_regs *kern_una_regs;
10426 unsigned int kern_una_insn;
10427
10428 + unsigned long lowest_stack;
10429 +
10430 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10431 __attribute__ ((aligned(64)));
10432 };
10433 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10434 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10435 /* flag bit 4 is available */
10436 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10437 -/* flag bit 6 is available */
10438 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10439 #define TIF_32BIT 7 /* 32-bit binary */
10440 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10441 #define TIF_SECCOMP 9 /* secure computing */
10442 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10443 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10444 +
10445 /* NOTE: Thread flags >= 12 should be ones we have no interest
10446 * in using in assembly, else we can't use the mask as
10447 * an immediate value in instructions such as andcc.
10448 @@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10449 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10450 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10451 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10452 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10453
10454 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10455 _TIF_DO_NOTIFY_RESUME_MASK | \
10456 _TIF_NEED_RESCHED)
10457 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10458
10459 +#define _TIF_WORK_SYSCALL \
10460 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10461 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10462 +
10463 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10464
10465 /*
10466 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10467 index bd56c28..4b63d83 100644
10468 --- a/arch/sparc/include/asm/uaccess.h
10469 +++ b/arch/sparc/include/asm/uaccess.h
10470 @@ -1,5 +1,6 @@
10471 #ifndef ___ASM_SPARC_UACCESS_H
10472 #define ___ASM_SPARC_UACCESS_H
10473 +
10474 #if defined(__sparc__) && defined(__arch64__)
10475 #include <asm/uaccess_64.h>
10476 #else
10477 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10478 index 9634d08..f55fe4f 100644
10479 --- a/arch/sparc/include/asm/uaccess_32.h
10480 +++ b/arch/sparc/include/asm/uaccess_32.h
10481 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10482
10483 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10484 {
10485 - if (n && __access_ok((unsigned long) to, n))
10486 + if ((long)n < 0)
10487 + return n;
10488 +
10489 + if (n && __access_ok((unsigned long) to, n)) {
10490 + if (!__builtin_constant_p(n))
10491 + check_object_size(from, n, true);
10492 return __copy_user(to, (__force void __user *) from, n);
10493 - else
10494 + } else
10495 return n;
10496 }
10497
10498 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10499 {
10500 + if ((long)n < 0)
10501 + return n;
10502 +
10503 + if (!__builtin_constant_p(n))
10504 + check_object_size(from, n, true);
10505 +
10506 return __copy_user(to, (__force void __user *) from, n);
10507 }
10508
10509 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10510 {
10511 - if (n && __access_ok((unsigned long) from, n))
10512 + if ((long)n < 0)
10513 + return n;
10514 +
10515 + if (n && __access_ok((unsigned long) from, n)) {
10516 + if (!__builtin_constant_p(n))
10517 + check_object_size(to, n, false);
10518 return __copy_user((__force void __user *) to, from, n);
10519 - else
10520 + } else
10521 return n;
10522 }
10523
10524 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10525 {
10526 + if ((long)n < 0)
10527 + return n;
10528 +
10529 return __copy_user((__force void __user *) to, from, n);
10530 }
10531
10532 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10533 index c990a5e..f17b9c1 100644
10534 --- a/arch/sparc/include/asm/uaccess_64.h
10535 +++ b/arch/sparc/include/asm/uaccess_64.h
10536 @@ -10,6 +10,7 @@
10537 #include <linux/compiler.h>
10538 #include <linux/string.h>
10539 #include <linux/thread_info.h>
10540 +#include <linux/kernel.h>
10541 #include <asm/asi.h>
10542 #include <asm/spitfire.h>
10543 #include <asm-generic/uaccess-unaligned.h>
10544 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10545 static inline unsigned long __must_check
10546 copy_from_user(void *to, const void __user *from, unsigned long size)
10547 {
10548 - unsigned long ret = ___copy_from_user(to, from, size);
10549 + unsigned long ret;
10550
10551 + if ((long)size < 0 || size > INT_MAX)
10552 + return size;
10553 +
10554 + if (!__builtin_constant_p(size))
10555 + check_object_size(to, size, false);
10556 +
10557 + ret = ___copy_from_user(to, from, size);
10558 if (unlikely(ret))
10559 ret = copy_from_user_fixup(to, from, size);
10560
10561 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10562 static inline unsigned long __must_check
10563 copy_to_user(void __user *to, const void *from, unsigned long size)
10564 {
10565 - unsigned long ret = ___copy_to_user(to, from, size);
10566 + unsigned long ret;
10567
10568 + if ((long)size < 0 || size > INT_MAX)
10569 + return size;
10570 +
10571 + if (!__builtin_constant_p(size))
10572 + check_object_size(from, size, true);
10573 +
10574 + ret = ___copy_to_user(to, from, size);
10575 if (unlikely(ret))
10576 ret = copy_to_user_fixup(to, from, size);
10577 return ret;
10578 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10579 index 7cf9c6e..6206648 100644
10580 --- a/arch/sparc/kernel/Makefile
10581 +++ b/arch/sparc/kernel/Makefile
10582 @@ -4,7 +4,7 @@
10583 #
10584
10585 asflags-y := -ansi
10586 -ccflags-y := -Werror
10587 +#ccflags-y := -Werror
10588
10589 extra-y := head_$(BITS).o
10590
10591 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10592 index 50e7b62..79fae35 100644
10593 --- a/arch/sparc/kernel/process_32.c
10594 +++ b/arch/sparc/kernel/process_32.c
10595 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10596
10597 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10598 r->psr, r->pc, r->npc, r->y, print_tainted());
10599 - printk("PC: <%pS>\n", (void *) r->pc);
10600 + printk("PC: <%pA>\n", (void *) r->pc);
10601 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10602 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10603 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10604 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10605 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10606 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10607 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10608 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10609
10610 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10611 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10612 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10613 rw = (struct reg_window32 *) fp;
10614 pc = rw->ins[7];
10615 printk("[%08lx : ", pc);
10616 - printk("%pS ] ", (void *) pc);
10617 + printk("%pA ] ", (void *) pc);
10618 fp = rw->ins[6];
10619 } while (++count < 16);
10620 printk("\n");
10621 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10622 index 0be7bf9..2b1cba8 100644
10623 --- a/arch/sparc/kernel/process_64.c
10624 +++ b/arch/sparc/kernel/process_64.c
10625 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10626 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10627 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10628 if (regs->tstate & TSTATE_PRIV)
10629 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10630 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10631 }
10632
10633 void show_regs(struct pt_regs *regs)
10634 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10635
10636 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10637 regs->tpc, regs->tnpc, regs->y, print_tainted());
10638 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10639 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10640 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10641 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10642 regs->u_regs[3]);
10643 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10644 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10645 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10646 regs->u_regs[15]);
10647 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10648 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10649 show_regwindow(regs);
10650 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10651 }
10652 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10653 ((tp && tp->task) ? tp->task->pid : -1));
10654
10655 if (gp->tstate & TSTATE_PRIV) {
10656 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10657 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10658 (void *) gp->tpc,
10659 (void *) gp->o7,
10660 (void *) gp->i7,
10661 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10662 index 79cc0d1..ec62734 100644
10663 --- a/arch/sparc/kernel/prom_common.c
10664 +++ b/arch/sparc/kernel/prom_common.c
10665 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10666
10667 unsigned int prom_early_allocated __initdata;
10668
10669 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10670 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10671 .nextprop = prom_common_nextprop,
10672 .getproplen = prom_getproplen,
10673 .getproperty = prom_getproperty,
10674 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10675 index 9ddc492..27a5619 100644
10676 --- a/arch/sparc/kernel/ptrace_64.c
10677 +++ b/arch/sparc/kernel/ptrace_64.c
10678 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10679 return ret;
10680 }
10681
10682 +#ifdef CONFIG_GRKERNSEC_SETXID
10683 +extern void gr_delayed_cred_worker(void);
10684 +#endif
10685 +
10686 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10687 {
10688 int ret = 0;
10689 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10690 if (test_thread_flag(TIF_NOHZ))
10691 user_exit();
10692
10693 +#ifdef CONFIG_GRKERNSEC_SETXID
10694 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10695 + gr_delayed_cred_worker();
10696 +#endif
10697 +
10698 if (test_thread_flag(TIF_SYSCALL_TRACE))
10699 ret = tracehook_report_syscall_entry(regs);
10700
10701 @@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10702 if (test_thread_flag(TIF_NOHZ))
10703 user_exit();
10704
10705 +#ifdef CONFIG_GRKERNSEC_SETXID
10706 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10707 + gr_delayed_cred_worker();
10708 +#endif
10709 +
10710 audit_syscall_exit(regs);
10711
10712 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10713 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10714 index da6f1a7..e5dea8f 100644
10715 --- a/arch/sparc/kernel/smp_64.c
10716 +++ b/arch/sparc/kernel/smp_64.c
10717 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10718 return;
10719
10720 #ifdef CONFIG_DEBUG_DCFLUSH
10721 - atomic_inc(&dcpage_flushes);
10722 + atomic_inc_unchecked(&dcpage_flushes);
10723 #endif
10724
10725 this_cpu = get_cpu();
10726 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10727 xcall_deliver(data0, __pa(pg_addr),
10728 (u64) pg_addr, cpumask_of(cpu));
10729 #ifdef CONFIG_DEBUG_DCFLUSH
10730 - atomic_inc(&dcpage_flushes_xcall);
10731 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10732 #endif
10733 }
10734 }
10735 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10736 preempt_disable();
10737
10738 #ifdef CONFIG_DEBUG_DCFLUSH
10739 - atomic_inc(&dcpage_flushes);
10740 + atomic_inc_unchecked(&dcpage_flushes);
10741 #endif
10742 data0 = 0;
10743 pg_addr = page_address(page);
10744 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10745 xcall_deliver(data0, __pa(pg_addr),
10746 (u64) pg_addr, cpu_online_mask);
10747 #ifdef CONFIG_DEBUG_DCFLUSH
10748 - atomic_inc(&dcpage_flushes_xcall);
10749 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10750 #endif
10751 }
10752 __local_flush_dcache_page(page);
10753 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10754 index 646988d..b88905f 100644
10755 --- a/arch/sparc/kernel/sys_sparc_32.c
10756 +++ b/arch/sparc/kernel/sys_sparc_32.c
10757 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10758 if (len > TASK_SIZE - PAGE_SIZE)
10759 return -ENOMEM;
10760 if (!addr)
10761 - addr = TASK_UNMAPPED_BASE;
10762 + addr = current->mm->mmap_base;
10763
10764 info.flags = 0;
10765 info.length = len;
10766 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10767 index c85403d..6af95c9 100644
10768 --- a/arch/sparc/kernel/sys_sparc_64.c
10769 +++ b/arch/sparc/kernel/sys_sparc_64.c
10770 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10771 struct vm_area_struct * vma;
10772 unsigned long task_size = TASK_SIZE;
10773 int do_color_align;
10774 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10775 struct vm_unmapped_area_info info;
10776
10777 if (flags & MAP_FIXED) {
10778 /* We do not accept a shared mapping if it would violate
10779 * cache aliasing constraints.
10780 */
10781 - if ((flags & MAP_SHARED) &&
10782 + if ((filp || (flags & MAP_SHARED)) &&
10783 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10784 return -EINVAL;
10785 return addr;
10786 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10787 if (filp || (flags & MAP_SHARED))
10788 do_color_align = 1;
10789
10790 +#ifdef CONFIG_PAX_RANDMMAP
10791 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10792 +#endif
10793 +
10794 if (addr) {
10795 if (do_color_align)
10796 addr = COLOR_ALIGN(addr, pgoff);
10797 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10798 addr = PAGE_ALIGN(addr);
10799
10800 vma = find_vma(mm, addr);
10801 - if (task_size - len >= addr &&
10802 - (!vma || addr + len <= vma->vm_start))
10803 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10804 return addr;
10805 }
10806
10807 info.flags = 0;
10808 info.length = len;
10809 - info.low_limit = TASK_UNMAPPED_BASE;
10810 + info.low_limit = mm->mmap_base;
10811 info.high_limit = min(task_size, VA_EXCLUDE_START);
10812 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10813 info.align_offset = pgoff << PAGE_SHIFT;
10814 + info.threadstack_offset = offset;
10815 addr = vm_unmapped_area(&info);
10816
10817 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10818 VM_BUG_ON(addr != -ENOMEM);
10819 info.low_limit = VA_EXCLUDE_END;
10820 +
10821 +#ifdef CONFIG_PAX_RANDMMAP
10822 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10823 + info.low_limit += mm->delta_mmap;
10824 +#endif
10825 +
10826 info.high_limit = task_size;
10827 addr = vm_unmapped_area(&info);
10828 }
10829 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10830 unsigned long task_size = STACK_TOP32;
10831 unsigned long addr = addr0;
10832 int do_color_align;
10833 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10834 struct vm_unmapped_area_info info;
10835
10836 /* This should only ever run for 32-bit processes. */
10837 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10838 /* We do not accept a shared mapping if it would violate
10839 * cache aliasing constraints.
10840 */
10841 - if ((flags & MAP_SHARED) &&
10842 + if ((filp || (flags & MAP_SHARED)) &&
10843 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10844 return -EINVAL;
10845 return addr;
10846 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10847 if (filp || (flags & MAP_SHARED))
10848 do_color_align = 1;
10849
10850 +#ifdef CONFIG_PAX_RANDMMAP
10851 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10852 +#endif
10853 +
10854 /* requesting a specific address */
10855 if (addr) {
10856 if (do_color_align)
10857 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10858 addr = PAGE_ALIGN(addr);
10859
10860 vma = find_vma(mm, addr);
10861 - if (task_size - len >= addr &&
10862 - (!vma || addr + len <= vma->vm_start))
10863 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10864 return addr;
10865 }
10866
10867 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10868 info.high_limit = mm->mmap_base;
10869 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10870 info.align_offset = pgoff << PAGE_SHIFT;
10871 + info.threadstack_offset = offset;
10872 addr = vm_unmapped_area(&info);
10873
10874 /*
10875 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10876 VM_BUG_ON(addr != -ENOMEM);
10877 info.flags = 0;
10878 info.low_limit = TASK_UNMAPPED_BASE;
10879 +
10880 +#ifdef CONFIG_PAX_RANDMMAP
10881 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10882 + info.low_limit += mm->delta_mmap;
10883 +#endif
10884 +
10885 info.high_limit = STACK_TOP32;
10886 addr = vm_unmapped_area(&info);
10887 }
10888 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10889 EXPORT_SYMBOL(get_fb_unmapped_area);
10890
10891 /* Essentially the same as PowerPC. */
10892 -static unsigned long mmap_rnd(void)
10893 +static unsigned long mmap_rnd(struct mm_struct *mm)
10894 {
10895 unsigned long rnd = 0UL;
10896
10897 +#ifdef CONFIG_PAX_RANDMMAP
10898 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10899 +#endif
10900 +
10901 if (current->flags & PF_RANDOMIZE) {
10902 unsigned long val = get_random_int();
10903 if (test_thread_flag(TIF_32BIT))
10904 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10905
10906 void arch_pick_mmap_layout(struct mm_struct *mm)
10907 {
10908 - unsigned long random_factor = mmap_rnd();
10909 + unsigned long random_factor = mmap_rnd(mm);
10910 unsigned long gap;
10911
10912 /*
10913 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10914 gap == RLIM_INFINITY ||
10915 sysctl_legacy_va_layout) {
10916 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10917 +
10918 +#ifdef CONFIG_PAX_RANDMMAP
10919 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10920 + mm->mmap_base += mm->delta_mmap;
10921 +#endif
10922 +
10923 mm->get_unmapped_area = arch_get_unmapped_area;
10924 } else {
10925 /* We know it's 32-bit */
10926 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10927 gap = (task_size / 6 * 5);
10928
10929 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10930 +
10931 +#ifdef CONFIG_PAX_RANDMMAP
10932 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10933 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10934 +#endif
10935 +
10936 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10937 }
10938 }
10939 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10940 index 33a17e7..d87fb1f 100644
10941 --- a/arch/sparc/kernel/syscalls.S
10942 +++ b/arch/sparc/kernel/syscalls.S
10943 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10944 #endif
10945 .align 32
10946 1: ldx [%g6 + TI_FLAGS], %l5
10947 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10948 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10949 be,pt %icc, rtrap
10950 nop
10951 call syscall_trace_leave
10952 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10953
10954 srl %i3, 0, %o3 ! IEU0
10955 srl %i2, 0, %o2 ! IEU0 Group
10956 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10957 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10958 bne,pn %icc, linux_syscall_trace32 ! CTI
10959 mov %i0, %l5 ! IEU1
10960 5: call %l7 ! CTI Group brk forced
10961 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10962
10963 mov %i3, %o3 ! IEU1
10964 mov %i4, %o4 ! IEU0 Group
10965 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10966 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10967 bne,pn %icc, linux_syscall_trace ! CTI Group
10968 mov %i0, %l5 ! IEU0
10969 2: call %l7 ! CTI Group brk forced
10970 @@ -223,7 +223,7 @@ ret_sys_call:
10971
10972 cmp %o0, -ERESTART_RESTARTBLOCK
10973 bgeu,pn %xcc, 1f
10974 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10975 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10976 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10977
10978 2:
10979 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10980 index 6fd386c5..6907d81 100644
10981 --- a/arch/sparc/kernel/traps_32.c
10982 +++ b/arch/sparc/kernel/traps_32.c
10983 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10984 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10985 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10986
10987 +extern void gr_handle_kernel_exploit(void);
10988 +
10989 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10990 {
10991 static int die_counter;
10992 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10993 count++ < 30 &&
10994 (((unsigned long) rw) >= PAGE_OFFSET) &&
10995 !(((unsigned long) rw) & 0x7)) {
10996 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10997 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10998 (void *) rw->ins[7]);
10999 rw = (struct reg_window32 *)rw->ins[6];
11000 }
11001 }
11002 printk("Instruction DUMP:");
11003 instruction_dump ((unsigned long *) regs->pc);
11004 - if(regs->psr & PSR_PS)
11005 + if(regs->psr & PSR_PS) {
11006 + gr_handle_kernel_exploit();
11007 do_exit(SIGKILL);
11008 + }
11009 do_exit(SIGSEGV);
11010 }
11011
11012 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11013 index 981a769..d906eda 100644
11014 --- a/arch/sparc/kernel/traps_64.c
11015 +++ b/arch/sparc/kernel/traps_64.c
11016 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11017 i + 1,
11018 p->trapstack[i].tstate, p->trapstack[i].tpc,
11019 p->trapstack[i].tnpc, p->trapstack[i].tt);
11020 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11021 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11022 }
11023 }
11024
11025 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11026
11027 lvl -= 0x100;
11028 if (regs->tstate & TSTATE_PRIV) {
11029 +
11030 +#ifdef CONFIG_PAX_REFCOUNT
11031 + if (lvl == 6)
11032 + pax_report_refcount_overflow(regs);
11033 +#endif
11034 +
11035 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11036 die_if_kernel(buffer, regs);
11037 }
11038 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11039 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11040 {
11041 char buffer[32];
11042 -
11043 +
11044 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11045 0, lvl, SIGTRAP) == NOTIFY_STOP)
11046 return;
11047
11048 +#ifdef CONFIG_PAX_REFCOUNT
11049 + if (lvl == 6)
11050 + pax_report_refcount_overflow(regs);
11051 +#endif
11052 +
11053 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11054
11055 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11056 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11057 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11058 printk("%s" "ERROR(%d): ",
11059 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11060 - printk("TPC<%pS>\n", (void *) regs->tpc);
11061 + printk("TPC<%pA>\n", (void *) regs->tpc);
11062 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11063 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11064 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11065 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11066 smp_processor_id(),
11067 (type & 0x1) ? 'I' : 'D',
11068 regs->tpc);
11069 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11070 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11071 panic("Irrecoverable Cheetah+ parity error.");
11072 }
11073
11074 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11075 smp_processor_id(),
11076 (type & 0x1) ? 'I' : 'D',
11077 regs->tpc);
11078 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11079 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11080 }
11081
11082 struct sun4v_error_entry {
11083 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11084 /*0x38*/u64 reserved_5;
11085 };
11086
11087 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11088 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11089 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11090 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11091
11092 static const char *sun4v_err_type_to_str(u8 type)
11093 {
11094 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11095 }
11096
11097 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11098 - int cpu, const char *pfx, atomic_t *ocnt)
11099 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11100 {
11101 u64 *raw_ptr = (u64 *) ent;
11102 u32 attrs;
11103 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11104
11105 show_regs(regs);
11106
11107 - if ((cnt = atomic_read(ocnt)) != 0) {
11108 - atomic_set(ocnt, 0);
11109 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11110 + atomic_set_unchecked(ocnt, 0);
11111 wmb();
11112 printk("%s: Queue overflowed %d times.\n",
11113 pfx, cnt);
11114 @@ -2048,7 +2059,7 @@ out:
11115 */
11116 void sun4v_resum_overflow(struct pt_regs *regs)
11117 {
11118 - atomic_inc(&sun4v_resum_oflow_cnt);
11119 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11120 }
11121
11122 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11123 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11124 /* XXX Actually even this can make not that much sense. Perhaps
11125 * XXX we should just pull the plug and panic directly from here?
11126 */
11127 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11128 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11129 }
11130
11131 static void sun4v_tlb_error(struct pt_regs *regs)
11132 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11133
11134 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11135 regs->tpc, tl);
11136 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11137 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11138 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11139 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11140 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11141 (void *) regs->u_regs[UREG_I7]);
11142 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11143 "pte[%lx] error[%lx]\n",
11144 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11145
11146 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11147 regs->tpc, tl);
11148 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11149 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11150 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11151 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11152 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11153 (void *) regs->u_regs[UREG_I7]);
11154 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11155 "pte[%lx] error[%lx]\n",
11156 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11157 fp = (unsigned long)sf->fp + STACK_BIAS;
11158 }
11159
11160 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11161 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11162 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11163 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11164 int index = tsk->curr_ret_stack;
11165 if (tsk->ret_stack && index >= graph) {
11166 pc = tsk->ret_stack[index - graph].ret;
11167 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11168 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11169 graph++;
11170 }
11171 }
11172 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11173 return (struct reg_window *) (fp + STACK_BIAS);
11174 }
11175
11176 +extern void gr_handle_kernel_exploit(void);
11177 +
11178 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11179 {
11180 static int die_counter;
11181 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11182 while (rw &&
11183 count++ < 30 &&
11184 kstack_valid(tp, (unsigned long) rw)) {
11185 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11186 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11187 (void *) rw->ins[7]);
11188
11189 rw = kernel_stack_up(rw);
11190 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11191 }
11192 user_instruction_dump ((unsigned int __user *) regs->tpc);
11193 }
11194 - if (regs->tstate & TSTATE_PRIV)
11195 + if (regs->tstate & TSTATE_PRIV) {
11196 + gr_handle_kernel_exploit();
11197 do_exit(SIGKILL);
11198 + }
11199 do_exit(SIGSEGV);
11200 }
11201 EXPORT_SYMBOL(die_if_kernel);
11202 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11203 index 62098a8..547ab2c 100644
11204 --- a/arch/sparc/kernel/unaligned_64.c
11205 +++ b/arch/sparc/kernel/unaligned_64.c
11206 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11207 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11208
11209 if (__ratelimit(&ratelimit)) {
11210 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11211 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11212 regs->tpc, (void *) regs->tpc);
11213 }
11214 }
11215 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11216 index 3269b02..64f5231 100644
11217 --- a/arch/sparc/lib/Makefile
11218 +++ b/arch/sparc/lib/Makefile
11219 @@ -2,7 +2,7 @@
11220 #
11221
11222 asflags-y := -ansi -DST_DIV0=0x02
11223 -ccflags-y := -Werror
11224 +#ccflags-y := -Werror
11225
11226 lib-$(CONFIG_SPARC32) += ashrdi3.o
11227 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11228 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11229 index 05dac43..76f8ed4 100644
11230 --- a/arch/sparc/lib/atomic_64.S
11231 +++ b/arch/sparc/lib/atomic_64.S
11232 @@ -15,11 +15,22 @@
11233 * a value and does the barriers.
11234 */
11235
11236 -#define ATOMIC_OP(op) \
11237 -ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11238 +#ifdef CONFIG_PAX_REFCOUNT
11239 +#define __REFCOUNT_OP(op) op##cc
11240 +#define __OVERFLOW_IOP tvs %icc, 6;
11241 +#define __OVERFLOW_XOP tvs %xcc, 6;
11242 +#else
11243 +#define __REFCOUNT_OP(op) op
11244 +#define __OVERFLOW_IOP
11245 +#define __OVERFLOW_XOP
11246 +#endif
11247 +
11248 +#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11249 +ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11250 BACKOFF_SETUP(%o2); \
11251 1: lduw [%o1], %g1; \
11252 - op %g1, %o0, %g7; \
11253 + asm_op %g1, %o0, %g7; \
11254 + post_op \
11255 cas [%o1], %g1, %g7; \
11256 cmp %g1, %g7; \
11257 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11258 @@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11259 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11260 ENDPROC(atomic_##op); \
11261
11262 -#define ATOMIC_OP_RETURN(op) \
11263 -ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11264 +#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11265 + __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11266 +
11267 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11268 +ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11269 BACKOFF_SETUP(%o2); \
11270 1: lduw [%o1], %g1; \
11271 - op %g1, %o0, %g7; \
11272 + asm_op %g1, %o0, %g7; \
11273 + post_op \
11274 cas [%o1], %g1, %g7; \
11275 cmp %g1, %g7; \
11276 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11277 @@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11278 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11279 ENDPROC(atomic_##op##_return);
11280
11281 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11282 + __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11283 +
11284 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11285
11286 ATOMIC_OPS(add)
11287 @@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11288
11289 #undef ATOMIC_OPS
11290 #undef ATOMIC_OP_RETURN
11291 +#undef __ATOMIC_OP_RETURN
11292 #undef ATOMIC_OP
11293 +#undef __ATOMIC_OP
11294
11295 -#define ATOMIC64_OP(op) \
11296 -ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11297 +#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11298 +ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11299 BACKOFF_SETUP(%o2); \
11300 1: ldx [%o1], %g1; \
11301 - op %g1, %o0, %g7; \
11302 + asm_op %g1, %o0, %g7; \
11303 + post_op \
11304 casx [%o1], %g1, %g7; \
11305 cmp %g1, %g7; \
11306 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11307 @@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11308 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11309 ENDPROC(atomic64_##op); \
11310
11311 -#define ATOMIC64_OP_RETURN(op) \
11312 -ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11313 +#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11314 + __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11315 +
11316 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11317 +ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11318 BACKOFF_SETUP(%o2); \
11319 1: ldx [%o1], %g1; \
11320 - op %g1, %o0, %g7; \
11321 + asm_op %g1, %o0, %g7; \
11322 + post_op \
11323 casx [%o1], %g1, %g7; \
11324 cmp %g1, %g7; \
11325 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11326 @@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11327 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11328 ENDPROC(atomic64_##op##_return);
11329
11330 +#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11331 +i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11332 +
11333 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11334
11335 ATOMIC64_OPS(add)
11336 @@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11337
11338 #undef ATOMIC64_OPS
11339 #undef ATOMIC64_OP_RETURN
11340 +#undef __ATOMIC64_OP_RETURN
11341 #undef ATOMIC64_OP
11342 +#undef __ATOMIC64_OP
11343 +#undef __OVERFLOW_XOP
11344 +#undef __OVERFLOW_IOP
11345 +#undef __REFCOUNT_OP
11346
11347 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11348 BACKOFF_SETUP(%o2)
11349 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11350 index 1d649a9..fbc5bfc 100644
11351 --- a/arch/sparc/lib/ksyms.c
11352 +++ b/arch/sparc/lib/ksyms.c
11353 @@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11354 /* Atomic counter implementation. */
11355 #define ATOMIC_OP(op) \
11356 EXPORT_SYMBOL(atomic_##op); \
11357 -EXPORT_SYMBOL(atomic64_##op);
11358 +EXPORT_SYMBOL(atomic_##op##_unchecked); \
11359 +EXPORT_SYMBOL(atomic64_##op); \
11360 +EXPORT_SYMBOL(atomic64_##op##_unchecked);
11361
11362 #define ATOMIC_OP_RETURN(op) \
11363 EXPORT_SYMBOL(atomic_##op##_return); \
11364 @@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11365 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11366
11367 ATOMIC_OPS(add)
11368 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11369 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11370 ATOMIC_OPS(sub)
11371
11372 #undef ATOMIC_OPS
11373 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11374 index 30c3ecc..736f015 100644
11375 --- a/arch/sparc/mm/Makefile
11376 +++ b/arch/sparc/mm/Makefile
11377 @@ -2,7 +2,7 @@
11378 #
11379
11380 asflags-y := -ansi
11381 -ccflags-y := -Werror
11382 +#ccflags-y := -Werror
11383
11384 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11385 obj-y += fault_$(BITS).o
11386 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11387 index 908e8c1..1524793 100644
11388 --- a/arch/sparc/mm/fault_32.c
11389 +++ b/arch/sparc/mm/fault_32.c
11390 @@ -21,6 +21,9 @@
11391 #include <linux/perf_event.h>
11392 #include <linux/interrupt.h>
11393 #include <linux/kdebug.h>
11394 +#include <linux/slab.h>
11395 +#include <linux/pagemap.h>
11396 +#include <linux/compiler.h>
11397
11398 #include <asm/page.h>
11399 #include <asm/pgtable.h>
11400 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11401 return safe_compute_effective_address(regs, insn);
11402 }
11403
11404 +#ifdef CONFIG_PAX_PAGEEXEC
11405 +#ifdef CONFIG_PAX_DLRESOLVE
11406 +static void pax_emuplt_close(struct vm_area_struct *vma)
11407 +{
11408 + vma->vm_mm->call_dl_resolve = 0UL;
11409 +}
11410 +
11411 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11412 +{
11413 + unsigned int *kaddr;
11414 +
11415 + vmf->page = alloc_page(GFP_HIGHUSER);
11416 + if (!vmf->page)
11417 + return VM_FAULT_OOM;
11418 +
11419 + kaddr = kmap(vmf->page);
11420 + memset(kaddr, 0, PAGE_SIZE);
11421 + kaddr[0] = 0x9DE3BFA8U; /* save */
11422 + flush_dcache_page(vmf->page);
11423 + kunmap(vmf->page);
11424 + return VM_FAULT_MAJOR;
11425 +}
11426 +
11427 +static const struct vm_operations_struct pax_vm_ops = {
11428 + .close = pax_emuplt_close,
11429 + .fault = pax_emuplt_fault
11430 +};
11431 +
11432 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11433 +{
11434 + int ret;
11435 +
11436 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11437 + vma->vm_mm = current->mm;
11438 + vma->vm_start = addr;
11439 + vma->vm_end = addr + PAGE_SIZE;
11440 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11441 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11442 + vma->vm_ops = &pax_vm_ops;
11443 +
11444 + ret = insert_vm_struct(current->mm, vma);
11445 + if (ret)
11446 + return ret;
11447 +
11448 + ++current->mm->total_vm;
11449 + return 0;
11450 +}
11451 +#endif
11452 +
11453 +/*
11454 + * PaX: decide what to do with offenders (regs->pc = fault address)
11455 + *
11456 + * returns 1 when task should be killed
11457 + * 2 when patched PLT trampoline was detected
11458 + * 3 when unpatched PLT trampoline was detected
11459 + */
11460 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11461 +{
11462 +
11463 +#ifdef CONFIG_PAX_EMUPLT
11464 + int err;
11465 +
11466 + do { /* PaX: patched PLT emulation #1 */
11467 + unsigned int sethi1, sethi2, jmpl;
11468 +
11469 + err = get_user(sethi1, (unsigned int *)regs->pc);
11470 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11471 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11472 +
11473 + if (err)
11474 + break;
11475 +
11476 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11477 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11478 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11479 + {
11480 + unsigned int addr;
11481 +
11482 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11483 + addr = regs->u_regs[UREG_G1];
11484 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11485 + regs->pc = addr;
11486 + regs->npc = addr+4;
11487 + return 2;
11488 + }
11489 + } while (0);
11490 +
11491 + do { /* PaX: patched PLT emulation #2 */
11492 + unsigned int ba;
11493 +
11494 + err = get_user(ba, (unsigned int *)regs->pc);
11495 +
11496 + if (err)
11497 + break;
11498 +
11499 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11500 + unsigned int addr;
11501 +
11502 + if ((ba & 0xFFC00000U) == 0x30800000U)
11503 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11504 + else
11505 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11506 + regs->pc = addr;
11507 + regs->npc = addr+4;
11508 + return 2;
11509 + }
11510 + } while (0);
11511 +
11512 + do { /* PaX: patched PLT emulation #3 */
11513 + unsigned int sethi, bajmpl, nop;
11514 +
11515 + err = get_user(sethi, (unsigned int *)regs->pc);
11516 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11517 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11518 +
11519 + if (err)
11520 + break;
11521 +
11522 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11523 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11524 + nop == 0x01000000U)
11525 + {
11526 + unsigned int addr;
11527 +
11528 + addr = (sethi & 0x003FFFFFU) << 10;
11529 + regs->u_regs[UREG_G1] = addr;
11530 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11531 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11532 + else
11533 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11534 + regs->pc = addr;
11535 + regs->npc = addr+4;
11536 + return 2;
11537 + }
11538 + } while (0);
11539 +
11540 + do { /* PaX: unpatched PLT emulation step 1 */
11541 + unsigned int sethi, ba, nop;
11542 +
11543 + err = get_user(sethi, (unsigned int *)regs->pc);
11544 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11545 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11546 +
11547 + if (err)
11548 + break;
11549 +
11550 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11551 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11552 + nop == 0x01000000U)
11553 + {
11554 + unsigned int addr, save, call;
11555 +
11556 + if ((ba & 0xFFC00000U) == 0x30800000U)
11557 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11558 + else
11559 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11560 +
11561 + err = get_user(save, (unsigned int *)addr);
11562 + err |= get_user(call, (unsigned int *)(addr+4));
11563 + err |= get_user(nop, (unsigned int *)(addr+8));
11564 + if (err)
11565 + break;
11566 +
11567 +#ifdef CONFIG_PAX_DLRESOLVE
11568 + if (save == 0x9DE3BFA8U &&
11569 + (call & 0xC0000000U) == 0x40000000U &&
11570 + nop == 0x01000000U)
11571 + {
11572 + struct vm_area_struct *vma;
11573 + unsigned long call_dl_resolve;
11574 +
11575 + down_read(&current->mm->mmap_sem);
11576 + call_dl_resolve = current->mm->call_dl_resolve;
11577 + up_read(&current->mm->mmap_sem);
11578 + if (likely(call_dl_resolve))
11579 + goto emulate;
11580 +
11581 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11582 +
11583 + down_write(&current->mm->mmap_sem);
11584 + if (current->mm->call_dl_resolve) {
11585 + call_dl_resolve = current->mm->call_dl_resolve;
11586 + up_write(&current->mm->mmap_sem);
11587 + if (vma)
11588 + kmem_cache_free(vm_area_cachep, vma);
11589 + goto emulate;
11590 + }
11591 +
11592 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11593 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11594 + up_write(&current->mm->mmap_sem);
11595 + if (vma)
11596 + kmem_cache_free(vm_area_cachep, vma);
11597 + return 1;
11598 + }
11599 +
11600 + if (pax_insert_vma(vma, call_dl_resolve)) {
11601 + up_write(&current->mm->mmap_sem);
11602 + kmem_cache_free(vm_area_cachep, vma);
11603 + return 1;
11604 + }
11605 +
11606 + current->mm->call_dl_resolve = call_dl_resolve;
11607 + up_write(&current->mm->mmap_sem);
11608 +
11609 +emulate:
11610 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11611 + regs->pc = call_dl_resolve;
11612 + regs->npc = addr+4;
11613 + return 3;
11614 + }
11615 +#endif
11616 +
11617 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11618 + if ((save & 0xFFC00000U) == 0x05000000U &&
11619 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11620 + nop == 0x01000000U)
11621 + {
11622 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11623 + regs->u_regs[UREG_G2] = addr + 4;
11624 + addr = (save & 0x003FFFFFU) << 10;
11625 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11626 + regs->pc = addr;
11627 + regs->npc = addr+4;
11628 + return 3;
11629 + }
11630 + }
11631 + } while (0);
11632 +
11633 + do { /* PaX: unpatched PLT emulation step 2 */
11634 + unsigned int save, call, nop;
11635 +
11636 + err = get_user(save, (unsigned int *)(regs->pc-4));
11637 + err |= get_user(call, (unsigned int *)regs->pc);
11638 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11639 + if (err)
11640 + break;
11641 +
11642 + if (save == 0x9DE3BFA8U &&
11643 + (call & 0xC0000000U) == 0x40000000U &&
11644 + nop == 0x01000000U)
11645 + {
11646 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11647 +
11648 + regs->u_regs[UREG_RETPC] = regs->pc;
11649 + regs->pc = dl_resolve;
11650 + regs->npc = dl_resolve+4;
11651 + return 3;
11652 + }
11653 + } while (0);
11654 +#endif
11655 +
11656 + return 1;
11657 +}
11658 +
11659 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11660 +{
11661 + unsigned long i;
11662 +
11663 + printk(KERN_ERR "PAX: bytes at PC: ");
11664 + for (i = 0; i < 8; i++) {
11665 + unsigned int c;
11666 + if (get_user(c, (unsigned int *)pc+i))
11667 + printk(KERN_CONT "???????? ");
11668 + else
11669 + printk(KERN_CONT "%08x ", c);
11670 + }
11671 + printk("\n");
11672 +}
11673 +#endif
11674 +
11675 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11676 int text_fault)
11677 {
11678 @@ -226,6 +500,24 @@ good_area:
11679 if (!(vma->vm_flags & VM_WRITE))
11680 goto bad_area;
11681 } else {
11682 +
11683 +#ifdef CONFIG_PAX_PAGEEXEC
11684 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11685 + up_read(&mm->mmap_sem);
11686 + switch (pax_handle_fetch_fault(regs)) {
11687 +
11688 +#ifdef CONFIG_PAX_EMUPLT
11689 + case 2:
11690 + case 3:
11691 + return;
11692 +#endif
11693 +
11694 + }
11695 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11696 + do_group_exit(SIGKILL);
11697 + }
11698 +#endif
11699 +
11700 /* Allow reads even for write-only mappings */
11701 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11702 goto bad_area;
11703 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11704 index 18fcd71..e4fe821 100644
11705 --- a/arch/sparc/mm/fault_64.c
11706 +++ b/arch/sparc/mm/fault_64.c
11707 @@ -22,6 +22,9 @@
11708 #include <linux/kdebug.h>
11709 #include <linux/percpu.h>
11710 #include <linux/context_tracking.h>
11711 +#include <linux/slab.h>
11712 +#include <linux/pagemap.h>
11713 +#include <linux/compiler.h>
11714
11715 #include <asm/page.h>
11716 #include <asm/pgtable.h>
11717 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11718 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11719 regs->tpc);
11720 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11721 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11722 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11723 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11724 dump_stack();
11725 unhandled_fault(regs->tpc, current, regs);
11726 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11727 show_regs(regs);
11728 }
11729
11730 +#ifdef CONFIG_PAX_PAGEEXEC
11731 +#ifdef CONFIG_PAX_DLRESOLVE
11732 +static void pax_emuplt_close(struct vm_area_struct *vma)
11733 +{
11734 + vma->vm_mm->call_dl_resolve = 0UL;
11735 +}
11736 +
11737 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11738 +{
11739 + unsigned int *kaddr;
11740 +
11741 + vmf->page = alloc_page(GFP_HIGHUSER);
11742 + if (!vmf->page)
11743 + return VM_FAULT_OOM;
11744 +
11745 + kaddr = kmap(vmf->page);
11746 + memset(kaddr, 0, PAGE_SIZE);
11747 + kaddr[0] = 0x9DE3BFA8U; /* save */
11748 + flush_dcache_page(vmf->page);
11749 + kunmap(vmf->page);
11750 + return VM_FAULT_MAJOR;
11751 +}
11752 +
11753 +static const struct vm_operations_struct pax_vm_ops = {
11754 + .close = pax_emuplt_close,
11755 + .fault = pax_emuplt_fault
11756 +};
11757 +
11758 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11759 +{
11760 + int ret;
11761 +
11762 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11763 + vma->vm_mm = current->mm;
11764 + vma->vm_start = addr;
11765 + vma->vm_end = addr + PAGE_SIZE;
11766 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11767 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11768 + vma->vm_ops = &pax_vm_ops;
11769 +
11770 + ret = insert_vm_struct(current->mm, vma);
11771 + if (ret)
11772 + return ret;
11773 +
11774 + ++current->mm->total_vm;
11775 + return 0;
11776 +}
11777 +#endif
11778 +
11779 +/*
11780 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11781 + *
11782 + * returns 1 when task should be killed
11783 + * 2 when patched PLT trampoline was detected
11784 + * 3 when unpatched PLT trampoline was detected
11785 + */
11786 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11787 +{
11788 +
11789 +#ifdef CONFIG_PAX_EMUPLT
11790 + int err;
11791 +
11792 + do { /* PaX: patched PLT emulation #1 */
11793 + unsigned int sethi1, sethi2, jmpl;
11794 +
11795 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11796 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11797 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11798 +
11799 + if (err)
11800 + break;
11801 +
11802 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11803 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11804 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11805 + {
11806 + unsigned long addr;
11807 +
11808 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11809 + addr = regs->u_regs[UREG_G1];
11810 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11811 +
11812 + if (test_thread_flag(TIF_32BIT))
11813 + addr &= 0xFFFFFFFFUL;
11814 +
11815 + regs->tpc = addr;
11816 + regs->tnpc = addr+4;
11817 + return 2;
11818 + }
11819 + } while (0);
11820 +
11821 + do { /* PaX: patched PLT emulation #2 */
11822 + unsigned int ba;
11823 +
11824 + err = get_user(ba, (unsigned int *)regs->tpc);
11825 +
11826 + if (err)
11827 + break;
11828 +
11829 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11830 + unsigned long addr;
11831 +
11832 + if ((ba & 0xFFC00000U) == 0x30800000U)
11833 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11834 + else
11835 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11836 +
11837 + if (test_thread_flag(TIF_32BIT))
11838 + addr &= 0xFFFFFFFFUL;
11839 +
11840 + regs->tpc = addr;
11841 + regs->tnpc = addr+4;
11842 + return 2;
11843 + }
11844 + } while (0);
11845 +
11846 + do { /* PaX: patched PLT emulation #3 */
11847 + unsigned int sethi, bajmpl, nop;
11848 +
11849 + err = get_user(sethi, (unsigned int *)regs->tpc);
11850 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11851 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11852 +
11853 + if (err)
11854 + break;
11855 +
11856 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11857 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11858 + nop == 0x01000000U)
11859 + {
11860 + unsigned long addr;
11861 +
11862 + addr = (sethi & 0x003FFFFFU) << 10;
11863 + regs->u_regs[UREG_G1] = addr;
11864 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11865 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11866 + else
11867 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11868 +
11869 + if (test_thread_flag(TIF_32BIT))
11870 + addr &= 0xFFFFFFFFUL;
11871 +
11872 + regs->tpc = addr;
11873 + regs->tnpc = addr+4;
11874 + return 2;
11875 + }
11876 + } while (0);
11877 +
11878 + do { /* PaX: patched PLT emulation #4 */
11879 + unsigned int sethi, mov1, call, mov2;
11880 +
11881 + err = get_user(sethi, (unsigned int *)regs->tpc);
11882 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11883 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11884 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11885 +
11886 + if (err)
11887 + break;
11888 +
11889 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11890 + mov1 == 0x8210000FU &&
11891 + (call & 0xC0000000U) == 0x40000000U &&
11892 + mov2 == 0x9E100001U)
11893 + {
11894 + unsigned long addr;
11895 +
11896 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11897 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11898 +
11899 + if (test_thread_flag(TIF_32BIT))
11900 + addr &= 0xFFFFFFFFUL;
11901 +
11902 + regs->tpc = addr;
11903 + regs->tnpc = addr+4;
11904 + return 2;
11905 + }
11906 + } while (0);
11907 +
11908 + do { /* PaX: patched PLT emulation #5 */
11909 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11910 +
11911 + err = get_user(sethi, (unsigned int *)regs->tpc);
11912 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11913 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11914 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11915 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11916 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11917 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11918 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11919 +
11920 + if (err)
11921 + break;
11922 +
11923 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11924 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11925 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11926 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11927 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11928 + sllx == 0x83287020U &&
11929 + jmpl == 0x81C04005U &&
11930 + nop == 0x01000000U)
11931 + {
11932 + unsigned long addr;
11933 +
11934 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11935 + regs->u_regs[UREG_G1] <<= 32;
11936 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11937 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11938 + regs->tpc = addr;
11939 + regs->tnpc = addr+4;
11940 + return 2;
11941 + }
11942 + } while (0);
11943 +
11944 + do { /* PaX: patched PLT emulation #6 */
11945 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11946 +
11947 + err = get_user(sethi, (unsigned int *)regs->tpc);
11948 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11949 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11950 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11951 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11952 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11953 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11954 +
11955 + if (err)
11956 + break;
11957 +
11958 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11959 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11960 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11961 + sllx == 0x83287020U &&
11962 + (or & 0xFFFFE000U) == 0x8A116000U &&
11963 + jmpl == 0x81C04005U &&
11964 + nop == 0x01000000U)
11965 + {
11966 + unsigned long addr;
11967 +
11968 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11969 + regs->u_regs[UREG_G1] <<= 32;
11970 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11971 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11972 + regs->tpc = addr;
11973 + regs->tnpc = addr+4;
11974 + return 2;
11975 + }
11976 + } while (0);
11977 +
11978 + do { /* PaX: unpatched PLT emulation step 1 */
11979 + unsigned int sethi, ba, nop;
11980 +
11981 + err = get_user(sethi, (unsigned int *)regs->tpc);
11982 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11983 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11984 +
11985 + if (err)
11986 + break;
11987 +
11988 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11989 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11990 + nop == 0x01000000U)
11991 + {
11992 + unsigned long addr;
11993 + unsigned int save, call;
11994 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11995 +
11996 + if ((ba & 0xFFC00000U) == 0x30800000U)
11997 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11998 + else
11999 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12000 +
12001 + if (test_thread_flag(TIF_32BIT))
12002 + addr &= 0xFFFFFFFFUL;
12003 +
12004 + err = get_user(save, (unsigned int *)addr);
12005 + err |= get_user(call, (unsigned int *)(addr+4));
12006 + err |= get_user(nop, (unsigned int *)(addr+8));
12007 + if (err)
12008 + break;
12009 +
12010 +#ifdef CONFIG_PAX_DLRESOLVE
12011 + if (save == 0x9DE3BFA8U &&
12012 + (call & 0xC0000000U) == 0x40000000U &&
12013 + nop == 0x01000000U)
12014 + {
12015 + struct vm_area_struct *vma;
12016 + unsigned long call_dl_resolve;
12017 +
12018 + down_read(&current->mm->mmap_sem);
12019 + call_dl_resolve = current->mm->call_dl_resolve;
12020 + up_read(&current->mm->mmap_sem);
12021 + if (likely(call_dl_resolve))
12022 + goto emulate;
12023 +
12024 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12025 +
12026 + down_write(&current->mm->mmap_sem);
12027 + if (current->mm->call_dl_resolve) {
12028 + call_dl_resolve = current->mm->call_dl_resolve;
12029 + up_write(&current->mm->mmap_sem);
12030 + if (vma)
12031 + kmem_cache_free(vm_area_cachep, vma);
12032 + goto emulate;
12033 + }
12034 +
12035 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12036 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12037 + up_write(&current->mm->mmap_sem);
12038 + if (vma)
12039 + kmem_cache_free(vm_area_cachep, vma);
12040 + return 1;
12041 + }
12042 +
12043 + if (pax_insert_vma(vma, call_dl_resolve)) {
12044 + up_write(&current->mm->mmap_sem);
12045 + kmem_cache_free(vm_area_cachep, vma);
12046 + return 1;
12047 + }
12048 +
12049 + current->mm->call_dl_resolve = call_dl_resolve;
12050 + up_write(&current->mm->mmap_sem);
12051 +
12052 +emulate:
12053 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12054 + regs->tpc = call_dl_resolve;
12055 + regs->tnpc = addr+4;
12056 + return 3;
12057 + }
12058 +#endif
12059 +
12060 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12061 + if ((save & 0xFFC00000U) == 0x05000000U &&
12062 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12063 + nop == 0x01000000U)
12064 + {
12065 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12066 + regs->u_regs[UREG_G2] = addr + 4;
12067 + addr = (save & 0x003FFFFFU) << 10;
12068 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12069 +
12070 + if (test_thread_flag(TIF_32BIT))
12071 + addr &= 0xFFFFFFFFUL;
12072 +
12073 + regs->tpc = addr;
12074 + regs->tnpc = addr+4;
12075 + return 3;
12076 + }
12077 +
12078 + /* PaX: 64-bit PLT stub */
12079 + err = get_user(sethi1, (unsigned int *)addr);
12080 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12081 + err |= get_user(or1, (unsigned int *)(addr+8));
12082 + err |= get_user(or2, (unsigned int *)(addr+12));
12083 + err |= get_user(sllx, (unsigned int *)(addr+16));
12084 + err |= get_user(add, (unsigned int *)(addr+20));
12085 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12086 + err |= get_user(nop, (unsigned int *)(addr+28));
12087 + if (err)
12088 + break;
12089 +
12090 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12091 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12092 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12093 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12094 + sllx == 0x89293020U &&
12095 + add == 0x8A010005U &&
12096 + jmpl == 0x89C14000U &&
12097 + nop == 0x01000000U)
12098 + {
12099 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12100 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12101 + regs->u_regs[UREG_G4] <<= 32;
12102 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12103 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12104 + regs->u_regs[UREG_G4] = addr + 24;
12105 + addr = regs->u_regs[UREG_G5];
12106 + regs->tpc = addr;
12107 + regs->tnpc = addr+4;
12108 + return 3;
12109 + }
12110 + }
12111 + } while (0);
12112 +
12113 +#ifdef CONFIG_PAX_DLRESOLVE
12114 + do { /* PaX: unpatched PLT emulation step 2 */
12115 + unsigned int save, call, nop;
12116 +
12117 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12118 + err |= get_user(call, (unsigned int *)regs->tpc);
12119 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12120 + if (err)
12121 + break;
12122 +
12123 + if (save == 0x9DE3BFA8U &&
12124 + (call & 0xC0000000U) == 0x40000000U &&
12125 + nop == 0x01000000U)
12126 + {
12127 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12128 +
12129 + if (test_thread_flag(TIF_32BIT))
12130 + dl_resolve &= 0xFFFFFFFFUL;
12131 +
12132 + regs->u_regs[UREG_RETPC] = regs->tpc;
12133 + regs->tpc = dl_resolve;
12134 + regs->tnpc = dl_resolve+4;
12135 + return 3;
12136 + }
12137 + } while (0);
12138 +#endif
12139 +
12140 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12141 + unsigned int sethi, ba, nop;
12142 +
12143 + err = get_user(sethi, (unsigned int *)regs->tpc);
12144 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12145 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12146 +
12147 + if (err)
12148 + break;
12149 +
12150 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12151 + (ba & 0xFFF00000U) == 0x30600000U &&
12152 + nop == 0x01000000U)
12153 + {
12154 + unsigned long addr;
12155 +
12156 + addr = (sethi & 0x003FFFFFU) << 10;
12157 + regs->u_regs[UREG_G1] = addr;
12158 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12159 +
12160 + if (test_thread_flag(TIF_32BIT))
12161 + addr &= 0xFFFFFFFFUL;
12162 +
12163 + regs->tpc = addr;
12164 + regs->tnpc = addr+4;
12165 + return 2;
12166 + }
12167 + } while (0);
12168 +
12169 +#endif
12170 +
12171 + return 1;
12172 +}
12173 +
12174 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12175 +{
12176 + unsigned long i;
12177 +
12178 + printk(KERN_ERR "PAX: bytes at PC: ");
12179 + for (i = 0; i < 8; i++) {
12180 + unsigned int c;
12181 + if (get_user(c, (unsigned int *)pc+i))
12182 + printk(KERN_CONT "???????? ");
12183 + else
12184 + printk(KERN_CONT "%08x ", c);
12185 + }
12186 + printk("\n");
12187 +}
12188 +#endif
12189 +
12190 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12191 {
12192 enum ctx_state prev_state = exception_enter();
12193 @@ -353,6 +816,29 @@ retry:
12194 if (!vma)
12195 goto bad_area;
12196
12197 +#ifdef CONFIG_PAX_PAGEEXEC
12198 + /* PaX: detect ITLB misses on non-exec pages */
12199 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12200 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12201 + {
12202 + if (address != regs->tpc)
12203 + goto good_area;
12204 +
12205 + up_read(&mm->mmap_sem);
12206 + switch (pax_handle_fetch_fault(regs)) {
12207 +
12208 +#ifdef CONFIG_PAX_EMUPLT
12209 + case 2:
12210 + case 3:
12211 + return;
12212 +#endif
12213 +
12214 + }
12215 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12216 + do_group_exit(SIGKILL);
12217 + }
12218 +#endif
12219 +
12220 /* Pure DTLB misses do not tell us whether the fault causing
12221 * load/store/atomic was a write or not, it only says that there
12222 * was no match. So in such a case we (carefully) read the
12223 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12224 index d329537..2c3746a 100644
12225 --- a/arch/sparc/mm/hugetlbpage.c
12226 +++ b/arch/sparc/mm/hugetlbpage.c
12227 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12228 unsigned long addr,
12229 unsigned long len,
12230 unsigned long pgoff,
12231 - unsigned long flags)
12232 + unsigned long flags,
12233 + unsigned long offset)
12234 {
12235 + struct mm_struct *mm = current->mm;
12236 unsigned long task_size = TASK_SIZE;
12237 struct vm_unmapped_area_info info;
12238
12239 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12240
12241 info.flags = 0;
12242 info.length = len;
12243 - info.low_limit = TASK_UNMAPPED_BASE;
12244 + info.low_limit = mm->mmap_base;
12245 info.high_limit = min(task_size, VA_EXCLUDE_START);
12246 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12247 info.align_offset = 0;
12248 + info.threadstack_offset = offset;
12249 addr = vm_unmapped_area(&info);
12250
12251 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12252 VM_BUG_ON(addr != -ENOMEM);
12253 info.low_limit = VA_EXCLUDE_END;
12254 +
12255 +#ifdef CONFIG_PAX_RANDMMAP
12256 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12257 + info.low_limit += mm->delta_mmap;
12258 +#endif
12259 +
12260 info.high_limit = task_size;
12261 addr = vm_unmapped_area(&info);
12262 }
12263 @@ -55,7 +64,8 @@ static unsigned long
12264 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12265 const unsigned long len,
12266 const unsigned long pgoff,
12267 - const unsigned long flags)
12268 + const unsigned long flags,
12269 + const unsigned long offset)
12270 {
12271 struct mm_struct *mm = current->mm;
12272 unsigned long addr = addr0;
12273 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12274 info.high_limit = mm->mmap_base;
12275 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12276 info.align_offset = 0;
12277 + info.threadstack_offset = offset;
12278 addr = vm_unmapped_area(&info);
12279
12280 /*
12281 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12282 VM_BUG_ON(addr != -ENOMEM);
12283 info.flags = 0;
12284 info.low_limit = TASK_UNMAPPED_BASE;
12285 +
12286 +#ifdef CONFIG_PAX_RANDMMAP
12287 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12288 + info.low_limit += mm->delta_mmap;
12289 +#endif
12290 +
12291 info.high_limit = STACK_TOP32;
12292 addr = vm_unmapped_area(&info);
12293 }
12294 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12295 struct mm_struct *mm = current->mm;
12296 struct vm_area_struct *vma;
12297 unsigned long task_size = TASK_SIZE;
12298 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12299
12300 if (test_thread_flag(TIF_32BIT))
12301 task_size = STACK_TOP32;
12302 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12303 return addr;
12304 }
12305
12306 +#ifdef CONFIG_PAX_RANDMMAP
12307 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12308 +#endif
12309 +
12310 if (addr) {
12311 addr = ALIGN(addr, HPAGE_SIZE);
12312 vma = find_vma(mm, addr);
12313 - if (task_size - len >= addr &&
12314 - (!vma || addr + len <= vma->vm_start))
12315 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12316 return addr;
12317 }
12318 if (mm->get_unmapped_area == arch_get_unmapped_area)
12319 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12320 - pgoff, flags);
12321 + pgoff, flags, offset);
12322 else
12323 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12324 - pgoff, flags);
12325 + pgoff, flags, offset);
12326 }
12327
12328 pte_t *huge_pte_alloc(struct mm_struct *mm,
12329 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12330 index 2d91c62..17a8fff 100644
12331 --- a/arch/sparc/mm/init_64.c
12332 +++ b/arch/sparc/mm/init_64.c
12333 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12334 int num_kernel_image_mappings;
12335
12336 #ifdef CONFIG_DEBUG_DCFLUSH
12337 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12338 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12339 #ifdef CONFIG_SMP
12340 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12341 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12342 #endif
12343 #endif
12344
12345 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12346 {
12347 BUG_ON(tlb_type == hypervisor);
12348 #ifdef CONFIG_DEBUG_DCFLUSH
12349 - atomic_inc(&dcpage_flushes);
12350 + atomic_inc_unchecked(&dcpage_flushes);
12351 #endif
12352
12353 #ifdef DCACHE_ALIASING_POSSIBLE
12354 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12355
12356 #ifdef CONFIG_DEBUG_DCFLUSH
12357 seq_printf(m, "DCPageFlushes\t: %d\n",
12358 - atomic_read(&dcpage_flushes));
12359 + atomic_read_unchecked(&dcpage_flushes));
12360 #ifdef CONFIG_SMP
12361 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12362 - atomic_read(&dcpage_flushes_xcall));
12363 + atomic_read_unchecked(&dcpage_flushes_xcall));
12364 #endif /* CONFIG_SMP */
12365 #endif /* CONFIG_DEBUG_DCFLUSH */
12366 }
12367 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12368 index 7cca418..53fc030 100644
12369 --- a/arch/tile/Kconfig
12370 +++ b/arch/tile/Kconfig
12371 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12372
12373 config KEXEC
12374 bool "kexec system call"
12375 + depends on !GRKERNSEC_KMEM
12376 ---help---
12377 kexec is a system call that implements the ability to shutdown your
12378 current kernel, and to start another kernel. It is like a reboot
12379 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12380 index 7b11c5f..755a026 100644
12381 --- a/arch/tile/include/asm/atomic_64.h
12382 +++ b/arch/tile/include/asm/atomic_64.h
12383 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12384
12385 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12386
12387 +#define atomic64_read_unchecked(v) atomic64_read(v)
12388 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12389 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12390 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12391 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12392 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12393 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12394 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12395 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12396 +
12397 /* Define this to indicate that cmpxchg is an efficient operation. */
12398 #define __HAVE_ARCH_CMPXCHG
12399
12400 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12401 index 6160761..00cac88 100644
12402 --- a/arch/tile/include/asm/cache.h
12403 +++ b/arch/tile/include/asm/cache.h
12404 @@ -15,11 +15,12 @@
12405 #ifndef _ASM_TILE_CACHE_H
12406 #define _ASM_TILE_CACHE_H
12407
12408 +#include <linux/const.h>
12409 #include <arch/chip.h>
12410
12411 /* bytes per L1 data cache line */
12412 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12413 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12414 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12415
12416 /* bytes per L2 cache line */
12417 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12418 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12419 index b6cde32..c0cb736 100644
12420 --- a/arch/tile/include/asm/uaccess.h
12421 +++ b/arch/tile/include/asm/uaccess.h
12422 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12423 const void __user *from,
12424 unsigned long n)
12425 {
12426 - int sz = __compiletime_object_size(to);
12427 + size_t sz = __compiletime_object_size(to);
12428
12429 - if (likely(sz == -1 || sz >= n))
12430 + if (likely(sz == (size_t)-1 || sz >= n))
12431 n = _copy_from_user(to, from, n);
12432 else
12433 copy_from_user_overflow();
12434 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12435 index e514899..f8743c4 100644
12436 --- a/arch/tile/mm/hugetlbpage.c
12437 +++ b/arch/tile/mm/hugetlbpage.c
12438 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12439 info.high_limit = TASK_SIZE;
12440 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12441 info.align_offset = 0;
12442 + info.threadstack_offset = 0;
12443 return vm_unmapped_area(&info);
12444 }
12445
12446 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12447 info.high_limit = current->mm->mmap_base;
12448 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12449 info.align_offset = 0;
12450 + info.threadstack_offset = 0;
12451 addr = vm_unmapped_area(&info);
12452
12453 /*
12454 diff --git a/arch/um/Makefile b/arch/um/Makefile
12455 index e4b1a96..16162f8 100644
12456 --- a/arch/um/Makefile
12457 +++ b/arch/um/Makefile
12458 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12459 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12460 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12461
12462 +ifdef CONSTIFY_PLUGIN
12463 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12464 +endif
12465 +
12466 #This will adjust *FLAGS accordingly to the platform.
12467 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12468
12469 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12470 index 19e1bdd..3665b77 100644
12471 --- a/arch/um/include/asm/cache.h
12472 +++ b/arch/um/include/asm/cache.h
12473 @@ -1,6 +1,7 @@
12474 #ifndef __UM_CACHE_H
12475 #define __UM_CACHE_H
12476
12477 +#include <linux/const.h>
12478
12479 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12480 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12481 @@ -12,6 +13,6 @@
12482 # define L1_CACHE_SHIFT 5
12483 #endif
12484
12485 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12486 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12487
12488 #endif
12489 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12490 index 2e0a6b1..a64d0f5 100644
12491 --- a/arch/um/include/asm/kmap_types.h
12492 +++ b/arch/um/include/asm/kmap_types.h
12493 @@ -8,6 +8,6 @@
12494
12495 /* No more #include "asm/arch/kmap_types.h" ! */
12496
12497 -#define KM_TYPE_NR 14
12498 +#define KM_TYPE_NR 15
12499
12500 #endif
12501 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12502 index 71c5d13..4c7b9f1 100644
12503 --- a/arch/um/include/asm/page.h
12504 +++ b/arch/um/include/asm/page.h
12505 @@ -14,6 +14,9 @@
12506 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12507 #define PAGE_MASK (~(PAGE_SIZE-1))
12508
12509 +#define ktla_ktva(addr) (addr)
12510 +#define ktva_ktla(addr) (addr)
12511 +
12512 #ifndef __ASSEMBLY__
12513
12514 struct page;
12515 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12516 index 0032f92..cd151e0 100644
12517 --- a/arch/um/include/asm/pgtable-3level.h
12518 +++ b/arch/um/include/asm/pgtable-3level.h
12519 @@ -58,6 +58,7 @@
12520 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12521 #define pud_populate(mm, pud, pmd) \
12522 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12523 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12524
12525 #ifdef CONFIG_64BIT
12526 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12527 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12528 index f17bca8..48adb87 100644
12529 --- a/arch/um/kernel/process.c
12530 +++ b/arch/um/kernel/process.c
12531 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12532 return 2;
12533 }
12534
12535 -/*
12536 - * Only x86 and x86_64 have an arch_align_stack().
12537 - * All other arches have "#define arch_align_stack(x) (x)"
12538 - * in their asm/exec.h
12539 - * As this is included in UML from asm-um/system-generic.h,
12540 - * we can use it to behave as the subarch does.
12541 - */
12542 -#ifndef arch_align_stack
12543 -unsigned long arch_align_stack(unsigned long sp)
12544 -{
12545 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12546 - sp -= get_random_int() % 8192;
12547 - return sp & ~0xf;
12548 -}
12549 -#endif
12550 -
12551 unsigned long get_wchan(struct task_struct *p)
12552 {
12553 unsigned long stack_page, sp, ip;
12554 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12555 index ad8f795..2c7eec6 100644
12556 --- a/arch/unicore32/include/asm/cache.h
12557 +++ b/arch/unicore32/include/asm/cache.h
12558 @@ -12,8 +12,10 @@
12559 #ifndef __UNICORE_CACHE_H__
12560 #define __UNICORE_CACHE_H__
12561
12562 -#define L1_CACHE_SHIFT (5)
12563 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12564 +#include <linux/const.h>
12565 +
12566 +#define L1_CACHE_SHIFT 5
12567 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12568
12569 /*
12570 * Memory returned by kmalloc() may be used for DMA, so we must make
12571 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12572 index 3635fff..c1f9fab 100644
12573 --- a/arch/x86/Kconfig
12574 +++ b/arch/x86/Kconfig
12575 @@ -129,7 +129,7 @@ config X86
12576 select RTC_LIB
12577 select HAVE_DEBUG_STACKOVERFLOW
12578 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12579 - select HAVE_CC_STACKPROTECTOR
12580 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12581 select GENERIC_CPU_AUTOPROBE
12582 select HAVE_ARCH_AUDITSYSCALL
12583 select ARCH_SUPPORTS_ATOMIC_RMW
12584 @@ -262,7 +262,7 @@ config X86_HT
12585
12586 config X86_32_LAZY_GS
12587 def_bool y
12588 - depends on X86_32 && !CC_STACKPROTECTOR
12589 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12590
12591 config ARCH_HWEIGHT_CFLAGS
12592 string
12593 @@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12594
12595 menuconfig HYPERVISOR_GUEST
12596 bool "Linux guest support"
12597 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12598 ---help---
12599 Say Y here to enable options for running Linux under various hyper-
12600 visors. This option enables basic hypervisor detection and platform
12601 @@ -977,6 +978,7 @@ config VM86
12602
12603 config X86_16BIT
12604 bool "Enable support for 16-bit segments" if EXPERT
12605 + depends on !GRKERNSEC
12606 default y
12607 ---help---
12608 This option is required by programs like Wine to run 16-bit
12609 @@ -1132,6 +1134,7 @@ choice
12610
12611 config NOHIGHMEM
12612 bool "off"
12613 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12614 ---help---
12615 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12616 However, the address space of 32-bit x86 processors is only 4
12617 @@ -1168,6 +1171,7 @@ config NOHIGHMEM
12618
12619 config HIGHMEM4G
12620 bool "4GB"
12621 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12622 ---help---
12623 Select this if you have a 32-bit processor and between 1 and 4
12624 gigabytes of physical RAM.
12625 @@ -1220,7 +1224,7 @@ config PAGE_OFFSET
12626 hex
12627 default 0xB0000000 if VMSPLIT_3G_OPT
12628 default 0x80000000 if VMSPLIT_2G
12629 - default 0x78000000 if VMSPLIT_2G_OPT
12630 + default 0x70000000 if VMSPLIT_2G_OPT
12631 default 0x40000000 if VMSPLIT_1G
12632 default 0xC0000000
12633 depends on X86_32
12634 @@ -1635,6 +1639,7 @@ source kernel/Kconfig.hz
12635
12636 config KEXEC
12637 bool "kexec system call"
12638 + depends on !GRKERNSEC_KMEM
12639 ---help---
12640 kexec is a system call that implements the ability to shutdown your
12641 current kernel, and to start another kernel. It is like a reboot
12642 @@ -1820,7 +1825,9 @@ config X86_NEED_RELOCS
12643
12644 config PHYSICAL_ALIGN
12645 hex "Alignment value to which kernel should be aligned"
12646 - default "0x200000"
12647 + default "0x1000000"
12648 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12649 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12650 range 0x2000 0x1000000 if X86_32
12651 range 0x200000 0x1000000 if X86_64
12652 ---help---
12653 @@ -1903,6 +1910,7 @@ config COMPAT_VDSO
12654 def_bool n
12655 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12656 depends on X86_32 || IA32_EMULATION
12657 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12658 ---help---
12659 Certain buggy versions of glibc will crash if they are
12660 presented with a 32-bit vDSO that is not mapped at the address
12661 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12662 index 6983314..54ad7e8 100644
12663 --- a/arch/x86/Kconfig.cpu
12664 +++ b/arch/x86/Kconfig.cpu
12665 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12666
12667 config X86_F00F_BUG
12668 def_bool y
12669 - depends on M586MMX || M586TSC || M586 || M486
12670 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12671
12672 config X86_INVD_BUG
12673 def_bool y
12674 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12675
12676 config X86_ALIGNMENT_16
12677 def_bool y
12678 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12679 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12680
12681 config X86_INTEL_USERCOPY
12682 def_bool y
12683 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12684 # generates cmov.
12685 config X86_CMOV
12686 def_bool y
12687 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12688 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12689
12690 config X86_MINIMUM_CPU_FAMILY
12691 int
12692 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12693 index 61bd2ad..50b625d 100644
12694 --- a/arch/x86/Kconfig.debug
12695 +++ b/arch/x86/Kconfig.debug
12696 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12697 config DEBUG_RODATA
12698 bool "Write protect kernel read-only data structures"
12699 default y
12700 - depends on DEBUG_KERNEL
12701 + depends on DEBUG_KERNEL && BROKEN
12702 ---help---
12703 Mark the kernel read-only data as write-protected in the pagetables,
12704 in order to catch accidental (and incorrect) writes to such const
12705 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12706
12707 config DEBUG_SET_MODULE_RONX
12708 bool "Set loadable kernel module data as NX and text as RO"
12709 - depends on MODULES
12710 + depends on MODULES && BROKEN
12711 ---help---
12712 This option helps catch unintended modifications to loadable
12713 kernel module's text and read-only data. It also prevents execution
12714 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12715 index 920e616..ac3d4df 100644
12716 --- a/arch/x86/Makefile
12717 +++ b/arch/x86/Makefile
12718 @@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12719 # CPU-specific tuning. Anything which can be shared with UML should go here.
12720 include $(srctree)/arch/x86/Makefile_32.cpu
12721 KBUILD_CFLAGS += $(cflags-y)
12722 -
12723 - # temporary until string.h is fixed
12724 - KBUILD_CFLAGS += -ffreestanding
12725 else
12726 BITS := 64
12727 UTS_MACHINE := x86_64
12728 @@ -107,6 +104,9 @@ else
12729 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12730 endif
12731
12732 +# temporary until string.h is fixed
12733 +KBUILD_CFLAGS += -ffreestanding
12734 +
12735 # Make sure compiler does not have buggy stack-protector support.
12736 ifdef CONFIG_CC_STACKPROTECTOR
12737 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12738 @@ -180,6 +180,7 @@ archheaders:
12739 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12740
12741 archprepare:
12742 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12743 ifeq ($(CONFIG_KEXEC_FILE),y)
12744 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12745 endif
12746 @@ -263,3 +264,9 @@ define archhelp
12747 echo ' FDARGS="..." arguments for the booted kernel'
12748 echo ' FDINITRD=file initrd for the booted kernel'
12749 endef
12750 +
12751 +define OLD_LD
12752 +
12753 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12754 +*** Please upgrade your binutils to 2.18 or newer
12755 +endef
12756 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12757 index 3db07f3..9d81d0f 100644
12758 --- a/arch/x86/boot/Makefile
12759 +++ b/arch/x86/boot/Makefile
12760 @@ -56,6 +56,9 @@ clean-files += cpustr.h
12761 # ---------------------------------------------------------------------------
12762
12763 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12764 +ifdef CONSTIFY_PLUGIN
12765 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12766 +endif
12767 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12768 GCOV_PROFILE := n
12769
12770 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12771 index 878e4b9..20537ab 100644
12772 --- a/arch/x86/boot/bitops.h
12773 +++ b/arch/x86/boot/bitops.h
12774 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12775 u8 v;
12776 const u32 *p = (const u32 *)addr;
12777
12778 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12779 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12780 return v;
12781 }
12782
12783 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12784
12785 static inline void set_bit(int nr, void *addr)
12786 {
12787 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12788 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12789 }
12790
12791 #endif /* BOOT_BITOPS_H */
12792 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12793 index bd49ec6..94c7f58 100644
12794 --- a/arch/x86/boot/boot.h
12795 +++ b/arch/x86/boot/boot.h
12796 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12797 static inline u16 ds(void)
12798 {
12799 u16 seg;
12800 - asm("movw %%ds,%0" : "=rm" (seg));
12801 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12802 return seg;
12803 }
12804
12805 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12806 index 45abc36..97bea2d 100644
12807 --- a/arch/x86/boot/compressed/Makefile
12808 +++ b/arch/x86/boot/compressed/Makefile
12809 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12810 KBUILD_CFLAGS += -mno-mmx -mno-sse
12811 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12812 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12813 +ifdef CONSTIFY_PLUGIN
12814 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12815 +endif
12816
12817 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12818 GCOV_PROFILE := n
12819 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12820 index a53440e..c3dbf1e 100644
12821 --- a/arch/x86/boot/compressed/efi_stub_32.S
12822 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12823 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12824 * parameter 2, ..., param n. To make things easy, we save the return
12825 * address of efi_call_phys in a global variable.
12826 */
12827 - popl %ecx
12828 - movl %ecx, saved_return_addr(%edx)
12829 - /* get the function pointer into ECX*/
12830 - popl %ecx
12831 - movl %ecx, efi_rt_function_ptr(%edx)
12832 + popl saved_return_addr(%edx)
12833 + popl efi_rt_function_ptr(%edx)
12834
12835 /*
12836 * 3. Call the physical function.
12837 */
12838 - call *%ecx
12839 + call *efi_rt_function_ptr(%edx)
12840
12841 /*
12842 * 4. Balance the stack. And because EAX contain the return value,
12843 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12844 1: popl %edx
12845 subl $1b, %edx
12846
12847 - movl efi_rt_function_ptr(%edx), %ecx
12848 - pushl %ecx
12849 + pushl efi_rt_function_ptr(%edx)
12850
12851 /*
12852 * 10. Push the saved return address onto the stack and return.
12853 */
12854 - movl saved_return_addr(%edx), %ecx
12855 - pushl %ecx
12856 - ret
12857 + jmpl *saved_return_addr(%edx)
12858 ENDPROC(efi_call_phys)
12859 .previous
12860
12861 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12862 index 1d7fbbc..36ecd58 100644
12863 --- a/arch/x86/boot/compressed/head_32.S
12864 +++ b/arch/x86/boot/compressed/head_32.S
12865 @@ -140,10 +140,10 @@ preferred_addr:
12866 addl %eax, %ebx
12867 notl %eax
12868 andl %eax, %ebx
12869 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12870 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12871 jge 1f
12872 #endif
12873 - movl $LOAD_PHYSICAL_ADDR, %ebx
12874 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12875 1:
12876
12877 /* Target address to relocate to for decompression */
12878 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12879 index 6b1766c..ad465c9 100644
12880 --- a/arch/x86/boot/compressed/head_64.S
12881 +++ b/arch/x86/boot/compressed/head_64.S
12882 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12883 addl %eax, %ebx
12884 notl %eax
12885 andl %eax, %ebx
12886 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12887 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12888 jge 1f
12889 #endif
12890 - movl $LOAD_PHYSICAL_ADDR, %ebx
12891 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12892 1:
12893
12894 /* Target address to relocate to for decompression */
12895 @@ -322,10 +322,10 @@ preferred_addr:
12896 addq %rax, %rbp
12897 notq %rax
12898 andq %rax, %rbp
12899 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12900 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12901 jge 1f
12902 #endif
12903 - movq $LOAD_PHYSICAL_ADDR, %rbp
12904 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12905 1:
12906
12907 /* Target address to relocate to for decompression */
12908 @@ -434,8 +434,8 @@ gdt:
12909 .long gdt
12910 .word 0
12911 .quad 0x0000000000000000 /* NULL descriptor */
12912 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12913 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12914 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12915 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12916 .quad 0x0080890000000000 /* TS descriptor */
12917 .quad 0x0000000000000000 /* TS continued */
12918 gdt_end:
12919 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12920 index 0c33a7c..be226ed 100644
12921 --- a/arch/x86/boot/compressed/misc.c
12922 +++ b/arch/x86/boot/compressed/misc.c
12923 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12924 * Calculate the delta between where vmlinux was linked to load
12925 * and where it was actually loaded.
12926 */
12927 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12928 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12929 if (!delta) {
12930 debug_putstr("No relocation needed... ");
12931 return;
12932 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12933 Elf32_Ehdr ehdr;
12934 Elf32_Phdr *phdrs, *phdr;
12935 #endif
12936 - void *dest;
12937 + void *dest, *prev;
12938 int i;
12939
12940 memcpy(&ehdr, output, sizeof(ehdr));
12941 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12942 case PT_LOAD:
12943 #ifdef CONFIG_RELOCATABLE
12944 dest = output;
12945 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12946 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12947 #else
12948 dest = (void *)(phdr->p_paddr);
12949 #endif
12950 memcpy(dest,
12951 output + phdr->p_offset,
12952 phdr->p_filesz);
12953 + if (i)
12954 + memset(prev, 0xff, dest - prev);
12955 + prev = dest + phdr->p_filesz;
12956 break;
12957 default: /* Ignore other PT_* */ break;
12958 }
12959 @@ -404,7 +407,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12960 error("Destination address too large");
12961 #endif
12962 #ifndef CONFIG_RELOCATABLE
12963 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12964 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12965 error("Wrong destination address");
12966 #endif
12967
12968 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12969 index 1fd7d57..0f7d096 100644
12970 --- a/arch/x86/boot/cpucheck.c
12971 +++ b/arch/x86/boot/cpucheck.c
12972 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12973 u32 ecx = MSR_K7_HWCR;
12974 u32 eax, edx;
12975
12976 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12977 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12978 eax &= ~(1 << 15);
12979 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12980 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12981
12982 get_cpuflags(); /* Make sure it really did something */
12983 err = check_cpuflags();
12984 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12985 u32 ecx = MSR_VIA_FCR;
12986 u32 eax, edx;
12987
12988 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12989 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12990 eax |= (1<<1)|(1<<7);
12991 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12992 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12993
12994 set_bit(X86_FEATURE_CX8, cpu.flags);
12995 err = check_cpuflags();
12996 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12997 u32 eax, edx;
12998 u32 level = 1;
12999
13000 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13001 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13002 - asm("cpuid"
13003 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13004 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13005 + asm volatile("cpuid"
13006 : "+a" (level), "=d" (cpu.flags[0])
13007 : : "ecx", "ebx");
13008 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13009 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13010
13011 err = check_cpuflags();
13012 } else if (err == 0x01 &&
13013 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13014 index 16ef025..91e033b 100644
13015 --- a/arch/x86/boot/header.S
13016 +++ b/arch/x86/boot/header.S
13017 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13018 # single linked list of
13019 # struct setup_data
13020
13021 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13022 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13023
13024 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13025 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13026 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13027 +#else
13028 #define VO_INIT_SIZE (VO__end - VO__text)
13029 +#endif
13030 #if ZO_INIT_SIZE > VO_INIT_SIZE
13031 #define INIT_SIZE ZO_INIT_SIZE
13032 #else
13033 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13034 index db75d07..8e6d0af 100644
13035 --- a/arch/x86/boot/memory.c
13036 +++ b/arch/x86/boot/memory.c
13037 @@ -19,7 +19,7 @@
13038
13039 static int detect_memory_e820(void)
13040 {
13041 - int count = 0;
13042 + unsigned int count = 0;
13043 struct biosregs ireg, oreg;
13044 struct e820entry *desc = boot_params.e820_map;
13045 static struct e820entry buf; /* static so it is zeroed */
13046 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13047 index ba3e100..6501b8f 100644
13048 --- a/arch/x86/boot/video-vesa.c
13049 +++ b/arch/x86/boot/video-vesa.c
13050 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13051
13052 boot_params.screen_info.vesapm_seg = oreg.es;
13053 boot_params.screen_info.vesapm_off = oreg.di;
13054 + boot_params.screen_info.vesapm_size = oreg.cx;
13055 }
13056
13057 /*
13058 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13059 index 43eda28..5ab5fdb 100644
13060 --- a/arch/x86/boot/video.c
13061 +++ b/arch/x86/boot/video.c
13062 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13063 static unsigned int get_entry(void)
13064 {
13065 char entry_buf[4];
13066 - int i, len = 0;
13067 + unsigned int i, len = 0;
13068 int key;
13069 unsigned int v;
13070
13071 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13072 index 9105655..41779c1 100644
13073 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13074 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13075 @@ -8,6 +8,8 @@
13076 * including this sentence is retained in full.
13077 */
13078
13079 +#include <asm/alternative-asm.h>
13080 +
13081 .extern crypto_ft_tab
13082 .extern crypto_it_tab
13083 .extern crypto_fl_tab
13084 @@ -70,6 +72,8 @@
13085 je B192; \
13086 leaq 32(r9),r9;
13087
13088 +#define ret pax_force_retaddr; ret
13089 +
13090 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13091 movq r1,r2; \
13092 movq r3,r4; \
13093 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13094 index 477e9d7..c92c7d8 100644
13095 --- a/arch/x86/crypto/aesni-intel_asm.S
13096 +++ b/arch/x86/crypto/aesni-intel_asm.S
13097 @@ -31,6 +31,7 @@
13098
13099 #include <linux/linkage.h>
13100 #include <asm/inst.h>
13101 +#include <asm/alternative-asm.h>
13102
13103 #ifdef __x86_64__
13104 .data
13105 @@ -205,7 +206,7 @@ enc: .octa 0x2
13106 * num_initial_blocks = b mod 4
13107 * encrypt the initial num_initial_blocks blocks and apply ghash on
13108 * the ciphertext
13109 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13110 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13111 * are clobbered
13112 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13113 */
13114 @@ -214,8 +215,8 @@ enc: .octa 0x2
13115 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13116 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13117 mov arg7, %r10 # %r10 = AAD
13118 - mov arg8, %r12 # %r12 = aadLen
13119 - mov %r12, %r11
13120 + mov arg8, %r15 # %r15 = aadLen
13121 + mov %r15, %r11
13122 pxor %xmm\i, %xmm\i
13123 _get_AAD_loop\num_initial_blocks\operation:
13124 movd (%r10), \TMP1
13125 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13126 psrldq $4, %xmm\i
13127 pxor \TMP1, %xmm\i
13128 add $4, %r10
13129 - sub $4, %r12
13130 + sub $4, %r15
13131 jne _get_AAD_loop\num_initial_blocks\operation
13132 cmp $16, %r11
13133 je _get_AAD_loop2_done\num_initial_blocks\operation
13134 - mov $16, %r12
13135 + mov $16, %r15
13136 _get_AAD_loop2\num_initial_blocks\operation:
13137 psrldq $4, %xmm\i
13138 - sub $4, %r12
13139 - cmp %r11, %r12
13140 + sub $4, %r15
13141 + cmp %r11, %r15
13142 jne _get_AAD_loop2\num_initial_blocks\operation
13143 _get_AAD_loop2_done\num_initial_blocks\operation:
13144 movdqa SHUF_MASK(%rip), %xmm14
13145 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13146 * num_initial_blocks = b mod 4
13147 * encrypt the initial num_initial_blocks blocks and apply ghash on
13148 * the ciphertext
13149 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13150 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13151 * are clobbered
13152 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13153 */
13154 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13155 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13156 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13157 mov arg7, %r10 # %r10 = AAD
13158 - mov arg8, %r12 # %r12 = aadLen
13159 - mov %r12, %r11
13160 + mov arg8, %r15 # %r15 = aadLen
13161 + mov %r15, %r11
13162 pxor %xmm\i, %xmm\i
13163 _get_AAD_loop\num_initial_blocks\operation:
13164 movd (%r10), \TMP1
13165 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13166 psrldq $4, %xmm\i
13167 pxor \TMP1, %xmm\i
13168 add $4, %r10
13169 - sub $4, %r12
13170 + sub $4, %r15
13171 jne _get_AAD_loop\num_initial_blocks\operation
13172 cmp $16, %r11
13173 je _get_AAD_loop2_done\num_initial_blocks\operation
13174 - mov $16, %r12
13175 + mov $16, %r15
13176 _get_AAD_loop2\num_initial_blocks\operation:
13177 psrldq $4, %xmm\i
13178 - sub $4, %r12
13179 - cmp %r11, %r12
13180 + sub $4, %r15
13181 + cmp %r11, %r15
13182 jne _get_AAD_loop2\num_initial_blocks\operation
13183 _get_AAD_loop2_done\num_initial_blocks\operation:
13184 movdqa SHUF_MASK(%rip), %xmm14
13185 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13186 *
13187 *****************************************************************************/
13188 ENTRY(aesni_gcm_dec)
13189 - push %r12
13190 + push %r15
13191 push %r13
13192 push %r14
13193 mov %rsp, %r14
13194 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13195 */
13196 sub $VARIABLE_OFFSET, %rsp
13197 and $~63, %rsp # align rsp to 64 bytes
13198 - mov %arg6, %r12
13199 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13200 + mov %arg6, %r15
13201 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13202 movdqa SHUF_MASK(%rip), %xmm2
13203 PSHUFB_XMM %xmm2, %xmm13
13204
13205 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13206 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13207 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13208 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13209 - mov %r13, %r12
13210 - and $(3<<4), %r12
13211 + mov %r13, %r15
13212 + and $(3<<4), %r15
13213 jz _initial_num_blocks_is_0_decrypt
13214 - cmp $(2<<4), %r12
13215 + cmp $(2<<4), %r15
13216 jb _initial_num_blocks_is_1_decrypt
13217 je _initial_num_blocks_is_2_decrypt
13218 _initial_num_blocks_is_3_decrypt:
13219 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13220 sub $16, %r11
13221 add %r13, %r11
13222 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13223 - lea SHIFT_MASK+16(%rip), %r12
13224 - sub %r13, %r12
13225 + lea SHIFT_MASK+16(%rip), %r15
13226 + sub %r13, %r15
13227 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13228 # (%r13 is the number of bytes in plaintext mod 16)
13229 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13230 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13231 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13232
13233 movdqa %xmm1, %xmm2
13234 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13235 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13236 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13237 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13238 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13239 pand %xmm1, %xmm2
13240 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13241 sub $1, %r13
13242 jne _less_than_8_bytes_left_decrypt
13243 _multiple_of_16_bytes_decrypt:
13244 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13245 - shl $3, %r12 # convert into number of bits
13246 - movd %r12d, %xmm15 # len(A) in %xmm15
13247 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13248 + shl $3, %r15 # convert into number of bits
13249 + movd %r15d, %xmm15 # len(A) in %xmm15
13250 shl $3, %arg4 # len(C) in bits (*128)
13251 MOVQ_R64_XMM %arg4, %xmm1
13252 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13253 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13254 mov %r14, %rsp
13255 pop %r14
13256 pop %r13
13257 - pop %r12
13258 + pop %r15
13259 + pax_force_retaddr
13260 ret
13261 ENDPROC(aesni_gcm_dec)
13262
13263 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13264 * poly = x^128 + x^127 + x^126 + x^121 + 1
13265 ***************************************************************************/
13266 ENTRY(aesni_gcm_enc)
13267 - push %r12
13268 + push %r15
13269 push %r13
13270 push %r14
13271 mov %rsp, %r14
13272 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13273 #
13274 sub $VARIABLE_OFFSET, %rsp
13275 and $~63, %rsp
13276 - mov %arg6, %r12
13277 - movdqu (%r12), %xmm13
13278 + mov %arg6, %r15
13279 + movdqu (%r15), %xmm13
13280 movdqa SHUF_MASK(%rip), %xmm2
13281 PSHUFB_XMM %xmm2, %xmm13
13282
13283 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13284 movdqa %xmm13, HashKey(%rsp)
13285 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13286 and $-16, %r13
13287 - mov %r13, %r12
13288 + mov %r13, %r15
13289
13290 # Encrypt first few blocks
13291
13292 - and $(3<<4), %r12
13293 + and $(3<<4), %r15
13294 jz _initial_num_blocks_is_0_encrypt
13295 - cmp $(2<<4), %r12
13296 + cmp $(2<<4), %r15
13297 jb _initial_num_blocks_is_1_encrypt
13298 je _initial_num_blocks_is_2_encrypt
13299 _initial_num_blocks_is_3_encrypt:
13300 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13301 sub $16, %r11
13302 add %r13, %r11
13303 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13304 - lea SHIFT_MASK+16(%rip), %r12
13305 - sub %r13, %r12
13306 + lea SHIFT_MASK+16(%rip), %r15
13307 + sub %r13, %r15
13308 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13309 # (%r13 is the number of bytes in plaintext mod 16)
13310 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13311 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13312 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13313 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13314 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13315 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13316 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13317 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13318 movdqa SHUF_MASK(%rip), %xmm10
13319 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13320 sub $1, %r13
13321 jne _less_than_8_bytes_left_encrypt
13322 _multiple_of_16_bytes_encrypt:
13323 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13324 - shl $3, %r12
13325 - movd %r12d, %xmm15 # len(A) in %xmm15
13326 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13327 + shl $3, %r15
13328 + movd %r15d, %xmm15 # len(A) in %xmm15
13329 shl $3, %arg4 # len(C) in bits (*128)
13330 MOVQ_R64_XMM %arg4, %xmm1
13331 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13332 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13333 mov %r14, %rsp
13334 pop %r14
13335 pop %r13
13336 - pop %r12
13337 + pop %r15
13338 + pax_force_retaddr
13339 ret
13340 ENDPROC(aesni_gcm_enc)
13341
13342 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13343 pxor %xmm1, %xmm0
13344 movaps %xmm0, (TKEYP)
13345 add $0x10, TKEYP
13346 + pax_force_retaddr
13347 ret
13348 ENDPROC(_key_expansion_128)
13349 ENDPROC(_key_expansion_256a)
13350 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13351 shufps $0b01001110, %xmm2, %xmm1
13352 movaps %xmm1, 0x10(TKEYP)
13353 add $0x20, TKEYP
13354 + pax_force_retaddr
13355 ret
13356 ENDPROC(_key_expansion_192a)
13357
13358 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13359
13360 movaps %xmm0, (TKEYP)
13361 add $0x10, TKEYP
13362 + pax_force_retaddr
13363 ret
13364 ENDPROC(_key_expansion_192b)
13365
13366 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13367 pxor %xmm1, %xmm2
13368 movaps %xmm2, (TKEYP)
13369 add $0x10, TKEYP
13370 + pax_force_retaddr
13371 ret
13372 ENDPROC(_key_expansion_256b)
13373
13374 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13375 #ifndef __x86_64__
13376 popl KEYP
13377 #endif
13378 + pax_force_retaddr
13379 ret
13380 ENDPROC(aesni_set_key)
13381
13382 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13383 popl KLEN
13384 popl KEYP
13385 #endif
13386 + pax_force_retaddr
13387 ret
13388 ENDPROC(aesni_enc)
13389
13390 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13391 AESENC KEY STATE
13392 movaps 0x70(TKEYP), KEY
13393 AESENCLAST KEY STATE
13394 + pax_force_retaddr
13395 ret
13396 ENDPROC(_aesni_enc1)
13397
13398 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13399 AESENCLAST KEY STATE2
13400 AESENCLAST KEY STATE3
13401 AESENCLAST KEY STATE4
13402 + pax_force_retaddr
13403 ret
13404 ENDPROC(_aesni_enc4)
13405
13406 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13407 popl KLEN
13408 popl KEYP
13409 #endif
13410 + pax_force_retaddr
13411 ret
13412 ENDPROC(aesni_dec)
13413
13414 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13415 AESDEC KEY STATE
13416 movaps 0x70(TKEYP), KEY
13417 AESDECLAST KEY STATE
13418 + pax_force_retaddr
13419 ret
13420 ENDPROC(_aesni_dec1)
13421
13422 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13423 AESDECLAST KEY STATE2
13424 AESDECLAST KEY STATE3
13425 AESDECLAST KEY STATE4
13426 + pax_force_retaddr
13427 ret
13428 ENDPROC(_aesni_dec4)
13429
13430 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13431 popl KEYP
13432 popl LEN
13433 #endif
13434 + pax_force_retaddr
13435 ret
13436 ENDPROC(aesni_ecb_enc)
13437
13438 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13439 popl KEYP
13440 popl LEN
13441 #endif
13442 + pax_force_retaddr
13443 ret
13444 ENDPROC(aesni_ecb_dec)
13445
13446 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13447 popl LEN
13448 popl IVP
13449 #endif
13450 + pax_force_retaddr
13451 ret
13452 ENDPROC(aesni_cbc_enc)
13453
13454 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13455 popl LEN
13456 popl IVP
13457 #endif
13458 + pax_force_retaddr
13459 ret
13460 ENDPROC(aesni_cbc_dec)
13461
13462 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13463 mov $1, TCTR_LOW
13464 MOVQ_R64_XMM TCTR_LOW INC
13465 MOVQ_R64_XMM CTR TCTR_LOW
13466 + pax_force_retaddr
13467 ret
13468 ENDPROC(_aesni_inc_init)
13469
13470 @@ -2579,6 +2598,7 @@ _aesni_inc:
13471 .Linc_low:
13472 movaps CTR, IV
13473 PSHUFB_XMM BSWAP_MASK IV
13474 + pax_force_retaddr
13475 ret
13476 ENDPROC(_aesni_inc)
13477
13478 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13479 .Lctr_enc_ret:
13480 movups IV, (IVP)
13481 .Lctr_enc_just_ret:
13482 + pax_force_retaddr
13483 ret
13484 ENDPROC(aesni_ctr_enc)
13485
13486 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13487 pxor INC, STATE4
13488 movdqu STATE4, 0x70(OUTP)
13489
13490 + pax_force_retaddr
13491 ret
13492 ENDPROC(aesni_xts_crypt8)
13493
13494 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13495 index 246c670..466e2d6 100644
13496 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13497 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13498 @@ -21,6 +21,7 @@
13499 */
13500
13501 #include <linux/linkage.h>
13502 +#include <asm/alternative-asm.h>
13503
13504 .file "blowfish-x86_64-asm.S"
13505 .text
13506 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13507 jnz .L__enc_xor;
13508
13509 write_block();
13510 + pax_force_retaddr
13511 ret;
13512 .L__enc_xor:
13513 xor_block();
13514 + pax_force_retaddr
13515 ret;
13516 ENDPROC(__blowfish_enc_blk)
13517
13518 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13519
13520 movq %r11, %rbp;
13521
13522 + pax_force_retaddr
13523 ret;
13524 ENDPROC(blowfish_dec_blk)
13525
13526 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13527
13528 popq %rbx;
13529 popq %rbp;
13530 + pax_force_retaddr
13531 ret;
13532
13533 .L__enc_xor4:
13534 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13535
13536 popq %rbx;
13537 popq %rbp;
13538 + pax_force_retaddr
13539 ret;
13540 ENDPROC(__blowfish_enc_blk_4way)
13541
13542 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13543 popq %rbx;
13544 popq %rbp;
13545
13546 + pax_force_retaddr
13547 ret;
13548 ENDPROC(blowfish_dec_blk_4way)
13549 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13550 index ce71f92..1dce7ec 100644
13551 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13552 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13553 @@ -16,6 +16,7 @@
13554 */
13555
13556 #include <linux/linkage.h>
13557 +#include <asm/alternative-asm.h>
13558
13559 #define CAMELLIA_TABLE_BYTE_LEN 272
13560
13561 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13562 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13563 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13564 %rcx, (%r9));
13565 + pax_force_retaddr
13566 ret;
13567 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13568
13569 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13570 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13571 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13572 %rax, (%r9));
13573 + pax_force_retaddr
13574 ret;
13575 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13576
13577 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13578 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13579 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13580
13581 + pax_force_retaddr
13582 ret;
13583
13584 .align 8
13585 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13586 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13587 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13588
13589 + pax_force_retaddr
13590 ret;
13591
13592 .align 8
13593 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13594 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13595 %xmm8, %rsi);
13596
13597 + pax_force_retaddr
13598 ret;
13599 ENDPROC(camellia_ecb_enc_16way)
13600
13601 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13602 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13603 %xmm8, %rsi);
13604
13605 + pax_force_retaddr
13606 ret;
13607 ENDPROC(camellia_ecb_dec_16way)
13608
13609 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13610 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13611 %xmm8, %rsi);
13612
13613 + pax_force_retaddr
13614 ret;
13615 ENDPROC(camellia_cbc_dec_16way)
13616
13617 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13618 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13619 %xmm8, %rsi);
13620
13621 + pax_force_retaddr
13622 ret;
13623 ENDPROC(camellia_ctr_16way)
13624
13625 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13626 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13627 %xmm8, %rsi);
13628
13629 + pax_force_retaddr
13630 ret;
13631 ENDPROC(camellia_xts_crypt_16way)
13632
13633 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13634 index 0e0b886..5a3123c 100644
13635 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13636 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13637 @@ -11,6 +11,7 @@
13638 */
13639
13640 #include <linux/linkage.h>
13641 +#include <asm/alternative-asm.h>
13642
13643 #define CAMELLIA_TABLE_BYTE_LEN 272
13644
13645 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13646 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13647 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13648 %rcx, (%r9));
13649 + pax_force_retaddr
13650 ret;
13651 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13652
13653 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13654 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13655 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13656 %rax, (%r9));
13657 + pax_force_retaddr
13658 ret;
13659 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13660
13661 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13662 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13663 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13664
13665 + pax_force_retaddr
13666 ret;
13667
13668 .align 8
13669 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13670 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13671 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13672
13673 + pax_force_retaddr
13674 ret;
13675
13676 .align 8
13677 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13678
13679 vzeroupper;
13680
13681 + pax_force_retaddr
13682 ret;
13683 ENDPROC(camellia_ecb_enc_32way)
13684
13685 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13686
13687 vzeroupper;
13688
13689 + pax_force_retaddr
13690 ret;
13691 ENDPROC(camellia_ecb_dec_32way)
13692
13693 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13694
13695 vzeroupper;
13696
13697 + pax_force_retaddr
13698 ret;
13699 ENDPROC(camellia_cbc_dec_32way)
13700
13701 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13702
13703 vzeroupper;
13704
13705 + pax_force_retaddr
13706 ret;
13707 ENDPROC(camellia_ctr_32way)
13708
13709 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13710
13711 vzeroupper;
13712
13713 + pax_force_retaddr
13714 ret;
13715 ENDPROC(camellia_xts_crypt_32way)
13716
13717 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13718 index 310319c..db3d7b5 100644
13719 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13720 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13721 @@ -21,6 +21,7 @@
13722 */
13723
13724 #include <linux/linkage.h>
13725 +#include <asm/alternative-asm.h>
13726
13727 .file "camellia-x86_64-asm_64.S"
13728 .text
13729 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13730 enc_outunpack(mov, RT1);
13731
13732 movq RRBP, %rbp;
13733 + pax_force_retaddr
13734 ret;
13735
13736 .L__enc_xor:
13737 enc_outunpack(xor, RT1);
13738
13739 movq RRBP, %rbp;
13740 + pax_force_retaddr
13741 ret;
13742 ENDPROC(__camellia_enc_blk)
13743
13744 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13745 dec_outunpack();
13746
13747 movq RRBP, %rbp;
13748 + pax_force_retaddr
13749 ret;
13750 ENDPROC(camellia_dec_blk)
13751
13752 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13753
13754 movq RRBP, %rbp;
13755 popq %rbx;
13756 + pax_force_retaddr
13757 ret;
13758
13759 .L__enc2_xor:
13760 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13761
13762 movq RRBP, %rbp;
13763 popq %rbx;
13764 + pax_force_retaddr
13765 ret;
13766 ENDPROC(__camellia_enc_blk_2way)
13767
13768 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13769
13770 movq RRBP, %rbp;
13771 movq RXOR, %rbx;
13772 + pax_force_retaddr
13773 ret;
13774 ENDPROC(camellia_dec_blk_2way)
13775 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13776 index c35fd5d..2d8c7db 100644
13777 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13778 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13779 @@ -24,6 +24,7 @@
13780 */
13781
13782 #include <linux/linkage.h>
13783 +#include <asm/alternative-asm.h>
13784
13785 .file "cast5-avx-x86_64-asm_64.S"
13786
13787 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13788 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13789 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13790
13791 + pax_force_retaddr
13792 ret;
13793 ENDPROC(__cast5_enc_blk16)
13794
13795 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13796 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13797 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13798
13799 + pax_force_retaddr
13800 ret;
13801
13802 .L__skip_dec:
13803 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13804 vmovdqu RR4, (6*4*4)(%r11);
13805 vmovdqu RL4, (7*4*4)(%r11);
13806
13807 + pax_force_retaddr
13808 ret;
13809 ENDPROC(cast5_ecb_enc_16way)
13810
13811 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13812 vmovdqu RR4, (6*4*4)(%r11);
13813 vmovdqu RL4, (7*4*4)(%r11);
13814
13815 + pax_force_retaddr
13816 ret;
13817 ENDPROC(cast5_ecb_dec_16way)
13818
13819 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13820 * %rdx: src
13821 */
13822
13823 - pushq %r12;
13824 + pushq %r14;
13825
13826 movq %rsi, %r11;
13827 - movq %rdx, %r12;
13828 + movq %rdx, %r14;
13829
13830 vmovdqu (0*16)(%rdx), RL1;
13831 vmovdqu (1*16)(%rdx), RR1;
13832 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13833 call __cast5_dec_blk16;
13834
13835 /* xor with src */
13836 - vmovq (%r12), RX;
13837 + vmovq (%r14), RX;
13838 vpshufd $0x4f, RX, RX;
13839 vpxor RX, RR1, RR1;
13840 - vpxor 0*16+8(%r12), RL1, RL1;
13841 - vpxor 1*16+8(%r12), RR2, RR2;
13842 - vpxor 2*16+8(%r12), RL2, RL2;
13843 - vpxor 3*16+8(%r12), RR3, RR3;
13844 - vpxor 4*16+8(%r12), RL3, RL3;
13845 - vpxor 5*16+8(%r12), RR4, RR4;
13846 - vpxor 6*16+8(%r12), RL4, RL4;
13847 + vpxor 0*16+8(%r14), RL1, RL1;
13848 + vpxor 1*16+8(%r14), RR2, RR2;
13849 + vpxor 2*16+8(%r14), RL2, RL2;
13850 + vpxor 3*16+8(%r14), RR3, RR3;
13851 + vpxor 4*16+8(%r14), RL3, RL3;
13852 + vpxor 5*16+8(%r14), RR4, RR4;
13853 + vpxor 6*16+8(%r14), RL4, RL4;
13854
13855 vmovdqu RR1, (0*16)(%r11);
13856 vmovdqu RL1, (1*16)(%r11);
13857 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13858 vmovdqu RR4, (6*16)(%r11);
13859 vmovdqu RL4, (7*16)(%r11);
13860
13861 - popq %r12;
13862 + popq %r14;
13863
13864 + pax_force_retaddr
13865 ret;
13866 ENDPROC(cast5_cbc_dec_16way)
13867
13868 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13869 * %rcx: iv (big endian, 64bit)
13870 */
13871
13872 - pushq %r12;
13873 + pushq %r14;
13874
13875 movq %rsi, %r11;
13876 - movq %rdx, %r12;
13877 + movq %rdx, %r14;
13878
13879 vpcmpeqd RTMP, RTMP, RTMP;
13880 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13881 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13882 call __cast5_enc_blk16;
13883
13884 /* dst = src ^ iv */
13885 - vpxor (0*16)(%r12), RR1, RR1;
13886 - vpxor (1*16)(%r12), RL1, RL1;
13887 - vpxor (2*16)(%r12), RR2, RR2;
13888 - vpxor (3*16)(%r12), RL2, RL2;
13889 - vpxor (4*16)(%r12), RR3, RR3;
13890 - vpxor (5*16)(%r12), RL3, RL3;
13891 - vpxor (6*16)(%r12), RR4, RR4;
13892 - vpxor (7*16)(%r12), RL4, RL4;
13893 + vpxor (0*16)(%r14), RR1, RR1;
13894 + vpxor (1*16)(%r14), RL1, RL1;
13895 + vpxor (2*16)(%r14), RR2, RR2;
13896 + vpxor (3*16)(%r14), RL2, RL2;
13897 + vpxor (4*16)(%r14), RR3, RR3;
13898 + vpxor (5*16)(%r14), RL3, RL3;
13899 + vpxor (6*16)(%r14), RR4, RR4;
13900 + vpxor (7*16)(%r14), RL4, RL4;
13901 vmovdqu RR1, (0*16)(%r11);
13902 vmovdqu RL1, (1*16)(%r11);
13903 vmovdqu RR2, (2*16)(%r11);
13904 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13905 vmovdqu RR4, (6*16)(%r11);
13906 vmovdqu RL4, (7*16)(%r11);
13907
13908 - popq %r12;
13909 + popq %r14;
13910
13911 + pax_force_retaddr
13912 ret;
13913 ENDPROC(cast5_ctr_16way)
13914 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13915 index e3531f8..e123f35 100644
13916 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13917 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13918 @@ -24,6 +24,7 @@
13919 */
13920
13921 #include <linux/linkage.h>
13922 +#include <asm/alternative-asm.h>
13923 #include "glue_helper-asm-avx.S"
13924
13925 .file "cast6-avx-x86_64-asm_64.S"
13926 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13927 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13928 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13929
13930 + pax_force_retaddr
13931 ret;
13932 ENDPROC(__cast6_enc_blk8)
13933
13934 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13935 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13936 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13937
13938 + pax_force_retaddr
13939 ret;
13940 ENDPROC(__cast6_dec_blk8)
13941
13942 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13943
13944 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13945
13946 + pax_force_retaddr
13947 ret;
13948 ENDPROC(cast6_ecb_enc_8way)
13949
13950 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13951
13952 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13953
13954 + pax_force_retaddr
13955 ret;
13956 ENDPROC(cast6_ecb_dec_8way)
13957
13958 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13959 * %rdx: src
13960 */
13961
13962 - pushq %r12;
13963 + pushq %r14;
13964
13965 movq %rsi, %r11;
13966 - movq %rdx, %r12;
13967 + movq %rdx, %r14;
13968
13969 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13970
13971 call __cast6_dec_blk8;
13972
13973 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13974 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13975
13976 - popq %r12;
13977 + popq %r14;
13978
13979 + pax_force_retaddr
13980 ret;
13981 ENDPROC(cast6_cbc_dec_8way)
13982
13983 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13984 * %rcx: iv (little endian, 128bit)
13985 */
13986
13987 - pushq %r12;
13988 + pushq %r14;
13989
13990 movq %rsi, %r11;
13991 - movq %rdx, %r12;
13992 + movq %rdx, %r14;
13993
13994 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13995 RD2, RX, RKR, RKM);
13996
13997 call __cast6_enc_blk8;
13998
13999 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14000 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14001
14002 - popq %r12;
14003 + popq %r14;
14004
14005 + pax_force_retaddr
14006 ret;
14007 ENDPROC(cast6_ctr_8way)
14008
14009 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14010 /* dst <= regs xor IVs(in dst) */
14011 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14012
14013 + pax_force_retaddr
14014 ret;
14015 ENDPROC(cast6_xts_enc_8way)
14016
14017 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14018 /* dst <= regs xor IVs(in dst) */
14019 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14020
14021 + pax_force_retaddr
14022 ret;
14023 ENDPROC(cast6_xts_dec_8way)
14024 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14025 index 26d49eb..c0a8c84 100644
14026 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14027 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14028 @@ -45,6 +45,7 @@
14029
14030 #include <asm/inst.h>
14031 #include <linux/linkage.h>
14032 +#include <asm/alternative-asm.h>
14033
14034 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14035
14036 @@ -309,6 +310,7 @@ do_return:
14037 popq %rsi
14038 popq %rdi
14039 popq %rbx
14040 + pax_force_retaddr
14041 ret
14042
14043 ################################################################
14044 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14045 index 5d1e007..098cb4f 100644
14046 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14047 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14048 @@ -18,6 +18,7 @@
14049
14050 #include <linux/linkage.h>
14051 #include <asm/inst.h>
14052 +#include <asm/alternative-asm.h>
14053
14054 .data
14055
14056 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14057 psrlq $1, T2
14058 pxor T2, T1
14059 pxor T1, DATA
14060 + pax_force_retaddr
14061 ret
14062 ENDPROC(__clmul_gf128mul_ble)
14063
14064 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14065 call __clmul_gf128mul_ble
14066 PSHUFB_XMM BSWAP DATA
14067 movups DATA, (%rdi)
14068 + pax_force_retaddr
14069 ret
14070 ENDPROC(clmul_ghash_mul)
14071
14072 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14073 PSHUFB_XMM BSWAP DATA
14074 movups DATA, (%rdi)
14075 .Lupdate_just_ret:
14076 + pax_force_retaddr
14077 ret
14078 ENDPROC(clmul_ghash_update)
14079 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14080 index 9279e0b..c4b3d2c 100644
14081 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14082 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14083 @@ -1,4 +1,5 @@
14084 #include <linux/linkage.h>
14085 +#include <asm/alternative-asm.h>
14086
14087 # enter salsa20_encrypt_bytes
14088 ENTRY(salsa20_encrypt_bytes)
14089 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14090 add %r11,%rsp
14091 mov %rdi,%rax
14092 mov %rsi,%rdx
14093 + pax_force_retaddr
14094 ret
14095 # bytesatleast65:
14096 ._bytesatleast65:
14097 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14098 add %r11,%rsp
14099 mov %rdi,%rax
14100 mov %rsi,%rdx
14101 + pax_force_retaddr
14102 ret
14103 ENDPROC(salsa20_keysetup)
14104
14105 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14106 add %r11,%rsp
14107 mov %rdi,%rax
14108 mov %rsi,%rdx
14109 + pax_force_retaddr
14110 ret
14111 ENDPROC(salsa20_ivsetup)
14112 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14113 index 2f202f4..d9164d6 100644
14114 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14115 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14116 @@ -24,6 +24,7 @@
14117 */
14118
14119 #include <linux/linkage.h>
14120 +#include <asm/alternative-asm.h>
14121 #include "glue_helper-asm-avx.S"
14122
14123 .file "serpent-avx-x86_64-asm_64.S"
14124 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14125 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14126 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14127
14128 + pax_force_retaddr
14129 ret;
14130 ENDPROC(__serpent_enc_blk8_avx)
14131
14132 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14133 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14134 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14135
14136 + pax_force_retaddr
14137 ret;
14138 ENDPROC(__serpent_dec_blk8_avx)
14139
14140 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14141
14142 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14143
14144 + pax_force_retaddr
14145 ret;
14146 ENDPROC(serpent_ecb_enc_8way_avx)
14147
14148 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14149
14150 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14151
14152 + pax_force_retaddr
14153 ret;
14154 ENDPROC(serpent_ecb_dec_8way_avx)
14155
14156 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14157
14158 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14159
14160 + pax_force_retaddr
14161 ret;
14162 ENDPROC(serpent_cbc_dec_8way_avx)
14163
14164 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14165
14166 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14167
14168 + pax_force_retaddr
14169 ret;
14170 ENDPROC(serpent_ctr_8way_avx)
14171
14172 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14173 /* dst <= regs xor IVs(in dst) */
14174 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14175
14176 + pax_force_retaddr
14177 ret;
14178 ENDPROC(serpent_xts_enc_8way_avx)
14179
14180 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14181 /* dst <= regs xor IVs(in dst) */
14182 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14183
14184 + pax_force_retaddr
14185 ret;
14186 ENDPROC(serpent_xts_dec_8way_avx)
14187 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14188 index b222085..abd483c 100644
14189 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14190 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14191 @@ -15,6 +15,7 @@
14192 */
14193
14194 #include <linux/linkage.h>
14195 +#include <asm/alternative-asm.h>
14196 #include "glue_helper-asm-avx2.S"
14197
14198 .file "serpent-avx2-asm_64.S"
14199 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14200 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14201 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14202
14203 + pax_force_retaddr
14204 ret;
14205 ENDPROC(__serpent_enc_blk16)
14206
14207 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14208 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14209 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14210
14211 + pax_force_retaddr
14212 ret;
14213 ENDPROC(__serpent_dec_blk16)
14214
14215 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14216
14217 vzeroupper;
14218
14219 + pax_force_retaddr
14220 ret;
14221 ENDPROC(serpent_ecb_enc_16way)
14222
14223 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14224
14225 vzeroupper;
14226
14227 + pax_force_retaddr
14228 ret;
14229 ENDPROC(serpent_ecb_dec_16way)
14230
14231 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14232
14233 vzeroupper;
14234
14235 + pax_force_retaddr
14236 ret;
14237 ENDPROC(serpent_cbc_dec_16way)
14238
14239 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14240
14241 vzeroupper;
14242
14243 + pax_force_retaddr
14244 ret;
14245 ENDPROC(serpent_ctr_16way)
14246
14247 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14248
14249 vzeroupper;
14250
14251 + pax_force_retaddr
14252 ret;
14253 ENDPROC(serpent_xts_enc_16way)
14254
14255 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14256
14257 vzeroupper;
14258
14259 + pax_force_retaddr
14260 ret;
14261 ENDPROC(serpent_xts_dec_16way)
14262 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14263 index acc066c..1559cc4 100644
14264 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14265 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14266 @@ -25,6 +25,7 @@
14267 */
14268
14269 #include <linux/linkage.h>
14270 +#include <asm/alternative-asm.h>
14271
14272 .file "serpent-sse2-x86_64-asm_64.S"
14273 .text
14274 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14275 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14276 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14277
14278 + pax_force_retaddr
14279 ret;
14280
14281 .L__enc_xor8:
14282 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14283 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14284
14285 + pax_force_retaddr
14286 ret;
14287 ENDPROC(__serpent_enc_blk_8way)
14288
14289 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14290 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14291 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14292
14293 + pax_force_retaddr
14294 ret;
14295 ENDPROC(serpent_dec_blk_8way)
14296 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14297 index a410950..9dfe7ad 100644
14298 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14299 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14300 @@ -29,6 +29,7 @@
14301 */
14302
14303 #include <linux/linkage.h>
14304 +#include <asm/alternative-asm.h>
14305
14306 #define CTX %rdi // arg1
14307 #define BUF %rsi // arg2
14308 @@ -75,9 +76,9 @@
14309
14310 push %rbx
14311 push %rbp
14312 - push %r12
14313 + push %r14
14314
14315 - mov %rsp, %r12
14316 + mov %rsp, %r14
14317 sub $64, %rsp # allocate workspace
14318 and $~15, %rsp # align stack
14319
14320 @@ -99,11 +100,12 @@
14321 xor %rax, %rax
14322 rep stosq
14323
14324 - mov %r12, %rsp # deallocate workspace
14325 + mov %r14, %rsp # deallocate workspace
14326
14327 - pop %r12
14328 + pop %r14
14329 pop %rbp
14330 pop %rbx
14331 + pax_force_retaddr
14332 ret
14333
14334 ENDPROC(\name)
14335 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14336 index 642f156..51a513c 100644
14337 --- a/arch/x86/crypto/sha256-avx-asm.S
14338 +++ b/arch/x86/crypto/sha256-avx-asm.S
14339 @@ -49,6 +49,7 @@
14340
14341 #ifdef CONFIG_AS_AVX
14342 #include <linux/linkage.h>
14343 +#include <asm/alternative-asm.h>
14344
14345 ## assume buffers not aligned
14346 #define VMOVDQ vmovdqu
14347 @@ -460,6 +461,7 @@ done_hash:
14348 popq %r13
14349 popq %rbp
14350 popq %rbx
14351 + pax_force_retaddr
14352 ret
14353 ENDPROC(sha256_transform_avx)
14354
14355 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14356 index 9e86944..3795e6a 100644
14357 --- a/arch/x86/crypto/sha256-avx2-asm.S
14358 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14359 @@ -50,6 +50,7 @@
14360
14361 #ifdef CONFIG_AS_AVX2
14362 #include <linux/linkage.h>
14363 +#include <asm/alternative-asm.h>
14364
14365 ## assume buffers not aligned
14366 #define VMOVDQ vmovdqu
14367 @@ -720,6 +721,7 @@ done_hash:
14368 popq %r12
14369 popq %rbp
14370 popq %rbx
14371 + pax_force_retaddr
14372 ret
14373 ENDPROC(sha256_transform_rorx)
14374
14375 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14376 index f833b74..8c62a9e 100644
14377 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14378 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14379 @@ -47,6 +47,7 @@
14380 ########################################################################
14381
14382 #include <linux/linkage.h>
14383 +#include <asm/alternative-asm.h>
14384
14385 ## assume buffers not aligned
14386 #define MOVDQ movdqu
14387 @@ -471,6 +472,7 @@ done_hash:
14388 popq %rbp
14389 popq %rbx
14390
14391 + pax_force_retaddr
14392 ret
14393 ENDPROC(sha256_transform_ssse3)
14394
14395 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14396 index 974dde9..a823ff9 100644
14397 --- a/arch/x86/crypto/sha512-avx-asm.S
14398 +++ b/arch/x86/crypto/sha512-avx-asm.S
14399 @@ -49,6 +49,7 @@
14400
14401 #ifdef CONFIG_AS_AVX
14402 #include <linux/linkage.h>
14403 +#include <asm/alternative-asm.h>
14404
14405 .text
14406
14407 @@ -364,6 +365,7 @@ updateblock:
14408 mov frame_RSPSAVE(%rsp), %rsp
14409
14410 nowork:
14411 + pax_force_retaddr
14412 ret
14413 ENDPROC(sha512_transform_avx)
14414
14415 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14416 index 568b961..ed20c37 100644
14417 --- a/arch/x86/crypto/sha512-avx2-asm.S
14418 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14419 @@ -51,6 +51,7 @@
14420
14421 #ifdef CONFIG_AS_AVX2
14422 #include <linux/linkage.h>
14423 +#include <asm/alternative-asm.h>
14424
14425 .text
14426
14427 @@ -678,6 +679,7 @@ done_hash:
14428
14429 # Restore Stack Pointer
14430 mov frame_RSPSAVE(%rsp), %rsp
14431 + pax_force_retaddr
14432 ret
14433 ENDPROC(sha512_transform_rorx)
14434
14435 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14436 index fb56855..6edd768 100644
14437 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14438 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14439 @@ -48,6 +48,7 @@
14440 ########################################################################
14441
14442 #include <linux/linkage.h>
14443 +#include <asm/alternative-asm.h>
14444
14445 .text
14446
14447 @@ -363,6 +364,7 @@ updateblock:
14448 mov frame_RSPSAVE(%rsp), %rsp
14449
14450 nowork:
14451 + pax_force_retaddr
14452 ret
14453 ENDPROC(sha512_transform_ssse3)
14454
14455 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14456 index 0505813..b067311 100644
14457 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14458 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14459 @@ -24,6 +24,7 @@
14460 */
14461
14462 #include <linux/linkage.h>
14463 +#include <asm/alternative-asm.h>
14464 #include "glue_helper-asm-avx.S"
14465
14466 .file "twofish-avx-x86_64-asm_64.S"
14467 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14468 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14469 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14470
14471 + pax_force_retaddr
14472 ret;
14473 ENDPROC(__twofish_enc_blk8)
14474
14475 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14476 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14477 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14478
14479 + pax_force_retaddr
14480 ret;
14481 ENDPROC(__twofish_dec_blk8)
14482
14483 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14484
14485 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14486
14487 + pax_force_retaddr
14488 ret;
14489 ENDPROC(twofish_ecb_enc_8way)
14490
14491 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14492
14493 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14494
14495 + pax_force_retaddr
14496 ret;
14497 ENDPROC(twofish_ecb_dec_8way)
14498
14499 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14500 * %rdx: src
14501 */
14502
14503 - pushq %r12;
14504 + pushq %r14;
14505
14506 movq %rsi, %r11;
14507 - movq %rdx, %r12;
14508 + movq %rdx, %r14;
14509
14510 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14511
14512 call __twofish_dec_blk8;
14513
14514 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14515 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14516
14517 - popq %r12;
14518 + popq %r14;
14519
14520 + pax_force_retaddr
14521 ret;
14522 ENDPROC(twofish_cbc_dec_8way)
14523
14524 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14525 * %rcx: iv (little endian, 128bit)
14526 */
14527
14528 - pushq %r12;
14529 + pushq %r14;
14530
14531 movq %rsi, %r11;
14532 - movq %rdx, %r12;
14533 + movq %rdx, %r14;
14534
14535 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14536 RD2, RX0, RX1, RY0);
14537
14538 call __twofish_enc_blk8;
14539
14540 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14541 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14542
14543 - popq %r12;
14544 + popq %r14;
14545
14546 + pax_force_retaddr
14547 ret;
14548 ENDPROC(twofish_ctr_8way)
14549
14550 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14551 /* dst <= regs xor IVs(in dst) */
14552 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14553
14554 + pax_force_retaddr
14555 ret;
14556 ENDPROC(twofish_xts_enc_8way)
14557
14558 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14559 /* dst <= regs xor IVs(in dst) */
14560 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14561
14562 + pax_force_retaddr
14563 ret;
14564 ENDPROC(twofish_xts_dec_8way)
14565 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14566 index 1c3b7ce..02f578d 100644
14567 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14568 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14569 @@ -21,6 +21,7 @@
14570 */
14571
14572 #include <linux/linkage.h>
14573 +#include <asm/alternative-asm.h>
14574
14575 .file "twofish-x86_64-asm-3way.S"
14576 .text
14577 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14578 popq %r13;
14579 popq %r14;
14580 popq %r15;
14581 + pax_force_retaddr
14582 ret;
14583
14584 .L__enc_xor3:
14585 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14586 popq %r13;
14587 popq %r14;
14588 popq %r15;
14589 + pax_force_retaddr
14590 ret;
14591 ENDPROC(__twofish_enc_blk_3way)
14592
14593 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14594 popq %r13;
14595 popq %r14;
14596 popq %r15;
14597 + pax_force_retaddr
14598 ret;
14599 ENDPROC(twofish_dec_blk_3way)
14600 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14601 index a039d21..524b8b2 100644
14602 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14603 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14604 @@ -22,6 +22,7 @@
14605
14606 #include <linux/linkage.h>
14607 #include <asm/asm-offsets.h>
14608 +#include <asm/alternative-asm.h>
14609
14610 #define a_offset 0
14611 #define b_offset 4
14612 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14613
14614 popq R1
14615 movq $1,%rax
14616 + pax_force_retaddr
14617 ret
14618 ENDPROC(twofish_enc_blk)
14619
14620 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14621
14622 popq R1
14623 movq $1,%rax
14624 + pax_force_retaddr
14625 ret
14626 ENDPROC(twofish_dec_blk)
14627 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14628 index df91466..74b31cb 100644
14629 --- a/arch/x86/ia32/ia32_aout.c
14630 +++ b/arch/x86/ia32/ia32_aout.c
14631 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14632 unsigned long dump_start, dump_size;
14633 struct user32 dump;
14634
14635 + memset(&dump, 0, sizeof(dump));
14636 +
14637 fs = get_fs();
14638 set_fs(KERNEL_DS);
14639 has_dumped = 1;
14640 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14641 index f9e181a..300544c 100644
14642 --- a/arch/x86/ia32/ia32_signal.c
14643 +++ b/arch/x86/ia32/ia32_signal.c
14644 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14645 if (__get_user(set.sig[0], &frame->sc.oldmask)
14646 || (_COMPAT_NSIG_WORDS > 1
14647 && __copy_from_user((((char *) &set.sig) + 4),
14648 - &frame->extramask,
14649 + frame->extramask,
14650 sizeof(frame->extramask))))
14651 goto badframe;
14652
14653 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14654 sp -= frame_size;
14655 /* Align the stack pointer according to the i386 ABI,
14656 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14657 - sp = ((sp + 4) & -16ul) - 4;
14658 + sp = ((sp - 12) & -16ul) - 4;
14659 return (void __user *) sp;
14660 }
14661
14662 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14663 } else {
14664 /* Return stub is in 32bit vsyscall page */
14665 if (current->mm->context.vdso)
14666 - restorer = current->mm->context.vdso +
14667 - selected_vdso32->sym___kernel_sigreturn;
14668 + restorer = (void __force_user *)(current->mm->context.vdso +
14669 + selected_vdso32->sym___kernel_sigreturn);
14670 else
14671 - restorer = &frame->retcode;
14672 + restorer = frame->retcode;
14673 }
14674
14675 put_user_try {
14676 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14677 * These are actually not used anymore, but left because some
14678 * gdb versions depend on them as a marker.
14679 */
14680 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14681 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14682 } put_user_catch(err);
14683
14684 if (err)
14685 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14686 0xb8,
14687 __NR_ia32_rt_sigreturn,
14688 0x80cd,
14689 - 0,
14690 + 0
14691 };
14692
14693 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14694 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14695
14696 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14697 restorer = ksig->ka.sa.sa_restorer;
14698 + else if (current->mm->context.vdso)
14699 + /* Return stub is in 32bit vsyscall page */
14700 + restorer = (void __force_user *)(current->mm->context.vdso +
14701 + selected_vdso32->sym___kernel_rt_sigreturn);
14702 else
14703 - restorer = current->mm->context.vdso +
14704 - selected_vdso32->sym___kernel_rt_sigreturn;
14705 + restorer = frame->retcode;
14706 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14707
14708 /*
14709 * Not actually used anymore, but left because some gdb
14710 * versions need it.
14711 */
14712 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14713 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14714 } put_user_catch(err);
14715
14716 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14717 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14718 index ffe7122..899bad3 100644
14719 --- a/arch/x86/ia32/ia32entry.S
14720 +++ b/arch/x86/ia32/ia32entry.S
14721 @@ -15,8 +15,10 @@
14722 #include <asm/irqflags.h>
14723 #include <asm/asm.h>
14724 #include <asm/smap.h>
14725 +#include <asm/pgtable.h>
14726 #include <linux/linkage.h>
14727 #include <linux/err.h>
14728 +#include <asm/alternative-asm.h>
14729
14730 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14731 #include <linux/elf-em.h>
14732 @@ -62,12 +64,12 @@
14733 */
14734 .macro LOAD_ARGS32 offset, _r9=0
14735 .if \_r9
14736 - movl \offset+16(%rsp),%r9d
14737 + movl \offset+R9(%rsp),%r9d
14738 .endif
14739 - movl \offset+40(%rsp),%ecx
14740 - movl \offset+48(%rsp),%edx
14741 - movl \offset+56(%rsp),%esi
14742 - movl \offset+64(%rsp),%edi
14743 + movl \offset+RCX(%rsp),%ecx
14744 + movl \offset+RDX(%rsp),%edx
14745 + movl \offset+RSI(%rsp),%esi
14746 + movl \offset+RDI(%rsp),%edi
14747 movl %eax,%eax /* zero extension */
14748 .endm
14749
14750 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14751 ENDPROC(native_irq_enable_sysexit)
14752 #endif
14753
14754 + .macro pax_enter_kernel_user
14755 + pax_set_fptr_mask
14756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14757 + call pax_enter_kernel_user
14758 +#endif
14759 + .endm
14760 +
14761 + .macro pax_exit_kernel_user
14762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14763 + call pax_exit_kernel_user
14764 +#endif
14765 +#ifdef CONFIG_PAX_RANDKSTACK
14766 + pushq %rax
14767 + pushq %r11
14768 + call pax_randomize_kstack
14769 + popq %r11
14770 + popq %rax
14771 +#endif
14772 + .endm
14773 +
14774 + .macro pax_erase_kstack
14775 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14776 + call pax_erase_kstack
14777 +#endif
14778 + .endm
14779 +
14780 /*
14781 * 32bit SYSENTER instruction entry.
14782 *
14783 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14784 CFI_REGISTER rsp,rbp
14785 SWAPGS_UNSAFE_STACK
14786 movq PER_CPU_VAR(kernel_stack), %rsp
14787 - addq $(KERNEL_STACK_OFFSET),%rsp
14788 - /*
14789 - * No need to follow this irqs on/off section: the syscall
14790 - * disabled irqs, here we enable it straight after entry:
14791 - */
14792 - ENABLE_INTERRUPTS(CLBR_NONE)
14793 movl %ebp,%ebp /* zero extension */
14794 pushq_cfi $__USER32_DS
14795 /*CFI_REL_OFFSET ss,0*/
14796 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14797 CFI_REL_OFFSET rsp,0
14798 pushfq_cfi
14799 /*CFI_REL_OFFSET rflags,0*/
14800 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14801 - CFI_REGISTER rip,r10
14802 + orl $X86_EFLAGS_IF,(%rsp)
14803 + GET_THREAD_INFO(%r11)
14804 + movl TI_sysenter_return(%r11), %r11d
14805 + CFI_REGISTER rip,r11
14806 pushq_cfi $__USER32_CS
14807 /*CFI_REL_OFFSET cs,0*/
14808 movl %eax, %eax
14809 - pushq_cfi %r10
14810 + pushq_cfi %r11
14811 CFI_REL_OFFSET rip,0
14812 pushq_cfi %rax
14813 cld
14814 SAVE_ARGS 0,1,0
14815 + pax_enter_kernel_user
14816 +
14817 +#ifdef CONFIG_PAX_RANDKSTACK
14818 + pax_erase_kstack
14819 +#endif
14820 +
14821 + /*
14822 + * No need to follow this irqs on/off section: the syscall
14823 + * disabled irqs, here we enable it straight after entry:
14824 + */
14825 + ENABLE_INTERRUPTS(CLBR_NONE)
14826 /* no need to do an access_ok check here because rbp has been
14827 32bit zero extended */
14828 +
14829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14830 + addq pax_user_shadow_base,%rbp
14831 + ASM_PAX_OPEN_USERLAND
14832 +#endif
14833 +
14834 ASM_STAC
14835 1: movl (%rbp),%ebp
14836 _ASM_EXTABLE(1b,ia32_badarg)
14837 ASM_CLAC
14838
14839 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14840 + ASM_PAX_CLOSE_USERLAND
14841 +#endif
14842 +
14843 /*
14844 * Sysenter doesn't filter flags, so we need to clear NT
14845 * ourselves. To save a few cycles, we can check whether
14846 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14847 jnz sysenter_fix_flags
14848 sysenter_flags_fixed:
14849
14850 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14851 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14852 + GET_THREAD_INFO(%r11)
14853 + orl $TS_COMPAT,TI_status(%r11)
14854 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14855 CFI_REMEMBER_STATE
14856 jnz sysenter_tracesys
14857 cmpq $(IA32_NR_syscalls-1),%rax
14858 @@ -172,15 +218,18 @@ sysenter_do_call:
14859 sysenter_dispatch:
14860 call *ia32_sys_call_table(,%rax,8)
14861 movq %rax,RAX-ARGOFFSET(%rsp)
14862 + GET_THREAD_INFO(%r11)
14863 DISABLE_INTERRUPTS(CLBR_NONE)
14864 TRACE_IRQS_OFF
14865 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14866 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14867 jnz sysexit_audit
14868 sysexit_from_sys_call:
14869 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14870 + pax_exit_kernel_user
14871 + pax_erase_kstack
14872 + andl $~TS_COMPAT,TI_status(%r11)
14873 /* clear IF, that popfq doesn't enable interrupts early */
14874 - andl $~0x200,EFLAGS-R11(%rsp)
14875 - movl RIP-R11(%rsp),%edx /* User %eip */
14876 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14877 + movl RIP(%rsp),%edx /* User %eip */
14878 CFI_REGISTER rip,rdx
14879 RESTORE_ARGS 0,24,0,0,0,0
14880 xorq %r8,%r8
14881 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
14882 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14883 movl %eax,%edi /* 1st arg: syscall number */
14884 call __audit_syscall_entry
14885 +
14886 + pax_erase_kstack
14887 +
14888 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14889 cmpq $(IA32_NR_syscalls-1),%rax
14890 ja ia32_badsys
14891 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
14892 .endm
14893
14894 .macro auditsys_exit exit
14895 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14896 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14897 jnz ia32_ret_from_sys_call
14898 TRACE_IRQS_ON
14899 ENABLE_INTERRUPTS(CLBR_NONE)
14900 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
14901 1: setbe %al /* 1 if error, 0 if not */
14902 movzbl %al,%edi /* zero-extend that into %edi */
14903 call __audit_syscall_exit
14904 + GET_THREAD_INFO(%r11)
14905 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14906 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14907 DISABLE_INTERRUPTS(CLBR_NONE)
14908 TRACE_IRQS_OFF
14909 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14910 + testl %edi,TI_flags(%r11)
14911 jz \exit
14912 CLEAR_RREGS -ARGOFFSET
14913 jmp int_with_check
14914 @@ -253,7 +306,7 @@ sysenter_fix_flags:
14915
14916 sysenter_tracesys:
14917 #ifdef CONFIG_AUDITSYSCALL
14918 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14919 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14920 jz sysenter_auditsys
14921 #endif
14922 SAVE_REST
14923 @@ -265,6 +318,9 @@ sysenter_tracesys:
14924 RESTORE_REST
14925 cmpq $(IA32_NR_syscalls-1),%rax
14926 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14927 +
14928 + pax_erase_kstack
14929 +
14930 jmp sysenter_do_call
14931 CFI_ENDPROC
14932 ENDPROC(ia32_sysenter_target)
14933 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14934 ENTRY(ia32_cstar_target)
14935 CFI_STARTPROC32 simple
14936 CFI_SIGNAL_FRAME
14937 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14938 + CFI_DEF_CFA rsp,0
14939 CFI_REGISTER rip,rcx
14940 /*CFI_REGISTER rflags,r11*/
14941 SWAPGS_UNSAFE_STACK
14942 movl %esp,%r8d
14943 CFI_REGISTER rsp,r8
14944 movq PER_CPU_VAR(kernel_stack),%rsp
14945 + SAVE_ARGS 8*6,0,0
14946 + pax_enter_kernel_user
14947 +
14948 +#ifdef CONFIG_PAX_RANDKSTACK
14949 + pax_erase_kstack
14950 +#endif
14951 +
14952 /*
14953 * No need to follow this irqs on/off section: the syscall
14954 * disabled irqs and here we enable it straight after entry:
14955 */
14956 ENABLE_INTERRUPTS(CLBR_NONE)
14957 - SAVE_ARGS 8,0,0
14958 movl %eax,%eax /* zero extension */
14959 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14960 movq %rcx,RIP-ARGOFFSET(%rsp)
14961 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14962 /* no need to do an access_ok check here because r8 has been
14963 32bit zero extended */
14964 /* hardware stack frame is complete now */
14965 +
14966 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14967 + ASM_PAX_OPEN_USERLAND
14968 + movq pax_user_shadow_base,%r8
14969 + addq RSP-ARGOFFSET(%rsp),%r8
14970 +#endif
14971 +
14972 ASM_STAC
14973 1: movl (%r8),%r9d
14974 _ASM_EXTABLE(1b,ia32_badarg)
14975 ASM_CLAC
14976 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14977 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14978 +
14979 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14980 + ASM_PAX_CLOSE_USERLAND
14981 +#endif
14982 +
14983 + GET_THREAD_INFO(%r11)
14984 + orl $TS_COMPAT,TI_status(%r11)
14985 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14986 CFI_REMEMBER_STATE
14987 jnz cstar_tracesys
14988 cmpq $IA32_NR_syscalls-1,%rax
14989 @@ -335,13 +410,16 @@ cstar_do_call:
14990 cstar_dispatch:
14991 call *ia32_sys_call_table(,%rax,8)
14992 movq %rax,RAX-ARGOFFSET(%rsp)
14993 + GET_THREAD_INFO(%r11)
14994 DISABLE_INTERRUPTS(CLBR_NONE)
14995 TRACE_IRQS_OFF
14996 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14997 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14998 jnz sysretl_audit
14999 sysretl_from_sys_call:
15000 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15001 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15002 + pax_exit_kernel_user
15003 + pax_erase_kstack
15004 + andl $~TS_COMPAT,TI_status(%r11)
15005 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15006 movl RIP-ARGOFFSET(%rsp),%ecx
15007 CFI_REGISTER rip,rcx
15008 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15009 @@ -368,7 +446,7 @@ sysretl_audit:
15010
15011 cstar_tracesys:
15012 #ifdef CONFIG_AUDITSYSCALL
15013 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15014 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15015 jz cstar_auditsys
15016 #endif
15017 xchgl %r9d,%ebp
15018 @@ -382,11 +460,19 @@ cstar_tracesys:
15019 xchgl %ebp,%r9d
15020 cmpq $(IA32_NR_syscalls-1),%rax
15021 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15022 +
15023 + pax_erase_kstack
15024 +
15025 jmp cstar_do_call
15026 END(ia32_cstar_target)
15027
15028 ia32_badarg:
15029 ASM_CLAC
15030 +
15031 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15032 + ASM_PAX_CLOSE_USERLAND
15033 +#endif
15034 +
15035 movq $-EFAULT,%rax
15036 jmp ia32_sysret
15037 CFI_ENDPROC
15038 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15039 CFI_REL_OFFSET rip,RIP-RIP
15040 PARAVIRT_ADJUST_EXCEPTION_FRAME
15041 SWAPGS
15042 - /*
15043 - * No need to follow this irqs on/off section: the syscall
15044 - * disabled irqs and here we enable it straight after entry:
15045 - */
15046 - ENABLE_INTERRUPTS(CLBR_NONE)
15047 movl %eax,%eax
15048 pushq_cfi %rax
15049 cld
15050 /* note the registers are not zero extended to the sf.
15051 this could be a problem. */
15052 SAVE_ARGS 0,1,0
15053 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15054 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15055 + pax_enter_kernel_user
15056 +
15057 +#ifdef CONFIG_PAX_RANDKSTACK
15058 + pax_erase_kstack
15059 +#endif
15060 +
15061 + /*
15062 + * No need to follow this irqs on/off section: the syscall
15063 + * disabled irqs and here we enable it straight after entry:
15064 + */
15065 + ENABLE_INTERRUPTS(CLBR_NONE)
15066 + GET_THREAD_INFO(%r11)
15067 + orl $TS_COMPAT,TI_status(%r11)
15068 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15069 jnz ia32_tracesys
15070 cmpq $(IA32_NR_syscalls-1),%rax
15071 ja ia32_badsys
15072 @@ -458,6 +551,9 @@ ia32_tracesys:
15073 RESTORE_REST
15074 cmpq $(IA32_NR_syscalls-1),%rax
15075 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15076 +
15077 + pax_erase_kstack
15078 +
15079 jmp ia32_do_call
15080 END(ia32_syscall)
15081
15082 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15083 index 8e0ceec..af13504 100644
15084 --- a/arch/x86/ia32/sys_ia32.c
15085 +++ b/arch/x86/ia32/sys_ia32.c
15086 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15087 */
15088 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15089 {
15090 - typeof(ubuf->st_uid) uid = 0;
15091 - typeof(ubuf->st_gid) gid = 0;
15092 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15093 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15094 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15095 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15096 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15097 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15098 index 372231c..51b537d 100644
15099 --- a/arch/x86/include/asm/alternative-asm.h
15100 +++ b/arch/x86/include/asm/alternative-asm.h
15101 @@ -18,6 +18,45 @@
15102 .endm
15103 #endif
15104
15105 +#ifdef KERNEXEC_PLUGIN
15106 + .macro pax_force_retaddr_bts rip=0
15107 + btsq $63,\rip(%rsp)
15108 + .endm
15109 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15110 + .macro pax_force_retaddr rip=0, reload=0
15111 + btsq $63,\rip(%rsp)
15112 + .endm
15113 + .macro pax_force_fptr ptr
15114 + btsq $63,\ptr
15115 + .endm
15116 + .macro pax_set_fptr_mask
15117 + .endm
15118 +#endif
15119 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15120 + .macro pax_force_retaddr rip=0, reload=0
15121 + .if \reload
15122 + pax_set_fptr_mask
15123 + .endif
15124 + orq %r12,\rip(%rsp)
15125 + .endm
15126 + .macro pax_force_fptr ptr
15127 + orq %r12,\ptr
15128 + .endm
15129 + .macro pax_set_fptr_mask
15130 + movabs $0x8000000000000000,%r12
15131 + .endm
15132 +#endif
15133 +#else
15134 + .macro pax_force_retaddr rip=0, reload=0
15135 + .endm
15136 + .macro pax_force_fptr ptr
15137 + .endm
15138 + .macro pax_force_retaddr_bts rip=0
15139 + .endm
15140 + .macro pax_set_fptr_mask
15141 + .endm
15142 +#endif
15143 +
15144 .macro altinstruction_entry orig alt feature orig_len alt_len
15145 .long \orig - .
15146 .long \alt - .
15147 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15148 index 473bdbe..b1e3377 100644
15149 --- a/arch/x86/include/asm/alternative.h
15150 +++ b/arch/x86/include/asm/alternative.h
15151 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15152 ".pushsection .discard,\"aw\",@progbits\n" \
15153 DISCARD_ENTRY(1) \
15154 ".popsection\n" \
15155 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15156 + ".pushsection .altinstr_replacement, \"a\"\n" \
15157 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15158 ".popsection"
15159
15160 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15161 DISCARD_ENTRY(1) \
15162 DISCARD_ENTRY(2) \
15163 ".popsection\n" \
15164 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15165 + ".pushsection .altinstr_replacement, \"a\"\n" \
15166 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15167 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15168 ".popsection"
15169 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15170 index 465b309..ab7e51f 100644
15171 --- a/arch/x86/include/asm/apic.h
15172 +++ b/arch/x86/include/asm/apic.h
15173 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15174
15175 #ifdef CONFIG_X86_LOCAL_APIC
15176
15177 -extern unsigned int apic_verbosity;
15178 +extern int apic_verbosity;
15179 extern int local_apic_timer_c2_ok;
15180
15181 extern int disable_apic;
15182 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15183 index 20370c6..a2eb9b0 100644
15184 --- a/arch/x86/include/asm/apm.h
15185 +++ b/arch/x86/include/asm/apm.h
15186 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15187 __asm__ __volatile__(APM_DO_ZERO_SEGS
15188 "pushl %%edi\n\t"
15189 "pushl %%ebp\n\t"
15190 - "lcall *%%cs:apm_bios_entry\n\t"
15191 + "lcall *%%ss:apm_bios_entry\n\t"
15192 "setc %%al\n\t"
15193 "popl %%ebp\n\t"
15194 "popl %%edi\n\t"
15195 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15196 __asm__ __volatile__(APM_DO_ZERO_SEGS
15197 "pushl %%edi\n\t"
15198 "pushl %%ebp\n\t"
15199 - "lcall *%%cs:apm_bios_entry\n\t"
15200 + "lcall *%%ss:apm_bios_entry\n\t"
15201 "setc %%bl\n\t"
15202 "popl %%ebp\n\t"
15203 "popl %%edi\n\t"
15204 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15205 index 5e5cd12..3d18208 100644
15206 --- a/arch/x86/include/asm/atomic.h
15207 +++ b/arch/x86/include/asm/atomic.h
15208 @@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15209 }
15210
15211 /**
15212 + * atomic_read_unchecked - read atomic variable
15213 + * @v: pointer of type atomic_unchecked_t
15214 + *
15215 + * Atomically reads the value of @v.
15216 + */
15217 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15218 +{
15219 + return ACCESS_ONCE((v)->counter);
15220 +}
15221 +
15222 +/**
15223 * atomic_set - set atomic variable
15224 * @v: pointer of type atomic_t
15225 * @i: required value
15226 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15227 }
15228
15229 /**
15230 + * atomic_set_unchecked - set atomic variable
15231 + * @v: pointer of type atomic_unchecked_t
15232 + * @i: required value
15233 + *
15234 + * Atomically sets the value of @v to @i.
15235 + */
15236 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15237 +{
15238 + v->counter = i;
15239 +}
15240 +
15241 +/**
15242 * atomic_add - add integer to atomic variable
15243 * @i: integer value to add
15244 * @v: pointer of type atomic_t
15245 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15246 */
15247 static inline void atomic_add(int i, atomic_t *v)
15248 {
15249 - asm volatile(LOCK_PREFIX "addl %1,%0"
15250 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15251 +
15252 +#ifdef CONFIG_PAX_REFCOUNT
15253 + "jno 0f\n"
15254 + LOCK_PREFIX "subl %1,%0\n"
15255 + "int $4\n0:\n"
15256 + _ASM_EXTABLE(0b, 0b)
15257 +#endif
15258 +
15259 + : "+m" (v->counter)
15260 + : "ir" (i));
15261 +}
15262 +
15263 +/**
15264 + * atomic_add_unchecked - add integer to atomic variable
15265 + * @i: integer value to add
15266 + * @v: pointer of type atomic_unchecked_t
15267 + *
15268 + * Atomically adds @i to @v.
15269 + */
15270 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15271 +{
15272 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15273 : "+m" (v->counter)
15274 : "ir" (i));
15275 }
15276 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15277 */
15278 static inline void atomic_sub(int i, atomic_t *v)
15279 {
15280 - asm volatile(LOCK_PREFIX "subl %1,%0"
15281 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15282 +
15283 +#ifdef CONFIG_PAX_REFCOUNT
15284 + "jno 0f\n"
15285 + LOCK_PREFIX "addl %1,%0\n"
15286 + "int $4\n0:\n"
15287 + _ASM_EXTABLE(0b, 0b)
15288 +#endif
15289 +
15290 + : "+m" (v->counter)
15291 + : "ir" (i));
15292 +}
15293 +
15294 +/**
15295 + * atomic_sub_unchecked - subtract integer from atomic variable
15296 + * @i: integer value to subtract
15297 + * @v: pointer of type atomic_unchecked_t
15298 + *
15299 + * Atomically subtracts @i from @v.
15300 + */
15301 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15302 +{
15303 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15304 : "+m" (v->counter)
15305 : "ir" (i));
15306 }
15307 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15308 */
15309 static inline int atomic_sub_and_test(int i, atomic_t *v)
15310 {
15311 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15312 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15313 }
15314
15315 /**
15316 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15317 */
15318 static inline void atomic_inc(atomic_t *v)
15319 {
15320 - asm volatile(LOCK_PREFIX "incl %0"
15321 + asm volatile(LOCK_PREFIX "incl %0\n"
15322 +
15323 +#ifdef CONFIG_PAX_REFCOUNT
15324 + "jno 0f\n"
15325 + LOCK_PREFIX "decl %0\n"
15326 + "int $4\n0:\n"
15327 + _ASM_EXTABLE(0b, 0b)
15328 +#endif
15329 +
15330 + : "+m" (v->counter));
15331 +}
15332 +
15333 +/**
15334 + * atomic_inc_unchecked - increment atomic variable
15335 + * @v: pointer of type atomic_unchecked_t
15336 + *
15337 + * Atomically increments @v by 1.
15338 + */
15339 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15340 +{
15341 + asm volatile(LOCK_PREFIX "incl %0\n"
15342 : "+m" (v->counter));
15343 }
15344
15345 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15346 */
15347 static inline void atomic_dec(atomic_t *v)
15348 {
15349 - asm volatile(LOCK_PREFIX "decl %0"
15350 + asm volatile(LOCK_PREFIX "decl %0\n"
15351 +
15352 +#ifdef CONFIG_PAX_REFCOUNT
15353 + "jno 0f\n"
15354 + LOCK_PREFIX "incl %0\n"
15355 + "int $4\n0:\n"
15356 + _ASM_EXTABLE(0b, 0b)
15357 +#endif
15358 +
15359 + : "+m" (v->counter));
15360 +}
15361 +
15362 +/**
15363 + * atomic_dec_unchecked - decrement atomic variable
15364 + * @v: pointer of type atomic_unchecked_t
15365 + *
15366 + * Atomically decrements @v by 1.
15367 + */
15368 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15369 +{
15370 + asm volatile(LOCK_PREFIX "decl %0\n"
15371 : "+m" (v->counter));
15372 }
15373
15374 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15375 */
15376 static inline int atomic_dec_and_test(atomic_t *v)
15377 {
15378 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15379 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15380 }
15381
15382 /**
15383 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15384 */
15385 static inline int atomic_inc_and_test(atomic_t *v)
15386 {
15387 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15388 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15389 +}
15390 +
15391 +/**
15392 + * atomic_inc_and_test_unchecked - increment and test
15393 + * @v: pointer of type atomic_unchecked_t
15394 + *
15395 + * Atomically increments @v by 1
15396 + * and returns true if the result is zero, or false for all
15397 + * other cases.
15398 + */
15399 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15400 +{
15401 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15402 }
15403
15404 /**
15405 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15406 */
15407 static inline int atomic_add_negative(int i, atomic_t *v)
15408 {
15409 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15410 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15411 }
15412
15413 /**
15414 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15415 *
15416 * Atomically adds @i to @v and returns @i + @v
15417 */
15418 -static inline int atomic_add_return(int i, atomic_t *v)
15419 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15420 +{
15421 + return i + xadd_check_overflow(&v->counter, i);
15422 +}
15423 +
15424 +/**
15425 + * atomic_add_return_unchecked - add integer and return
15426 + * @i: integer value to add
15427 + * @v: pointer of type atomic_unchecked_t
15428 + *
15429 + * Atomically adds @i to @v and returns @i + @v
15430 + */
15431 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15432 {
15433 return i + xadd(&v->counter, i);
15434 }
15435 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15436 *
15437 * Atomically subtracts @i from @v and returns @v - @i
15438 */
15439 -static inline int atomic_sub_return(int i, atomic_t *v)
15440 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15441 {
15442 return atomic_add_return(-i, v);
15443 }
15444
15445 #define atomic_inc_return(v) (atomic_add_return(1, v))
15446 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15447 +{
15448 + return atomic_add_return_unchecked(1, v);
15449 +}
15450 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15451
15452 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15453 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15454 +{
15455 + return cmpxchg(&v->counter, old, new);
15456 +}
15457 +
15458 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15459 {
15460 return cmpxchg(&v->counter, old, new);
15461 }
15462 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15463 return xchg(&v->counter, new);
15464 }
15465
15466 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15467 +{
15468 + return xchg(&v->counter, new);
15469 +}
15470 +
15471 /**
15472 * __atomic_add_unless - add unless the number is already a given value
15473 * @v: pointer of type atomic_t
15474 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15475 * Atomically adds @a to @v, so long as @v was not already @u.
15476 * Returns the old value of @v.
15477 */
15478 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15479 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15480 {
15481 - int c, old;
15482 + int c, old, new;
15483 c = atomic_read(v);
15484 for (;;) {
15485 - if (unlikely(c == (u)))
15486 + if (unlikely(c == u))
15487 break;
15488 - old = atomic_cmpxchg((v), c, c + (a));
15489 +
15490 + asm volatile("addl %2,%0\n"
15491 +
15492 +#ifdef CONFIG_PAX_REFCOUNT
15493 + "jno 0f\n"
15494 + "subl %2,%0\n"
15495 + "int $4\n0:\n"
15496 + _ASM_EXTABLE(0b, 0b)
15497 +#endif
15498 +
15499 + : "=r" (new)
15500 + : "0" (c), "ir" (a));
15501 +
15502 + old = atomic_cmpxchg(v, c, new);
15503 if (likely(old == c))
15504 break;
15505 c = old;
15506 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15507 }
15508
15509 /**
15510 + * atomic_inc_not_zero_hint - increment if not null
15511 + * @v: pointer of type atomic_t
15512 + * @hint: probable value of the atomic before the increment
15513 + *
15514 + * This version of atomic_inc_not_zero() gives a hint of probable
15515 + * value of the atomic. This helps processor to not read the memory
15516 + * before doing the atomic read/modify/write cycle, lowering
15517 + * number of bus transactions on some arches.
15518 + *
15519 + * Returns: 0 if increment was not done, 1 otherwise.
15520 + */
15521 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15522 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15523 +{
15524 + int val, c = hint, new;
15525 +
15526 + /* sanity test, should be removed by compiler if hint is a constant */
15527 + if (!hint)
15528 + return __atomic_add_unless(v, 1, 0);
15529 +
15530 + do {
15531 + asm volatile("incl %0\n"
15532 +
15533 +#ifdef CONFIG_PAX_REFCOUNT
15534 + "jno 0f\n"
15535 + "decl %0\n"
15536 + "int $4\n0:\n"
15537 + _ASM_EXTABLE(0b, 0b)
15538 +#endif
15539 +
15540 + : "=r" (new)
15541 + : "0" (c));
15542 +
15543 + val = atomic_cmpxchg(v, c, new);
15544 + if (val == c)
15545 + return 1;
15546 + c = val;
15547 + } while (c);
15548 +
15549 + return 0;
15550 +}
15551 +
15552 +/**
15553 * atomic_inc_short - increment of a short integer
15554 * @v: pointer to type int
15555 *
15556 @@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15557 }
15558
15559 /* These are x86-specific, used by some header files */
15560 -#define atomic_clear_mask(mask, addr) \
15561 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15562 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15563 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15564 +{
15565 + asm volatile(LOCK_PREFIX "andl %1,%0"
15566 + : "+m" (v->counter)
15567 + : "r" (~(mask))
15568 + : "memory");
15569 +}
15570
15571 -#define atomic_set_mask(mask, addr) \
15572 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15573 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15574 - : "memory")
15575 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15576 +{
15577 + asm volatile(LOCK_PREFIX "andl %1,%0"
15578 + : "+m" (v->counter)
15579 + : "r" (~(mask))
15580 + : "memory");
15581 +}
15582 +
15583 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15584 +{
15585 + asm volatile(LOCK_PREFIX "orl %1,%0"
15586 + : "+m" (v->counter)
15587 + : "r" (mask)
15588 + : "memory");
15589 +}
15590 +
15591 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15592 +{
15593 + asm volatile(LOCK_PREFIX "orl %1,%0"
15594 + : "+m" (v->counter)
15595 + : "r" (mask)
15596 + : "memory");
15597 +}
15598
15599 #ifdef CONFIG_X86_32
15600 # include <asm/atomic64_32.h>
15601 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15602 index b154de7..bf18a5a 100644
15603 --- a/arch/x86/include/asm/atomic64_32.h
15604 +++ b/arch/x86/include/asm/atomic64_32.h
15605 @@ -12,6 +12,14 @@ typedef struct {
15606 u64 __aligned(8) counter;
15607 } atomic64_t;
15608
15609 +#ifdef CONFIG_PAX_REFCOUNT
15610 +typedef struct {
15611 + u64 __aligned(8) counter;
15612 +} atomic64_unchecked_t;
15613 +#else
15614 +typedef atomic64_t atomic64_unchecked_t;
15615 +#endif
15616 +
15617 #define ATOMIC64_INIT(val) { (val) }
15618
15619 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15620 @@ -37,21 +45,31 @@ typedef struct {
15621 ATOMIC64_DECL_ONE(sym##_386)
15622
15623 ATOMIC64_DECL_ONE(add_386);
15624 +ATOMIC64_DECL_ONE(add_unchecked_386);
15625 ATOMIC64_DECL_ONE(sub_386);
15626 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15627 ATOMIC64_DECL_ONE(inc_386);
15628 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15629 ATOMIC64_DECL_ONE(dec_386);
15630 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15631 #endif
15632
15633 #define alternative_atomic64(f, out, in...) \
15634 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15635
15636 ATOMIC64_DECL(read);
15637 +ATOMIC64_DECL(read_unchecked);
15638 ATOMIC64_DECL(set);
15639 +ATOMIC64_DECL(set_unchecked);
15640 ATOMIC64_DECL(xchg);
15641 ATOMIC64_DECL(add_return);
15642 +ATOMIC64_DECL(add_return_unchecked);
15643 ATOMIC64_DECL(sub_return);
15644 +ATOMIC64_DECL(sub_return_unchecked);
15645 ATOMIC64_DECL(inc_return);
15646 +ATOMIC64_DECL(inc_return_unchecked);
15647 ATOMIC64_DECL(dec_return);
15648 +ATOMIC64_DECL(dec_return_unchecked);
15649 ATOMIC64_DECL(dec_if_positive);
15650 ATOMIC64_DECL(inc_not_zero);
15651 ATOMIC64_DECL(add_unless);
15652 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15653 }
15654
15655 /**
15656 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15657 + * @p: pointer to type atomic64_unchecked_t
15658 + * @o: expected value
15659 + * @n: new value
15660 + *
15661 + * Atomically sets @v to @n if it was equal to @o and returns
15662 + * the old value.
15663 + */
15664 +
15665 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15666 +{
15667 + return cmpxchg64(&v->counter, o, n);
15668 +}
15669 +
15670 +/**
15671 * atomic64_xchg - xchg atomic64 variable
15672 * @v: pointer to type atomic64_t
15673 * @n: value to assign
15674 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15675 }
15676
15677 /**
15678 + * atomic64_set_unchecked - set atomic64 variable
15679 + * @v: pointer to type atomic64_unchecked_t
15680 + * @n: value to assign
15681 + *
15682 + * Atomically sets the value of @v to @n.
15683 + */
15684 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15685 +{
15686 + unsigned high = (unsigned)(i >> 32);
15687 + unsigned low = (unsigned)i;
15688 + alternative_atomic64(set, /* no output */,
15689 + "S" (v), "b" (low), "c" (high)
15690 + : "eax", "edx", "memory");
15691 +}
15692 +
15693 +/**
15694 * atomic64_read - read atomic64 variable
15695 * @v: pointer to type atomic64_t
15696 *
15697 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15698 }
15699
15700 /**
15701 + * atomic64_read_unchecked - read atomic64 variable
15702 + * @v: pointer to type atomic64_unchecked_t
15703 + *
15704 + * Atomically reads the value of @v and returns it.
15705 + */
15706 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15707 +{
15708 + long long r;
15709 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15710 + return r;
15711 + }
15712 +
15713 +/**
15714 * atomic64_add_return - add and return
15715 * @i: integer value to add
15716 * @v: pointer to type atomic64_t
15717 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15718 return i;
15719 }
15720
15721 +/**
15722 + * atomic64_add_return_unchecked - add and return
15723 + * @i: integer value to add
15724 + * @v: pointer to type atomic64_unchecked_t
15725 + *
15726 + * Atomically adds @i to @v and returns @i + *@v
15727 + */
15728 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15729 +{
15730 + alternative_atomic64(add_return_unchecked,
15731 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15732 + ASM_NO_INPUT_CLOBBER("memory"));
15733 + return i;
15734 +}
15735 +
15736 /*
15737 * Other variants with different arithmetic operators:
15738 */
15739 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15740 return a;
15741 }
15742
15743 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15744 +{
15745 + long long a;
15746 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15747 + "S" (v) : "memory", "ecx");
15748 + return a;
15749 +}
15750 +
15751 static inline long long atomic64_dec_return(atomic64_t *v)
15752 {
15753 long long a;
15754 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15755 }
15756
15757 /**
15758 + * atomic64_add_unchecked - add integer to atomic64 variable
15759 + * @i: integer value to add
15760 + * @v: pointer to type atomic64_unchecked_t
15761 + *
15762 + * Atomically adds @i to @v.
15763 + */
15764 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15765 +{
15766 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15767 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15768 + ASM_NO_INPUT_CLOBBER("memory"));
15769 + return i;
15770 +}
15771 +
15772 +/**
15773 * atomic64_sub - subtract the atomic64 variable
15774 * @i: integer value to subtract
15775 * @v: pointer to type atomic64_t
15776 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15777 index f8d273e..02f39f3 100644
15778 --- a/arch/x86/include/asm/atomic64_64.h
15779 +++ b/arch/x86/include/asm/atomic64_64.h
15780 @@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15781 }
15782
15783 /**
15784 + * atomic64_read_unchecked - read atomic64 variable
15785 + * @v: pointer of type atomic64_unchecked_t
15786 + *
15787 + * Atomically reads the value of @v.
15788 + * Doesn't imply a read memory barrier.
15789 + */
15790 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15791 +{
15792 + return ACCESS_ONCE((v)->counter);
15793 +}
15794 +
15795 +/**
15796 * atomic64_set - set atomic64 variable
15797 * @v: pointer to type atomic64_t
15798 * @i: required value
15799 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15800 }
15801
15802 /**
15803 + * atomic64_set_unchecked - set atomic64 variable
15804 + * @v: pointer to type atomic64_unchecked_t
15805 + * @i: required value
15806 + *
15807 + * Atomically sets the value of @v to @i.
15808 + */
15809 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15810 +{
15811 + v->counter = i;
15812 +}
15813 +
15814 +/**
15815 * atomic64_add - add integer to atomic64 variable
15816 * @i: integer value to add
15817 * @v: pointer to type atomic64_t
15818 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15819 */
15820 static inline void atomic64_add(long i, atomic64_t *v)
15821 {
15822 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15823 +
15824 +#ifdef CONFIG_PAX_REFCOUNT
15825 + "jno 0f\n"
15826 + LOCK_PREFIX "subq %1,%0\n"
15827 + "int $4\n0:\n"
15828 + _ASM_EXTABLE(0b, 0b)
15829 +#endif
15830 +
15831 + : "=m" (v->counter)
15832 + : "er" (i), "m" (v->counter));
15833 +}
15834 +
15835 +/**
15836 + * atomic64_add_unchecked - add integer to atomic64 variable
15837 + * @i: integer value to add
15838 + * @v: pointer to type atomic64_unchecked_t
15839 + *
15840 + * Atomically adds @i to @v.
15841 + */
15842 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15843 +{
15844 asm volatile(LOCK_PREFIX "addq %1,%0"
15845 : "=m" (v->counter)
15846 : "er" (i), "m" (v->counter));
15847 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15848 */
15849 static inline void atomic64_sub(long i, atomic64_t *v)
15850 {
15851 - asm volatile(LOCK_PREFIX "subq %1,%0"
15852 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15853 +
15854 +#ifdef CONFIG_PAX_REFCOUNT
15855 + "jno 0f\n"
15856 + LOCK_PREFIX "addq %1,%0\n"
15857 + "int $4\n0:\n"
15858 + _ASM_EXTABLE(0b, 0b)
15859 +#endif
15860 +
15861 + : "=m" (v->counter)
15862 + : "er" (i), "m" (v->counter));
15863 +}
15864 +
15865 +/**
15866 + * atomic64_sub_unchecked - subtract the atomic64 variable
15867 + * @i: integer value to subtract
15868 + * @v: pointer to type atomic64_unchecked_t
15869 + *
15870 + * Atomically subtracts @i from @v.
15871 + */
15872 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15873 +{
15874 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15875 : "=m" (v->counter)
15876 : "er" (i), "m" (v->counter));
15877 }
15878 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15879 */
15880 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15881 {
15882 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15883 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15884 }
15885
15886 /**
15887 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15888 */
15889 static inline void atomic64_inc(atomic64_t *v)
15890 {
15891 + asm volatile(LOCK_PREFIX "incq %0\n"
15892 +
15893 +#ifdef CONFIG_PAX_REFCOUNT
15894 + "jno 0f\n"
15895 + LOCK_PREFIX "decq %0\n"
15896 + "int $4\n0:\n"
15897 + _ASM_EXTABLE(0b, 0b)
15898 +#endif
15899 +
15900 + : "=m" (v->counter)
15901 + : "m" (v->counter));
15902 +}
15903 +
15904 +/**
15905 + * atomic64_inc_unchecked - increment atomic64 variable
15906 + * @v: pointer to type atomic64_unchecked_t
15907 + *
15908 + * Atomically increments @v by 1.
15909 + */
15910 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15911 +{
15912 asm volatile(LOCK_PREFIX "incq %0"
15913 : "=m" (v->counter)
15914 : "m" (v->counter));
15915 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15916 */
15917 static inline void atomic64_dec(atomic64_t *v)
15918 {
15919 - asm volatile(LOCK_PREFIX "decq %0"
15920 + asm volatile(LOCK_PREFIX "decq %0\n"
15921 +
15922 +#ifdef CONFIG_PAX_REFCOUNT
15923 + "jno 0f\n"
15924 + LOCK_PREFIX "incq %0\n"
15925 + "int $4\n0:\n"
15926 + _ASM_EXTABLE(0b, 0b)
15927 +#endif
15928 +
15929 + : "=m" (v->counter)
15930 + : "m" (v->counter));
15931 +}
15932 +
15933 +/**
15934 + * atomic64_dec_unchecked - decrement atomic64 variable
15935 + * @v: pointer to type atomic64_t
15936 + *
15937 + * Atomically decrements @v by 1.
15938 + */
15939 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15940 +{
15941 + asm volatile(LOCK_PREFIX "decq %0\n"
15942 : "=m" (v->counter)
15943 : "m" (v->counter));
15944 }
15945 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15946 */
15947 static inline int atomic64_dec_and_test(atomic64_t *v)
15948 {
15949 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15950 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15951 }
15952
15953 /**
15954 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15955 */
15956 static inline int atomic64_inc_and_test(atomic64_t *v)
15957 {
15958 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15959 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15960 }
15961
15962 /**
15963 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15964 */
15965 static inline int atomic64_add_negative(long i, atomic64_t *v)
15966 {
15967 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15968 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15969 }
15970
15971 /**
15972 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15973 */
15974 static inline long atomic64_add_return(long i, atomic64_t *v)
15975 {
15976 + return i + xadd_check_overflow(&v->counter, i);
15977 +}
15978 +
15979 +/**
15980 + * atomic64_add_return_unchecked - add and return
15981 + * @i: integer value to add
15982 + * @v: pointer to type atomic64_unchecked_t
15983 + *
15984 + * Atomically adds @i to @v and returns @i + @v
15985 + */
15986 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15987 +{
15988 return i + xadd(&v->counter, i);
15989 }
15990
15991 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15992 }
15993
15994 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15995 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15996 +{
15997 + return atomic64_add_return_unchecked(1, v);
15998 +}
15999 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16000
16001 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16002 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16003 return cmpxchg(&v->counter, old, new);
16004 }
16005
16006 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16007 +{
16008 + return cmpxchg(&v->counter, old, new);
16009 +}
16010 +
16011 static inline long atomic64_xchg(atomic64_t *v, long new)
16012 {
16013 return xchg(&v->counter, new);
16014 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16015 */
16016 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16017 {
16018 - long c, old;
16019 + long c, old, new;
16020 c = atomic64_read(v);
16021 for (;;) {
16022 - if (unlikely(c == (u)))
16023 + if (unlikely(c == u))
16024 break;
16025 - old = atomic64_cmpxchg((v), c, c + (a));
16026 +
16027 + asm volatile("add %2,%0\n"
16028 +
16029 +#ifdef CONFIG_PAX_REFCOUNT
16030 + "jno 0f\n"
16031 + "sub %2,%0\n"
16032 + "int $4\n0:\n"
16033 + _ASM_EXTABLE(0b, 0b)
16034 +#endif
16035 +
16036 + : "=r" (new)
16037 + : "0" (c), "ir" (a));
16038 +
16039 + old = atomic64_cmpxchg(v, c, new);
16040 if (likely(old == c))
16041 break;
16042 c = old;
16043 }
16044 - return c != (u);
16045 + return c != u;
16046 }
16047
16048 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16049 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16050 index 0f4460b..fa1ee19 100644
16051 --- a/arch/x86/include/asm/barrier.h
16052 +++ b/arch/x86/include/asm/barrier.h
16053 @@ -107,7 +107,7 @@
16054 do { \
16055 compiletime_assert_atomic_type(*p); \
16056 smp_mb(); \
16057 - ACCESS_ONCE(*p) = (v); \
16058 + ACCESS_ONCE_RW(*p) = (v); \
16059 } while (0)
16060
16061 #define smp_load_acquire(p) \
16062 @@ -124,7 +124,7 @@ do { \
16063 do { \
16064 compiletime_assert_atomic_type(*p); \
16065 barrier(); \
16066 - ACCESS_ONCE(*p) = (v); \
16067 + ACCESS_ONCE_RW(*p) = (v); \
16068 } while (0)
16069
16070 #define smp_load_acquire(p) \
16071 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16072 index cfe3b95..d01b118 100644
16073 --- a/arch/x86/include/asm/bitops.h
16074 +++ b/arch/x86/include/asm/bitops.h
16075 @@ -50,7 +50,7 @@
16076 * a mask operation on a byte.
16077 */
16078 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16079 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16080 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16081 #define CONST_MASK(nr) (1 << ((nr) & 7))
16082
16083 /**
16084 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16085 */
16086 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16087 {
16088 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16089 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16090 }
16091
16092 /**
16093 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16094 */
16095 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16096 {
16097 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16098 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16099 }
16100
16101 /**
16102 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16103 */
16104 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16105 {
16106 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16107 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16108 }
16109
16110 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16111 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16112 *
16113 * Undefined if no bit exists, so code should check against 0 first.
16114 */
16115 -static inline unsigned long __ffs(unsigned long word)
16116 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16117 {
16118 asm("rep; bsf %1,%0"
16119 : "=r" (word)
16120 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16121 *
16122 * Undefined if no zero exists, so code should check against ~0UL first.
16123 */
16124 -static inline unsigned long ffz(unsigned long word)
16125 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16126 {
16127 asm("rep; bsf %1,%0"
16128 : "=r" (word)
16129 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16130 *
16131 * Undefined if no set bit exists, so code should check against 0 first.
16132 */
16133 -static inline unsigned long __fls(unsigned long word)
16134 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16135 {
16136 asm("bsr %1,%0"
16137 : "=r" (word)
16138 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16139 * set bit if value is nonzero. The last (most significant) bit is
16140 * at position 32.
16141 */
16142 -static inline int fls(int x)
16143 +static inline int __intentional_overflow(-1) fls(int x)
16144 {
16145 int r;
16146
16147 @@ -476,7 +476,7 @@ static inline int fls(int x)
16148 * at position 64.
16149 */
16150 #ifdef CONFIG_X86_64
16151 -static __always_inline int fls64(__u64 x)
16152 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16153 {
16154 int bitpos = -1;
16155 /*
16156 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16157 index 4fa687a..60f2d39 100644
16158 --- a/arch/x86/include/asm/boot.h
16159 +++ b/arch/x86/include/asm/boot.h
16160 @@ -6,10 +6,15 @@
16161 #include <uapi/asm/boot.h>
16162
16163 /* Physical address where kernel should be loaded. */
16164 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16165 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16166 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16167 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16168
16169 +#ifndef __ASSEMBLY__
16170 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16171 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16172 +#endif
16173 +
16174 /* Minimum kernel alignment, as a power of two */
16175 #ifdef CONFIG_X86_64
16176 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16177 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16178 index 48f99f1..d78ebf9 100644
16179 --- a/arch/x86/include/asm/cache.h
16180 +++ b/arch/x86/include/asm/cache.h
16181 @@ -5,12 +5,13 @@
16182
16183 /* L1 cache line size */
16184 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16185 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16186 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16187
16188 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16189 +#define __read_only __attribute__((__section__(".data..read_only")))
16190
16191 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16192 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16193 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16194
16195 #ifdef CONFIG_X86_VSMP
16196 #ifdef CONFIG_SMP
16197 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16198 index 9863ee3..4a1f8e1 100644
16199 --- a/arch/x86/include/asm/cacheflush.h
16200 +++ b/arch/x86/include/asm/cacheflush.h
16201 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16202 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16203
16204 if (pg_flags == _PGMT_DEFAULT)
16205 - return -1;
16206 + return ~0UL;
16207 else if (pg_flags == _PGMT_WC)
16208 return _PAGE_CACHE_WC;
16209 else if (pg_flags == _PGMT_UC_MINUS)
16210 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16211 index 76659b6..72b8439 100644
16212 --- a/arch/x86/include/asm/calling.h
16213 +++ b/arch/x86/include/asm/calling.h
16214 @@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16215 #define RSP 152
16216 #define SS 160
16217
16218 -#define ARGOFFSET R11
16219 -#define SWFRAME ORIG_RAX
16220 +#define ARGOFFSET R15
16221
16222 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16223 - subq $9*8+\addskip, %rsp
16224 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16225 - movq_cfi rdi, 8*8
16226 - movq_cfi rsi, 7*8
16227 - movq_cfi rdx, 6*8
16228 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16229 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16230 + movq_cfi rdi, RDI
16231 + movq_cfi rsi, RSI
16232 + movq_cfi rdx, RDX
16233
16234 .if \save_rcx
16235 - movq_cfi rcx, 5*8
16236 + movq_cfi rcx, RCX
16237 .endif
16238
16239 .if \rax_enosys
16240 - movq $-ENOSYS, 4*8(%rsp)
16241 + movq $-ENOSYS, RAX(%rsp)
16242 .else
16243 - movq_cfi rax, 4*8
16244 + movq_cfi rax, RAX
16245 .endif
16246
16247 .if \save_r891011
16248 - movq_cfi r8, 3*8
16249 - movq_cfi r9, 2*8
16250 - movq_cfi r10, 1*8
16251 - movq_cfi r11, 0*8
16252 + movq_cfi r8, R8
16253 + movq_cfi r9, R9
16254 + movq_cfi r10, R10
16255 + movq_cfi r11, R11
16256 .endif
16257
16258 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16259 + movq_cfi r12, R12
16260 +#endif
16261 +
16262 .endm
16263
16264 -#define ARG_SKIP (9*8)
16265 +#define ARG_SKIP ORIG_RAX
16266
16267 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16268 rstor_r8910=1, rstor_rdx=1
16269 +
16270 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16271 + movq_cfi_restore R12, r12
16272 +#endif
16273 +
16274 .if \rstor_r11
16275 - movq_cfi_restore 0*8, r11
16276 + movq_cfi_restore R11, r11
16277 .endif
16278
16279 .if \rstor_r8910
16280 - movq_cfi_restore 1*8, r10
16281 - movq_cfi_restore 2*8, r9
16282 - movq_cfi_restore 3*8, r8
16283 + movq_cfi_restore R10, r10
16284 + movq_cfi_restore R9, r9
16285 + movq_cfi_restore R8, r8
16286 .endif
16287
16288 .if \rstor_rax
16289 - movq_cfi_restore 4*8, rax
16290 + movq_cfi_restore RAX, rax
16291 .endif
16292
16293 .if \rstor_rcx
16294 - movq_cfi_restore 5*8, rcx
16295 + movq_cfi_restore RCX, rcx
16296 .endif
16297
16298 .if \rstor_rdx
16299 - movq_cfi_restore 6*8, rdx
16300 + movq_cfi_restore RDX, rdx
16301 .endif
16302
16303 - movq_cfi_restore 7*8, rsi
16304 - movq_cfi_restore 8*8, rdi
16305 + movq_cfi_restore RSI, rsi
16306 + movq_cfi_restore RDI, rdi
16307
16308 - .if ARG_SKIP+\addskip > 0
16309 - addq $ARG_SKIP+\addskip, %rsp
16310 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16311 + .if ORIG_RAX+\addskip > 0
16312 + addq $ORIG_RAX+\addskip, %rsp
16313 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16314 .endif
16315 .endm
16316
16317 - .macro LOAD_ARGS offset, skiprax=0
16318 - movq \offset(%rsp), %r11
16319 - movq \offset+8(%rsp), %r10
16320 - movq \offset+16(%rsp), %r9
16321 - movq \offset+24(%rsp), %r8
16322 - movq \offset+40(%rsp), %rcx
16323 - movq \offset+48(%rsp), %rdx
16324 - movq \offset+56(%rsp), %rsi
16325 - movq \offset+64(%rsp), %rdi
16326 + .macro LOAD_ARGS skiprax=0
16327 + movq R11(%rsp), %r11
16328 + movq R10(%rsp), %r10
16329 + movq R9(%rsp), %r9
16330 + movq R8(%rsp), %r8
16331 + movq RCX(%rsp), %rcx
16332 + movq RDX(%rsp), %rdx
16333 + movq RSI(%rsp), %rsi
16334 + movq RDI(%rsp), %rdi
16335 .if \skiprax
16336 .else
16337 - movq \offset+72(%rsp), %rax
16338 + movq ORIG_RAX(%rsp), %rax
16339 .endif
16340 .endm
16341
16342 -#define REST_SKIP (6*8)
16343 -
16344 .macro SAVE_REST
16345 - subq $REST_SKIP, %rsp
16346 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16347 - movq_cfi rbx, 5*8
16348 - movq_cfi rbp, 4*8
16349 - movq_cfi r12, 3*8
16350 - movq_cfi r13, 2*8
16351 - movq_cfi r14, 1*8
16352 - movq_cfi r15, 0*8
16353 + movq_cfi rbx, RBX
16354 + movq_cfi rbp, RBP
16355 +
16356 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16357 + movq_cfi r12, R12
16358 +#endif
16359 +
16360 + movq_cfi r13, R13
16361 + movq_cfi r14, R14
16362 + movq_cfi r15, R15
16363 .endm
16364
16365 .macro RESTORE_REST
16366 - movq_cfi_restore 0*8, r15
16367 - movq_cfi_restore 1*8, r14
16368 - movq_cfi_restore 2*8, r13
16369 - movq_cfi_restore 3*8, r12
16370 - movq_cfi_restore 4*8, rbp
16371 - movq_cfi_restore 5*8, rbx
16372 - addq $REST_SKIP, %rsp
16373 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16374 + movq_cfi_restore R15, r15
16375 + movq_cfi_restore R14, r14
16376 + movq_cfi_restore R13, r13
16377 +
16378 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16379 + movq_cfi_restore R12, r12
16380 +#endif
16381 +
16382 + movq_cfi_restore RBP, rbp
16383 + movq_cfi_restore RBX, rbx
16384 .endm
16385
16386 .macro SAVE_ALL
16387 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16388 index f50de69..2b0a458 100644
16389 --- a/arch/x86/include/asm/checksum_32.h
16390 +++ b/arch/x86/include/asm/checksum_32.h
16391 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16392 int len, __wsum sum,
16393 int *src_err_ptr, int *dst_err_ptr);
16394
16395 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16396 + int len, __wsum sum,
16397 + int *src_err_ptr, int *dst_err_ptr);
16398 +
16399 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16400 + int len, __wsum sum,
16401 + int *src_err_ptr, int *dst_err_ptr);
16402 +
16403 /*
16404 * Note: when you get a NULL pointer exception here this means someone
16405 * passed in an incorrect kernel address to one of these functions.
16406 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16407
16408 might_sleep();
16409 stac();
16410 - ret = csum_partial_copy_generic((__force void *)src, dst,
16411 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16412 len, sum, err_ptr, NULL);
16413 clac();
16414
16415 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16416 might_sleep();
16417 if (access_ok(VERIFY_WRITE, dst, len)) {
16418 stac();
16419 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16420 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16421 len, sum, NULL, err_ptr);
16422 clac();
16423 return ret;
16424 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16425 index 99c105d7..2f667ac 100644
16426 --- a/arch/x86/include/asm/cmpxchg.h
16427 +++ b/arch/x86/include/asm/cmpxchg.h
16428 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16429 __compiletime_error("Bad argument size for cmpxchg");
16430 extern void __xadd_wrong_size(void)
16431 __compiletime_error("Bad argument size for xadd");
16432 +extern void __xadd_check_overflow_wrong_size(void)
16433 + __compiletime_error("Bad argument size for xadd_check_overflow");
16434 extern void __add_wrong_size(void)
16435 __compiletime_error("Bad argument size for add");
16436 +extern void __add_check_overflow_wrong_size(void)
16437 + __compiletime_error("Bad argument size for add_check_overflow");
16438
16439 /*
16440 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16441 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16442 __ret; \
16443 })
16444
16445 +#ifdef CONFIG_PAX_REFCOUNT
16446 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16447 + ({ \
16448 + __typeof__ (*(ptr)) __ret = (arg); \
16449 + switch (sizeof(*(ptr))) { \
16450 + case __X86_CASE_L: \
16451 + asm volatile (lock #op "l %0, %1\n" \
16452 + "jno 0f\n" \
16453 + "mov %0,%1\n" \
16454 + "int $4\n0:\n" \
16455 + _ASM_EXTABLE(0b, 0b) \
16456 + : "+r" (__ret), "+m" (*(ptr)) \
16457 + : : "memory", "cc"); \
16458 + break; \
16459 + case __X86_CASE_Q: \
16460 + asm volatile (lock #op "q %q0, %1\n" \
16461 + "jno 0f\n" \
16462 + "mov %0,%1\n" \
16463 + "int $4\n0:\n" \
16464 + _ASM_EXTABLE(0b, 0b) \
16465 + : "+r" (__ret), "+m" (*(ptr)) \
16466 + : : "memory", "cc"); \
16467 + break; \
16468 + default: \
16469 + __ ## op ## _check_overflow_wrong_size(); \
16470 + } \
16471 + __ret; \
16472 + })
16473 +#else
16474 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16475 +#endif
16476 +
16477 /*
16478 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16479 * Since this is generally used to protect other memory information, we
16480 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16481 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16482 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16483
16484 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16485 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16486 +
16487 #define __add(ptr, inc, lock) \
16488 ({ \
16489 __typeof__ (*(ptr)) __ret = (inc); \
16490 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16491 index 59c6c40..5e0b22c 100644
16492 --- a/arch/x86/include/asm/compat.h
16493 +++ b/arch/x86/include/asm/compat.h
16494 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16495 typedef u32 compat_uint_t;
16496 typedef u32 compat_ulong_t;
16497 typedef u64 __attribute__((aligned(4))) compat_u64;
16498 -typedef u32 compat_uptr_t;
16499 +typedef u32 __user compat_uptr_t;
16500
16501 struct compat_timespec {
16502 compat_time_t tv_sec;
16503 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16504 index 0bb1335..8f1aec7 100644
16505 --- a/arch/x86/include/asm/cpufeature.h
16506 +++ b/arch/x86/include/asm/cpufeature.h
16507 @@ -207,7 +207,7 @@
16508 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16509 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16510 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16511 -
16512 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16513
16514 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16515 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16516 @@ -215,7 +215,7 @@
16517 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16518 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16519 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16520 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16521 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16522 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16523 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16524 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16525 @@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16526 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16527 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16528 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16529 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16530
16531 #if __GNUC__ >= 4
16532 extern void warn_pre_alternatives(void);
16533 @@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16534
16535 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16536 t_warn:
16537 - warn_pre_alternatives();
16538 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16539 + warn_pre_alternatives();
16540 return false;
16541 #endif
16542
16543 @@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16544 ".section .discard,\"aw\",@progbits\n"
16545 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16546 ".previous\n"
16547 - ".section .altinstr_replacement,\"ax\"\n"
16548 + ".section .altinstr_replacement,\"a\"\n"
16549 "3: movb $1,%0\n"
16550 "4:\n"
16551 ".previous\n"
16552 @@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16553 " .byte 2b - 1b\n" /* src len */
16554 " .byte 4f - 3f\n" /* repl len */
16555 ".previous\n"
16556 - ".section .altinstr_replacement,\"ax\"\n"
16557 + ".section .altinstr_replacement,\"a\"\n"
16558 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16559 "4:\n"
16560 ".previous\n"
16561 @@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16562 ".section .discard,\"aw\",@progbits\n"
16563 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16564 ".previous\n"
16565 - ".section .altinstr_replacement,\"ax\"\n"
16566 + ".section .altinstr_replacement,\"a\"\n"
16567 "3: movb $0,%0\n"
16568 "4:\n"
16569 ".previous\n"
16570 @@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16571 ".section .discard,\"aw\",@progbits\n"
16572 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16573 ".previous\n"
16574 - ".section .altinstr_replacement,\"ax\"\n"
16575 + ".section .altinstr_replacement,\"a\"\n"
16576 "5: movb $1,%0\n"
16577 "6:\n"
16578 ".previous\n"
16579 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16580 index a94b82e..59ecefa 100644
16581 --- a/arch/x86/include/asm/desc.h
16582 +++ b/arch/x86/include/asm/desc.h
16583 @@ -4,6 +4,7 @@
16584 #include <asm/desc_defs.h>
16585 #include <asm/ldt.h>
16586 #include <asm/mmu.h>
16587 +#include <asm/pgtable.h>
16588
16589 #include <linux/smp.h>
16590 #include <linux/percpu.h>
16591 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16592
16593 desc->type = (info->read_exec_only ^ 1) << 1;
16594 desc->type |= info->contents << 2;
16595 + desc->type |= info->seg_not_present ^ 1;
16596
16597 desc->s = 1;
16598 desc->dpl = 0x3;
16599 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16600 }
16601
16602 extern struct desc_ptr idt_descr;
16603 -extern gate_desc idt_table[];
16604 -extern struct desc_ptr debug_idt_descr;
16605 -extern gate_desc debug_idt_table[];
16606 -
16607 -struct gdt_page {
16608 - struct desc_struct gdt[GDT_ENTRIES];
16609 -} __attribute__((aligned(PAGE_SIZE)));
16610 -
16611 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16612 +extern gate_desc idt_table[IDT_ENTRIES];
16613 +extern const struct desc_ptr debug_idt_descr;
16614 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16615
16616 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16617 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16618 {
16619 - return per_cpu(gdt_page, cpu).gdt;
16620 + return cpu_gdt_table[cpu];
16621 }
16622
16623 #ifdef CONFIG_X86_64
16624 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16625 unsigned long base, unsigned dpl, unsigned flags,
16626 unsigned short seg)
16627 {
16628 - gate->a = (seg << 16) | (base & 0xffff);
16629 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16630 + gate->gate.offset_low = base;
16631 + gate->gate.seg = seg;
16632 + gate->gate.reserved = 0;
16633 + gate->gate.type = type;
16634 + gate->gate.s = 0;
16635 + gate->gate.dpl = dpl;
16636 + gate->gate.p = 1;
16637 + gate->gate.offset_high = base >> 16;
16638 }
16639
16640 #endif
16641 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16642
16643 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16644 {
16645 + pax_open_kernel();
16646 memcpy(&idt[entry], gate, sizeof(*gate));
16647 + pax_close_kernel();
16648 }
16649
16650 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16651 {
16652 + pax_open_kernel();
16653 memcpy(&ldt[entry], desc, 8);
16654 + pax_close_kernel();
16655 }
16656
16657 static inline void
16658 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16659 default: size = sizeof(*gdt); break;
16660 }
16661
16662 + pax_open_kernel();
16663 memcpy(&gdt[entry], desc, size);
16664 + pax_close_kernel();
16665 }
16666
16667 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16668 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16669
16670 static inline void native_load_tr_desc(void)
16671 {
16672 + pax_open_kernel();
16673 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16674 + pax_close_kernel();
16675 }
16676
16677 static inline void native_load_gdt(const struct desc_ptr *dtr)
16678 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16679 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16680 unsigned int i;
16681
16682 + pax_open_kernel();
16683 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16684 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16685 + pax_close_kernel();
16686 }
16687
16688 /* This intentionally ignores lm, since 32-bit apps don't have that field. */
16689 @@ -295,7 +308,7 @@ static inline void load_LDT(mm_context_t *pc)
16690 preempt_enable();
16691 }
16692
16693 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16694 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16695 {
16696 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16697 }
16698 @@ -319,7 +332,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16699 }
16700
16701 #ifdef CONFIG_X86_64
16702 -static inline void set_nmi_gate(int gate, void *addr)
16703 +static inline void set_nmi_gate(int gate, const void *addr)
16704 {
16705 gate_desc s;
16706
16707 @@ -329,14 +342,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16708 #endif
16709
16710 #ifdef CONFIG_TRACING
16711 -extern struct desc_ptr trace_idt_descr;
16712 -extern gate_desc trace_idt_table[];
16713 +extern const struct desc_ptr trace_idt_descr;
16714 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16715 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16716 {
16717 write_idt_entry(trace_idt_table, entry, gate);
16718 }
16719
16720 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16721 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16722 unsigned dpl, unsigned ist, unsigned seg)
16723 {
16724 gate_desc s;
16725 @@ -356,7 +369,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16726 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16727 #endif
16728
16729 -static inline void _set_gate(int gate, unsigned type, void *addr,
16730 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16731 unsigned dpl, unsigned ist, unsigned seg)
16732 {
16733 gate_desc s;
16734 @@ -379,9 +392,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16735 #define set_intr_gate(n, addr) \
16736 do { \
16737 BUG_ON((unsigned)n > 0xFF); \
16738 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16739 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16740 __KERNEL_CS); \
16741 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16742 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16743 0, 0, __KERNEL_CS); \
16744 } while (0)
16745
16746 @@ -409,19 +422,19 @@ static inline void alloc_system_vector(int vector)
16747 /*
16748 * This routine sets up an interrupt gate at directory privilege level 3.
16749 */
16750 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16751 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16752 {
16753 BUG_ON((unsigned)n > 0xFF);
16754 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16755 }
16756
16757 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16758 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16759 {
16760 BUG_ON((unsigned)n > 0xFF);
16761 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16762 }
16763
16764 -static inline void set_trap_gate(unsigned int n, void *addr)
16765 +static inline void set_trap_gate(unsigned int n, const void *addr)
16766 {
16767 BUG_ON((unsigned)n > 0xFF);
16768 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16769 @@ -430,16 +443,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16770 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16771 {
16772 BUG_ON((unsigned)n > 0xFF);
16773 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16774 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16775 }
16776
16777 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16778 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16779 {
16780 BUG_ON((unsigned)n > 0xFF);
16781 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16782 }
16783
16784 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16785 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16786 {
16787 BUG_ON((unsigned)n > 0xFF);
16788 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16789 @@ -511,4 +524,17 @@ static inline void load_current_idt(void)
16790 else
16791 load_idt((const struct desc_ptr *)&idt_descr);
16792 }
16793 +
16794 +#ifdef CONFIG_X86_32
16795 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16796 +{
16797 + struct desc_struct d;
16798 +
16799 + if (likely(limit))
16800 + limit = (limit - 1UL) >> PAGE_SHIFT;
16801 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16802 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16803 +}
16804 +#endif
16805 +
16806 #endif /* _ASM_X86_DESC_H */
16807 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16808 index 278441f..b95a174 100644
16809 --- a/arch/x86/include/asm/desc_defs.h
16810 +++ b/arch/x86/include/asm/desc_defs.h
16811 @@ -31,6 +31,12 @@ struct desc_struct {
16812 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16813 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16814 };
16815 + struct {
16816 + u16 offset_low;
16817 + u16 seg;
16818 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16819 + unsigned offset_high: 16;
16820 + } gate;
16821 };
16822 } __attribute__((packed));
16823
16824 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16825 index ced283a..ffe04cc 100644
16826 --- a/arch/x86/include/asm/div64.h
16827 +++ b/arch/x86/include/asm/div64.h
16828 @@ -39,7 +39,7 @@
16829 __mod; \
16830 })
16831
16832 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16833 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16834 {
16835 union {
16836 u64 v64;
16837 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16838 index ca3347a..1a5082a 100644
16839 --- a/arch/x86/include/asm/elf.h
16840 +++ b/arch/x86/include/asm/elf.h
16841 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16842
16843 #include <asm/vdso.h>
16844
16845 -#ifdef CONFIG_X86_64
16846 -extern unsigned int vdso64_enabled;
16847 -#endif
16848 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16849 extern unsigned int vdso32_enabled;
16850 #endif
16851 @@ -249,7 +246,25 @@ extern int force_personality32;
16852 the loader. We need to make sure that it is out of the way of the program
16853 that it will "exec", and that there is sufficient room for the brk. */
16854
16855 +#ifdef CONFIG_PAX_SEGMEXEC
16856 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16857 +#else
16858 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16859 +#endif
16860 +
16861 +#ifdef CONFIG_PAX_ASLR
16862 +#ifdef CONFIG_X86_32
16863 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16864 +
16865 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16866 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16867 +#else
16868 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16869 +
16870 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16871 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16872 +#endif
16873 +#endif
16874
16875 /* This yields a mask that user programs can use to figure out what
16876 instruction set this CPU supports. This could be done in user space,
16877 @@ -298,17 +313,13 @@ do { \
16878
16879 #define ARCH_DLINFO \
16880 do { \
16881 - if (vdso64_enabled) \
16882 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16883 - (unsigned long __force)current->mm->context.vdso); \
16884 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16885 } while (0)
16886
16887 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16888 #define ARCH_DLINFO_X32 \
16889 do { \
16890 - if (vdso64_enabled) \
16891 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16892 - (unsigned long __force)current->mm->context.vdso); \
16893 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16894 } while (0)
16895
16896 #define AT_SYSINFO 32
16897 @@ -323,10 +334,10 @@ else \
16898
16899 #endif /* !CONFIG_X86_32 */
16900
16901 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16902 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16903
16904 #define VDSO_ENTRY \
16905 - ((unsigned long)current->mm->context.vdso + \
16906 + (current->mm->context.vdso + \
16907 selected_vdso32->sym___kernel_vsyscall)
16908
16909 struct linux_binprm;
16910 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16911 int uses_interp);
16912 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16913
16914 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16915 -#define arch_randomize_brk arch_randomize_brk
16916 -
16917 /*
16918 * True on X86_32 or when emulating IA32 on X86_64
16919 */
16920 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16921 index 77a99ac..39ff7f5 100644
16922 --- a/arch/x86/include/asm/emergency-restart.h
16923 +++ b/arch/x86/include/asm/emergency-restart.h
16924 @@ -1,6 +1,6 @@
16925 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16926 #define _ASM_X86_EMERGENCY_RESTART_H
16927
16928 -extern void machine_emergency_restart(void);
16929 +extern void machine_emergency_restart(void) __noreturn;
16930
16931 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16932 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16933 index 1c7eefe..d0e4702 100644
16934 --- a/arch/x86/include/asm/floppy.h
16935 +++ b/arch/x86/include/asm/floppy.h
16936 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16937 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16938 } fd_routine[] = {
16939 {
16940 - request_dma,
16941 - free_dma,
16942 - get_dma_residue,
16943 - dma_mem_alloc,
16944 - hard_dma_setup
16945 + ._request_dma = request_dma,
16946 + ._free_dma = free_dma,
16947 + ._get_dma_residue = get_dma_residue,
16948 + ._dma_mem_alloc = dma_mem_alloc,
16949 + ._dma_setup = hard_dma_setup
16950 },
16951 {
16952 - vdma_request_dma,
16953 - vdma_nop,
16954 - vdma_get_dma_residue,
16955 - vdma_mem_alloc,
16956 - vdma_dma_setup
16957 + ._request_dma = vdma_request_dma,
16958 + ._free_dma = vdma_nop,
16959 + ._get_dma_residue = vdma_get_dma_residue,
16960 + ._dma_mem_alloc = vdma_mem_alloc,
16961 + ._dma_setup = vdma_dma_setup
16962 }
16963 };
16964
16965 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16966 index e97622f..d0ba77a 100644
16967 --- a/arch/x86/include/asm/fpu-internal.h
16968 +++ b/arch/x86/include/asm/fpu-internal.h
16969 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16970 #define user_insn(insn, output, input...) \
16971 ({ \
16972 int err; \
16973 + pax_open_userland(); \
16974 asm volatile(ASM_STAC "\n" \
16975 - "1:" #insn "\n\t" \
16976 + "1:" \
16977 + __copyuser_seg \
16978 + #insn "\n\t" \
16979 "2: " ASM_CLAC "\n" \
16980 ".section .fixup,\"ax\"\n" \
16981 "3: movl $-1,%[err]\n" \
16982 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16983 _ASM_EXTABLE(1b, 3b) \
16984 : [err] "=r" (err), output \
16985 : "0"(0), input); \
16986 + pax_close_userland(); \
16987 err; \
16988 })
16989
16990 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16991 "fnclex\n\t"
16992 "emms\n\t"
16993 "fildl %P[addr]" /* set F?P to defined value */
16994 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16995 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16996 }
16997
16998 return fpu_restore_checking(&tsk->thread.fpu);
16999 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17000 index b4c1f54..e290c08 100644
17001 --- a/arch/x86/include/asm/futex.h
17002 +++ b/arch/x86/include/asm/futex.h
17003 @@ -12,6 +12,7 @@
17004 #include <asm/smap.h>
17005
17006 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17007 + typecheck(u32 __user *, uaddr); \
17008 asm volatile("\t" ASM_STAC "\n" \
17009 "1:\t" insn "\n" \
17010 "2:\t" ASM_CLAC "\n" \
17011 @@ -20,15 +21,16 @@
17012 "\tjmp\t2b\n" \
17013 "\t.previous\n" \
17014 _ASM_EXTABLE(1b, 3b) \
17015 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17016 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17017 : "i" (-EFAULT), "0" (oparg), "1" (0))
17018
17019 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17020 + typecheck(u32 __user *, uaddr); \
17021 asm volatile("\t" ASM_STAC "\n" \
17022 "1:\tmovl %2, %0\n" \
17023 "\tmovl\t%0, %3\n" \
17024 "\t" insn "\n" \
17025 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17026 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17027 "\tjnz\t1b\n" \
17028 "3:\t" ASM_CLAC "\n" \
17029 "\t.section .fixup,\"ax\"\n" \
17030 @@ -38,7 +40,7 @@
17031 _ASM_EXTABLE(1b, 4b) \
17032 _ASM_EXTABLE(2b, 4b) \
17033 : "=&a" (oldval), "=&r" (ret), \
17034 - "+m" (*uaddr), "=&r" (tem) \
17035 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17036 : "r" (oparg), "i" (-EFAULT), "1" (0))
17037
17038 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17039 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17040
17041 pagefault_disable();
17042
17043 + pax_open_userland();
17044 switch (op) {
17045 case FUTEX_OP_SET:
17046 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17047 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17048 break;
17049 case FUTEX_OP_ADD:
17050 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17051 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17052 uaddr, oparg);
17053 break;
17054 case FUTEX_OP_OR:
17055 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17056 default:
17057 ret = -ENOSYS;
17058 }
17059 + pax_close_userland();
17060
17061 pagefault_enable();
17062
17063 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17064 index 4615906..788c817 100644
17065 --- a/arch/x86/include/asm/hw_irq.h
17066 +++ b/arch/x86/include/asm/hw_irq.h
17067 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17068 extern void enable_IO_APIC(void);
17069
17070 /* Statistics */
17071 -extern atomic_t irq_err_count;
17072 -extern atomic_t irq_mis_count;
17073 +extern atomic_unchecked_t irq_err_count;
17074 +extern atomic_unchecked_t irq_mis_count;
17075
17076 /* EISA */
17077 extern void eisa_set_level_irq(unsigned int irq);
17078 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17079 index ccffa53..3c90c87 100644
17080 --- a/arch/x86/include/asm/i8259.h
17081 +++ b/arch/x86/include/asm/i8259.h
17082 @@ -62,7 +62,7 @@ struct legacy_pic {
17083 void (*init)(int auto_eoi);
17084 int (*irq_pending)(unsigned int irq);
17085 void (*make_irq)(unsigned int irq);
17086 -};
17087 +} __do_const;
17088
17089 extern struct legacy_pic *legacy_pic;
17090 extern struct legacy_pic null_legacy_pic;
17091 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17092 index b8237d8..3e8864e 100644
17093 --- a/arch/x86/include/asm/io.h
17094 +++ b/arch/x86/include/asm/io.h
17095 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17096 "m" (*(volatile type __force *)addr) barrier); }
17097
17098 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17099 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17100 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17101 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17102 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17103
17104 build_mmio_read(__readb, "b", unsigned char, "=q", )
17105 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17106 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17107 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17108 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17109
17110 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17111 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17112 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17113 * this function
17114 */
17115
17116 -static inline phys_addr_t virt_to_phys(volatile void *address)
17117 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17118 {
17119 return __pa(address);
17120 }
17121 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17122 return ioremap_nocache(offset, size);
17123 }
17124
17125 -extern void iounmap(volatile void __iomem *addr);
17126 +extern void iounmap(const volatile void __iomem *addr);
17127
17128 extern void set_iounmap_nonlazy(void);
17129
17130 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17131
17132 #include <linux/vmalloc.h>
17133
17134 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17135 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17136 +{
17137 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17138 +}
17139 +
17140 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17141 +{
17142 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17143 +}
17144 +
17145 /*
17146 * Convert a virtual cached pointer to an uncached pointer
17147 */
17148 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17149 index 0a8b519..80e7d5b 100644
17150 --- a/arch/x86/include/asm/irqflags.h
17151 +++ b/arch/x86/include/asm/irqflags.h
17152 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17153 sti; \
17154 sysexit
17155
17156 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17157 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17158 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17159 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17160 +
17161 #else
17162 #define INTERRUPT_RETURN iret
17163 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17164 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17165 index 4421b5d..8543006 100644
17166 --- a/arch/x86/include/asm/kprobes.h
17167 +++ b/arch/x86/include/asm/kprobes.h
17168 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17169 #define RELATIVEJUMP_SIZE 5
17170 #define RELATIVECALL_OPCODE 0xe8
17171 #define RELATIVE_ADDR_SIZE 4
17172 -#define MAX_STACK_SIZE 64
17173 -#define MIN_STACK_SIZE(ADDR) \
17174 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17175 - THREAD_SIZE - (unsigned long)(ADDR))) \
17176 - ? (MAX_STACK_SIZE) \
17177 - : (((unsigned long)current_thread_info()) + \
17178 - THREAD_SIZE - (unsigned long)(ADDR)))
17179 +#define MAX_STACK_SIZE 64UL
17180 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17181
17182 #define flush_insn_slot(p) do { } while (0)
17183
17184 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17185 index 6ed0c30..74fb6c3 100644
17186 --- a/arch/x86/include/asm/kvm_host.h
17187 +++ b/arch/x86/include/asm/kvm_host.h
17188 @@ -51,6 +51,7 @@
17189 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17190
17191 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17192 +#define CR3_PCID_INVD (1UL << 63)
17193 #define CR4_RESERVED_BITS \
17194 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17195 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17196 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17197 index 4ad6560..75c7bdd 100644
17198 --- a/arch/x86/include/asm/local.h
17199 +++ b/arch/x86/include/asm/local.h
17200 @@ -10,33 +10,97 @@ typedef struct {
17201 atomic_long_t a;
17202 } local_t;
17203
17204 +typedef struct {
17205 + atomic_long_unchecked_t a;
17206 +} local_unchecked_t;
17207 +
17208 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17209
17210 #define local_read(l) atomic_long_read(&(l)->a)
17211 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17212 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17213 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17214
17215 static inline void local_inc(local_t *l)
17216 {
17217 - asm volatile(_ASM_INC "%0"
17218 + asm volatile(_ASM_INC "%0\n"
17219 +
17220 +#ifdef CONFIG_PAX_REFCOUNT
17221 + "jno 0f\n"
17222 + _ASM_DEC "%0\n"
17223 + "int $4\n0:\n"
17224 + _ASM_EXTABLE(0b, 0b)
17225 +#endif
17226 +
17227 + : "+m" (l->a.counter));
17228 +}
17229 +
17230 +static inline void local_inc_unchecked(local_unchecked_t *l)
17231 +{
17232 + asm volatile(_ASM_INC "%0\n"
17233 : "+m" (l->a.counter));
17234 }
17235
17236 static inline void local_dec(local_t *l)
17237 {
17238 - asm volatile(_ASM_DEC "%0"
17239 + asm volatile(_ASM_DEC "%0\n"
17240 +
17241 +#ifdef CONFIG_PAX_REFCOUNT
17242 + "jno 0f\n"
17243 + _ASM_INC "%0\n"
17244 + "int $4\n0:\n"
17245 + _ASM_EXTABLE(0b, 0b)
17246 +#endif
17247 +
17248 + : "+m" (l->a.counter));
17249 +}
17250 +
17251 +static inline void local_dec_unchecked(local_unchecked_t *l)
17252 +{
17253 + asm volatile(_ASM_DEC "%0\n"
17254 : "+m" (l->a.counter));
17255 }
17256
17257 static inline void local_add(long i, local_t *l)
17258 {
17259 - asm volatile(_ASM_ADD "%1,%0"
17260 + asm volatile(_ASM_ADD "%1,%0\n"
17261 +
17262 +#ifdef CONFIG_PAX_REFCOUNT
17263 + "jno 0f\n"
17264 + _ASM_SUB "%1,%0\n"
17265 + "int $4\n0:\n"
17266 + _ASM_EXTABLE(0b, 0b)
17267 +#endif
17268 +
17269 + : "+m" (l->a.counter)
17270 + : "ir" (i));
17271 +}
17272 +
17273 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17274 +{
17275 + asm volatile(_ASM_ADD "%1,%0\n"
17276 : "+m" (l->a.counter)
17277 : "ir" (i));
17278 }
17279
17280 static inline void local_sub(long i, local_t *l)
17281 {
17282 - asm volatile(_ASM_SUB "%1,%0"
17283 + asm volatile(_ASM_SUB "%1,%0\n"
17284 +
17285 +#ifdef CONFIG_PAX_REFCOUNT
17286 + "jno 0f\n"
17287 + _ASM_ADD "%1,%0\n"
17288 + "int $4\n0:\n"
17289 + _ASM_EXTABLE(0b, 0b)
17290 +#endif
17291 +
17292 + : "+m" (l->a.counter)
17293 + : "ir" (i));
17294 +}
17295 +
17296 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17297 +{
17298 + asm volatile(_ASM_SUB "%1,%0\n"
17299 : "+m" (l->a.counter)
17300 : "ir" (i));
17301 }
17302 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17303 */
17304 static inline int local_sub_and_test(long i, local_t *l)
17305 {
17306 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17307 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17308 }
17309
17310 /**
17311 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17312 */
17313 static inline int local_dec_and_test(local_t *l)
17314 {
17315 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17316 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17317 }
17318
17319 /**
17320 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17321 */
17322 static inline int local_inc_and_test(local_t *l)
17323 {
17324 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17325 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17326 }
17327
17328 /**
17329 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17330 */
17331 static inline int local_add_negative(long i, local_t *l)
17332 {
17333 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17334 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17335 }
17336
17337 /**
17338 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17339 static inline long local_add_return(long i, local_t *l)
17340 {
17341 long __i = i;
17342 + asm volatile(_ASM_XADD "%0, %1\n"
17343 +
17344 +#ifdef CONFIG_PAX_REFCOUNT
17345 + "jno 0f\n"
17346 + _ASM_MOV "%0,%1\n"
17347 + "int $4\n0:\n"
17348 + _ASM_EXTABLE(0b, 0b)
17349 +#endif
17350 +
17351 + : "+r" (i), "+m" (l->a.counter)
17352 + : : "memory");
17353 + return i + __i;
17354 +}
17355 +
17356 +/**
17357 + * local_add_return_unchecked - add and return
17358 + * @i: integer value to add
17359 + * @l: pointer to type local_unchecked_t
17360 + *
17361 + * Atomically adds @i to @l and returns @i + @l
17362 + */
17363 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17364 +{
17365 + long __i = i;
17366 asm volatile(_ASM_XADD "%0, %1;"
17367 : "+r" (i), "+m" (l->a.counter)
17368 : : "memory");
17369 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17370
17371 #define local_cmpxchg(l, o, n) \
17372 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17373 +#define local_cmpxchg_unchecked(l, o, n) \
17374 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17375 /* Always has a lock prefix */
17376 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17377
17378 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17379 new file mode 100644
17380 index 0000000..2bfd3ba
17381 --- /dev/null
17382 +++ b/arch/x86/include/asm/mman.h
17383 @@ -0,0 +1,15 @@
17384 +#ifndef _X86_MMAN_H
17385 +#define _X86_MMAN_H
17386 +
17387 +#include <uapi/asm/mman.h>
17388 +
17389 +#ifdef __KERNEL__
17390 +#ifndef __ASSEMBLY__
17391 +#ifdef CONFIG_X86_32
17392 +#define arch_mmap_check i386_mmap_check
17393 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17394 +#endif
17395 +#endif
17396 +#endif
17397 +
17398 +#endif /* X86_MMAN_H */
17399 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17400 index 876e74e..e20bfb1 100644
17401 --- a/arch/x86/include/asm/mmu.h
17402 +++ b/arch/x86/include/asm/mmu.h
17403 @@ -9,7 +9,7 @@
17404 * we put the segment information here.
17405 */
17406 typedef struct {
17407 - void *ldt;
17408 + struct desc_struct *ldt;
17409 int size;
17410
17411 #ifdef CONFIG_X86_64
17412 @@ -18,7 +18,19 @@ typedef struct {
17413 #endif
17414
17415 struct mutex lock;
17416 - void __user *vdso;
17417 + unsigned long vdso;
17418 +
17419 +#ifdef CONFIG_X86_32
17420 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17421 + unsigned long user_cs_base;
17422 + unsigned long user_cs_limit;
17423 +
17424 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17425 + cpumask_t cpu_user_cs_mask;
17426 +#endif
17427 +
17428 +#endif
17429 +#endif
17430 } mm_context_t;
17431
17432 #ifdef CONFIG_SMP
17433 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17434 index 166af2a..648c200 100644
17435 --- a/arch/x86/include/asm/mmu_context.h
17436 +++ b/arch/x86/include/asm/mmu_context.h
17437 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17438
17439 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17440 {
17441 +
17442 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17443 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17444 + unsigned int i;
17445 + pgd_t *pgd;
17446 +
17447 + pax_open_kernel();
17448 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17449 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17450 + set_pgd_batched(pgd+i, native_make_pgd(0));
17451 + pax_close_kernel();
17452 + }
17453 +#endif
17454 +
17455 #ifdef CONFIG_SMP
17456 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17457 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17458 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17459 struct task_struct *tsk)
17460 {
17461 unsigned cpu = smp_processor_id();
17462 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17463 + int tlbstate = TLBSTATE_OK;
17464 +#endif
17465
17466 if (likely(prev != next)) {
17467 #ifdef CONFIG_SMP
17468 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17469 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17470 +#endif
17471 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17472 this_cpu_write(cpu_tlbstate.active_mm, next);
17473 #endif
17474 cpumask_set_cpu(cpu, mm_cpumask(next));
17475
17476 /* Re-load page tables */
17477 +#ifdef CONFIG_PAX_PER_CPU_PGD
17478 + pax_open_kernel();
17479 +
17480 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17481 + if (static_cpu_has(X86_FEATURE_PCID))
17482 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17483 + else
17484 +#endif
17485 +
17486 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17487 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17488 + pax_close_kernel();
17489 + 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));
17490 +
17491 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17492 + if (static_cpu_has(X86_FEATURE_PCID)) {
17493 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17494 + u64 descriptor[2];
17495 + descriptor[0] = PCID_USER;
17496 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17497 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17498 + descriptor[0] = PCID_KERNEL;
17499 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17500 + }
17501 + } else {
17502 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17503 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17504 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17505 + else
17506 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17507 + }
17508 + } else
17509 +#endif
17510 +
17511 + load_cr3(get_cpu_pgd(cpu, kernel));
17512 +#else
17513 load_cr3(next->pgd);
17514 +#endif
17515 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17516
17517 /* Stop flush ipis for the previous mm */
17518 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17519 /* Load the LDT, if the LDT is different: */
17520 if (unlikely(prev->context.ldt != next->context.ldt))
17521 load_LDT_nolock(&next->context);
17522 +
17523 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17524 + if (!(__supported_pte_mask & _PAGE_NX)) {
17525 + smp_mb__before_atomic();
17526 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17527 + smp_mb__after_atomic();
17528 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17529 + }
17530 +#endif
17531 +
17532 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17533 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17534 + prev->context.user_cs_limit != next->context.user_cs_limit))
17535 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17536 +#ifdef CONFIG_SMP
17537 + else if (unlikely(tlbstate != TLBSTATE_OK))
17538 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17539 +#endif
17540 +#endif
17541 +
17542 }
17543 + else {
17544 +
17545 +#ifdef CONFIG_PAX_PER_CPU_PGD
17546 + pax_open_kernel();
17547 +
17548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17549 + if (static_cpu_has(X86_FEATURE_PCID))
17550 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17551 + else
17552 +#endif
17553 +
17554 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17555 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17556 + pax_close_kernel();
17557 + 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));
17558 +
17559 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17560 + if (static_cpu_has(X86_FEATURE_PCID)) {
17561 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17562 + u64 descriptor[2];
17563 + descriptor[0] = PCID_USER;
17564 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17565 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17566 + descriptor[0] = PCID_KERNEL;
17567 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17568 + }
17569 + } else {
17570 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17571 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17572 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17573 + else
17574 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17575 + }
17576 + } else
17577 +#endif
17578 +
17579 + load_cr3(get_cpu_pgd(cpu, kernel));
17580 +#endif
17581 +
17582 #ifdef CONFIG_SMP
17583 - else {
17584 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17585 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17586
17587 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17588 * tlb flush IPI delivery. We must reload CR3
17589 * to make sure to use no freed page tables.
17590 */
17591 +
17592 +#ifndef CONFIG_PAX_PER_CPU_PGD
17593 load_cr3(next->pgd);
17594 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17595 +#endif
17596 +
17597 load_LDT_nolock(&next->context);
17598 +
17599 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17600 + if (!(__supported_pte_mask & _PAGE_NX))
17601 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17602 +#endif
17603 +
17604 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17605 +#ifdef CONFIG_PAX_PAGEEXEC
17606 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17607 +#endif
17608 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17609 +#endif
17610 +
17611 }
17612 +#endif
17613 }
17614 -#endif
17615 }
17616
17617 #define activate_mm(prev, next) \
17618 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17619 index e3b7819..b257c64 100644
17620 --- a/arch/x86/include/asm/module.h
17621 +++ b/arch/x86/include/asm/module.h
17622 @@ -5,6 +5,7 @@
17623
17624 #ifdef CONFIG_X86_64
17625 /* X86_64 does not define MODULE_PROC_FAMILY */
17626 +#define MODULE_PROC_FAMILY ""
17627 #elif defined CONFIG_M486
17628 #define MODULE_PROC_FAMILY "486 "
17629 #elif defined CONFIG_M586
17630 @@ -57,8 +58,20 @@
17631 #error unknown processor family
17632 #endif
17633
17634 -#ifdef CONFIG_X86_32
17635 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17636 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17637 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17638 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17639 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17640 +#else
17641 +#define MODULE_PAX_KERNEXEC ""
17642 #endif
17643
17644 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17645 +#define MODULE_PAX_UDEREF "UDEREF "
17646 +#else
17647 +#define MODULE_PAX_UDEREF ""
17648 +#endif
17649 +
17650 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17651 +
17652 #endif /* _ASM_X86_MODULE_H */
17653 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17654 index 5f2fc44..106caa6 100644
17655 --- a/arch/x86/include/asm/nmi.h
17656 +++ b/arch/x86/include/asm/nmi.h
17657 @@ -36,26 +36,35 @@ enum {
17658
17659 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17660
17661 +struct nmiaction;
17662 +
17663 +struct nmiwork {
17664 + const struct nmiaction *action;
17665 + u64 max_duration;
17666 + struct irq_work irq_work;
17667 +};
17668 +
17669 struct nmiaction {
17670 struct list_head list;
17671 nmi_handler_t handler;
17672 - u64 max_duration;
17673 - struct irq_work irq_work;
17674 unsigned long flags;
17675 const char *name;
17676 -};
17677 + struct nmiwork *work;
17678 +} __do_const;
17679
17680 #define register_nmi_handler(t, fn, fg, n, init...) \
17681 ({ \
17682 - static struct nmiaction init fn##_na = { \
17683 + static struct nmiwork fn##_nw; \
17684 + static const struct nmiaction init fn##_na = { \
17685 .handler = (fn), \
17686 .name = (n), \
17687 .flags = (fg), \
17688 + .work = &fn##_nw, \
17689 }; \
17690 __register_nmi_handler((t), &fn##_na); \
17691 })
17692
17693 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17694 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17695
17696 void unregister_nmi_handler(unsigned int, const char *);
17697
17698 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17699 index 802dde3..9183e68 100644
17700 --- a/arch/x86/include/asm/page.h
17701 +++ b/arch/x86/include/asm/page.h
17702 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17703 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17704
17705 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17706 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17707
17708 #define __boot_va(x) __va(x)
17709 #define __boot_pa(x) __pa(x)
17710 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17711 * virt_to_page(kaddr) returns a valid pointer if and only if
17712 * virt_addr_valid(kaddr) returns true.
17713 */
17714 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17715 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17716 extern bool __virt_addr_valid(unsigned long kaddr);
17717 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17718
17719 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17720 +#define virt_to_page(kaddr) \
17721 + ({ \
17722 + const void *__kaddr = (const void *)(kaddr); \
17723 + BUG_ON(!virt_addr_valid(__kaddr)); \
17724 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17725 + })
17726 +#else
17727 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17728 +#endif
17729 +
17730 #endif /* __ASSEMBLY__ */
17731
17732 #include <asm-generic/memory_model.h>
17733 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17734 index f408caf..4a0455e 100644
17735 --- a/arch/x86/include/asm/page_64.h
17736 +++ b/arch/x86/include/asm/page_64.h
17737 @@ -7,9 +7,9 @@
17738
17739 /* duplicated to the one in bootmem.h */
17740 extern unsigned long max_pfn;
17741 -extern unsigned long phys_base;
17742 +extern const unsigned long phys_base;
17743
17744 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17745 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17746 {
17747 unsigned long y = x - __START_KERNEL_map;
17748
17749 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17750 index cd6e1610..70f4418 100644
17751 --- a/arch/x86/include/asm/paravirt.h
17752 +++ b/arch/x86/include/asm/paravirt.h
17753 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17754 return (pmd_t) { ret };
17755 }
17756
17757 -static inline pmdval_t pmd_val(pmd_t pmd)
17758 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17759 {
17760 pmdval_t ret;
17761
17762 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17763 val);
17764 }
17765
17766 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17767 +{
17768 + pgdval_t val = native_pgd_val(pgd);
17769 +
17770 + if (sizeof(pgdval_t) > sizeof(long))
17771 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17772 + val, (u64)val >> 32);
17773 + else
17774 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17775 + val);
17776 +}
17777 +
17778 static inline void pgd_clear(pgd_t *pgdp)
17779 {
17780 set_pgd(pgdp, __pgd(0));
17781 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17782 pv_mmu_ops.set_fixmap(idx, phys, flags);
17783 }
17784
17785 +#ifdef CONFIG_PAX_KERNEXEC
17786 +static inline unsigned long pax_open_kernel(void)
17787 +{
17788 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17789 +}
17790 +
17791 +static inline unsigned long pax_close_kernel(void)
17792 +{
17793 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17794 +}
17795 +#else
17796 +static inline unsigned long pax_open_kernel(void) { return 0; }
17797 +static inline unsigned long pax_close_kernel(void) { return 0; }
17798 +#endif
17799 +
17800 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17801
17802 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17803 @@ -906,7 +933,7 @@ extern void default_banner(void);
17804
17805 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17806 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17807 -#define PARA_INDIRECT(addr) *%cs:addr
17808 +#define PARA_INDIRECT(addr) *%ss:addr
17809 #endif
17810
17811 #define INTERRUPT_RETURN \
17812 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17813 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17814 CLBR_NONE, \
17815 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17816 +
17817 +#define GET_CR0_INTO_RDI \
17818 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17819 + mov %rax,%rdi
17820 +
17821 +#define SET_RDI_INTO_CR0 \
17822 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17823 +
17824 +#define GET_CR3_INTO_RDI \
17825 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17826 + mov %rax,%rdi
17827 +
17828 +#define SET_RDI_INTO_CR3 \
17829 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17830 +
17831 #endif /* CONFIG_X86_32 */
17832
17833 #endif /* __ASSEMBLY__ */
17834 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17835 index 7549b8b..f0edfda 100644
17836 --- a/arch/x86/include/asm/paravirt_types.h
17837 +++ b/arch/x86/include/asm/paravirt_types.h
17838 @@ -84,7 +84,7 @@ struct pv_init_ops {
17839 */
17840 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17841 unsigned long addr, unsigned len);
17842 -};
17843 +} __no_const __no_randomize_layout;
17844
17845
17846 struct pv_lazy_ops {
17847 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17848 void (*enter)(void);
17849 void (*leave)(void);
17850 void (*flush)(void);
17851 -};
17852 +} __no_randomize_layout;
17853
17854 struct pv_time_ops {
17855 unsigned long long (*sched_clock)(void);
17856 unsigned long long (*steal_clock)(int cpu);
17857 unsigned long (*get_tsc_khz)(void);
17858 -};
17859 +} __no_const __no_randomize_layout;
17860
17861 struct pv_cpu_ops {
17862 /* hooks for various privileged instructions */
17863 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17864
17865 void (*start_context_switch)(struct task_struct *prev);
17866 void (*end_context_switch)(struct task_struct *next);
17867 -};
17868 +} __no_const __no_randomize_layout;
17869
17870 struct pv_irq_ops {
17871 /*
17872 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17873 #ifdef CONFIG_X86_64
17874 void (*adjust_exception_frame)(void);
17875 #endif
17876 -};
17877 +} __no_randomize_layout;
17878
17879 struct pv_apic_ops {
17880 #ifdef CONFIG_X86_LOCAL_APIC
17881 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17882 unsigned long start_eip,
17883 unsigned long start_esp);
17884 #endif
17885 -};
17886 +} __no_const __no_randomize_layout;
17887
17888 struct pv_mmu_ops {
17889 unsigned long (*read_cr2)(void);
17890 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17891 struct paravirt_callee_save make_pud;
17892
17893 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17894 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17895 #endif /* PAGETABLE_LEVELS == 4 */
17896 #endif /* PAGETABLE_LEVELS >= 3 */
17897
17898 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17899 an mfn. We can tell which is which from the index. */
17900 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17901 phys_addr_t phys, pgprot_t flags);
17902 -};
17903 +
17904 +#ifdef CONFIG_PAX_KERNEXEC
17905 + unsigned long (*pax_open_kernel)(void);
17906 + unsigned long (*pax_close_kernel)(void);
17907 +#endif
17908 +
17909 +} __no_randomize_layout;
17910
17911 struct arch_spinlock;
17912 #ifdef CONFIG_SMP
17913 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17914 struct pv_lock_ops {
17915 struct paravirt_callee_save lock_spinning;
17916 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17917 -};
17918 +} __no_randomize_layout;
17919
17920 /* This contains all the paravirt structures: we get a convenient
17921 * number for each function using the offset which we use to indicate
17922 - * what to patch. */
17923 + * what to patch.
17924 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17925 + */
17926 +
17927 struct paravirt_patch_template {
17928 struct pv_init_ops pv_init_ops;
17929 struct pv_time_ops pv_time_ops;
17930 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17931 struct pv_apic_ops pv_apic_ops;
17932 struct pv_mmu_ops pv_mmu_ops;
17933 struct pv_lock_ops pv_lock_ops;
17934 -};
17935 +} __no_randomize_layout;
17936
17937 extern struct pv_info pv_info;
17938 extern struct pv_init_ops pv_init_ops;
17939 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17940 index c4412e9..90e88c5 100644
17941 --- a/arch/x86/include/asm/pgalloc.h
17942 +++ b/arch/x86/include/asm/pgalloc.h
17943 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17944 pmd_t *pmd, pte_t *pte)
17945 {
17946 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17947 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17948 +}
17949 +
17950 +static inline void pmd_populate_user(struct mm_struct *mm,
17951 + pmd_t *pmd, pte_t *pte)
17952 +{
17953 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17954 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17955 }
17956
17957 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17958
17959 #ifdef CONFIG_X86_PAE
17960 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17961 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17962 +{
17963 + pud_populate(mm, pudp, pmd);
17964 +}
17965 #else /* !CONFIG_X86_PAE */
17966 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17967 {
17968 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17969 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17970 }
17971 +
17972 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17973 +{
17974 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17975 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17976 +}
17977 #endif /* CONFIG_X86_PAE */
17978
17979 #if PAGETABLE_LEVELS > 3
17980 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17981 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17982 }
17983
17984 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17985 +{
17986 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17987 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17988 +}
17989 +
17990 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17991 {
17992 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17993 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17994 index 206a87f..1623b06 100644
17995 --- a/arch/x86/include/asm/pgtable-2level.h
17996 +++ b/arch/x86/include/asm/pgtable-2level.h
17997 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17998
17999 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18000 {
18001 + pax_open_kernel();
18002 *pmdp = pmd;
18003 + pax_close_kernel();
18004 }
18005
18006 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18007 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18008 index 81bb91b..9392125 100644
18009 --- a/arch/x86/include/asm/pgtable-3level.h
18010 +++ b/arch/x86/include/asm/pgtable-3level.h
18011 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18012
18013 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18014 {
18015 + pax_open_kernel();
18016 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18017 + pax_close_kernel();
18018 }
18019
18020 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18021 {
18022 + pax_open_kernel();
18023 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18024 + pax_close_kernel();
18025 }
18026
18027 /*
18028 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18029 index aa97a07..5c53c32 100644
18030 --- a/arch/x86/include/asm/pgtable.h
18031 +++ b/arch/x86/include/asm/pgtable.h
18032 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18033
18034 #ifndef __PAGETABLE_PUD_FOLDED
18035 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18036 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18037 #define pgd_clear(pgd) native_pgd_clear(pgd)
18038 #endif
18039
18040 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18041
18042 #define arch_end_context_switch(prev) do {} while(0)
18043
18044 +#define pax_open_kernel() native_pax_open_kernel()
18045 +#define pax_close_kernel() native_pax_close_kernel()
18046 #endif /* CONFIG_PARAVIRT */
18047
18048 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18049 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18050 +
18051 +#ifdef CONFIG_PAX_KERNEXEC
18052 +static inline unsigned long native_pax_open_kernel(void)
18053 +{
18054 + unsigned long cr0;
18055 +
18056 + preempt_disable();
18057 + barrier();
18058 + cr0 = read_cr0() ^ X86_CR0_WP;
18059 + BUG_ON(cr0 & X86_CR0_WP);
18060 + write_cr0(cr0);
18061 + barrier();
18062 + return cr0 ^ X86_CR0_WP;
18063 +}
18064 +
18065 +static inline unsigned long native_pax_close_kernel(void)
18066 +{
18067 + unsigned long cr0;
18068 +
18069 + barrier();
18070 + cr0 = read_cr0() ^ X86_CR0_WP;
18071 + BUG_ON(!(cr0 & X86_CR0_WP));
18072 + write_cr0(cr0);
18073 + barrier();
18074 + preempt_enable_no_resched();
18075 + return cr0 ^ X86_CR0_WP;
18076 +}
18077 +#else
18078 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18079 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18080 +#endif
18081 +
18082 /*
18083 * The following only work if pte_present() is true.
18084 * Undefined behaviour if not..
18085 */
18086 +static inline int pte_user(pte_t pte)
18087 +{
18088 + return pte_val(pte) & _PAGE_USER;
18089 +}
18090 +
18091 static inline int pte_dirty(pte_t pte)
18092 {
18093 return pte_flags(pte) & _PAGE_DIRTY;
18094 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18095 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18096 }
18097
18098 +static inline unsigned long pgd_pfn(pgd_t pgd)
18099 +{
18100 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18101 +}
18102 +
18103 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18104
18105 static inline int pmd_large(pmd_t pte)
18106 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18107 return pte_clear_flags(pte, _PAGE_RW);
18108 }
18109
18110 +static inline pte_t pte_mkread(pte_t pte)
18111 +{
18112 + return __pte(pte_val(pte) | _PAGE_USER);
18113 +}
18114 +
18115 static inline pte_t pte_mkexec(pte_t pte)
18116 {
18117 - return pte_clear_flags(pte, _PAGE_NX);
18118 +#ifdef CONFIG_X86_PAE
18119 + if (__supported_pte_mask & _PAGE_NX)
18120 + return pte_clear_flags(pte, _PAGE_NX);
18121 + else
18122 +#endif
18123 + return pte_set_flags(pte, _PAGE_USER);
18124 +}
18125 +
18126 +static inline pte_t pte_exprotect(pte_t pte)
18127 +{
18128 +#ifdef CONFIG_X86_PAE
18129 + if (__supported_pte_mask & _PAGE_NX)
18130 + return pte_set_flags(pte, _PAGE_NX);
18131 + else
18132 +#endif
18133 + return pte_clear_flags(pte, _PAGE_USER);
18134 }
18135
18136 static inline pte_t pte_mkdirty(pte_t pte)
18137 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18138 #endif
18139
18140 #ifndef __ASSEMBLY__
18141 +
18142 +#ifdef CONFIG_PAX_PER_CPU_PGD
18143 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18144 +enum cpu_pgd_type {kernel = 0, user = 1};
18145 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18146 +{
18147 + return cpu_pgd[cpu][type];
18148 +}
18149 +#endif
18150 +
18151 #include <linux/mm_types.h>
18152 #include <linux/mmdebug.h>
18153 #include <linux/log2.h>
18154 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18155 * Currently stuck as a macro due to indirect forward reference to
18156 * linux/mmzone.h's __section_mem_map_addr() definition:
18157 */
18158 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18159 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18160
18161 /* Find an entry in the second-level page table.. */
18162 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18163 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18164 * Currently stuck as a macro due to indirect forward reference to
18165 * linux/mmzone.h's __section_mem_map_addr() definition:
18166 */
18167 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18168 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18169
18170 /* to find an entry in a page-table-directory. */
18171 static inline unsigned long pud_index(unsigned long address)
18172 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18173
18174 static inline int pgd_bad(pgd_t pgd)
18175 {
18176 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18177 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18178 }
18179
18180 static inline int pgd_none(pgd_t pgd)
18181 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18182 * pgd_offset() returns a (pgd_t *)
18183 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18184 */
18185 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18186 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18187 +
18188 +#ifdef CONFIG_PAX_PER_CPU_PGD
18189 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18190 +#endif
18191 +
18192 /*
18193 * a shortcut which implies the use of the kernel's pgd, instead
18194 * of a process's
18195 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18196 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18197 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18198
18199 +#ifdef CONFIG_X86_32
18200 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18201 +#else
18202 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18203 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18204 +
18205 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18206 +#ifdef __ASSEMBLY__
18207 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18208 +#else
18209 +extern unsigned long pax_user_shadow_base;
18210 +extern pgdval_t clone_pgd_mask;
18211 +#endif
18212 +#endif
18213 +
18214 +#endif
18215 +
18216 #ifndef __ASSEMBLY__
18217
18218 extern int direct_gbpages;
18219 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18220 * dst and src can be on the same page, but the range must not overlap,
18221 * and must not cross a page boundary.
18222 */
18223 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18224 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18225 {
18226 - memcpy(dst, src, count * sizeof(pgd_t));
18227 + pax_open_kernel();
18228 + while (count--)
18229 + *dst++ = *src++;
18230 + pax_close_kernel();
18231 }
18232
18233 +#ifdef CONFIG_PAX_PER_CPU_PGD
18234 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18235 +#endif
18236 +
18237 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18238 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18239 +#else
18240 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18241 +#endif
18242 +
18243 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18244 static inline int page_level_shift(enum pg_level level)
18245 {
18246 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18247 index b6c0b40..3535d47 100644
18248 --- a/arch/x86/include/asm/pgtable_32.h
18249 +++ b/arch/x86/include/asm/pgtable_32.h
18250 @@ -25,9 +25,6 @@
18251 struct mm_struct;
18252 struct vm_area_struct;
18253
18254 -extern pgd_t swapper_pg_dir[1024];
18255 -extern pgd_t initial_page_table[1024];
18256 -
18257 static inline void pgtable_cache_init(void) { }
18258 static inline void check_pgt_cache(void) { }
18259 void paging_init(void);
18260 @@ -45,6 +42,12 @@ void paging_init(void);
18261 # include <asm/pgtable-2level.h>
18262 #endif
18263
18264 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18265 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18266 +#ifdef CONFIG_X86_PAE
18267 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18268 +#endif
18269 +
18270 #if defined(CONFIG_HIGHPTE)
18271 #define pte_offset_map(dir, address) \
18272 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18273 @@ -59,12 +62,17 @@ void paging_init(void);
18274 /* Clear a kernel PTE and flush it from the TLB */
18275 #define kpte_clear_flush(ptep, vaddr) \
18276 do { \
18277 + pax_open_kernel(); \
18278 pte_clear(&init_mm, (vaddr), (ptep)); \
18279 + pax_close_kernel(); \
18280 __flush_tlb_one((vaddr)); \
18281 } while (0)
18282
18283 #endif /* !__ASSEMBLY__ */
18284
18285 +#define HAVE_ARCH_UNMAPPED_AREA
18286 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18287 +
18288 /*
18289 * kern_addr_valid() is (1) for FLATMEM and (0) for
18290 * SPARSEMEM and DISCONTIGMEM
18291 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18292 index ed5903b..c7fe163 100644
18293 --- a/arch/x86/include/asm/pgtable_32_types.h
18294 +++ b/arch/x86/include/asm/pgtable_32_types.h
18295 @@ -8,7 +8,7 @@
18296 */
18297 #ifdef CONFIG_X86_PAE
18298 # include <asm/pgtable-3level_types.h>
18299 -# define PMD_SIZE (1UL << PMD_SHIFT)
18300 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18301 # define PMD_MASK (~(PMD_SIZE - 1))
18302 #else
18303 # include <asm/pgtable-2level_types.h>
18304 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18305 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18306 #endif
18307
18308 +#ifdef CONFIG_PAX_KERNEXEC
18309 +#ifndef __ASSEMBLY__
18310 +extern unsigned char MODULES_EXEC_VADDR[];
18311 +extern unsigned char MODULES_EXEC_END[];
18312 +#endif
18313 +#include <asm/boot.h>
18314 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18315 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18316 +#else
18317 +#define ktla_ktva(addr) (addr)
18318 +#define ktva_ktla(addr) (addr)
18319 +#endif
18320 +
18321 #define MODULES_VADDR VMALLOC_START
18322 #define MODULES_END VMALLOC_END
18323 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18324 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18325 index 4572b2f..4430113 100644
18326 --- a/arch/x86/include/asm/pgtable_64.h
18327 +++ b/arch/x86/include/asm/pgtable_64.h
18328 @@ -16,11 +16,16 @@
18329
18330 extern pud_t level3_kernel_pgt[512];
18331 extern pud_t level3_ident_pgt[512];
18332 +extern pud_t level3_vmalloc_start_pgt[512];
18333 +extern pud_t level3_vmalloc_end_pgt[512];
18334 +extern pud_t level3_vmemmap_pgt[512];
18335 +extern pud_t level2_vmemmap_pgt[512];
18336 extern pmd_t level2_kernel_pgt[512];
18337 extern pmd_t level2_fixmap_pgt[512];
18338 -extern pmd_t level2_ident_pgt[512];
18339 +extern pmd_t level2_ident_pgt[512*2];
18340 extern pte_t level1_fixmap_pgt[512];
18341 -extern pgd_t init_level4_pgt[];
18342 +extern pte_t level1_vsyscall_pgt[512];
18343 +extern pgd_t init_level4_pgt[512];
18344
18345 #define swapper_pg_dir init_level4_pgt
18346
18347 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18348
18349 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18350 {
18351 + pax_open_kernel();
18352 *pmdp = pmd;
18353 + pax_close_kernel();
18354 }
18355
18356 static inline void native_pmd_clear(pmd_t *pmd)
18357 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18358
18359 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18360 {
18361 + pax_open_kernel();
18362 *pudp = pud;
18363 + pax_close_kernel();
18364 }
18365
18366 static inline void native_pud_clear(pud_t *pud)
18367 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18368
18369 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18370 {
18371 + pax_open_kernel();
18372 + *pgdp = pgd;
18373 + pax_close_kernel();
18374 +}
18375 +
18376 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18377 +{
18378 *pgdp = pgd;
18379 }
18380
18381 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18382 index 7166e25..baaa6fe 100644
18383 --- a/arch/x86/include/asm/pgtable_64_types.h
18384 +++ b/arch/x86/include/asm/pgtable_64_types.h
18385 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18386 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18387 #define MODULES_END _AC(0xffffffffff000000, UL)
18388 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18389 +#define MODULES_EXEC_VADDR MODULES_VADDR
18390 +#define MODULES_EXEC_END MODULES_END
18391 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18392 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18393
18394 +#define ktla_ktva(addr) (addr)
18395 +#define ktva_ktla(addr) (addr)
18396 +
18397 #define EARLY_DYNAMIC_PAGE_TABLES 64
18398
18399 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18400 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18401 index 0778964..0e94758 100644
18402 --- a/arch/x86/include/asm/pgtable_types.h
18403 +++ b/arch/x86/include/asm/pgtable_types.h
18404 @@ -110,8 +110,10 @@
18405
18406 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18407 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18408 -#else
18409 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18410 #define _PAGE_NX (_AT(pteval_t, 0))
18411 +#else
18412 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18413 #endif
18414
18415 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18416 @@ -150,6 +152,9 @@
18417 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18418 _PAGE_ACCESSED)
18419
18420 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18421 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18422 +
18423 #define __PAGE_KERNEL_EXEC \
18424 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18425 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18426 @@ -160,7 +165,7 @@
18427 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18428 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18429 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18430 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18431 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18432 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18433 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18434 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18435 @@ -217,7 +222,7 @@
18436 #ifdef CONFIG_X86_64
18437 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18438 #else
18439 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18440 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18441 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18442 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18443 #endif
18444 @@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18445 {
18446 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18447 }
18448 +#endif
18449
18450 +#if PAGETABLE_LEVELS == 3
18451 +#include <asm-generic/pgtable-nopud.h>
18452 +#endif
18453 +
18454 +#if PAGETABLE_LEVELS == 2
18455 +#include <asm-generic/pgtable-nopmd.h>
18456 +#endif
18457 +
18458 +#ifndef __ASSEMBLY__
18459 #if PAGETABLE_LEVELS > 3
18460 typedef struct { pudval_t pud; } pud_t;
18461
18462 @@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18463 return pud.pud;
18464 }
18465 #else
18466 -#include <asm-generic/pgtable-nopud.h>
18467 -
18468 static inline pudval_t native_pud_val(pud_t pud)
18469 {
18470 return native_pgd_val(pud.pgd);
18471 @@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18472 return pmd.pmd;
18473 }
18474 #else
18475 -#include <asm-generic/pgtable-nopmd.h>
18476 -
18477 static inline pmdval_t native_pmd_val(pmd_t pmd)
18478 {
18479 return native_pgd_val(pmd.pud.pgd);
18480 @@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18481
18482 extern pteval_t __supported_pte_mask;
18483 extern void set_nx(void);
18484 -extern int nx_enabled;
18485
18486 #define pgprot_writecombine pgprot_writecombine
18487 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18488 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18489 index 4008734..48f0d81 100644
18490 --- a/arch/x86/include/asm/preempt.h
18491 +++ b/arch/x86/include/asm/preempt.h
18492 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18493 */
18494 static __always_inline bool __preempt_count_dec_and_test(void)
18495 {
18496 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18497 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18498 }
18499
18500 /*
18501 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18502 index eb71ec7..f06532a 100644
18503 --- a/arch/x86/include/asm/processor.h
18504 +++ b/arch/x86/include/asm/processor.h
18505 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18506 /* Index into per_cpu list: */
18507 u16 cpu_index;
18508 u32 microcode;
18509 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18510 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18511
18512 #define X86_VENDOR_INTEL 0
18513 #define X86_VENDOR_CYRIX 1
18514 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18515 : "memory");
18516 }
18517
18518 +/* invpcid (%rdx),%rax */
18519 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18520 +
18521 +#define INVPCID_SINGLE_ADDRESS 0UL
18522 +#define INVPCID_SINGLE_CONTEXT 1UL
18523 +#define INVPCID_ALL_GLOBAL 2UL
18524 +#define INVPCID_ALL_NONGLOBAL 3UL
18525 +
18526 +#define PCID_KERNEL 0UL
18527 +#define PCID_USER 1UL
18528 +#define PCID_NOFLUSH (1UL << 63)
18529 +
18530 static inline void load_cr3(pgd_t *pgdir)
18531 {
18532 - write_cr3(__pa(pgdir));
18533 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18534 }
18535
18536 #ifdef CONFIG_X86_32
18537 @@ -282,7 +294,7 @@ struct tss_struct {
18538
18539 } ____cacheline_aligned;
18540
18541 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18542 +extern struct tss_struct init_tss[NR_CPUS];
18543
18544 /*
18545 * Save the original ist values for checking stack pointers during debugging
18546 @@ -478,6 +490,7 @@ struct thread_struct {
18547 unsigned short ds;
18548 unsigned short fsindex;
18549 unsigned short gsindex;
18550 + unsigned short ss;
18551 #endif
18552 #ifdef CONFIG_X86_32
18553 unsigned long ip;
18554 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18555 extern unsigned long mmu_cr4_features;
18556 extern u32 *trampoline_cr4_features;
18557
18558 -static inline void set_in_cr4(unsigned long mask)
18559 -{
18560 - unsigned long cr4;
18561 -
18562 - mmu_cr4_features |= mask;
18563 - if (trampoline_cr4_features)
18564 - *trampoline_cr4_features = mmu_cr4_features;
18565 - cr4 = read_cr4();
18566 - cr4 |= mask;
18567 - write_cr4(cr4);
18568 -}
18569 -
18570 -static inline void clear_in_cr4(unsigned long mask)
18571 -{
18572 - unsigned long cr4;
18573 -
18574 - mmu_cr4_features &= ~mask;
18575 - if (trampoline_cr4_features)
18576 - *trampoline_cr4_features = mmu_cr4_features;
18577 - cr4 = read_cr4();
18578 - cr4 &= ~mask;
18579 - write_cr4(cr4);
18580 -}
18581 +extern void set_in_cr4(unsigned long mask);
18582 +extern void clear_in_cr4(unsigned long mask);
18583
18584 typedef struct {
18585 unsigned long seg;
18586 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18587 */
18588 #define TASK_SIZE PAGE_OFFSET
18589 #define TASK_SIZE_MAX TASK_SIZE
18590 +
18591 +#ifdef CONFIG_PAX_SEGMEXEC
18592 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18593 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18594 +#else
18595 #define STACK_TOP TASK_SIZE
18596 -#define STACK_TOP_MAX STACK_TOP
18597 +#endif
18598 +
18599 +#define STACK_TOP_MAX TASK_SIZE
18600
18601 #define INIT_THREAD { \
18602 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18603 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18604 .vm86_info = NULL, \
18605 .sysenter_cs = __KERNEL_CS, \
18606 .io_bitmap_ptr = NULL, \
18607 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18608 */
18609 #define INIT_TSS { \
18610 .x86_tss = { \
18611 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18612 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18613 .ss0 = __KERNEL_DS, \
18614 .ss1 = __KERNEL_CS, \
18615 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18616 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18617 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18618
18619 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18620 -#define KSTK_TOP(info) \
18621 -({ \
18622 - unsigned long *__ptr = (unsigned long *)(info); \
18623 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18624 -})
18625 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18626
18627 /*
18628 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18629 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18630 #define task_pt_regs(task) \
18631 ({ \
18632 struct pt_regs *__regs__; \
18633 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18634 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18635 __regs__ - 1; \
18636 })
18637
18638 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18639 /*
18640 * User space process size. 47bits minus one guard page.
18641 */
18642 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18643 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18644
18645 /* This decides where the kernel will search for a free chunk of vm
18646 * space during mmap's.
18647 */
18648 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18649 - 0xc0000000 : 0xFFFFe000)
18650 + 0xc0000000 : 0xFFFFf000)
18651
18652 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18653 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18654 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18655 #define STACK_TOP_MAX TASK_SIZE_MAX
18656
18657 #define INIT_THREAD { \
18658 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18659 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18660 }
18661
18662 #define INIT_TSS { \
18663 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18664 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18665 }
18666
18667 /*
18668 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18669 */
18670 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18671
18672 +#ifdef CONFIG_PAX_SEGMEXEC
18673 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18674 +#endif
18675 +
18676 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18677
18678 /* Get/set a process' ability to use the timestamp counter instruction */
18679 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18680 return 0;
18681 }
18682
18683 -extern unsigned long arch_align_stack(unsigned long sp);
18684 +#define arch_align_stack(x) ((x) & ~0xfUL)
18685 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18686
18687 void default_idle(void);
18688 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18689 #define xen_set_default_idle 0
18690 #endif
18691
18692 -void stop_this_cpu(void *dummy);
18693 +void stop_this_cpu(void *dummy) __noreturn;
18694 void df_debug(struct pt_regs *regs, long error_code);
18695 #endif /* _ASM_X86_PROCESSOR_H */
18696 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18697 index 86fc2bb..bd5049a 100644
18698 --- a/arch/x86/include/asm/ptrace.h
18699 +++ b/arch/x86/include/asm/ptrace.h
18700 @@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18701 }
18702
18703 /*
18704 - * user_mode_vm(regs) determines whether a register set came from user mode.
18705 + * user_mode(regs) determines whether a register set came from user mode.
18706 * This is true if V8086 mode was enabled OR if the register set was from
18707 * protected mode with RPL-3 CS value. This tricky test checks that with
18708 * one comparison. Many places in the kernel can bypass this full check
18709 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18710 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18711 + * be used.
18712 */
18713 -static inline int user_mode(struct pt_regs *regs)
18714 +static inline int user_mode_novm(struct pt_regs *regs)
18715 {
18716 #ifdef CONFIG_X86_32
18717 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18718 #else
18719 - return !!(regs->cs & 3);
18720 + return !!(regs->cs & SEGMENT_RPL_MASK);
18721 #endif
18722 }
18723
18724 -static inline int user_mode_vm(struct pt_regs *regs)
18725 +static inline int user_mode(struct pt_regs *regs)
18726 {
18727 #ifdef CONFIG_X86_32
18728 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18729 USER_RPL;
18730 #else
18731 - return user_mode(regs);
18732 + return user_mode_novm(regs);
18733 #endif
18734 }
18735
18736 @@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18737 #ifdef CONFIG_X86_64
18738 static inline bool user_64bit_mode(struct pt_regs *regs)
18739 {
18740 + unsigned long cs = regs->cs & 0xffff;
18741 #ifndef CONFIG_PARAVIRT
18742 /*
18743 * On non-paravirt systems, this is the only long mode CPL 3
18744 * selector. We do not allow long mode selectors in the LDT.
18745 */
18746 - return regs->cs == __USER_CS;
18747 + return cs == __USER_CS;
18748 #else
18749 /* Headers are too twisted for this to go in paravirt.h. */
18750 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18751 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18752 #endif
18753 }
18754
18755 @@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18756 * Traps from the kernel do not save sp and ss.
18757 * Use the helper function to retrieve sp.
18758 */
18759 - if (offset == offsetof(struct pt_regs, sp) &&
18760 - regs->cs == __KERNEL_CS)
18761 - return kernel_stack_pointer(regs);
18762 + if (offset == offsetof(struct pt_regs, sp)) {
18763 + unsigned long cs = regs->cs & 0xffff;
18764 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18765 + return kernel_stack_pointer(regs);
18766 + }
18767 #endif
18768 return *(unsigned long *)((unsigned long)regs + offset);
18769 }
18770 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18771 index ae0e241..e80b10b 100644
18772 --- a/arch/x86/include/asm/qrwlock.h
18773 +++ b/arch/x86/include/asm/qrwlock.h
18774 @@ -7,8 +7,8 @@
18775 #define queue_write_unlock queue_write_unlock
18776 static inline void queue_write_unlock(struct qrwlock *lock)
18777 {
18778 - barrier();
18779 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18780 + barrier();
18781 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18782 }
18783 #endif
18784
18785 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18786 index 9c6b890..5305f53 100644
18787 --- a/arch/x86/include/asm/realmode.h
18788 +++ b/arch/x86/include/asm/realmode.h
18789 @@ -22,16 +22,14 @@ struct real_mode_header {
18790 #endif
18791 /* APM/BIOS reboot */
18792 u32 machine_real_restart_asm;
18793 -#ifdef CONFIG_X86_64
18794 u32 machine_real_restart_seg;
18795 -#endif
18796 };
18797
18798 /* This must match data at trampoline_32/64.S */
18799 struct trampoline_header {
18800 #ifdef CONFIG_X86_32
18801 u32 start;
18802 - u16 gdt_pad;
18803 + u16 boot_cs;
18804 u16 gdt_limit;
18805 u32 gdt_base;
18806 #else
18807 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18808 index a82c4f1..ac45053 100644
18809 --- a/arch/x86/include/asm/reboot.h
18810 +++ b/arch/x86/include/asm/reboot.h
18811 @@ -6,13 +6,13 @@
18812 struct pt_regs;
18813
18814 struct machine_ops {
18815 - void (*restart)(char *cmd);
18816 - void (*halt)(void);
18817 - void (*power_off)(void);
18818 + void (* __noreturn restart)(char *cmd);
18819 + void (* __noreturn halt)(void);
18820 + void (* __noreturn power_off)(void);
18821 void (*shutdown)(void);
18822 void (*crash_shutdown)(struct pt_regs *);
18823 - void (*emergency_restart)(void);
18824 -};
18825 + void (* __noreturn emergency_restart)(void);
18826 +} __no_const;
18827
18828 extern struct machine_ops machine_ops;
18829
18830 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18831 index 8f7866a..e442f20 100644
18832 --- a/arch/x86/include/asm/rmwcc.h
18833 +++ b/arch/x86/include/asm/rmwcc.h
18834 @@ -3,7 +3,34 @@
18835
18836 #ifdef CC_HAVE_ASM_GOTO
18837
18838 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18839 +#ifdef CONFIG_PAX_REFCOUNT
18840 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18841 +do { \
18842 + asm_volatile_goto (fullop \
18843 + ";jno 0f\n" \
18844 + fullantiop \
18845 + ";int $4\n0:\n" \
18846 + _ASM_EXTABLE(0b, 0b) \
18847 + ";j" cc " %l[cc_label]" \
18848 + : : "m" (var), ## __VA_ARGS__ \
18849 + : "memory" : cc_label); \
18850 + return 0; \
18851 +cc_label: \
18852 + return 1; \
18853 +} while (0)
18854 +#else
18855 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18856 +do { \
18857 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18858 + : : "m" (var), ## __VA_ARGS__ \
18859 + : "memory" : cc_label); \
18860 + return 0; \
18861 +cc_label: \
18862 + return 1; \
18863 +} while (0)
18864 +#endif
18865 +
18866 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18867 do { \
18868 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18869 : : "m" (var), ## __VA_ARGS__ \
18870 @@ -13,15 +40,46 @@ cc_label: \
18871 return 1; \
18872 } while (0)
18873
18874 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18875 - __GEN_RMWcc(op " " arg0, var, cc)
18876 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18877 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18878
18879 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18880 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18881 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18882 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18883 +
18884 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18885 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18886 +
18887 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18888 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18889
18890 #else /* !CC_HAVE_ASM_GOTO */
18891
18892 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18893 +#ifdef CONFIG_PAX_REFCOUNT
18894 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18895 +do { \
18896 + char c; \
18897 + asm volatile (fullop \
18898 + ";jno 0f\n" \
18899 + fullantiop \
18900 + ";int $4\n0:\n" \
18901 + _ASM_EXTABLE(0b, 0b) \
18902 + "; set" cc " %1" \
18903 + : "+m" (var), "=qm" (c) \
18904 + : __VA_ARGS__ : "memory"); \
18905 + return c != 0; \
18906 +} while (0)
18907 +#else
18908 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18909 +do { \
18910 + char c; \
18911 + asm volatile (fullop "; set" cc " %1" \
18912 + : "+m" (var), "=qm" (c) \
18913 + : __VA_ARGS__ : "memory"); \
18914 + return c != 0; \
18915 +} while (0)
18916 +#endif
18917 +
18918 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18919 do { \
18920 char c; \
18921 asm volatile (fullop "; set" cc " %1" \
18922 @@ -30,11 +88,17 @@ do { \
18923 return c != 0; \
18924 } while (0)
18925
18926 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18927 - __GEN_RMWcc(op " " arg0, var, cc)
18928 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18929 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18930 +
18931 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18932 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18933 +
18934 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18935 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18936
18937 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18938 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18939 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18940 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18941
18942 #endif /* CC_HAVE_ASM_GOTO */
18943
18944 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18945 index cad82c9..2e5c5c1 100644
18946 --- a/arch/x86/include/asm/rwsem.h
18947 +++ b/arch/x86/include/asm/rwsem.h
18948 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18949 {
18950 asm volatile("# beginning down_read\n\t"
18951 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18952 +
18953 +#ifdef CONFIG_PAX_REFCOUNT
18954 + "jno 0f\n"
18955 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18956 + "int $4\n0:\n"
18957 + _ASM_EXTABLE(0b, 0b)
18958 +#endif
18959 +
18960 /* adds 0x00000001 */
18961 " jns 1f\n"
18962 " call call_rwsem_down_read_failed\n"
18963 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18964 "1:\n\t"
18965 " mov %1,%2\n\t"
18966 " add %3,%2\n\t"
18967 +
18968 +#ifdef CONFIG_PAX_REFCOUNT
18969 + "jno 0f\n"
18970 + "sub %3,%2\n"
18971 + "int $4\n0:\n"
18972 + _ASM_EXTABLE(0b, 0b)
18973 +#endif
18974 +
18975 " jle 2f\n\t"
18976 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18977 " jnz 1b\n\t"
18978 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18979 long tmp;
18980 asm volatile("# beginning down_write\n\t"
18981 LOCK_PREFIX " xadd %1,(%2)\n\t"
18982 +
18983 +#ifdef CONFIG_PAX_REFCOUNT
18984 + "jno 0f\n"
18985 + "mov %1,(%2)\n"
18986 + "int $4\n0:\n"
18987 + _ASM_EXTABLE(0b, 0b)
18988 +#endif
18989 +
18990 /* adds 0xffff0001, returns the old value */
18991 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18992 /* was the active mask 0 before? */
18993 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18994 long tmp;
18995 asm volatile("# beginning __up_read\n\t"
18996 LOCK_PREFIX " xadd %1,(%2)\n\t"
18997 +
18998 +#ifdef CONFIG_PAX_REFCOUNT
18999 + "jno 0f\n"
19000 + "mov %1,(%2)\n"
19001 + "int $4\n0:\n"
19002 + _ASM_EXTABLE(0b, 0b)
19003 +#endif
19004 +
19005 /* subtracts 1, returns the old value */
19006 " jns 1f\n\t"
19007 " call call_rwsem_wake\n" /* expects old value in %edx */
19008 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19009 long tmp;
19010 asm volatile("# beginning __up_write\n\t"
19011 LOCK_PREFIX " xadd %1,(%2)\n\t"
19012 +
19013 +#ifdef CONFIG_PAX_REFCOUNT
19014 + "jno 0f\n"
19015 + "mov %1,(%2)\n"
19016 + "int $4\n0:\n"
19017 + _ASM_EXTABLE(0b, 0b)
19018 +#endif
19019 +
19020 /* subtracts 0xffff0001, returns the old value */
19021 " jns 1f\n\t"
19022 " call call_rwsem_wake\n" /* expects old value in %edx */
19023 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19024 {
19025 asm volatile("# beginning __downgrade_write\n\t"
19026 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19027 +
19028 +#ifdef CONFIG_PAX_REFCOUNT
19029 + "jno 0f\n"
19030 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19031 + "int $4\n0:\n"
19032 + _ASM_EXTABLE(0b, 0b)
19033 +#endif
19034 +
19035 /*
19036 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19037 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19038 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19039 */
19040 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19041 {
19042 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19043 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19044 +
19045 +#ifdef CONFIG_PAX_REFCOUNT
19046 + "jno 0f\n"
19047 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19048 + "int $4\n0:\n"
19049 + _ASM_EXTABLE(0b, 0b)
19050 +#endif
19051 +
19052 : "+m" (sem->count)
19053 : "er" (delta));
19054 }
19055 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19056 */
19057 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19058 {
19059 - return delta + xadd(&sem->count, delta);
19060 + return delta + xadd_check_overflow(&sem->count, delta);
19061 }
19062
19063 #endif /* __KERNEL__ */
19064 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19065 index 6f1c3a8..7744f19 100644
19066 --- a/arch/x86/include/asm/segment.h
19067 +++ b/arch/x86/include/asm/segment.h
19068 @@ -64,10 +64,15 @@
19069 * 26 - ESPFIX small SS
19070 * 27 - per-cpu [ offset to per-cpu data area ]
19071 * 28 - stack_canary-20 [ for stack protector ]
19072 - * 29 - unused
19073 - * 30 - unused
19074 + * 29 - PCI BIOS CS
19075 + * 30 - PCI BIOS DS
19076 * 31 - TSS for double fault handler
19077 */
19078 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19079 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19080 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19081 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19082 +
19083 #define GDT_ENTRY_TLS_MIN 6
19084 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19085
19086 @@ -79,6 +84,8 @@
19087
19088 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19089
19090 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19091 +
19092 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19093
19094 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19095 @@ -104,6 +111,12 @@
19096 #define __KERNEL_STACK_CANARY 0
19097 #endif
19098
19099 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19100 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19101 +
19102 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19103 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19104 +
19105 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19106
19107 /*
19108 @@ -141,7 +154,7 @@
19109 */
19110
19111 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19112 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19113 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19114
19115
19116 #else
19117 @@ -165,6 +178,8 @@
19118 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19119 #define __USER32_DS __USER_DS
19120
19121 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19122 +
19123 #define GDT_ENTRY_TSS 8 /* needs two entries */
19124 #define GDT_ENTRY_LDT 10 /* needs two entries */
19125 #define GDT_ENTRY_TLS_MIN 12
19126 @@ -173,6 +188,8 @@
19127 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19128 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19129
19130 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19131 +
19132 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19133 #define FS_TLS 0
19134 #define GS_TLS 1
19135 @@ -180,12 +197,14 @@
19136 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19137 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19138
19139 -#define GDT_ENTRIES 16
19140 +#define GDT_ENTRIES 17
19141
19142 #endif
19143
19144 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19145 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19146 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19147 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19148 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19149 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19150 #ifndef CONFIG_PARAVIRT
19151 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19152 {
19153 unsigned long __limit;
19154 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19155 - return __limit + 1;
19156 + return __limit;
19157 }
19158
19159 #endif /* !__ASSEMBLY__ */
19160 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19161 index 8d3120f..352b440 100644
19162 --- a/arch/x86/include/asm/smap.h
19163 +++ b/arch/x86/include/asm/smap.h
19164 @@ -25,11 +25,40 @@
19165
19166 #include <asm/alternative-asm.h>
19167
19168 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19169 +#define ASM_PAX_OPEN_USERLAND \
19170 + 661: jmp 663f; \
19171 + .pushsection .altinstr_replacement, "a" ; \
19172 + 662: pushq %rax; nop; \
19173 + .popsection ; \
19174 + .pushsection .altinstructions, "a" ; \
19175 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19176 + .popsection ; \
19177 + call __pax_open_userland; \
19178 + popq %rax; \
19179 + 663:
19180 +
19181 +#define ASM_PAX_CLOSE_USERLAND \
19182 + 661: jmp 663f; \
19183 + .pushsection .altinstr_replacement, "a" ; \
19184 + 662: pushq %rax; nop; \
19185 + .popsection; \
19186 + .pushsection .altinstructions, "a" ; \
19187 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19188 + .popsection; \
19189 + call __pax_close_userland; \
19190 + popq %rax; \
19191 + 663:
19192 +#else
19193 +#define ASM_PAX_OPEN_USERLAND
19194 +#define ASM_PAX_CLOSE_USERLAND
19195 +#endif
19196 +
19197 #ifdef CONFIG_X86_SMAP
19198
19199 #define ASM_CLAC \
19200 661: ASM_NOP3 ; \
19201 - .pushsection .altinstr_replacement, "ax" ; \
19202 + .pushsection .altinstr_replacement, "a" ; \
19203 662: __ASM_CLAC ; \
19204 .popsection ; \
19205 .pushsection .altinstructions, "a" ; \
19206 @@ -38,7 +67,7 @@
19207
19208 #define ASM_STAC \
19209 661: ASM_NOP3 ; \
19210 - .pushsection .altinstr_replacement, "ax" ; \
19211 + .pushsection .altinstr_replacement, "a" ; \
19212 662: __ASM_STAC ; \
19213 .popsection ; \
19214 .pushsection .altinstructions, "a" ; \
19215 @@ -56,6 +85,37 @@
19216
19217 #include <asm/alternative.h>
19218
19219 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19220 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19221 +
19222 +extern void __pax_open_userland(void);
19223 +static __always_inline unsigned long pax_open_userland(void)
19224 +{
19225 +
19226 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19227 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19228 + :
19229 + : [open] "i" (__pax_open_userland)
19230 + : "memory", "rax");
19231 +#endif
19232 +
19233 + return 0;
19234 +}
19235 +
19236 +extern void __pax_close_userland(void);
19237 +static __always_inline unsigned long pax_close_userland(void)
19238 +{
19239 +
19240 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19241 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19242 + :
19243 + : [close] "i" (__pax_close_userland)
19244 + : "memory", "rax");
19245 +#endif
19246 +
19247 + return 0;
19248 +}
19249 +
19250 #ifdef CONFIG_X86_SMAP
19251
19252 static __always_inline void clac(void)
19253 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19254 index 8cd1cc3..827e09e 100644
19255 --- a/arch/x86/include/asm/smp.h
19256 +++ b/arch/x86/include/asm/smp.h
19257 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19258 /* cpus sharing the last level cache: */
19259 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19260 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19261 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19262 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19263
19264 static inline struct cpumask *cpu_sibling_mask(int cpu)
19265 {
19266 @@ -78,7 +78,7 @@ struct smp_ops {
19267
19268 void (*send_call_func_ipi)(const struct cpumask *mask);
19269 void (*send_call_func_single_ipi)(int cpu);
19270 -};
19271 +} __no_const;
19272
19273 /* Globals due to paravirt */
19274 extern void set_cpu_sibling_map(int cpu);
19275 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19276 extern int safe_smp_processor_id(void);
19277
19278 #elif defined(CONFIG_X86_64_SMP)
19279 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19280 -
19281 -#define stack_smp_processor_id() \
19282 -({ \
19283 - struct thread_info *ti; \
19284 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19285 - ti->cpu; \
19286 -})
19287 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19288 +#define stack_smp_processor_id() raw_smp_processor_id()
19289 #define safe_smp_processor_id() smp_processor_id()
19290
19291 #endif
19292 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19293 index 6a99859..03cb807 100644
19294 --- a/arch/x86/include/asm/stackprotector.h
19295 +++ b/arch/x86/include/asm/stackprotector.h
19296 @@ -47,7 +47,7 @@
19297 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19298 */
19299 #define GDT_STACK_CANARY_INIT \
19300 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19301 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19302
19303 /*
19304 * Initialize the stackprotector canary value.
19305 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19306
19307 static inline void load_stack_canary_segment(void)
19308 {
19309 -#ifdef CONFIG_X86_32
19310 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19311 asm volatile ("mov %0, %%gs" : : "r" (0));
19312 #endif
19313 }
19314 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19315 index 70bbe39..4ae2bd4 100644
19316 --- a/arch/x86/include/asm/stacktrace.h
19317 +++ b/arch/x86/include/asm/stacktrace.h
19318 @@ -11,28 +11,20 @@
19319
19320 extern int kstack_depth_to_print;
19321
19322 -struct thread_info;
19323 +struct task_struct;
19324 struct stacktrace_ops;
19325
19326 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19327 - unsigned long *stack,
19328 - unsigned long bp,
19329 - const struct stacktrace_ops *ops,
19330 - void *data,
19331 - unsigned long *end,
19332 - int *graph);
19333 +typedef unsigned long walk_stack_t(struct task_struct *task,
19334 + void *stack_start,
19335 + unsigned long *stack,
19336 + unsigned long bp,
19337 + const struct stacktrace_ops *ops,
19338 + void *data,
19339 + unsigned long *end,
19340 + int *graph);
19341
19342 -extern unsigned long
19343 -print_context_stack(struct thread_info *tinfo,
19344 - unsigned long *stack, unsigned long bp,
19345 - const struct stacktrace_ops *ops, void *data,
19346 - unsigned long *end, int *graph);
19347 -
19348 -extern unsigned long
19349 -print_context_stack_bp(struct thread_info *tinfo,
19350 - unsigned long *stack, unsigned long bp,
19351 - const struct stacktrace_ops *ops, void *data,
19352 - unsigned long *end, int *graph);
19353 +extern walk_stack_t print_context_stack;
19354 +extern walk_stack_t print_context_stack_bp;
19355
19356 /* Generic stack tracer with callbacks */
19357
19358 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19359 void (*address)(void *data, unsigned long address, int reliable);
19360 /* On negative return stop dumping */
19361 int (*stack)(void *data, char *name);
19362 - walk_stack_t walk_stack;
19363 + walk_stack_t *walk_stack;
19364 };
19365
19366 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19367 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19368 index d7f3b3b..3cc39f1 100644
19369 --- a/arch/x86/include/asm/switch_to.h
19370 +++ b/arch/x86/include/asm/switch_to.h
19371 @@ -108,7 +108,7 @@ do { \
19372 "call __switch_to\n\t" \
19373 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19374 __switch_canary \
19375 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19376 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19377 "movq %%rax,%%rdi\n\t" \
19378 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19379 "jnz ret_from_fork\n\t" \
19380 @@ -119,7 +119,7 @@ do { \
19381 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19382 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19383 [_tif_fork] "i" (_TIF_FORK), \
19384 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19385 + [thread_info] "m" (current_tinfo), \
19386 [current_task] "m" (current_task) \
19387 __switch_canary_iparam \
19388 : "memory", "cc" __EXTRA_CLOBBER)
19389 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19390 index 547e344..6be1175 100644
19391 --- a/arch/x86/include/asm/thread_info.h
19392 +++ b/arch/x86/include/asm/thread_info.h
19393 @@ -24,7 +24,6 @@ struct exec_domain;
19394 #include <linux/atomic.h>
19395
19396 struct thread_info {
19397 - struct task_struct *task; /* main task structure */
19398 struct exec_domain *exec_domain; /* execution domain */
19399 __u32 flags; /* low level flags */
19400 __u32 status; /* thread synchronous flags */
19401 @@ -33,13 +32,13 @@ struct thread_info {
19402 mm_segment_t addr_limit;
19403 struct restart_block restart_block;
19404 void __user *sysenter_return;
19405 + unsigned long lowest_stack;
19406 unsigned int sig_on_uaccess_error:1;
19407 unsigned int uaccess_err:1; /* uaccess failed */
19408 };
19409
19410 -#define INIT_THREAD_INFO(tsk) \
19411 +#define INIT_THREAD_INFO \
19412 { \
19413 - .task = &tsk, \
19414 .exec_domain = &default_exec_domain, \
19415 .flags = 0, \
19416 .cpu = 0, \
19417 @@ -50,7 +49,7 @@ struct thread_info {
19418 }, \
19419 }
19420
19421 -#define init_thread_info (init_thread_union.thread_info)
19422 +#define init_thread_info (init_thread_union.stack)
19423 #define init_stack (init_thread_union.stack)
19424
19425 #else /* !__ASSEMBLY__ */
19426 @@ -91,6 +90,7 @@ struct thread_info {
19427 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19428 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19429 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19430 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19431
19432 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19433 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19434 @@ -115,17 +115,18 @@ struct thread_info {
19435 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19436 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19437 #define _TIF_X32 (1 << TIF_X32)
19438 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19439
19440 /* work to do in syscall_trace_enter() */
19441 #define _TIF_WORK_SYSCALL_ENTRY \
19442 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19443 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19444 - _TIF_NOHZ)
19445 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19446
19447 /* work to do in syscall_trace_leave() */
19448 #define _TIF_WORK_SYSCALL_EXIT \
19449 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19450 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19451 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19452
19453 /* work to do on interrupt/exception return */
19454 #define _TIF_WORK_MASK \
19455 @@ -136,7 +137,7 @@ struct thread_info {
19456 /* work to do on any return to user space */
19457 #define _TIF_ALLWORK_MASK \
19458 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19459 - _TIF_NOHZ)
19460 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19461
19462 /* Only used for 64 bit */
19463 #define _TIF_DO_NOTIFY_MASK \
19464 @@ -151,7 +152,6 @@ struct thread_info {
19465 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19466
19467 #define STACK_WARN (THREAD_SIZE/8)
19468 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19469
19470 /*
19471 * macros/functions for gaining access to the thread information structure
19472 @@ -162,26 +162,18 @@ struct thread_info {
19473
19474 DECLARE_PER_CPU(unsigned long, kernel_stack);
19475
19476 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19477 +
19478 static inline struct thread_info *current_thread_info(void)
19479 {
19480 - struct thread_info *ti;
19481 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19482 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19483 - return ti;
19484 + return this_cpu_read_stable(current_tinfo);
19485 }
19486
19487 #else /* !__ASSEMBLY__ */
19488
19489 /* how to get the thread information struct from ASM */
19490 #define GET_THREAD_INFO(reg) \
19491 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19492 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19493 -
19494 -/*
19495 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19496 - * a certain register (to be used in assembler memory operands).
19497 - */
19498 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19499 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19500
19501 #endif
19502
19503 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19504 extern void arch_task_cache_init(void);
19505 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19506 extern void arch_release_task_struct(struct task_struct *tsk);
19507 +
19508 +#define __HAVE_THREAD_FUNCTIONS
19509 +#define task_thread_info(task) (&(task)->tinfo)
19510 +#define task_stack_page(task) ((task)->stack)
19511 +#define setup_thread_stack(p, org) do {} while (0)
19512 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19513 +
19514 #endif
19515 #endif /* _ASM_X86_THREAD_INFO_H */
19516 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19517 index 04905bf..1178cdf 100644
19518 --- a/arch/x86/include/asm/tlbflush.h
19519 +++ b/arch/x86/include/asm/tlbflush.h
19520 @@ -17,18 +17,44 @@
19521
19522 static inline void __native_flush_tlb(void)
19523 {
19524 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19525 + u64 descriptor[2];
19526 +
19527 + descriptor[0] = PCID_KERNEL;
19528 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19529 + return;
19530 + }
19531 +
19532 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19533 + if (static_cpu_has(X86_FEATURE_PCID)) {
19534 + unsigned int cpu = raw_get_cpu();
19535 +
19536 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19537 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19538 + raw_put_cpu_no_resched();
19539 + return;
19540 + }
19541 +#endif
19542 +
19543 native_write_cr3(native_read_cr3());
19544 }
19545
19546 static inline void __native_flush_tlb_global_irq_disabled(void)
19547 {
19548 - unsigned long cr4;
19549 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19550 + u64 descriptor[2];
19551
19552 - cr4 = native_read_cr4();
19553 - /* clear PGE */
19554 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19555 - /* write old PGE again and flush TLBs */
19556 - native_write_cr4(cr4);
19557 + descriptor[0] = PCID_KERNEL;
19558 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19559 + } else {
19560 + unsigned long cr4;
19561 +
19562 + cr4 = native_read_cr4();
19563 + /* clear PGE */
19564 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19565 + /* write old PGE again and flush TLBs */
19566 + native_write_cr4(cr4);
19567 + }
19568 }
19569
19570 static inline void __native_flush_tlb_global(void)
19571 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19572
19573 static inline void __native_flush_tlb_single(unsigned long addr)
19574 {
19575 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19576 + u64 descriptor[2];
19577 +
19578 + descriptor[0] = PCID_KERNEL;
19579 + descriptor[1] = addr;
19580 +
19581 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19582 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19583 + if (addr < TASK_SIZE_MAX)
19584 + descriptor[1] += pax_user_shadow_base;
19585 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19586 + }
19587 +
19588 + descriptor[0] = PCID_USER;
19589 + descriptor[1] = addr;
19590 +#endif
19591 +
19592 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19593 + return;
19594 + }
19595 +
19596 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19597 + if (static_cpu_has(X86_FEATURE_PCID)) {
19598 + unsigned int cpu = raw_get_cpu();
19599 +
19600 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19601 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19602 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19603 + raw_put_cpu_no_resched();
19604 +
19605 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19606 + addr += pax_user_shadow_base;
19607 + }
19608 +#endif
19609 +
19610 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19611 }
19612
19613 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19614 index 0d592e0..526f797 100644
19615 --- a/arch/x86/include/asm/uaccess.h
19616 +++ b/arch/x86/include/asm/uaccess.h
19617 @@ -7,6 +7,7 @@
19618 #include <linux/compiler.h>
19619 #include <linux/thread_info.h>
19620 #include <linux/string.h>
19621 +#include <linux/spinlock.h>
19622 #include <asm/asm.h>
19623 #include <asm/page.h>
19624 #include <asm/smap.h>
19625 @@ -29,7 +30,12 @@
19626
19627 #define get_ds() (KERNEL_DS)
19628 #define get_fs() (current_thread_info()->addr_limit)
19629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19630 +void __set_fs(mm_segment_t x);
19631 +void set_fs(mm_segment_t x);
19632 +#else
19633 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19634 +#endif
19635
19636 #define segment_eq(a, b) ((a).seg == (b).seg)
19637
19638 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19639 * checks that the pointer is in the user space range - after calling
19640 * this function, memory access functions may still return -EFAULT.
19641 */
19642 -#define access_ok(type, addr, size) \
19643 - likely(!__range_not_ok(addr, size, user_addr_max()))
19644 +extern int _cond_resched(void);
19645 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19646 +#define access_ok(type, addr, size) \
19647 +({ \
19648 + unsigned long __size = size; \
19649 + unsigned long __addr = (unsigned long)addr; \
19650 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19651 + if (__ret_ao && __size) { \
19652 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19653 + unsigned long __end_ao = __addr + __size - 1; \
19654 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19655 + while (__addr_ao <= __end_ao) { \
19656 + char __c_ao; \
19657 + __addr_ao += PAGE_SIZE; \
19658 + if (__size > PAGE_SIZE) \
19659 + _cond_resched(); \
19660 + if (__get_user(__c_ao, (char __user *)__addr)) \
19661 + break; \
19662 + if (type != VERIFY_WRITE) { \
19663 + __addr = __addr_ao; \
19664 + continue; \
19665 + } \
19666 + if (__put_user(__c_ao, (char __user *)__addr)) \
19667 + break; \
19668 + __addr = __addr_ao; \
19669 + } \
19670 + } \
19671 + } \
19672 + __ret_ao; \
19673 +})
19674
19675 /*
19676 * The exception table consists of pairs of addresses relative to the
19677 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19678 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19679 __chk_user_ptr(ptr); \
19680 might_fault(); \
19681 + pax_open_userland(); \
19682 asm volatile("call __get_user_%P3" \
19683 : "=a" (__ret_gu), "=r" (__val_gu) \
19684 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19685 (x) = (__typeof__(*(ptr))) __val_gu; \
19686 + pax_close_userland(); \
19687 __ret_gu; \
19688 })
19689
19690 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19691 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19692 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19693
19694 -
19695 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19696 +#define __copyuser_seg "gs;"
19697 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19698 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19699 +#else
19700 +#define __copyuser_seg
19701 +#define __COPYUSER_SET_ES
19702 +#define __COPYUSER_RESTORE_ES
19703 +#endif
19704
19705 #ifdef CONFIG_X86_32
19706 #define __put_user_asm_u64(x, addr, err, errret) \
19707 asm volatile(ASM_STAC "\n" \
19708 - "1: movl %%eax,0(%2)\n" \
19709 - "2: movl %%edx,4(%2)\n" \
19710 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19711 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19712 "3: " ASM_CLAC "\n" \
19713 ".section .fixup,\"ax\"\n" \
19714 "4: movl %3,%0\n" \
19715 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19716
19717 #define __put_user_asm_ex_u64(x, addr) \
19718 asm volatile(ASM_STAC "\n" \
19719 - "1: movl %%eax,0(%1)\n" \
19720 - "2: movl %%edx,4(%1)\n" \
19721 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19722 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19723 "3: " ASM_CLAC "\n" \
19724 _ASM_EXTABLE_EX(1b, 2b) \
19725 _ASM_EXTABLE_EX(2b, 3b) \
19726 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19727 __typeof__(*(ptr)) __pu_val; \
19728 __chk_user_ptr(ptr); \
19729 might_fault(); \
19730 - __pu_val = x; \
19731 + __pu_val = (x); \
19732 + pax_open_userland(); \
19733 switch (sizeof(*(ptr))) { \
19734 case 1: \
19735 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19736 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19737 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19738 break; \
19739 } \
19740 + pax_close_userland(); \
19741 __ret_pu; \
19742 })
19743
19744 @@ -355,8 +401,10 @@ do { \
19745 } while (0)
19746
19747 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19748 +do { \
19749 + pax_open_userland(); \
19750 asm volatile(ASM_STAC "\n" \
19751 - "1: mov"itype" %2,%"rtype"1\n" \
19752 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19753 "2: " ASM_CLAC "\n" \
19754 ".section .fixup,\"ax\"\n" \
19755 "3: mov %3,%0\n" \
19756 @@ -364,8 +412,10 @@ do { \
19757 " jmp 2b\n" \
19758 ".previous\n" \
19759 _ASM_EXTABLE(1b, 3b) \
19760 - : "=r" (err), ltype(x) \
19761 - : "m" (__m(addr)), "i" (errret), "0" (err))
19762 + : "=r" (err), ltype (x) \
19763 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19764 + pax_close_userland(); \
19765 +} while (0)
19766
19767 #define __get_user_size_ex(x, ptr, size) \
19768 do { \
19769 @@ -389,7 +439,7 @@ do { \
19770 } while (0)
19771
19772 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19773 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19774 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19775 "2:\n" \
19776 _ASM_EXTABLE_EX(1b, 2b) \
19777 : ltype(x) : "m" (__m(addr)))
19778 @@ -406,13 +456,24 @@ do { \
19779 int __gu_err; \
19780 unsigned long __gu_val; \
19781 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19782 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19783 + (x) = (__typeof__(*(ptr)))__gu_val; \
19784 __gu_err; \
19785 })
19786
19787 /* FIXME: this hack is definitely wrong -AK */
19788 struct __large_struct { unsigned long buf[100]; };
19789 -#define __m(x) (*(struct __large_struct __user *)(x))
19790 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19791 +#define ____m(x) \
19792 +({ \
19793 + unsigned long ____x = (unsigned long)(x); \
19794 + if (____x < pax_user_shadow_base) \
19795 + ____x += pax_user_shadow_base; \
19796 + (typeof(x))____x; \
19797 +})
19798 +#else
19799 +#define ____m(x) (x)
19800 +#endif
19801 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19802
19803 /*
19804 * Tell gcc we read from memory instead of writing: this is because
19805 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19806 * aliasing issues.
19807 */
19808 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19809 +do { \
19810 + pax_open_userland(); \
19811 asm volatile(ASM_STAC "\n" \
19812 - "1: mov"itype" %"rtype"1,%2\n" \
19813 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19814 "2: " ASM_CLAC "\n" \
19815 ".section .fixup,\"ax\"\n" \
19816 "3: mov %3,%0\n" \
19817 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19818 ".previous\n" \
19819 _ASM_EXTABLE(1b, 3b) \
19820 : "=r"(err) \
19821 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19822 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19823 + pax_close_userland(); \
19824 +} while (0)
19825
19826 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19827 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19828 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19829 "2:\n" \
19830 _ASM_EXTABLE_EX(1b, 2b) \
19831 : : ltype(x), "m" (__m(addr)))
19832 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19833 */
19834 #define uaccess_try do { \
19835 current_thread_info()->uaccess_err = 0; \
19836 + pax_open_userland(); \
19837 stac(); \
19838 barrier();
19839
19840 #define uaccess_catch(err) \
19841 clac(); \
19842 + pax_close_userland(); \
19843 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19844 } while (0)
19845
19846 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19847 * On error, the variable @x is set to zero.
19848 */
19849
19850 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19851 +#define __get_user(x, ptr) get_user((x), (ptr))
19852 +#else
19853 #define __get_user(x, ptr) \
19854 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19855 +#endif
19856
19857 /**
19858 * __put_user: - Write a simple value into user space, with less checking.
19859 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19860 * Returns zero on success, or -EFAULT on error.
19861 */
19862
19863 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19864 +#define __put_user(x, ptr) put_user((x), (ptr))
19865 +#else
19866 #define __put_user(x, ptr) \
19867 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19868 +#endif
19869
19870 #define __get_user_unaligned __get_user
19871 #define __put_user_unaligned __put_user
19872 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19873 #define get_user_ex(x, ptr) do { \
19874 unsigned long __gue_val; \
19875 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19876 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19877 + (x) = (__typeof__(*(ptr)))__gue_val; \
19878 } while (0)
19879
19880 #define put_user_try uaccess_try
19881 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19882 __typeof__(ptr) __uval = (uval); \
19883 __typeof__(*(ptr)) __old = (old); \
19884 __typeof__(*(ptr)) __new = (new); \
19885 + pax_open_userland(); \
19886 switch (size) { \
19887 case 1: \
19888 { \
19889 asm volatile("\t" ASM_STAC "\n" \
19890 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19891 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19892 "2:\t" ASM_CLAC "\n" \
19893 "\t.section .fixup, \"ax\"\n" \
19894 "3:\tmov %3, %0\n" \
19895 "\tjmp 2b\n" \
19896 "\t.previous\n" \
19897 _ASM_EXTABLE(1b, 3b) \
19898 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19899 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19900 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19901 : "memory" \
19902 ); \
19903 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19904 case 2: \
19905 { \
19906 asm volatile("\t" ASM_STAC "\n" \
19907 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19908 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19909 "2:\t" ASM_CLAC "\n" \
19910 "\t.section .fixup, \"ax\"\n" \
19911 "3:\tmov %3, %0\n" \
19912 "\tjmp 2b\n" \
19913 "\t.previous\n" \
19914 _ASM_EXTABLE(1b, 3b) \
19915 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19916 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19917 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19918 : "memory" \
19919 ); \
19920 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19921 case 4: \
19922 { \
19923 asm volatile("\t" ASM_STAC "\n" \
19924 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19925 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19926 "2:\t" ASM_CLAC "\n" \
19927 "\t.section .fixup, \"ax\"\n" \
19928 "3:\tmov %3, %0\n" \
19929 "\tjmp 2b\n" \
19930 "\t.previous\n" \
19931 _ASM_EXTABLE(1b, 3b) \
19932 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19933 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19934 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19935 : "memory" \
19936 ); \
19937 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19938 __cmpxchg_wrong_size(); \
19939 \
19940 asm volatile("\t" ASM_STAC "\n" \
19941 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19942 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19943 "2:\t" ASM_CLAC "\n" \
19944 "\t.section .fixup, \"ax\"\n" \
19945 "3:\tmov %3, %0\n" \
19946 "\tjmp 2b\n" \
19947 "\t.previous\n" \
19948 _ASM_EXTABLE(1b, 3b) \
19949 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19950 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19951 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19952 : "memory" \
19953 ); \
19954 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19955 default: \
19956 __cmpxchg_wrong_size(); \
19957 } \
19958 + pax_close_userland(); \
19959 *__uval = __old; \
19960 __ret; \
19961 })
19962 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19963
19964 #define ARCH_HAS_NOCACHE_UACCESS 1
19965
19966 -#ifdef CONFIG_X86_32
19967 -# include <asm/uaccess_32.h>
19968 -#else
19969 -# include <asm/uaccess_64.h>
19970 -#endif
19971 -
19972 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19973 - unsigned n);
19974 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19975 - unsigned n);
19976 -
19977 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19978 # define copy_user_diag __compiletime_error
19979 #else
19980 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19981 extern void copy_user_diag("copy_from_user() buffer size is too small")
19982 copy_from_user_overflow(void);
19983 extern void copy_user_diag("copy_to_user() buffer size is too small")
19984 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19985 +copy_to_user_overflow(void);
19986
19987 #undef copy_user_diag
19988
19989 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19990
19991 extern void
19992 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19993 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19994 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19995 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19996
19997 #else
19998 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19999
20000 #endif
20001
20002 +#ifdef CONFIG_X86_32
20003 +# include <asm/uaccess_32.h>
20004 +#else
20005 +# include <asm/uaccess_64.h>
20006 +#endif
20007 +
20008 static inline unsigned long __must_check
20009 copy_from_user(void *to, const void __user *from, unsigned long n)
20010 {
20011 - int sz = __compiletime_object_size(to);
20012 + size_t sz = __compiletime_object_size(to);
20013
20014 might_fault();
20015
20016 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20017 * case, and do only runtime checking for non-constant sizes.
20018 */
20019
20020 - if (likely(sz < 0 || sz >= n))
20021 - n = _copy_from_user(to, from, n);
20022 - else if(__builtin_constant_p(n))
20023 - copy_from_user_overflow();
20024 - else
20025 - __copy_from_user_overflow(sz, n);
20026 + if (likely(sz != (size_t)-1 && sz < n)) {
20027 + if(__builtin_constant_p(n))
20028 + copy_from_user_overflow();
20029 + else
20030 + __copy_from_user_overflow(sz, n);
20031 + } else if (access_ok(VERIFY_READ, from, n))
20032 + n = __copy_from_user(to, from, n);
20033 + else if ((long)n > 0)
20034 + memset(to, 0, n);
20035
20036 return n;
20037 }
20038 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20039 static inline unsigned long __must_check
20040 copy_to_user(void __user *to, const void *from, unsigned long n)
20041 {
20042 - int sz = __compiletime_object_size(from);
20043 + size_t sz = __compiletime_object_size(from);
20044
20045 might_fault();
20046
20047 /* See the comment in copy_from_user() above. */
20048 - if (likely(sz < 0 || sz >= n))
20049 - n = _copy_to_user(to, from, n);
20050 - else if(__builtin_constant_p(n))
20051 - copy_to_user_overflow();
20052 - else
20053 - __copy_to_user_overflow(sz, n);
20054 + if (likely(sz != (size_t)-1 && sz < n)) {
20055 + if(__builtin_constant_p(n))
20056 + copy_to_user_overflow();
20057 + else
20058 + __copy_to_user_overflow(sz, n);
20059 + } else if (access_ok(VERIFY_WRITE, to, n))
20060 + n = __copy_to_user(to, from, n);
20061
20062 return n;
20063 }
20064 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20065 index 3c03a5d..1071638 100644
20066 --- a/arch/x86/include/asm/uaccess_32.h
20067 +++ b/arch/x86/include/asm/uaccess_32.h
20068 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20069 static __always_inline unsigned long __must_check
20070 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20071 {
20072 + if ((long)n < 0)
20073 + return n;
20074 +
20075 + check_object_size(from, n, true);
20076 +
20077 if (__builtin_constant_p(n)) {
20078 unsigned long ret;
20079
20080 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20081 __copy_to_user(void __user *to, const void *from, unsigned long n)
20082 {
20083 might_fault();
20084 +
20085 return __copy_to_user_inatomic(to, from, n);
20086 }
20087
20088 static __always_inline unsigned long
20089 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20090 {
20091 + if ((long)n < 0)
20092 + return n;
20093 +
20094 /* Avoid zeroing the tail if the copy fails..
20095 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20096 * but as the zeroing behaviour is only significant when n is not
20097 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20098 __copy_from_user(void *to, const void __user *from, unsigned long n)
20099 {
20100 might_fault();
20101 +
20102 + if ((long)n < 0)
20103 + return n;
20104 +
20105 + check_object_size(to, n, false);
20106 +
20107 if (__builtin_constant_p(n)) {
20108 unsigned long ret;
20109
20110 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20111 const void __user *from, unsigned long n)
20112 {
20113 might_fault();
20114 +
20115 + if ((long)n < 0)
20116 + return n;
20117 +
20118 if (__builtin_constant_p(n)) {
20119 unsigned long ret;
20120
20121 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20122 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20123 unsigned long n)
20124 {
20125 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20126 + if ((long)n < 0)
20127 + return n;
20128 +
20129 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20130 }
20131
20132 #endif /* _ASM_X86_UACCESS_32_H */
20133 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20134 index 12a26b9..206c200 100644
20135 --- a/arch/x86/include/asm/uaccess_64.h
20136 +++ b/arch/x86/include/asm/uaccess_64.h
20137 @@ -10,6 +10,9 @@
20138 #include <asm/alternative.h>
20139 #include <asm/cpufeature.h>
20140 #include <asm/page.h>
20141 +#include <asm/pgtable.h>
20142 +
20143 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20144
20145 /*
20146 * Copy To/From Userspace
20147 @@ -17,14 +20,14 @@
20148
20149 /* Handles exceptions in both to and from, but doesn't do access_ok */
20150 __must_check unsigned long
20151 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20152 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20153 __must_check unsigned long
20154 -copy_user_generic_string(void *to, const void *from, unsigned len);
20155 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20156 __must_check unsigned long
20157 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20158 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20159
20160 static __always_inline __must_check unsigned long
20161 -copy_user_generic(void *to, const void *from, unsigned len)
20162 +copy_user_generic(void *to, const void *from, unsigned long len)
20163 {
20164 unsigned ret;
20165
20166 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20167 }
20168
20169 __must_check unsigned long
20170 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20171 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20172
20173 static __always_inline __must_check
20174 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20175 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20176 {
20177 - int ret = 0;
20178 + size_t sz = __compiletime_object_size(dst);
20179 + unsigned ret = 0;
20180 +
20181 + if (size > INT_MAX)
20182 + return size;
20183 +
20184 + check_object_size(dst, size, false);
20185 +
20186 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20187 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20188 + return size;
20189 +#endif
20190 +
20191 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20192 + if(__builtin_constant_p(size))
20193 + copy_from_user_overflow();
20194 + else
20195 + __copy_from_user_overflow(sz, size);
20196 + return size;
20197 + }
20198
20199 if (!__builtin_constant_p(size))
20200 - return copy_user_generic(dst, (__force void *)src, size);
20201 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20202 switch (size) {
20203 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20204 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20205 ret, "b", "b", "=q", 1);
20206 return ret;
20207 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20208 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20209 ret, "w", "w", "=r", 2);
20210 return ret;
20211 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20212 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20213 ret, "l", "k", "=r", 4);
20214 return ret;
20215 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20216 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20217 ret, "q", "", "=r", 8);
20218 return ret;
20219 case 10:
20220 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20221 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20222 ret, "q", "", "=r", 10);
20223 if (unlikely(ret))
20224 return ret;
20225 __get_user_asm(*(u16 *)(8 + (char *)dst),
20226 - (u16 __user *)(8 + (char __user *)src),
20227 + (const u16 __user *)(8 + (const char __user *)src),
20228 ret, "w", "w", "=r", 2);
20229 return ret;
20230 case 16:
20231 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20232 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20233 ret, "q", "", "=r", 16);
20234 if (unlikely(ret))
20235 return ret;
20236 __get_user_asm(*(u64 *)(8 + (char *)dst),
20237 - (u64 __user *)(8 + (char __user *)src),
20238 + (const u64 __user *)(8 + (const char __user *)src),
20239 ret, "q", "", "=r", 8);
20240 return ret;
20241 default:
20242 - return copy_user_generic(dst, (__force void *)src, size);
20243 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20244 }
20245 }
20246
20247 static __always_inline __must_check
20248 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20249 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20250 {
20251 might_fault();
20252 return __copy_from_user_nocheck(dst, src, size);
20253 }
20254
20255 static __always_inline __must_check
20256 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20257 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20258 {
20259 - int ret = 0;
20260 + size_t sz = __compiletime_object_size(src);
20261 + unsigned ret = 0;
20262 +
20263 + if (size > INT_MAX)
20264 + return size;
20265 +
20266 + check_object_size(src, size, true);
20267 +
20268 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20269 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20270 + return size;
20271 +#endif
20272 +
20273 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20274 + if(__builtin_constant_p(size))
20275 + copy_to_user_overflow();
20276 + else
20277 + __copy_to_user_overflow(sz, size);
20278 + return size;
20279 + }
20280
20281 if (!__builtin_constant_p(size))
20282 - return copy_user_generic((__force void *)dst, src, size);
20283 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20284 switch (size) {
20285 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20286 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20287 ret, "b", "b", "iq", 1);
20288 return ret;
20289 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20290 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20291 ret, "w", "w", "ir", 2);
20292 return ret;
20293 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20294 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20295 ret, "l", "k", "ir", 4);
20296 return ret;
20297 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20298 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20299 ret, "q", "", "er", 8);
20300 return ret;
20301 case 10:
20302 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20303 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20304 ret, "q", "", "er", 10);
20305 if (unlikely(ret))
20306 return ret;
20307 asm("":::"memory");
20308 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20309 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20310 ret, "w", "w", "ir", 2);
20311 return ret;
20312 case 16:
20313 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20314 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20315 ret, "q", "", "er", 16);
20316 if (unlikely(ret))
20317 return ret;
20318 asm("":::"memory");
20319 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20320 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20321 ret, "q", "", "er", 8);
20322 return ret;
20323 default:
20324 - return copy_user_generic((__force void *)dst, src, size);
20325 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20326 }
20327 }
20328
20329 static __always_inline __must_check
20330 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20331 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20332 {
20333 might_fault();
20334 return __copy_to_user_nocheck(dst, src, size);
20335 }
20336
20337 static __always_inline __must_check
20338 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20339 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20340 {
20341 - int ret = 0;
20342 + unsigned ret = 0;
20343
20344 might_fault();
20345 +
20346 + if (size > INT_MAX)
20347 + return size;
20348 +
20349 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20350 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20351 + return size;
20352 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20353 + return size;
20354 +#endif
20355 +
20356 if (!__builtin_constant_p(size))
20357 - return copy_user_generic((__force void *)dst,
20358 - (__force void *)src, size);
20359 + return copy_user_generic((__force_kernel void *)____m(dst),
20360 + (__force_kernel const void *)____m(src), size);
20361 switch (size) {
20362 case 1: {
20363 u8 tmp;
20364 - __get_user_asm(tmp, (u8 __user *)src,
20365 + __get_user_asm(tmp, (const u8 __user *)src,
20366 ret, "b", "b", "=q", 1);
20367 if (likely(!ret))
20368 __put_user_asm(tmp, (u8 __user *)dst,
20369 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20370 }
20371 case 2: {
20372 u16 tmp;
20373 - __get_user_asm(tmp, (u16 __user *)src,
20374 + __get_user_asm(tmp, (const u16 __user *)src,
20375 ret, "w", "w", "=r", 2);
20376 if (likely(!ret))
20377 __put_user_asm(tmp, (u16 __user *)dst,
20378 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20379
20380 case 4: {
20381 u32 tmp;
20382 - __get_user_asm(tmp, (u32 __user *)src,
20383 + __get_user_asm(tmp, (const u32 __user *)src,
20384 ret, "l", "k", "=r", 4);
20385 if (likely(!ret))
20386 __put_user_asm(tmp, (u32 __user *)dst,
20387 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20388 }
20389 case 8: {
20390 u64 tmp;
20391 - __get_user_asm(tmp, (u64 __user *)src,
20392 + __get_user_asm(tmp, (const u64 __user *)src,
20393 ret, "q", "", "=r", 8);
20394 if (likely(!ret))
20395 __put_user_asm(tmp, (u64 __user *)dst,
20396 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20397 return ret;
20398 }
20399 default:
20400 - return copy_user_generic((__force void *)dst,
20401 - (__force void *)src, size);
20402 + return copy_user_generic((__force_kernel void *)____m(dst),
20403 + (__force_kernel const void *)____m(src), size);
20404 }
20405 }
20406
20407 -static __must_check __always_inline int
20408 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20409 +static __must_check __always_inline unsigned long
20410 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20411 {
20412 return __copy_from_user_nocheck(dst, src, size);
20413 }
20414
20415 -static __must_check __always_inline int
20416 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20417 +static __must_check __always_inline unsigned long
20418 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20419 {
20420 return __copy_to_user_nocheck(dst, src, size);
20421 }
20422
20423 -extern long __copy_user_nocache(void *dst, const void __user *src,
20424 - unsigned size, int zerorest);
20425 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20426 + unsigned long size, int zerorest);
20427
20428 -static inline int
20429 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20430 +static inline unsigned long
20431 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20432 {
20433 might_fault();
20434 +
20435 + if (size > INT_MAX)
20436 + return size;
20437 +
20438 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20439 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20440 + return size;
20441 +#endif
20442 +
20443 return __copy_user_nocache(dst, src, size, 1);
20444 }
20445
20446 -static inline int
20447 +static inline unsigned long
20448 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20449 - unsigned size)
20450 + unsigned long size)
20451 {
20452 + if (size > INT_MAX)
20453 + return size;
20454 +
20455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20456 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20457 + return size;
20458 +#endif
20459 +
20460 return __copy_user_nocache(dst, src, size, 0);
20461 }
20462
20463 unsigned long
20464 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20465 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20466
20467 #endif /* _ASM_X86_UACCESS_64_H */
20468 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20469 index 5b238981..77fdd78 100644
20470 --- a/arch/x86/include/asm/word-at-a-time.h
20471 +++ b/arch/x86/include/asm/word-at-a-time.h
20472 @@ -11,7 +11,7 @@
20473 * and shift, for example.
20474 */
20475 struct word_at_a_time {
20476 - const unsigned long one_bits, high_bits;
20477 + unsigned long one_bits, high_bits;
20478 };
20479
20480 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20481 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20482 index e45e4da..44e8572 100644
20483 --- a/arch/x86/include/asm/x86_init.h
20484 +++ b/arch/x86/include/asm/x86_init.h
20485 @@ -129,7 +129,7 @@ struct x86_init_ops {
20486 struct x86_init_timers timers;
20487 struct x86_init_iommu iommu;
20488 struct x86_init_pci pci;
20489 -};
20490 +} __no_const;
20491
20492 /**
20493 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20494 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20495 void (*setup_percpu_clockev)(void);
20496 void (*early_percpu_clock_init)(void);
20497 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20498 -};
20499 +} __no_const;
20500
20501 struct timespec;
20502
20503 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20504 void (*save_sched_clock_state)(void);
20505 void (*restore_sched_clock_state)(void);
20506 void (*apic_post_init)(void);
20507 -};
20508 +} __no_const;
20509
20510 struct pci_dev;
20511 struct msi_msg;
20512 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20513 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20514 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20515 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20516 -};
20517 +} __no_const;
20518
20519 struct IO_APIC_route_entry;
20520 struct io_apic_irq_attr;
20521 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20522 unsigned int destination, int vector,
20523 struct io_apic_irq_attr *attr);
20524 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20525 -};
20526 +} __no_const;
20527
20528 extern struct x86_init_ops x86_init;
20529 extern struct x86_cpuinit_ops x86_cpuinit;
20530 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20531 index c949923..c22bfa4 100644
20532 --- a/arch/x86/include/asm/xen/page.h
20533 +++ b/arch/x86/include/asm/xen/page.h
20534 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20535 extern struct page *m2p_find_override(unsigned long mfn);
20536 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20537
20538 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20539 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20540 {
20541 unsigned long mfn;
20542
20543 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20544 index 7e7a79a..0824666 100644
20545 --- a/arch/x86/include/asm/xsave.h
20546 +++ b/arch/x86/include/asm/xsave.h
20547 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20548 if (unlikely(err))
20549 return -EFAULT;
20550
20551 + pax_open_userland();
20552 __asm__ __volatile__(ASM_STAC "\n"
20553 - "1:"XSAVE"\n"
20554 + "1:"
20555 + __copyuser_seg
20556 + XSAVE"\n"
20557 "2: " ASM_CLAC "\n"
20558 xstate_fault
20559 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20560 : "memory");
20561 + pax_close_userland();
20562 return err;
20563 }
20564
20565 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20566 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20567 {
20568 int err = 0;
20569 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20570 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20571 u32 lmask = mask;
20572 u32 hmask = mask >> 32;
20573
20574 + pax_open_userland();
20575 __asm__ __volatile__(ASM_STAC "\n"
20576 - "1:"XRSTOR"\n"
20577 + "1:"
20578 + __copyuser_seg
20579 + XRSTOR"\n"
20580 "2: " ASM_CLAC "\n"
20581 xstate_fault
20582 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20583 : "memory"); /* memory required? */
20584 + pax_close_userland();
20585 return err;
20586 }
20587
20588 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20589 index d993e33..8db1b18 100644
20590 --- a/arch/x86/include/uapi/asm/e820.h
20591 +++ b/arch/x86/include/uapi/asm/e820.h
20592 @@ -58,7 +58,7 @@ struct e820map {
20593 #define ISA_START_ADDRESS 0xa0000
20594 #define ISA_END_ADDRESS 0x100000
20595
20596 -#define BIOS_BEGIN 0x000a0000
20597 +#define BIOS_BEGIN 0x000c0000
20598 #define BIOS_END 0x00100000
20599
20600 #define BIOS_ROM_BASE 0xffe00000
20601 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20602 index 7b0a55a..ad115bf 100644
20603 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20604 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20605 @@ -49,7 +49,6 @@
20606 #define EFLAGS 144
20607 #define RSP 152
20608 #define SS 160
20609 -#define ARGOFFSET R11
20610 #endif /* __ASSEMBLY__ */
20611
20612 /* top of stack page */
20613 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20614 index 8f1e774..9b4c381 100644
20615 --- a/arch/x86/kernel/Makefile
20616 +++ b/arch/x86/kernel/Makefile
20617 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20618 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20619 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20620 obj-y += probe_roms.o
20621 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20622 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20623 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20624 obj-$(CONFIG_X86_64) += mcount_64.o
20625 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20626 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20627 index a142e77..6222cdd 100644
20628 --- a/arch/x86/kernel/acpi/boot.c
20629 +++ b/arch/x86/kernel/acpi/boot.c
20630 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20631 * If your system is blacklisted here, but you find that acpi=force
20632 * works for you, please contact linux-acpi@vger.kernel.org
20633 */
20634 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20635 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20636 /*
20637 * Boxes that need ACPI disabled
20638 */
20639 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20640 };
20641
20642 /* second table for DMI checks that should run after early-quirks */
20643 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20644 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20645 /*
20646 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20647 * which includes some code which overrides all temperature
20648 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20649 index 3136820..e2c6577 100644
20650 --- a/arch/x86/kernel/acpi/sleep.c
20651 +++ b/arch/x86/kernel/acpi/sleep.c
20652 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20653 #else /* CONFIG_64BIT */
20654 #ifdef CONFIG_SMP
20655 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20656 +
20657 + pax_open_kernel();
20658 early_gdt_descr.address =
20659 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20660 + pax_close_kernel();
20661 +
20662 initial_gs = per_cpu_offset(smp_processor_id());
20663 #endif
20664 initial_code = (unsigned long)wakeup_long64;
20665 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20666 index 665c6b7..eae4d56 100644
20667 --- a/arch/x86/kernel/acpi/wakeup_32.S
20668 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20669 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20670 # and restore the stack ... but you need gdt for this to work
20671 movl saved_context_esp, %esp
20672
20673 - movl %cs:saved_magic, %eax
20674 - cmpl $0x12345678, %eax
20675 + cmpl $0x12345678, saved_magic
20676 jne bogus_magic
20677
20678 # jump to place where we left off
20679 - movl saved_eip, %eax
20680 - jmp *%eax
20681 + jmp *(saved_eip)
20682
20683 bogus_magic:
20684 jmp bogus_magic
20685 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20686 index 703130f..27a155d 100644
20687 --- a/arch/x86/kernel/alternative.c
20688 +++ b/arch/x86/kernel/alternative.c
20689 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20690 */
20691 for (a = start; a < end; a++) {
20692 instr = (u8 *)&a->instr_offset + a->instr_offset;
20693 +
20694 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20695 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20696 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20697 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20698 +#endif
20699 +
20700 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20701 BUG_ON(a->replacementlen > a->instrlen);
20702 BUG_ON(a->instrlen > sizeof(insnbuf));
20703 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20704 add_nops(insnbuf + a->replacementlen,
20705 a->instrlen - a->replacementlen);
20706
20707 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20708 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20709 + instr = ktva_ktla(instr);
20710 +#endif
20711 +
20712 text_poke_early(instr, insnbuf, a->instrlen);
20713 }
20714 }
20715 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20716 for (poff = start; poff < end; poff++) {
20717 u8 *ptr = (u8 *)poff + *poff;
20718
20719 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20720 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20721 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20722 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20723 +#endif
20724 +
20725 if (!*poff || ptr < text || ptr >= text_end)
20726 continue;
20727 /* turn DS segment override prefix into lock prefix */
20728 - if (*ptr == 0x3e)
20729 + if (*ktla_ktva(ptr) == 0x3e)
20730 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20731 }
20732 mutex_unlock(&text_mutex);
20733 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20734 for (poff = start; poff < end; poff++) {
20735 u8 *ptr = (u8 *)poff + *poff;
20736
20737 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20738 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20739 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20740 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20741 +#endif
20742 +
20743 if (!*poff || ptr < text || ptr >= text_end)
20744 continue;
20745 /* turn lock prefix into DS segment override prefix */
20746 - if (*ptr == 0xf0)
20747 + if (*ktla_ktva(ptr) == 0xf0)
20748 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20749 }
20750 mutex_unlock(&text_mutex);
20751 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20752
20753 BUG_ON(p->len > MAX_PATCH_LEN);
20754 /* prep the buffer with the original instructions */
20755 - memcpy(insnbuf, p->instr, p->len);
20756 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20757 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20758 (unsigned long)p->instr, p->len);
20759
20760 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20761 if (!uniproc_patched || num_possible_cpus() == 1)
20762 free_init_pages("SMP alternatives",
20763 (unsigned long)__smp_locks,
20764 - (unsigned long)__smp_locks_end);
20765 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20766 #endif
20767
20768 apply_paravirt(__parainstructions, __parainstructions_end);
20769 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20770 * instructions. And on the local CPU you need to be protected again NMI or MCE
20771 * handlers seeing an inconsistent instruction while you patch.
20772 */
20773 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20774 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20775 size_t len)
20776 {
20777 unsigned long flags;
20778 local_irq_save(flags);
20779 - memcpy(addr, opcode, len);
20780 +
20781 + pax_open_kernel();
20782 + memcpy(ktla_ktva(addr), opcode, len);
20783 sync_core();
20784 + pax_close_kernel();
20785 +
20786 local_irq_restore(flags);
20787 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20788 that causes hangs on some VIA CPUs. */
20789 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20790 */
20791 void *text_poke(void *addr, const void *opcode, size_t len)
20792 {
20793 - unsigned long flags;
20794 - char *vaddr;
20795 + unsigned char *vaddr = ktla_ktva(addr);
20796 struct page *pages[2];
20797 - int i;
20798 + size_t i;
20799
20800 if (!core_kernel_text((unsigned long)addr)) {
20801 - pages[0] = vmalloc_to_page(addr);
20802 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20803 + pages[0] = vmalloc_to_page(vaddr);
20804 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20805 } else {
20806 - pages[0] = virt_to_page(addr);
20807 + pages[0] = virt_to_page(vaddr);
20808 WARN_ON(!PageReserved(pages[0]));
20809 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20810 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20811 }
20812 BUG_ON(!pages[0]);
20813 - local_irq_save(flags);
20814 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20815 - if (pages[1])
20816 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20817 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20818 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20819 - clear_fixmap(FIX_TEXT_POKE0);
20820 - if (pages[1])
20821 - clear_fixmap(FIX_TEXT_POKE1);
20822 - local_flush_tlb();
20823 - sync_core();
20824 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20825 - that causes hangs on some VIA CPUs. */
20826 + text_poke_early(addr, opcode, len);
20827 for (i = 0; i < len; i++)
20828 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20829 - local_irq_restore(flags);
20830 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20831 return addr;
20832 }
20833
20834 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20835 if (likely(!bp_patching_in_progress))
20836 return 0;
20837
20838 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20839 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20840 return 0;
20841
20842 /* set up the specified breakpoint handler */
20843 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20844 */
20845 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20846 {
20847 - unsigned char int3 = 0xcc;
20848 + const unsigned char int3 = 0xcc;
20849
20850 bp_int3_handler = handler;
20851 bp_int3_addr = (u8 *)addr + sizeof(int3);
20852 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20853 index ba6cc04..06fd971 100644
20854 --- a/arch/x86/kernel/apic/apic.c
20855 +++ b/arch/x86/kernel/apic/apic.c
20856 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20857 /*
20858 * Debug level, exported for io_apic.c
20859 */
20860 -unsigned int apic_verbosity;
20861 +int apic_verbosity;
20862
20863 int pic_mode;
20864
20865 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20866 apic_write(APIC_ESR, 0);
20867 v = apic_read(APIC_ESR);
20868 ack_APIC_irq();
20869 - atomic_inc(&irq_err_count);
20870 + atomic_inc_unchecked(&irq_err_count);
20871
20872 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20873 smp_processor_id(), v);
20874 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20875 index de918c4..32eed23 100644
20876 --- a/arch/x86/kernel/apic/apic_flat_64.c
20877 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20878 @@ -154,7 +154,7 @@ static int flat_probe(void)
20879 return 1;
20880 }
20881
20882 -static struct apic apic_flat = {
20883 +static struct apic apic_flat __read_only = {
20884 .name = "flat",
20885 .probe = flat_probe,
20886 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20887 @@ -260,7 +260,7 @@ static int physflat_probe(void)
20888 return 0;
20889 }
20890
20891 -static struct apic apic_physflat = {
20892 +static struct apic apic_physflat __read_only = {
20893
20894 .name = "physical flat",
20895 .probe = physflat_probe,
20896 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20897 index b205cdb..d8503ff 100644
20898 --- a/arch/x86/kernel/apic/apic_noop.c
20899 +++ b/arch/x86/kernel/apic/apic_noop.c
20900 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20901 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20902 }
20903
20904 -struct apic apic_noop = {
20905 +struct apic apic_noop __read_only = {
20906 .name = "noop",
20907 .probe = noop_probe,
20908 .acpi_madt_oem_check = NULL,
20909 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20910 index c4a8d63..fe893ac 100644
20911 --- a/arch/x86/kernel/apic/bigsmp_32.c
20912 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20913 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20914 return dmi_bigsmp;
20915 }
20916
20917 -static struct apic apic_bigsmp = {
20918 +static struct apic apic_bigsmp __read_only = {
20919
20920 .name = "bigsmp",
20921 .probe = probe_bigsmp,
20922 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20923 index 1183d54..6158e47 100644
20924 --- a/arch/x86/kernel/apic/io_apic.c
20925 +++ b/arch/x86/kernel/apic/io_apic.c
20926 @@ -1230,7 +1230,7 @@ out:
20927 }
20928 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20929
20930 -void lock_vector_lock(void)
20931 +void lock_vector_lock(void) __acquires(vector_lock)
20932 {
20933 /* Used to the online set of cpus does not change
20934 * during assign_irq_vector.
20935 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20936 raw_spin_lock(&vector_lock);
20937 }
20938
20939 -void unlock_vector_lock(void)
20940 +void unlock_vector_lock(void) __releases(vector_lock)
20941 {
20942 raw_spin_unlock(&vector_lock);
20943 }
20944 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20945 ack_APIC_irq();
20946 }
20947
20948 -atomic_t irq_mis_count;
20949 +atomic_unchecked_t irq_mis_count;
20950
20951 #ifdef CONFIG_GENERIC_PENDING_IRQ
20952 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20953 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20954 * at the cpu.
20955 */
20956 if (!(v & (1 << (i & 0x1f)))) {
20957 - atomic_inc(&irq_mis_count);
20958 + atomic_inc_unchecked(&irq_mis_count);
20959
20960 eoi_ioapic_irq(irq, cfg);
20961 }
20962 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20963 index bda4886..f9c7195 100644
20964 --- a/arch/x86/kernel/apic/probe_32.c
20965 +++ b/arch/x86/kernel/apic/probe_32.c
20966 @@ -72,7 +72,7 @@ static int probe_default(void)
20967 return 1;
20968 }
20969
20970 -static struct apic apic_default = {
20971 +static struct apic apic_default __read_only = {
20972
20973 .name = "default",
20974 .probe = probe_default,
20975 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20976 index e658f21..b695a1a 100644
20977 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20978 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20979 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20980 return notifier_from_errno(err);
20981 }
20982
20983 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20984 +static struct notifier_block x2apic_cpu_notifier = {
20985 .notifier_call = update_clusterinfo,
20986 };
20987
20988 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20989 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20990 }
20991
20992 -static struct apic apic_x2apic_cluster = {
20993 +static struct apic apic_x2apic_cluster __read_only = {
20994
20995 .name = "cluster x2apic",
20996 .probe = x2apic_cluster_probe,
20997 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20998 index 6fae733..5ca17af 100644
20999 --- a/arch/x86/kernel/apic/x2apic_phys.c
21000 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21001 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21002 return apic == &apic_x2apic_phys;
21003 }
21004
21005 -static struct apic apic_x2apic_phys = {
21006 +static struct apic apic_x2apic_phys __read_only = {
21007
21008 .name = "physical x2apic",
21009 .probe = x2apic_phys_probe,
21010 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21011 index 8e9dcfd..c61b3e4 100644
21012 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21013 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21014 @@ -348,7 +348,7 @@ static int uv_probe(void)
21015 return apic == &apic_x2apic_uv_x;
21016 }
21017
21018 -static struct apic __refdata apic_x2apic_uv_x = {
21019 +static struct apic apic_x2apic_uv_x __read_only = {
21020
21021 .name = "UV large system",
21022 .probe = uv_probe,
21023 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21024 index 5848744..56cb598 100644
21025 --- a/arch/x86/kernel/apm_32.c
21026 +++ b/arch/x86/kernel/apm_32.c
21027 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21028 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21029 * even though they are called in protected mode.
21030 */
21031 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21032 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21033 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21034
21035 static const char driver_version[] = "1.16ac"; /* no spaces */
21036 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21037 BUG_ON(cpu != 0);
21038 gdt = get_cpu_gdt_table(cpu);
21039 save_desc_40 = gdt[0x40 / 8];
21040 +
21041 + pax_open_kernel();
21042 gdt[0x40 / 8] = bad_bios_desc;
21043 + pax_close_kernel();
21044
21045 apm_irq_save(flags);
21046 APM_DO_SAVE_SEGS;
21047 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21048 &call->esi);
21049 APM_DO_RESTORE_SEGS;
21050 apm_irq_restore(flags);
21051 +
21052 + pax_open_kernel();
21053 gdt[0x40 / 8] = save_desc_40;
21054 + pax_close_kernel();
21055 +
21056 put_cpu();
21057
21058 return call->eax & 0xff;
21059 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21060 BUG_ON(cpu != 0);
21061 gdt = get_cpu_gdt_table(cpu);
21062 save_desc_40 = gdt[0x40 / 8];
21063 +
21064 + pax_open_kernel();
21065 gdt[0x40 / 8] = bad_bios_desc;
21066 + pax_close_kernel();
21067
21068 apm_irq_save(flags);
21069 APM_DO_SAVE_SEGS;
21070 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21071 &call->eax);
21072 APM_DO_RESTORE_SEGS;
21073 apm_irq_restore(flags);
21074 +
21075 + pax_open_kernel();
21076 gdt[0x40 / 8] = save_desc_40;
21077 + pax_close_kernel();
21078 +
21079 put_cpu();
21080 return error;
21081 }
21082 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21083 * code to that CPU.
21084 */
21085 gdt = get_cpu_gdt_table(0);
21086 +
21087 + pax_open_kernel();
21088 set_desc_base(&gdt[APM_CS >> 3],
21089 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21090 set_desc_base(&gdt[APM_CS_16 >> 3],
21091 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21092 set_desc_base(&gdt[APM_DS >> 3],
21093 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21094 + pax_close_kernel();
21095
21096 proc_create("apm", 0, NULL, &apm_file_ops);
21097
21098 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21099 index 9f6b934..cf5ffb3 100644
21100 --- a/arch/x86/kernel/asm-offsets.c
21101 +++ b/arch/x86/kernel/asm-offsets.c
21102 @@ -32,6 +32,8 @@ void common(void) {
21103 OFFSET(TI_flags, thread_info, flags);
21104 OFFSET(TI_status, thread_info, status);
21105 OFFSET(TI_addr_limit, thread_info, addr_limit);
21106 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21107 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21108
21109 BLANK();
21110 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21111 @@ -52,8 +54,26 @@ void common(void) {
21112 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21113 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21114 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21115 +
21116 +#ifdef CONFIG_PAX_KERNEXEC
21117 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21118 #endif
21119
21120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21121 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21122 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21123 +#ifdef CONFIG_X86_64
21124 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21125 +#endif
21126 +#endif
21127 +
21128 +#endif
21129 +
21130 + BLANK();
21131 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21132 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21133 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21134 +
21135 #ifdef CONFIG_XEN
21136 BLANK();
21137 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21138 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21139 index e7c798b..2b2019b 100644
21140 --- a/arch/x86/kernel/asm-offsets_64.c
21141 +++ b/arch/x86/kernel/asm-offsets_64.c
21142 @@ -77,6 +77,7 @@ int main(void)
21143 BLANK();
21144 #undef ENTRY
21145
21146 + DEFINE(TSS_size, sizeof(struct tss_struct));
21147 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21148 BLANK();
21149
21150 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21151 index 80091ae..0c5184f 100644
21152 --- a/arch/x86/kernel/cpu/Makefile
21153 +++ b/arch/x86/kernel/cpu/Makefile
21154 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21155 CFLAGS_REMOVE_perf_event.o = -pg
21156 endif
21157
21158 -# Make sure load_percpu_segment has no stackprotector
21159 -nostackp := $(call cc-option, -fno-stack-protector)
21160 -CFLAGS_common.o := $(nostackp)
21161 -
21162 obj-y := intel_cacheinfo.o scattered.o topology.o
21163 obj-y += common.o
21164 obj-y += rdrand.o
21165 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21166 index 813d29d..6e542d4 100644
21167 --- a/arch/x86/kernel/cpu/amd.c
21168 +++ b/arch/x86/kernel/cpu/amd.c
21169 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21170 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21171 {
21172 /* AMD errata T13 (order #21922) */
21173 - if ((c->x86 == 6)) {
21174 + if (c->x86 == 6) {
21175 /* Duron Rev A0 */
21176 if (c->x86_model == 3 && c->x86_mask == 0)
21177 size = 64;
21178 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21179 index cfa9b5b..19b5084 100644
21180 --- a/arch/x86/kernel/cpu/common.c
21181 +++ b/arch/x86/kernel/cpu/common.c
21182 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21183
21184 static const struct cpu_dev *this_cpu = &default_cpu;
21185
21186 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21187 -#ifdef CONFIG_X86_64
21188 - /*
21189 - * We need valid kernel segments for data and code in long mode too
21190 - * IRET will check the segment types kkeil 2000/10/28
21191 - * Also sysret mandates a special GDT layout
21192 - *
21193 - * TLS descriptors are currently at a different place compared to i386.
21194 - * Hopefully nobody expects them at a fixed place (Wine?)
21195 - */
21196 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21197 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21198 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21199 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21200 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21201 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21202 -#else
21203 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21204 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21205 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21206 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21207 - /*
21208 - * Segments used for calling PnP BIOS have byte granularity.
21209 - * They code segments and data segments have fixed 64k limits,
21210 - * the transfer segment sizes are set at run time.
21211 - */
21212 - /* 32-bit code */
21213 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21214 - /* 16-bit code */
21215 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21216 - /* 16-bit data */
21217 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21218 - /* 16-bit data */
21219 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21220 - /* 16-bit data */
21221 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21222 - /*
21223 - * The APM segments have byte granularity and their bases
21224 - * are set at run time. All have 64k limits.
21225 - */
21226 - /* 32-bit code */
21227 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21228 - /* 16-bit code */
21229 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21230 - /* data */
21231 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21232 -
21233 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21234 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21235 - GDT_STACK_CANARY_INIT
21236 -#endif
21237 -} };
21238 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21239 -
21240 static int __init x86_xsave_setup(char *s)
21241 {
21242 if (strlen(s))
21243 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21244 }
21245 }
21246
21247 +#ifdef CONFIG_X86_64
21248 +static __init int setup_disable_pcid(char *arg)
21249 +{
21250 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21251 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21252 +
21253 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21254 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21255 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21256 +#endif
21257 +
21258 + return 1;
21259 +}
21260 +__setup("nopcid", setup_disable_pcid);
21261 +
21262 +static void setup_pcid(struct cpuinfo_x86 *c)
21263 +{
21264 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21265 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21266 +
21267 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21268 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21269 + pax_open_kernel();
21270 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21271 + pax_close_kernel();
21272 + printk("PAX: slow and weak UDEREF enabled\n");
21273 + } else
21274 + printk("PAX: UDEREF disabled\n");
21275 +#endif
21276 +
21277 + return;
21278 + }
21279 +
21280 + printk("PAX: PCID detected\n");
21281 + set_in_cr4(X86_CR4_PCIDE);
21282 +
21283 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21284 + pax_open_kernel();
21285 + clone_pgd_mask = ~(pgdval_t)0UL;
21286 + pax_close_kernel();
21287 + if (pax_user_shadow_base)
21288 + printk("PAX: weak UDEREF enabled\n");
21289 + else {
21290 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21291 + printk("PAX: strong UDEREF enabled\n");
21292 + }
21293 +#endif
21294 +
21295 + if (cpu_has(c, X86_FEATURE_INVPCID))
21296 + printk("PAX: INVPCID detected\n");
21297 +}
21298 +#endif
21299 +
21300 /*
21301 * Some CPU features depend on higher CPUID levels, which may not always
21302 * be available due to CPUID level capping or broken virtualization
21303 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21304 {
21305 struct desc_ptr gdt_descr;
21306
21307 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21308 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21309 gdt_descr.size = GDT_SIZE - 1;
21310 load_gdt(&gdt_descr);
21311 /* Reload the per-cpu base */
21312 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21313 setup_smep(c);
21314 setup_smap(c);
21315
21316 +#ifdef CONFIG_X86_64
21317 + setup_pcid(c);
21318 +#endif
21319 +
21320 /*
21321 * The vendor-specific functions might have changed features.
21322 * Now we do "generic changes."
21323 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21324 /* Filter out anything that depends on CPUID levels we don't have */
21325 filter_cpuid_features(c, true);
21326
21327 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21328 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21329 +#endif
21330 +
21331 /* If the model name is still unset, do table lookup. */
21332 if (!c->x86_model_id[0]) {
21333 const char *p;
21334 @@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21335 void enable_sep_cpu(void)
21336 {
21337 int cpu = get_cpu();
21338 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21339 + struct tss_struct *tss = init_tss + cpu;
21340
21341 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21342 put_cpu();
21343 @@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21344 }
21345 __setup("clearcpuid=", setup_disablecpuid);
21346
21347 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21348 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21349 +
21350 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21351 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21352 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21353 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21354
21355 #ifdef CONFIG_X86_64
21356 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21357 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21358 - (unsigned long) debug_idt_table };
21359 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21360 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21361
21362 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21363 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21364 @@ -1309,7 +1318,7 @@ void cpu_init(void)
21365 */
21366 load_ucode_ap();
21367
21368 - t = &per_cpu(init_tss, cpu);
21369 + t = init_tss + cpu;
21370 oist = &per_cpu(orig_ist, cpu);
21371
21372 #ifdef CONFIG_NUMA
21373 @@ -1341,7 +1350,6 @@ void cpu_init(void)
21374 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21375 barrier();
21376
21377 - x86_configure_nx();
21378 enable_x2apic();
21379
21380 /*
21381 @@ -1393,7 +1401,7 @@ void cpu_init(void)
21382 {
21383 int cpu = smp_processor_id();
21384 struct task_struct *curr = current;
21385 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21386 + struct tss_struct *t = init_tss + cpu;
21387 struct thread_struct *thread = &curr->thread;
21388
21389 wait_for_master_cpu(cpu);
21390 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21391 index c703507..28535e3 100644
21392 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21393 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21394 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21395 };
21396
21397 #ifdef CONFIG_AMD_NB
21398 +static struct attribute *default_attrs_amd_nb[] = {
21399 + &type.attr,
21400 + &level.attr,
21401 + &coherency_line_size.attr,
21402 + &physical_line_partition.attr,
21403 + &ways_of_associativity.attr,
21404 + &number_of_sets.attr,
21405 + &size.attr,
21406 + &shared_cpu_map.attr,
21407 + &shared_cpu_list.attr,
21408 + NULL,
21409 + NULL,
21410 + NULL,
21411 + NULL
21412 +};
21413 +
21414 static struct attribute **amd_l3_attrs(void)
21415 {
21416 static struct attribute **attrs;
21417 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21418
21419 n = ARRAY_SIZE(default_attrs);
21420
21421 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21422 - n += 2;
21423 -
21424 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21425 - n += 1;
21426 -
21427 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21428 - if (attrs == NULL)
21429 - return attrs = default_attrs;
21430 -
21431 - for (n = 0; default_attrs[n]; n++)
21432 - attrs[n] = default_attrs[n];
21433 + attrs = default_attrs_amd_nb;
21434
21435 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21436 attrs[n++] = &cache_disable_0.attr;
21437 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21438 .default_attrs = default_attrs,
21439 };
21440
21441 +#ifdef CONFIG_AMD_NB
21442 +static struct kobj_type ktype_cache_amd_nb = {
21443 + .sysfs_ops = &sysfs_ops,
21444 + .default_attrs = default_attrs_amd_nb,
21445 +};
21446 +#endif
21447 +
21448 static struct kobj_type ktype_percpu_entry = {
21449 .sysfs_ops = &sysfs_ops,
21450 };
21451 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21452 return retval;
21453 }
21454
21455 +#ifdef CONFIG_AMD_NB
21456 + amd_l3_attrs();
21457 +#endif
21458 +
21459 for (i = 0; i < num_cache_leaves; i++) {
21460 + struct kobj_type *ktype;
21461 +
21462 this_object = INDEX_KOBJECT_PTR(cpu, i);
21463 this_object->cpu = cpu;
21464 this_object->index = i;
21465
21466 this_leaf = CPUID4_INFO_IDX(cpu, i);
21467
21468 - ktype_cache.default_attrs = default_attrs;
21469 + ktype = &ktype_cache;
21470 #ifdef CONFIG_AMD_NB
21471 if (this_leaf->base.nb)
21472 - ktype_cache.default_attrs = amd_l3_attrs();
21473 + ktype = &ktype_cache_amd_nb;
21474 #endif
21475 retval = kobject_init_and_add(&(this_object->kobj),
21476 - &ktype_cache,
21477 + ktype,
21478 per_cpu(ici_cache_kobject, cpu),
21479 "index%1lu", i);
21480 if (unlikely(retval)) {
21481 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21482 index 61a9668ce..b446a37 100644
21483 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21484 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21485 @@ -45,6 +45,7 @@
21486 #include <asm/processor.h>
21487 #include <asm/mce.h>
21488 #include <asm/msr.h>
21489 +#include <asm/local.h>
21490
21491 #include "mce-internal.h"
21492
21493 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21494 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21495 m->cs, m->ip);
21496
21497 - if (m->cs == __KERNEL_CS)
21498 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21499 print_symbol("{%s}", m->ip);
21500 pr_cont("\n");
21501 }
21502 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21503
21504 #define PANIC_TIMEOUT 5 /* 5 seconds */
21505
21506 -static atomic_t mce_paniced;
21507 +static atomic_unchecked_t mce_paniced;
21508
21509 static int fake_panic;
21510 -static atomic_t mce_fake_paniced;
21511 +static atomic_unchecked_t mce_fake_paniced;
21512
21513 /* Panic in progress. Enable interrupts and wait for final IPI */
21514 static void wait_for_panic(void)
21515 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21516 /*
21517 * Make sure only one CPU runs in machine check panic
21518 */
21519 - if (atomic_inc_return(&mce_paniced) > 1)
21520 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21521 wait_for_panic();
21522 barrier();
21523
21524 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21525 console_verbose();
21526 } else {
21527 /* Don't log too much for fake panic */
21528 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21529 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21530 return;
21531 }
21532 /* First print corrected ones that are still unlogged */
21533 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21534 if (!fake_panic) {
21535 if (panic_timeout == 0)
21536 panic_timeout = mca_cfg.panic_timeout;
21537 - panic(msg);
21538 + panic("%s", msg);
21539 } else
21540 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21541 }
21542 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21543 * might have been modified by someone else.
21544 */
21545 rmb();
21546 - if (atomic_read(&mce_paniced))
21547 + if (atomic_read_unchecked(&mce_paniced))
21548 wait_for_panic();
21549 if (!mca_cfg.monarch_timeout)
21550 goto out;
21551 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21552 }
21553
21554 /* Call the installed machine check handler for this CPU setup. */
21555 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21556 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21557 unexpected_machine_check;
21558
21559 /*
21560 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21561 return;
21562 }
21563
21564 + pax_open_kernel();
21565 machine_check_vector = do_machine_check;
21566 + pax_close_kernel();
21567
21568 __mcheck_cpu_init_generic();
21569 __mcheck_cpu_init_vendor(c);
21570 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21571 */
21572
21573 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21574 -static int mce_chrdev_open_count; /* #times opened */
21575 +static local_t mce_chrdev_open_count; /* #times opened */
21576 static int mce_chrdev_open_exclu; /* already open exclusive? */
21577
21578 static int mce_chrdev_open(struct inode *inode, struct file *file)
21579 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21580 spin_lock(&mce_chrdev_state_lock);
21581
21582 if (mce_chrdev_open_exclu ||
21583 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21584 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21585 spin_unlock(&mce_chrdev_state_lock);
21586
21587 return -EBUSY;
21588 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21589
21590 if (file->f_flags & O_EXCL)
21591 mce_chrdev_open_exclu = 1;
21592 - mce_chrdev_open_count++;
21593 + local_inc(&mce_chrdev_open_count);
21594
21595 spin_unlock(&mce_chrdev_state_lock);
21596
21597 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21598 {
21599 spin_lock(&mce_chrdev_state_lock);
21600
21601 - mce_chrdev_open_count--;
21602 + local_dec(&mce_chrdev_open_count);
21603 mce_chrdev_open_exclu = 0;
21604
21605 spin_unlock(&mce_chrdev_state_lock);
21606 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21607
21608 for (i = 0; i < mca_cfg.banks; i++) {
21609 struct mce_bank *b = &mce_banks[i];
21610 - struct device_attribute *a = &b->attr;
21611 + device_attribute_no_const *a = &b->attr;
21612
21613 sysfs_attr_init(&a->attr);
21614 a->attr.name = b->attrname;
21615 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21616 static void mce_reset(void)
21617 {
21618 cpu_missing = 0;
21619 - atomic_set(&mce_fake_paniced, 0);
21620 + atomic_set_unchecked(&mce_fake_paniced, 0);
21621 atomic_set(&mce_executing, 0);
21622 atomic_set(&mce_callin, 0);
21623 atomic_set(&global_nwo, 0);
21624 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21625 index a304298..49b6d06 100644
21626 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21627 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21628 @@ -10,6 +10,7 @@
21629 #include <asm/processor.h>
21630 #include <asm/mce.h>
21631 #include <asm/msr.h>
21632 +#include <asm/pgtable.h>
21633
21634 /* By default disabled */
21635 int mce_p5_enabled __read_mostly;
21636 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21637 if (!cpu_has(c, X86_FEATURE_MCE))
21638 return;
21639
21640 + pax_open_kernel();
21641 machine_check_vector = pentium_machine_check;
21642 + pax_close_kernel();
21643 /* Make sure the vector pointer is visible before we enable MCEs: */
21644 wmb();
21645
21646 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21647 index 7dc5564..1273569 100644
21648 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21649 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21650 @@ -9,6 +9,7 @@
21651 #include <asm/processor.h>
21652 #include <asm/mce.h>
21653 #include <asm/msr.h>
21654 +#include <asm/pgtable.h>
21655
21656 /* Machine check handler for WinChip C6: */
21657 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21658 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21659 {
21660 u32 lo, hi;
21661
21662 + pax_open_kernel();
21663 machine_check_vector = winchip_machine_check;
21664 + pax_close_kernel();
21665 /* Make sure the vector pointer is visible before we enable MCEs: */
21666 wmb();
21667
21668 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21669 index 15c2909..2cef20c 100644
21670 --- a/arch/x86/kernel/cpu/microcode/core.c
21671 +++ b/arch/x86/kernel/cpu/microcode/core.c
21672 @@ -518,7 +518,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21673 return NOTIFY_OK;
21674 }
21675
21676 -static struct notifier_block __refdata mc_cpu_notifier = {
21677 +static struct notifier_block mc_cpu_notifier = {
21678 .notifier_call = mc_cpu_callback,
21679 };
21680
21681 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21682 index c6826d1..ad18e14a 100644
21683 --- a/arch/x86/kernel/cpu/microcode/intel.c
21684 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21685 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21686
21687 static int get_ucode_user(void *to, const void *from, size_t n)
21688 {
21689 - return copy_from_user(to, from, n);
21690 + return copy_from_user(to, (const void __force_user *)from, n);
21691 }
21692
21693 static enum ucode_state
21694 request_microcode_user(int cpu, const void __user *buf, size_t size)
21695 {
21696 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21697 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21698 }
21699
21700 static void microcode_fini_cpu(int cpu)
21701 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21702 index ea5f363..cb0e905 100644
21703 --- a/arch/x86/kernel/cpu/mtrr/main.c
21704 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21705 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21706 u64 size_or_mask, size_and_mask;
21707 static bool mtrr_aps_delayed_init;
21708
21709 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21710 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21711
21712 const struct mtrr_ops *mtrr_if;
21713
21714 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21715 index df5e41f..816c719 100644
21716 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21717 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21718 @@ -25,7 +25,7 @@ struct mtrr_ops {
21719 int (*validate_add_page)(unsigned long base, unsigned long size,
21720 unsigned int type);
21721 int (*have_wrcomb)(void);
21722 -};
21723 +} __do_const;
21724
21725 extern int generic_get_free_region(unsigned long base, unsigned long size,
21726 int replace_reg);
21727 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21728 index 143e5f5..5825081 100644
21729 --- a/arch/x86/kernel/cpu/perf_event.c
21730 +++ b/arch/x86/kernel/cpu/perf_event.c
21731 @@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21732
21733 }
21734
21735 -static struct attribute_group x86_pmu_format_group = {
21736 +static attribute_group_no_const x86_pmu_format_group = {
21737 .name = "format",
21738 .attrs = NULL,
21739 };
21740 @@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21741 NULL,
21742 };
21743
21744 -static struct attribute_group x86_pmu_events_group = {
21745 +static attribute_group_no_const x86_pmu_events_group = {
21746 .name = "events",
21747 .attrs = events_attr,
21748 };
21749 @@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21750 if (idx > GDT_ENTRIES)
21751 return 0;
21752
21753 - desc = raw_cpu_ptr(gdt_page.gdt);
21754 + desc = get_cpu_gdt_table(smp_processor_id());
21755 }
21756
21757 return get_desc_base(desc + idx);
21758 @@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21759 break;
21760
21761 perf_callchain_store(entry, frame.return_address);
21762 - fp = frame.next_frame;
21763 + fp = (const void __force_user *)frame.next_frame;
21764 }
21765 }
21766
21767 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21768 index 639d128..e92d7e5 100644
21769 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21770 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21771 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21772 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21773 {
21774 struct attribute **attrs;
21775 - struct attribute_group *attr_group;
21776 + attribute_group_no_const *attr_group;
21777 int i = 0, j;
21778
21779 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21780 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21781 index 944bf01..4a4392f 100644
21782 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21783 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21784 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21785 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21786
21787 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21788 - u64 capabilities;
21789 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21790
21791 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21792 - x86_pmu.intel_cap.capabilities = capabilities;
21793 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21794 + x86_pmu.intel_cap.capabilities = capabilities;
21795 }
21796
21797 intel_ds_init();
21798 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21799 index d64f275..26522ff 100644
21800 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21801 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21802 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21803 NULL,
21804 };
21805
21806 -static struct attribute_group rapl_pmu_events_group = {
21807 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21808 .name = "events",
21809 .attrs = NULL, /* patched at runtime */
21810 };
21811 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21812 index e98f68c..1992b15 100644
21813 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21814 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21815 @@ -737,7 +737,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21816 static int __init uncore_type_init(struct intel_uncore_type *type)
21817 {
21818 struct intel_uncore_pmu *pmus;
21819 - struct attribute_group *attr_group;
21820 + attribute_group_no_const *attr_group;
21821 struct attribute **attrs;
21822 int i, j;
21823
21824 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21825 index 863d9b0..6289b63 100644
21826 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21827 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21828 @@ -114,7 +114,7 @@ struct intel_uncore_box {
21829 struct uncore_event_desc {
21830 struct kobj_attribute attr;
21831 const char *config;
21832 -};
21833 +} __do_const;
21834
21835 ssize_t uncore_event_show(struct kobject *kobj,
21836 struct kobj_attribute *attr, char *buf);
21837 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21838 index 3225ae6c..ee3c6db 100644
21839 --- a/arch/x86/kernel/cpuid.c
21840 +++ b/arch/x86/kernel/cpuid.c
21841 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21842 return notifier_from_errno(err);
21843 }
21844
21845 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21846 +static struct notifier_block cpuid_class_cpu_notifier =
21847 {
21848 .notifier_call = cpuid_class_cpu_callback,
21849 };
21850 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21851 index f5ab56d..d3b201a 100644
21852 --- a/arch/x86/kernel/crash.c
21853 +++ b/arch/x86/kernel/crash.c
21854 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21855 #ifdef CONFIG_X86_32
21856 struct pt_regs fixed_regs;
21857
21858 - if (!user_mode_vm(regs)) {
21859 + if (!user_mode(regs)) {
21860 crash_fixup_ss_esp(&fixed_regs, regs);
21861 regs = &fixed_regs;
21862 }
21863 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21864 index afa64ad..dce67dd 100644
21865 --- a/arch/x86/kernel/crash_dump_64.c
21866 +++ b/arch/x86/kernel/crash_dump_64.c
21867 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21868 return -ENOMEM;
21869
21870 if (userbuf) {
21871 - if (copy_to_user(buf, vaddr + offset, csize)) {
21872 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21873 iounmap(vaddr);
21874 return -EFAULT;
21875 }
21876 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21877 index f6dfd93..892ade4 100644
21878 --- a/arch/x86/kernel/doublefault.c
21879 +++ b/arch/x86/kernel/doublefault.c
21880 @@ -12,7 +12,7 @@
21881
21882 #define DOUBLEFAULT_STACKSIZE (1024)
21883 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21884 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21885 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21886
21887 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21888
21889 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21890 unsigned long gdt, tss;
21891
21892 native_store_gdt(&gdt_desc);
21893 - gdt = gdt_desc.address;
21894 + gdt = (unsigned long)gdt_desc.address;
21895
21896 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21897
21898 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21899 /* 0x2 bit is always set */
21900 .flags = X86_EFLAGS_SF | 0x2,
21901 .sp = STACK_START,
21902 - .es = __USER_DS,
21903 + .es = __KERNEL_DS,
21904 .cs = __KERNEL_CS,
21905 .ss = __KERNEL_DS,
21906 - .ds = __USER_DS,
21907 + .ds = __KERNEL_DS,
21908 .fs = __KERNEL_PERCPU,
21909
21910 .__cr3 = __pa_nodebug(swapper_pg_dir),
21911 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21912 index b74ebc7..2c95874 100644
21913 --- a/arch/x86/kernel/dumpstack.c
21914 +++ b/arch/x86/kernel/dumpstack.c
21915 @@ -2,6 +2,9 @@
21916 * Copyright (C) 1991, 1992 Linus Torvalds
21917 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21918 */
21919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21920 +#define __INCLUDED_BY_HIDESYM 1
21921 +#endif
21922 #include <linux/kallsyms.h>
21923 #include <linux/kprobes.h>
21924 #include <linux/uaccess.h>
21925 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21926
21927 void printk_address(unsigned long address)
21928 {
21929 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21930 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21931 }
21932
21933 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21934 static void
21935 print_ftrace_graph_addr(unsigned long addr, void *data,
21936 const struct stacktrace_ops *ops,
21937 - struct thread_info *tinfo, int *graph)
21938 + struct task_struct *task, int *graph)
21939 {
21940 - struct task_struct *task;
21941 unsigned long ret_addr;
21942 int index;
21943
21944 if (addr != (unsigned long)return_to_handler)
21945 return;
21946
21947 - task = tinfo->task;
21948 index = task->curr_ret_stack;
21949
21950 if (!task->ret_stack || index < *graph)
21951 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21952 static inline void
21953 print_ftrace_graph_addr(unsigned long addr, void *data,
21954 const struct stacktrace_ops *ops,
21955 - struct thread_info *tinfo, int *graph)
21956 + struct task_struct *task, int *graph)
21957 { }
21958 #endif
21959
21960 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21961 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21962 */
21963
21964 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21965 - void *p, unsigned int size, void *end)
21966 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21967 {
21968 - void *t = tinfo;
21969 if (end) {
21970 if (p < end && p >= (end-THREAD_SIZE))
21971 return 1;
21972 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21973 }
21974
21975 unsigned long
21976 -print_context_stack(struct thread_info *tinfo,
21977 +print_context_stack(struct task_struct *task, void *stack_start,
21978 unsigned long *stack, unsigned long bp,
21979 const struct stacktrace_ops *ops, void *data,
21980 unsigned long *end, int *graph)
21981 {
21982 struct stack_frame *frame = (struct stack_frame *)bp;
21983
21984 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21985 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21986 unsigned long addr;
21987
21988 addr = *stack;
21989 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21990 } else {
21991 ops->address(data, addr, 0);
21992 }
21993 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21994 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21995 }
21996 stack++;
21997 }
21998 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21999 EXPORT_SYMBOL_GPL(print_context_stack);
22000
22001 unsigned long
22002 -print_context_stack_bp(struct thread_info *tinfo,
22003 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22004 unsigned long *stack, unsigned long bp,
22005 const struct stacktrace_ops *ops, void *data,
22006 unsigned long *end, int *graph)
22007 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22008 struct stack_frame *frame = (struct stack_frame *)bp;
22009 unsigned long *ret_addr = &frame->return_address;
22010
22011 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22012 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22013 unsigned long addr = *ret_addr;
22014
22015 if (!__kernel_text_address(addr))
22016 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22017 ops->address(data, addr, 1);
22018 frame = frame->next_frame;
22019 ret_addr = &frame->return_address;
22020 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22021 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22022 }
22023
22024 return (unsigned long)frame;
22025 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22026 static void print_trace_address(void *data, unsigned long addr, int reliable)
22027 {
22028 touch_nmi_watchdog();
22029 - printk(data);
22030 + printk("%s", (char *)data);
22031 printk_stack_address(addr, reliable);
22032 }
22033
22034 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22035 EXPORT_SYMBOL_GPL(oops_begin);
22036 NOKPROBE_SYMBOL(oops_begin);
22037
22038 +extern void gr_handle_kernel_exploit(void);
22039 +
22040 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22041 {
22042 if (regs && kexec_should_crash(current))
22043 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22044 panic("Fatal exception in interrupt");
22045 if (panic_on_oops)
22046 panic("Fatal exception");
22047 - do_exit(signr);
22048 +
22049 + gr_handle_kernel_exploit();
22050 +
22051 + do_group_exit(signr);
22052 }
22053 NOKPROBE_SYMBOL(oops_end);
22054
22055 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22056 print_modules();
22057 show_regs(regs);
22058 #ifdef CONFIG_X86_32
22059 - if (user_mode_vm(regs)) {
22060 + if (user_mode(regs)) {
22061 sp = regs->sp;
22062 ss = regs->ss & 0xffff;
22063 } else {
22064 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22065 unsigned long flags = oops_begin();
22066 int sig = SIGSEGV;
22067
22068 - if (!user_mode_vm(regs))
22069 + if (!user_mode(regs))
22070 report_bug(regs->ip, regs);
22071
22072 if (__die(str, regs, err))
22073 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22074 index 5abd4cd..c65733b 100644
22075 --- a/arch/x86/kernel/dumpstack_32.c
22076 +++ b/arch/x86/kernel/dumpstack_32.c
22077 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22078 bp = stack_frame(task, regs);
22079
22080 for (;;) {
22081 - struct thread_info *context;
22082 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22083 void *end_stack;
22084
22085 end_stack = is_hardirq_stack(stack, cpu);
22086 if (!end_stack)
22087 end_stack = is_softirq_stack(stack, cpu);
22088
22089 - context = task_thread_info(task);
22090 - bp = ops->walk_stack(context, stack, bp, ops, data,
22091 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22092 end_stack, &graph);
22093
22094 /* Stop if not on irq stack */
22095 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22096 int i;
22097
22098 show_regs_print_info(KERN_EMERG);
22099 - __show_regs(regs, !user_mode_vm(regs));
22100 + __show_regs(regs, !user_mode(regs));
22101
22102 /*
22103 * When in-kernel, we also print out the stack and code at the
22104 * time of the fault..
22105 */
22106 - if (!user_mode_vm(regs)) {
22107 + if (!user_mode(regs)) {
22108 unsigned int code_prologue = code_bytes * 43 / 64;
22109 unsigned int code_len = code_bytes;
22110 unsigned char c;
22111 u8 *ip;
22112 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22113
22114 pr_emerg("Stack:\n");
22115 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22116
22117 pr_emerg("Code:");
22118
22119 - ip = (u8 *)regs->ip - code_prologue;
22120 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22121 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22122 /* try starting at IP */
22123 - ip = (u8 *)regs->ip;
22124 + ip = (u8 *)regs->ip + cs_base;
22125 code_len = code_len - code_prologue + 1;
22126 }
22127 for (i = 0; i < code_len; i++, ip++) {
22128 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22129 pr_cont(" Bad EIP value.");
22130 break;
22131 }
22132 - if (ip == (u8 *)regs->ip)
22133 + if (ip == (u8 *)regs->ip + cs_base)
22134 pr_cont(" <%02x>", c);
22135 else
22136 pr_cont(" %02x", c);
22137 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22138 {
22139 unsigned short ud2;
22140
22141 + ip = ktla_ktva(ip);
22142 if (ip < PAGE_OFFSET)
22143 return 0;
22144 if (probe_kernel_address((unsigned short *)ip, ud2))
22145 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22146
22147 return ud2 == 0x0b0f;
22148 }
22149 +
22150 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22151 +void pax_check_alloca(unsigned long size)
22152 +{
22153 + unsigned long sp = (unsigned long)&sp, stack_left;
22154 +
22155 + /* all kernel stacks are of the same size */
22156 + stack_left = sp & (THREAD_SIZE - 1);
22157 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22158 +}
22159 +EXPORT_SYMBOL(pax_check_alloca);
22160 +#endif
22161 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22162 index ff86f19..73eabf4 100644
22163 --- a/arch/x86/kernel/dumpstack_64.c
22164 +++ b/arch/x86/kernel/dumpstack_64.c
22165 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22166 const struct stacktrace_ops *ops, void *data)
22167 {
22168 const unsigned cpu = get_cpu();
22169 - struct thread_info *tinfo;
22170 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22171 unsigned long dummy;
22172 unsigned used = 0;
22173 int graph = 0;
22174 int done = 0;
22175 + void *stack_start;
22176
22177 if (!task)
22178 task = current;
22179 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22180 * current stack address. If the stacks consist of nested
22181 * exceptions
22182 */
22183 - tinfo = task_thread_info(task);
22184 while (!done) {
22185 unsigned long *stack_end;
22186 enum stack_type stype;
22187 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22188 if (ops->stack(data, id) < 0)
22189 break;
22190
22191 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22192 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22193 data, stack_end, &graph);
22194 ops->stack(data, "<EOE>");
22195 /*
22196 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22197 * second-to-last pointer (index -2 to end) in the
22198 * exception stack:
22199 */
22200 + if ((u16)stack_end[-1] != __KERNEL_DS)
22201 + goto out;
22202 stack = (unsigned long *) stack_end[-2];
22203 done = 0;
22204 break;
22205 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22206
22207 if (ops->stack(data, "IRQ") < 0)
22208 break;
22209 - bp = ops->walk_stack(tinfo, stack, bp,
22210 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22211 ops, data, stack_end, &graph);
22212 /*
22213 * We link to the next stack (which would be
22214 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22215 /*
22216 * This handles the process stack:
22217 */
22218 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22219 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22220 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22221 +out:
22222 put_cpu();
22223 }
22224 EXPORT_SYMBOL(dump_trace);
22225 @@ -344,8 +347,55 @@ int is_valid_bugaddr(unsigned long ip)
22226 {
22227 unsigned short ud2;
22228
22229 - if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
22230 + if (probe_kernel_address((unsigned short *)ip, ud2))
22231 return 0;
22232
22233 return ud2 == 0x0b0f;
22234 }
22235 +
22236 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22237 +void pax_check_alloca(unsigned long size)
22238 +{
22239 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22240 + unsigned cpu, used;
22241 + char *id;
22242 +
22243 + /* check the process stack first */
22244 + stack_start = (unsigned long)task_stack_page(current);
22245 + stack_end = stack_start + THREAD_SIZE;
22246 + if (likely(stack_start <= sp && sp < stack_end)) {
22247 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22248 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22249 + return;
22250 + }
22251 +
22252 + cpu = get_cpu();
22253 +
22254 + /* check the irq stacks */
22255 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22256 + stack_start = stack_end - IRQ_STACK_SIZE;
22257 + if (stack_start <= sp && sp < stack_end) {
22258 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22259 + put_cpu();
22260 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22261 + return;
22262 + }
22263 +
22264 + /* check the exception stacks */
22265 + used = 0;
22266 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22267 + stack_start = stack_end - EXCEPTION_STKSZ;
22268 + if (stack_end && stack_start <= sp && sp < stack_end) {
22269 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22270 + put_cpu();
22271 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22272 + return;
22273 + }
22274 +
22275 + put_cpu();
22276 +
22277 + /* unknown stack */
22278 + BUG();
22279 +}
22280 +EXPORT_SYMBOL(pax_check_alloca);
22281 +#endif
22282 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22283 index 49f8864..1cc6d07 100644
22284 --- a/arch/x86/kernel/e820.c
22285 +++ b/arch/x86/kernel/e820.c
22286 @@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22287
22288 static void early_panic(char *msg)
22289 {
22290 - early_printk(msg);
22291 - panic(msg);
22292 + early_printk("%s", msg);
22293 + panic("%s", msg);
22294 }
22295
22296 static int userdef __initdata;
22297 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22298 index 01d1c18..8073693 100644
22299 --- a/arch/x86/kernel/early_printk.c
22300 +++ b/arch/x86/kernel/early_printk.c
22301 @@ -7,6 +7,7 @@
22302 #include <linux/pci_regs.h>
22303 #include <linux/pci_ids.h>
22304 #include <linux/errno.h>
22305 +#include <linux/sched.h>
22306 #include <asm/io.h>
22307 #include <asm/processor.h>
22308 #include <asm/fcntl.h>
22309 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22310 index 344b63f..55adf14 100644
22311 --- a/arch/x86/kernel/entry_32.S
22312 +++ b/arch/x86/kernel/entry_32.S
22313 @@ -177,13 +177,154 @@
22314 /*CFI_REL_OFFSET gs, PT_GS*/
22315 .endm
22316 .macro SET_KERNEL_GS reg
22317 +
22318 +#ifdef CONFIG_CC_STACKPROTECTOR
22319 movl $(__KERNEL_STACK_CANARY), \reg
22320 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22321 + movl $(__USER_DS), \reg
22322 +#else
22323 + xorl \reg, \reg
22324 +#endif
22325 +
22326 movl \reg, %gs
22327 .endm
22328
22329 #endif /* CONFIG_X86_32_LAZY_GS */
22330
22331 -.macro SAVE_ALL
22332 +.macro pax_enter_kernel
22333 +#ifdef CONFIG_PAX_KERNEXEC
22334 + call pax_enter_kernel
22335 +#endif
22336 +.endm
22337 +
22338 +.macro pax_exit_kernel
22339 +#ifdef CONFIG_PAX_KERNEXEC
22340 + call pax_exit_kernel
22341 +#endif
22342 +.endm
22343 +
22344 +#ifdef CONFIG_PAX_KERNEXEC
22345 +ENTRY(pax_enter_kernel)
22346 +#ifdef CONFIG_PARAVIRT
22347 + pushl %eax
22348 + pushl %ecx
22349 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22350 + mov %eax, %esi
22351 +#else
22352 + mov %cr0, %esi
22353 +#endif
22354 + bts $16, %esi
22355 + jnc 1f
22356 + mov %cs, %esi
22357 + cmp $__KERNEL_CS, %esi
22358 + jz 3f
22359 + ljmp $__KERNEL_CS, $3f
22360 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22361 +2:
22362 +#ifdef CONFIG_PARAVIRT
22363 + mov %esi, %eax
22364 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22365 +#else
22366 + mov %esi, %cr0
22367 +#endif
22368 +3:
22369 +#ifdef CONFIG_PARAVIRT
22370 + popl %ecx
22371 + popl %eax
22372 +#endif
22373 + ret
22374 +ENDPROC(pax_enter_kernel)
22375 +
22376 +ENTRY(pax_exit_kernel)
22377 +#ifdef CONFIG_PARAVIRT
22378 + pushl %eax
22379 + pushl %ecx
22380 +#endif
22381 + mov %cs, %esi
22382 + cmp $__KERNEXEC_KERNEL_CS, %esi
22383 + jnz 2f
22384 +#ifdef CONFIG_PARAVIRT
22385 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22386 + mov %eax, %esi
22387 +#else
22388 + mov %cr0, %esi
22389 +#endif
22390 + btr $16, %esi
22391 + ljmp $__KERNEL_CS, $1f
22392 +1:
22393 +#ifdef CONFIG_PARAVIRT
22394 + mov %esi, %eax
22395 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22396 +#else
22397 + mov %esi, %cr0
22398 +#endif
22399 +2:
22400 +#ifdef CONFIG_PARAVIRT
22401 + popl %ecx
22402 + popl %eax
22403 +#endif
22404 + ret
22405 +ENDPROC(pax_exit_kernel)
22406 +#endif
22407 +
22408 + .macro pax_erase_kstack
22409 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22410 + call pax_erase_kstack
22411 +#endif
22412 + .endm
22413 +
22414 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22415 +/*
22416 + * ebp: thread_info
22417 + */
22418 +ENTRY(pax_erase_kstack)
22419 + pushl %edi
22420 + pushl %ecx
22421 + pushl %eax
22422 +
22423 + mov TI_lowest_stack(%ebp), %edi
22424 + mov $-0xBEEF, %eax
22425 + std
22426 +
22427 +1: mov %edi, %ecx
22428 + and $THREAD_SIZE_asm - 1, %ecx
22429 + shr $2, %ecx
22430 + repne scasl
22431 + jecxz 2f
22432 +
22433 + cmp $2*16, %ecx
22434 + jc 2f
22435 +
22436 + mov $2*16, %ecx
22437 + repe scasl
22438 + jecxz 2f
22439 + jne 1b
22440 +
22441 +2: cld
22442 + or $2*4, %edi
22443 + mov %esp, %ecx
22444 + sub %edi, %ecx
22445 +
22446 + cmp $THREAD_SIZE_asm, %ecx
22447 + jb 3f
22448 + ud2
22449 +3:
22450 +
22451 + shr $2, %ecx
22452 + rep stosl
22453 +
22454 + mov TI_task_thread_sp0(%ebp), %edi
22455 + sub $128, %edi
22456 + mov %edi, TI_lowest_stack(%ebp)
22457 +
22458 + popl %eax
22459 + popl %ecx
22460 + popl %edi
22461 + ret
22462 +ENDPROC(pax_erase_kstack)
22463 +#endif
22464 +
22465 +.macro __SAVE_ALL _DS
22466 cld
22467 PUSH_GS
22468 pushl_cfi %fs
22469 @@ -206,7 +347,7 @@
22470 CFI_REL_OFFSET ecx, 0
22471 pushl_cfi %ebx
22472 CFI_REL_OFFSET ebx, 0
22473 - movl $(__USER_DS), %edx
22474 + movl $\_DS, %edx
22475 movl %edx, %ds
22476 movl %edx, %es
22477 movl $(__KERNEL_PERCPU), %edx
22478 @@ -214,6 +355,15 @@
22479 SET_KERNEL_GS %edx
22480 .endm
22481
22482 +.macro SAVE_ALL
22483 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22484 + __SAVE_ALL __KERNEL_DS
22485 + pax_enter_kernel
22486 +#else
22487 + __SAVE_ALL __USER_DS
22488 +#endif
22489 +.endm
22490 +
22491 .macro RESTORE_INT_REGS
22492 popl_cfi %ebx
22493 CFI_RESTORE ebx
22494 @@ -297,7 +447,7 @@ ENTRY(ret_from_fork)
22495 popfl_cfi
22496 jmp syscall_exit
22497 CFI_ENDPROC
22498 -END(ret_from_fork)
22499 +ENDPROC(ret_from_fork)
22500
22501 ENTRY(ret_from_kernel_thread)
22502 CFI_STARTPROC
22503 @@ -340,7 +490,15 @@ ret_from_intr:
22504 andl $SEGMENT_RPL_MASK, %eax
22505 #endif
22506 cmpl $USER_RPL, %eax
22507 +
22508 +#ifdef CONFIG_PAX_KERNEXEC
22509 + jae resume_userspace
22510 +
22511 + pax_exit_kernel
22512 + jmp resume_kernel
22513 +#else
22514 jb resume_kernel # not returning to v8086 or userspace
22515 +#endif
22516
22517 ENTRY(resume_userspace)
22518 LOCKDEP_SYS_EXIT
22519 @@ -352,8 +510,8 @@ ENTRY(resume_userspace)
22520 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22521 # int/exception return?
22522 jne work_pending
22523 - jmp restore_all
22524 -END(ret_from_exception)
22525 + jmp restore_all_pax
22526 +ENDPROC(ret_from_exception)
22527
22528 #ifdef CONFIG_PREEMPT
22529 ENTRY(resume_kernel)
22530 @@ -365,7 +523,7 @@ need_resched:
22531 jz restore_all
22532 call preempt_schedule_irq
22533 jmp need_resched
22534 -END(resume_kernel)
22535 +ENDPROC(resume_kernel)
22536 #endif
22537 CFI_ENDPROC
22538
22539 @@ -395,30 +553,45 @@ sysenter_past_esp:
22540 /*CFI_REL_OFFSET cs, 0*/
22541 /*
22542 * Push current_thread_info()->sysenter_return to the stack.
22543 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22544 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22545 */
22546 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22547 + pushl_cfi $0
22548 CFI_REL_OFFSET eip, 0
22549
22550 pushl_cfi %eax
22551 SAVE_ALL
22552 + GET_THREAD_INFO(%ebp)
22553 + movl TI_sysenter_return(%ebp),%ebp
22554 + movl %ebp,PT_EIP(%esp)
22555 ENABLE_INTERRUPTS(CLBR_NONE)
22556
22557 /*
22558 * Load the potential sixth argument from user stack.
22559 * Careful about security.
22560 */
22561 + movl PT_OLDESP(%esp),%ebp
22562 +
22563 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22564 + mov PT_OLDSS(%esp),%ds
22565 +1: movl %ds:(%ebp),%ebp
22566 + push %ss
22567 + pop %ds
22568 +#else
22569 cmpl $__PAGE_OFFSET-3,%ebp
22570 jae syscall_fault
22571 ASM_STAC
22572 1: movl (%ebp),%ebp
22573 ASM_CLAC
22574 +#endif
22575 +
22576 movl %ebp,PT_EBP(%esp)
22577 _ASM_EXTABLE(1b,syscall_fault)
22578
22579 GET_THREAD_INFO(%ebp)
22580
22581 +#ifdef CONFIG_PAX_RANDKSTACK
22582 + pax_erase_kstack
22583 +#endif
22584 +
22585 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22586 jnz sysenter_audit
22587 sysenter_do_call:
22588 @@ -434,12 +607,24 @@ sysenter_after_call:
22589 testl $_TIF_ALLWORK_MASK, %ecx
22590 jne sysexit_audit
22591 sysenter_exit:
22592 +
22593 +#ifdef CONFIG_PAX_RANDKSTACK
22594 + pushl_cfi %eax
22595 + movl %esp, %eax
22596 + call pax_randomize_kstack
22597 + popl_cfi %eax
22598 +#endif
22599 +
22600 + pax_erase_kstack
22601 +
22602 /* if something modifies registers it must also disable sysexit */
22603 movl PT_EIP(%esp), %edx
22604 movl PT_OLDESP(%esp), %ecx
22605 xorl %ebp,%ebp
22606 TRACE_IRQS_ON
22607 1: mov PT_FS(%esp), %fs
22608 +2: mov PT_DS(%esp), %ds
22609 +3: mov PT_ES(%esp), %es
22610 PTGS_TO_GS
22611 ENABLE_INTERRUPTS_SYSEXIT
22612
22613 @@ -453,6 +638,9 @@ sysenter_audit:
22614 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22615 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22616 call __audit_syscall_entry
22617 +
22618 + pax_erase_kstack
22619 +
22620 popl_cfi %ecx /* get that remapped edx off the stack */
22621 popl_cfi %ecx /* get that remapped esi off the stack */
22622 movl PT_EAX(%esp),%eax /* reload syscall number */
22623 @@ -479,10 +667,16 @@ sysexit_audit:
22624
22625 CFI_ENDPROC
22626 .pushsection .fixup,"ax"
22627 -2: movl $0,PT_FS(%esp)
22628 +4: movl $0,PT_FS(%esp)
22629 + jmp 1b
22630 +5: movl $0,PT_DS(%esp)
22631 + jmp 1b
22632 +6: movl $0,PT_ES(%esp)
22633 jmp 1b
22634 .popsection
22635 - _ASM_EXTABLE(1b,2b)
22636 + _ASM_EXTABLE(1b,4b)
22637 + _ASM_EXTABLE(2b,5b)
22638 + _ASM_EXTABLE(3b,6b)
22639 PTGS_TO_GS_EX
22640 ENDPROC(ia32_sysenter_target)
22641
22642 @@ -493,6 +687,11 @@ ENTRY(system_call)
22643 pushl_cfi %eax # save orig_eax
22644 SAVE_ALL
22645 GET_THREAD_INFO(%ebp)
22646 +
22647 +#ifdef CONFIG_PAX_RANDKSTACK
22648 + pax_erase_kstack
22649 +#endif
22650 +
22651 # system call tracing in operation / emulation
22652 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22653 jnz syscall_trace_entry
22654 @@ -512,6 +711,15 @@ syscall_exit:
22655 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22656 jne syscall_exit_work
22657
22658 +restore_all_pax:
22659 +
22660 +#ifdef CONFIG_PAX_RANDKSTACK
22661 + movl %esp, %eax
22662 + call pax_randomize_kstack
22663 +#endif
22664 +
22665 + pax_erase_kstack
22666 +
22667 restore_all:
22668 TRACE_IRQS_IRET
22669 restore_all_notrace:
22670 @@ -566,14 +774,34 @@ ldt_ss:
22671 * compensating for the offset by changing to the ESPFIX segment with
22672 * a base address that matches for the difference.
22673 */
22674 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22675 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22676 mov %esp, %edx /* load kernel esp */
22677 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22678 mov %dx, %ax /* eax: new kernel esp */
22679 sub %eax, %edx /* offset (low word is 0) */
22680 +#ifdef CONFIG_SMP
22681 + movl PER_CPU_VAR(cpu_number), %ebx
22682 + shll $PAGE_SHIFT_asm, %ebx
22683 + addl $cpu_gdt_table, %ebx
22684 +#else
22685 + movl $cpu_gdt_table, %ebx
22686 +#endif
22687 shr $16, %edx
22688 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22689 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22690 +
22691 +#ifdef CONFIG_PAX_KERNEXEC
22692 + mov %cr0, %esi
22693 + btr $16, %esi
22694 + mov %esi, %cr0
22695 +#endif
22696 +
22697 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22698 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22699 +
22700 +#ifdef CONFIG_PAX_KERNEXEC
22701 + bts $16, %esi
22702 + mov %esi, %cr0
22703 +#endif
22704 +
22705 pushl_cfi $__ESPFIX_SS
22706 pushl_cfi %eax /* new kernel esp */
22707 /* Disable interrupts, but do not irqtrace this section: we
22708 @@ -603,20 +831,18 @@ work_resched:
22709 movl TI_flags(%ebp), %ecx
22710 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22711 # than syscall tracing?
22712 - jz restore_all
22713 + jz restore_all_pax
22714 testb $_TIF_NEED_RESCHED, %cl
22715 jnz work_resched
22716
22717 work_notifysig: # deal with pending signals and
22718 # notify-resume requests
22719 + movl %esp, %eax
22720 #ifdef CONFIG_VM86
22721 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22722 - movl %esp, %eax
22723 jne work_notifysig_v86 # returning to kernel-space or
22724 # vm86-space
22725 1:
22726 -#else
22727 - movl %esp, %eax
22728 #endif
22729 TRACE_IRQS_ON
22730 ENABLE_INTERRUPTS(CLBR_NONE)
22731 @@ -637,7 +863,7 @@ work_notifysig_v86:
22732 movl %eax, %esp
22733 jmp 1b
22734 #endif
22735 -END(work_pending)
22736 +ENDPROC(work_pending)
22737
22738 # perform syscall exit tracing
22739 ALIGN
22740 @@ -645,11 +871,14 @@ syscall_trace_entry:
22741 movl $-ENOSYS,PT_EAX(%esp)
22742 movl %esp, %eax
22743 call syscall_trace_enter
22744 +
22745 + pax_erase_kstack
22746 +
22747 /* What it returned is what we'll actually use. */
22748 cmpl $(NR_syscalls), %eax
22749 jnae syscall_call
22750 jmp syscall_exit
22751 -END(syscall_trace_entry)
22752 +ENDPROC(syscall_trace_entry)
22753
22754 # perform syscall exit tracing
22755 ALIGN
22756 @@ -662,26 +891,30 @@ syscall_exit_work:
22757 movl %esp, %eax
22758 call syscall_trace_leave
22759 jmp resume_userspace
22760 -END(syscall_exit_work)
22761 +ENDPROC(syscall_exit_work)
22762 CFI_ENDPROC
22763
22764 RING0_INT_FRAME # can't unwind into user space anyway
22765 syscall_fault:
22766 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22767 + push %ss
22768 + pop %ds
22769 +#endif
22770 ASM_CLAC
22771 GET_THREAD_INFO(%ebp)
22772 movl $-EFAULT,PT_EAX(%esp)
22773 jmp resume_userspace
22774 -END(syscall_fault)
22775 +ENDPROC(syscall_fault)
22776
22777 syscall_badsys:
22778 movl $-ENOSYS,%eax
22779 jmp syscall_after_call
22780 -END(syscall_badsys)
22781 +ENDPROC(syscall_badsys)
22782
22783 sysenter_badsys:
22784 movl $-ENOSYS,%eax
22785 jmp sysenter_after_call
22786 -END(sysenter_badsys)
22787 +ENDPROC(sysenter_badsys)
22788 CFI_ENDPROC
22789
22790 .macro FIXUP_ESPFIX_STACK
22791 @@ -694,8 +927,15 @@ END(sysenter_badsys)
22792 */
22793 #ifdef CONFIG_X86_ESPFIX32
22794 /* fixup the stack */
22795 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22796 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22797 +#ifdef CONFIG_SMP
22798 + movl PER_CPU_VAR(cpu_number), %ebx
22799 + shll $PAGE_SHIFT_asm, %ebx
22800 + addl $cpu_gdt_table, %ebx
22801 +#else
22802 + movl $cpu_gdt_table, %ebx
22803 +#endif
22804 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22805 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22806 shl $16, %eax
22807 addl %esp, %eax /* the adjusted stack pointer */
22808 pushl_cfi $__KERNEL_DS
22809 @@ -751,7 +991,7 @@ vector=vector+1
22810 .endr
22811 2: jmp common_interrupt
22812 .endr
22813 -END(irq_entries_start)
22814 +ENDPROC(irq_entries_start)
22815
22816 .previous
22817 END(interrupt)
22818 @@ -808,7 +1048,7 @@ ENTRY(coprocessor_error)
22819 pushl_cfi $do_coprocessor_error
22820 jmp error_code
22821 CFI_ENDPROC
22822 -END(coprocessor_error)
22823 +ENDPROC(coprocessor_error)
22824
22825 ENTRY(simd_coprocessor_error)
22826 RING0_INT_FRAME
22827 @@ -821,7 +1061,7 @@ ENTRY(simd_coprocessor_error)
22828 .section .altinstructions,"a"
22829 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22830 .previous
22831 -.section .altinstr_replacement,"ax"
22832 +.section .altinstr_replacement,"a"
22833 663: pushl $do_simd_coprocessor_error
22834 664:
22835 .previous
22836 @@ -830,7 +1070,7 @@ ENTRY(simd_coprocessor_error)
22837 #endif
22838 jmp error_code
22839 CFI_ENDPROC
22840 -END(simd_coprocessor_error)
22841 +ENDPROC(simd_coprocessor_error)
22842
22843 ENTRY(device_not_available)
22844 RING0_INT_FRAME
22845 @@ -839,18 +1079,18 @@ ENTRY(device_not_available)
22846 pushl_cfi $do_device_not_available
22847 jmp error_code
22848 CFI_ENDPROC
22849 -END(device_not_available)
22850 +ENDPROC(device_not_available)
22851
22852 #ifdef CONFIG_PARAVIRT
22853 ENTRY(native_iret)
22854 iret
22855 _ASM_EXTABLE(native_iret, iret_exc)
22856 -END(native_iret)
22857 +ENDPROC(native_iret)
22858
22859 ENTRY(native_irq_enable_sysexit)
22860 sti
22861 sysexit
22862 -END(native_irq_enable_sysexit)
22863 +ENDPROC(native_irq_enable_sysexit)
22864 #endif
22865
22866 ENTRY(overflow)
22867 @@ -860,7 +1100,7 @@ ENTRY(overflow)
22868 pushl_cfi $do_overflow
22869 jmp error_code
22870 CFI_ENDPROC
22871 -END(overflow)
22872 +ENDPROC(overflow)
22873
22874 ENTRY(bounds)
22875 RING0_INT_FRAME
22876 @@ -869,7 +1109,7 @@ ENTRY(bounds)
22877 pushl_cfi $do_bounds
22878 jmp error_code
22879 CFI_ENDPROC
22880 -END(bounds)
22881 +ENDPROC(bounds)
22882
22883 ENTRY(invalid_op)
22884 RING0_INT_FRAME
22885 @@ -878,7 +1118,7 @@ ENTRY(invalid_op)
22886 pushl_cfi $do_invalid_op
22887 jmp error_code
22888 CFI_ENDPROC
22889 -END(invalid_op)
22890 +ENDPROC(invalid_op)
22891
22892 ENTRY(coprocessor_segment_overrun)
22893 RING0_INT_FRAME
22894 @@ -887,7 +1127,7 @@ ENTRY(coprocessor_segment_overrun)
22895 pushl_cfi $do_coprocessor_segment_overrun
22896 jmp error_code
22897 CFI_ENDPROC
22898 -END(coprocessor_segment_overrun)
22899 +ENDPROC(coprocessor_segment_overrun)
22900
22901 ENTRY(invalid_TSS)
22902 RING0_EC_FRAME
22903 @@ -895,7 +1135,7 @@ ENTRY(invalid_TSS)
22904 pushl_cfi $do_invalid_TSS
22905 jmp error_code
22906 CFI_ENDPROC
22907 -END(invalid_TSS)
22908 +ENDPROC(invalid_TSS)
22909
22910 ENTRY(segment_not_present)
22911 RING0_EC_FRAME
22912 @@ -903,7 +1143,7 @@ ENTRY(segment_not_present)
22913 pushl_cfi $do_segment_not_present
22914 jmp error_code
22915 CFI_ENDPROC
22916 -END(segment_not_present)
22917 +ENDPROC(segment_not_present)
22918
22919 ENTRY(stack_segment)
22920 RING0_EC_FRAME
22921 @@ -911,7 +1151,7 @@ ENTRY(stack_segment)
22922 pushl_cfi $do_stack_segment
22923 jmp error_code
22924 CFI_ENDPROC
22925 -END(stack_segment)
22926 +ENDPROC(stack_segment)
22927
22928 ENTRY(alignment_check)
22929 RING0_EC_FRAME
22930 @@ -919,7 +1159,7 @@ ENTRY(alignment_check)
22931 pushl_cfi $do_alignment_check
22932 jmp error_code
22933 CFI_ENDPROC
22934 -END(alignment_check)
22935 +ENDPROC(alignment_check)
22936
22937 ENTRY(divide_error)
22938 RING0_INT_FRAME
22939 @@ -928,7 +1168,7 @@ ENTRY(divide_error)
22940 pushl_cfi $do_divide_error
22941 jmp error_code
22942 CFI_ENDPROC
22943 -END(divide_error)
22944 +ENDPROC(divide_error)
22945
22946 #ifdef CONFIG_X86_MCE
22947 ENTRY(machine_check)
22948 @@ -938,7 +1178,7 @@ ENTRY(machine_check)
22949 pushl_cfi machine_check_vector
22950 jmp error_code
22951 CFI_ENDPROC
22952 -END(machine_check)
22953 +ENDPROC(machine_check)
22954 #endif
22955
22956 ENTRY(spurious_interrupt_bug)
22957 @@ -948,7 +1188,7 @@ ENTRY(spurious_interrupt_bug)
22958 pushl_cfi $do_spurious_interrupt_bug
22959 jmp error_code
22960 CFI_ENDPROC
22961 -END(spurious_interrupt_bug)
22962 +ENDPROC(spurious_interrupt_bug)
22963
22964 #ifdef CONFIG_XEN
22965 /* Xen doesn't set %esp to be precisely what the normal sysenter
22966 @@ -1054,7 +1294,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22967
22968 ENTRY(mcount)
22969 ret
22970 -END(mcount)
22971 +ENDPROC(mcount)
22972
22973 ENTRY(ftrace_caller)
22974 pushl %eax
22975 @@ -1084,7 +1324,7 @@ ftrace_graph_call:
22976 .globl ftrace_stub
22977 ftrace_stub:
22978 ret
22979 -END(ftrace_caller)
22980 +ENDPROC(ftrace_caller)
22981
22982 ENTRY(ftrace_regs_caller)
22983 pushf /* push flags before compare (in cs location) */
22984 @@ -1182,7 +1422,7 @@ trace:
22985 popl %ecx
22986 popl %eax
22987 jmp ftrace_stub
22988 -END(mcount)
22989 +ENDPROC(mcount)
22990 #endif /* CONFIG_DYNAMIC_FTRACE */
22991 #endif /* CONFIG_FUNCTION_TRACER */
22992
22993 @@ -1200,7 +1440,7 @@ ENTRY(ftrace_graph_caller)
22994 popl %ecx
22995 popl %eax
22996 ret
22997 -END(ftrace_graph_caller)
22998 +ENDPROC(ftrace_graph_caller)
22999
23000 .globl return_to_handler
23001 return_to_handler:
23002 @@ -1261,15 +1501,18 @@ error_code:
23003 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23004 REG_TO_PTGS %ecx
23005 SET_KERNEL_GS %ecx
23006 - movl $(__USER_DS), %ecx
23007 + movl $(__KERNEL_DS), %ecx
23008 movl %ecx, %ds
23009 movl %ecx, %es
23010 +
23011 + pax_enter_kernel
23012 +
23013 TRACE_IRQS_OFF
23014 movl %esp,%eax # pt_regs pointer
23015 call *%edi
23016 jmp ret_from_exception
23017 CFI_ENDPROC
23018 -END(page_fault)
23019 +ENDPROC(page_fault)
23020
23021 /*
23022 * Debug traps and NMI can happen at the one SYSENTER instruction
23023 @@ -1312,7 +1555,7 @@ debug_stack_correct:
23024 call do_debug
23025 jmp ret_from_exception
23026 CFI_ENDPROC
23027 -END(debug)
23028 +ENDPROC(debug)
23029
23030 /*
23031 * NMI is doubly nasty. It can happen _while_ we're handling
23032 @@ -1352,6 +1595,9 @@ nmi_stack_correct:
23033 xorl %edx,%edx # zero error code
23034 movl %esp,%eax # pt_regs pointer
23035 call do_nmi
23036 +
23037 + pax_exit_kernel
23038 +
23039 jmp restore_all_notrace
23040 CFI_ENDPROC
23041
23042 @@ -1389,13 +1635,16 @@ nmi_espfix_stack:
23043 FIXUP_ESPFIX_STACK # %eax == %esp
23044 xorl %edx,%edx # zero error code
23045 call do_nmi
23046 +
23047 + pax_exit_kernel
23048 +
23049 RESTORE_REGS
23050 lss 12+4(%esp), %esp # back to espfix stack
23051 CFI_ADJUST_CFA_OFFSET -24
23052 jmp irq_return
23053 #endif
23054 CFI_ENDPROC
23055 -END(nmi)
23056 +ENDPROC(nmi)
23057
23058 ENTRY(int3)
23059 RING0_INT_FRAME
23060 @@ -1408,14 +1657,14 @@ ENTRY(int3)
23061 call do_int3
23062 jmp ret_from_exception
23063 CFI_ENDPROC
23064 -END(int3)
23065 +ENDPROC(int3)
23066
23067 ENTRY(general_protection)
23068 RING0_EC_FRAME
23069 pushl_cfi $do_general_protection
23070 jmp error_code
23071 CFI_ENDPROC
23072 -END(general_protection)
23073 +ENDPROC(general_protection)
23074
23075 #ifdef CONFIG_KVM_GUEST
23076 ENTRY(async_page_fault)
23077 @@ -1424,6 +1673,6 @@ ENTRY(async_page_fault)
23078 pushl_cfi $do_async_page_fault
23079 jmp error_code
23080 CFI_ENDPROC
23081 -END(async_page_fault)
23082 +ENDPROC(async_page_fault)
23083 #endif
23084
23085 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23086 index c0226ab..0d1dc48 100644
23087 --- a/arch/x86/kernel/entry_64.S
23088 +++ b/arch/x86/kernel/entry_64.S
23089 @@ -59,6 +59,8 @@
23090 #include <asm/smap.h>
23091 #include <asm/pgtable_types.h>
23092 #include <linux/err.h>
23093 +#include <asm/pgtable.h>
23094 +#include <asm/alternative-asm.h>
23095
23096 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23097 #include <linux/elf-em.h>
23098 @@ -81,6 +83,431 @@ ENTRY(native_usergs_sysret64)
23099 ENDPROC(native_usergs_sysret64)
23100 #endif /* CONFIG_PARAVIRT */
23101
23102 + .macro ljmpq sel, off
23103 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23104 + .byte 0x48; ljmp *1234f(%rip)
23105 + .pushsection .rodata
23106 + .align 16
23107 + 1234: .quad \off; .word \sel
23108 + .popsection
23109 +#else
23110 + pushq $\sel
23111 + pushq $\off
23112 + lretq
23113 +#endif
23114 + .endm
23115 +
23116 + .macro pax_enter_kernel
23117 + pax_set_fptr_mask
23118 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23119 + call pax_enter_kernel
23120 +#endif
23121 + .endm
23122 +
23123 + .macro pax_exit_kernel
23124 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23125 + call pax_exit_kernel
23126 +#endif
23127 +
23128 + .endm
23129 +
23130 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23131 +ENTRY(pax_enter_kernel)
23132 + pushq %rdi
23133 +
23134 +#ifdef CONFIG_PARAVIRT
23135 + PV_SAVE_REGS(CLBR_RDI)
23136 +#endif
23137 +
23138 +#ifdef CONFIG_PAX_KERNEXEC
23139 + GET_CR0_INTO_RDI
23140 + bts $16,%rdi
23141 + jnc 3f
23142 + mov %cs,%edi
23143 + cmp $__KERNEL_CS,%edi
23144 + jnz 2f
23145 +1:
23146 +#endif
23147 +
23148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23149 + 661: jmp 111f
23150 + .pushsection .altinstr_replacement, "a"
23151 + 662: ASM_NOP2
23152 + .popsection
23153 + .pushsection .altinstructions, "a"
23154 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23155 + .popsection
23156 + GET_CR3_INTO_RDI
23157 + cmp $0,%dil
23158 + jnz 112f
23159 + mov $__KERNEL_DS,%edi
23160 + mov %edi,%ss
23161 + jmp 111f
23162 +112: cmp $1,%dil
23163 + jz 113f
23164 + ud2
23165 +113: sub $4097,%rdi
23166 + bts $63,%rdi
23167 + SET_RDI_INTO_CR3
23168 + mov $__UDEREF_KERNEL_DS,%edi
23169 + mov %edi,%ss
23170 +111:
23171 +#endif
23172 +
23173 +#ifdef CONFIG_PARAVIRT
23174 + PV_RESTORE_REGS(CLBR_RDI)
23175 +#endif
23176 +
23177 + popq %rdi
23178 + pax_force_retaddr
23179 + retq
23180 +
23181 +#ifdef CONFIG_PAX_KERNEXEC
23182 +2: ljmpq __KERNEL_CS,1b
23183 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23184 +4: SET_RDI_INTO_CR0
23185 + jmp 1b
23186 +#endif
23187 +ENDPROC(pax_enter_kernel)
23188 +
23189 +ENTRY(pax_exit_kernel)
23190 + pushq %rdi
23191 +
23192 +#ifdef CONFIG_PARAVIRT
23193 + PV_SAVE_REGS(CLBR_RDI)
23194 +#endif
23195 +
23196 +#ifdef CONFIG_PAX_KERNEXEC
23197 + mov %cs,%rdi
23198 + cmp $__KERNEXEC_KERNEL_CS,%edi
23199 + jz 2f
23200 + GET_CR0_INTO_RDI
23201 + bts $16,%rdi
23202 + jnc 4f
23203 +1:
23204 +#endif
23205 +
23206 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23207 + 661: jmp 111f
23208 + .pushsection .altinstr_replacement, "a"
23209 + 662: ASM_NOP2
23210 + .popsection
23211 + .pushsection .altinstructions, "a"
23212 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23213 + .popsection
23214 + mov %ss,%edi
23215 + cmp $__UDEREF_KERNEL_DS,%edi
23216 + jnz 111f
23217 + GET_CR3_INTO_RDI
23218 + cmp $0,%dil
23219 + jz 112f
23220 + ud2
23221 +112: add $4097,%rdi
23222 + bts $63,%rdi
23223 + SET_RDI_INTO_CR3
23224 + mov $__KERNEL_DS,%edi
23225 + mov %edi,%ss
23226 +111:
23227 +#endif
23228 +
23229 +#ifdef CONFIG_PARAVIRT
23230 + PV_RESTORE_REGS(CLBR_RDI);
23231 +#endif
23232 +
23233 + popq %rdi
23234 + pax_force_retaddr
23235 + retq
23236 +
23237 +#ifdef CONFIG_PAX_KERNEXEC
23238 +2: GET_CR0_INTO_RDI
23239 + btr $16,%rdi
23240 + jnc 4f
23241 + ljmpq __KERNEL_CS,3f
23242 +3: SET_RDI_INTO_CR0
23243 + jmp 1b
23244 +4: ud2
23245 + jmp 4b
23246 +#endif
23247 +ENDPROC(pax_exit_kernel)
23248 +#endif
23249 +
23250 + .macro pax_enter_kernel_user
23251 + pax_set_fptr_mask
23252 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23253 + call pax_enter_kernel_user
23254 +#endif
23255 + .endm
23256 +
23257 + .macro pax_exit_kernel_user
23258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23259 + call pax_exit_kernel_user
23260 +#endif
23261 +#ifdef CONFIG_PAX_RANDKSTACK
23262 + pushq %rax
23263 + pushq %r11
23264 + call pax_randomize_kstack
23265 + popq %r11
23266 + popq %rax
23267 +#endif
23268 + .endm
23269 +
23270 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23271 +ENTRY(pax_enter_kernel_user)
23272 + pushq %rdi
23273 + pushq %rbx
23274 +
23275 +#ifdef CONFIG_PARAVIRT
23276 + PV_SAVE_REGS(CLBR_RDI)
23277 +#endif
23278 +
23279 + 661: jmp 111f
23280 + .pushsection .altinstr_replacement, "a"
23281 + 662: ASM_NOP2
23282 + .popsection
23283 + .pushsection .altinstructions, "a"
23284 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23285 + .popsection
23286 + GET_CR3_INTO_RDI
23287 + cmp $1,%dil
23288 + jnz 4f
23289 + sub $4097,%rdi
23290 + bts $63,%rdi
23291 + SET_RDI_INTO_CR3
23292 + jmp 3f
23293 +111:
23294 +
23295 + GET_CR3_INTO_RDI
23296 + mov %rdi,%rbx
23297 + add $__START_KERNEL_map,%rbx
23298 + sub phys_base(%rip),%rbx
23299 +
23300 +#ifdef CONFIG_PARAVIRT
23301 + cmpl $0, pv_info+PARAVIRT_enabled
23302 + jz 1f
23303 + pushq %rdi
23304 + i = 0
23305 + .rept USER_PGD_PTRS
23306 + mov i*8(%rbx),%rsi
23307 + mov $0,%sil
23308 + lea i*8(%rbx),%rdi
23309 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23310 + i = i + 1
23311 + .endr
23312 + popq %rdi
23313 + jmp 2f
23314 +1:
23315 +#endif
23316 +
23317 + i = 0
23318 + .rept USER_PGD_PTRS
23319 + movb $0,i*8(%rbx)
23320 + i = i + 1
23321 + .endr
23322 +
23323 +2: SET_RDI_INTO_CR3
23324 +
23325 +#ifdef CONFIG_PAX_KERNEXEC
23326 + GET_CR0_INTO_RDI
23327 + bts $16,%rdi
23328 + SET_RDI_INTO_CR0
23329 +#endif
23330 +
23331 +3:
23332 +
23333 +#ifdef CONFIG_PARAVIRT
23334 + PV_RESTORE_REGS(CLBR_RDI)
23335 +#endif
23336 +
23337 + popq %rbx
23338 + popq %rdi
23339 + pax_force_retaddr
23340 + retq
23341 +4: ud2
23342 +ENDPROC(pax_enter_kernel_user)
23343 +
23344 +ENTRY(pax_exit_kernel_user)
23345 + pushq %rdi
23346 + pushq %rbx
23347 +
23348 +#ifdef CONFIG_PARAVIRT
23349 + PV_SAVE_REGS(CLBR_RDI)
23350 +#endif
23351 +
23352 + GET_CR3_INTO_RDI
23353 + 661: jmp 1f
23354 + .pushsection .altinstr_replacement, "a"
23355 + 662: ASM_NOP2
23356 + .popsection
23357 + .pushsection .altinstructions, "a"
23358 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23359 + .popsection
23360 + cmp $0,%dil
23361 + jnz 3f
23362 + add $4097,%rdi
23363 + bts $63,%rdi
23364 + SET_RDI_INTO_CR3
23365 + jmp 2f
23366 +1:
23367 +
23368 + mov %rdi,%rbx
23369 +
23370 +#ifdef CONFIG_PAX_KERNEXEC
23371 + GET_CR0_INTO_RDI
23372 + btr $16,%rdi
23373 + jnc 3f
23374 + SET_RDI_INTO_CR0
23375 +#endif
23376 +
23377 + add $__START_KERNEL_map,%rbx
23378 + sub phys_base(%rip),%rbx
23379 +
23380 +#ifdef CONFIG_PARAVIRT
23381 + cmpl $0, pv_info+PARAVIRT_enabled
23382 + jz 1f
23383 + i = 0
23384 + .rept USER_PGD_PTRS
23385 + mov i*8(%rbx),%rsi
23386 + mov $0x67,%sil
23387 + lea i*8(%rbx),%rdi
23388 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23389 + i = i + 1
23390 + .endr
23391 + jmp 2f
23392 +1:
23393 +#endif
23394 +
23395 + i = 0
23396 + .rept USER_PGD_PTRS
23397 + movb $0x67,i*8(%rbx)
23398 + i = i + 1
23399 + .endr
23400 +2:
23401 +
23402 +#ifdef CONFIG_PARAVIRT
23403 + PV_RESTORE_REGS(CLBR_RDI)
23404 +#endif
23405 +
23406 + popq %rbx
23407 + popq %rdi
23408 + pax_force_retaddr
23409 + retq
23410 +3: ud2
23411 +ENDPROC(pax_exit_kernel_user)
23412 +#endif
23413 +
23414 + .macro pax_enter_kernel_nmi
23415 + pax_set_fptr_mask
23416 +
23417 +#ifdef CONFIG_PAX_KERNEXEC
23418 + GET_CR0_INTO_RDI
23419 + bts $16,%rdi
23420 + jc 110f
23421 + SET_RDI_INTO_CR0
23422 + or $2,%ebx
23423 +110:
23424 +#endif
23425 +
23426 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23427 + 661: jmp 111f
23428 + .pushsection .altinstr_replacement, "a"
23429 + 662: ASM_NOP2
23430 + .popsection
23431 + .pushsection .altinstructions, "a"
23432 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23433 + .popsection
23434 + GET_CR3_INTO_RDI
23435 + cmp $0,%dil
23436 + jz 111f
23437 + sub $4097,%rdi
23438 + or $4,%ebx
23439 + bts $63,%rdi
23440 + SET_RDI_INTO_CR3
23441 + mov $__UDEREF_KERNEL_DS,%edi
23442 + mov %edi,%ss
23443 +111:
23444 +#endif
23445 + .endm
23446 +
23447 + .macro pax_exit_kernel_nmi
23448 +#ifdef CONFIG_PAX_KERNEXEC
23449 + btr $1,%ebx
23450 + jnc 110f
23451 + GET_CR0_INTO_RDI
23452 + btr $16,%rdi
23453 + SET_RDI_INTO_CR0
23454 +110:
23455 +#endif
23456 +
23457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23458 + btr $2,%ebx
23459 + jnc 111f
23460 + GET_CR3_INTO_RDI
23461 + add $4097,%rdi
23462 + bts $63,%rdi
23463 + SET_RDI_INTO_CR3
23464 + mov $__KERNEL_DS,%edi
23465 + mov %edi,%ss
23466 +111:
23467 +#endif
23468 + .endm
23469 +
23470 + .macro pax_erase_kstack
23471 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23472 + call pax_erase_kstack
23473 +#endif
23474 + .endm
23475 +
23476 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23477 +ENTRY(pax_erase_kstack)
23478 + pushq %rdi
23479 + pushq %rcx
23480 + pushq %rax
23481 + pushq %r11
23482 +
23483 + GET_THREAD_INFO(%r11)
23484 + mov TI_lowest_stack(%r11), %rdi
23485 + mov $-0xBEEF, %rax
23486 + std
23487 +
23488 +1: mov %edi, %ecx
23489 + and $THREAD_SIZE_asm - 1, %ecx
23490 + shr $3, %ecx
23491 + repne scasq
23492 + jecxz 2f
23493 +
23494 + cmp $2*8, %ecx
23495 + jc 2f
23496 +
23497 + mov $2*8, %ecx
23498 + repe scasq
23499 + jecxz 2f
23500 + jne 1b
23501 +
23502 +2: cld
23503 + or $2*8, %rdi
23504 + mov %esp, %ecx
23505 + sub %edi, %ecx
23506 +
23507 + cmp $THREAD_SIZE_asm, %rcx
23508 + jb 3f
23509 + ud2
23510 +3:
23511 +
23512 + shr $3, %ecx
23513 + rep stosq
23514 +
23515 + mov TI_task_thread_sp0(%r11), %rdi
23516 + sub $256, %rdi
23517 + mov %rdi, TI_lowest_stack(%r11)
23518 +
23519 + popq %r11
23520 + popq %rax
23521 + popq %rcx
23522 + popq %rdi
23523 + pax_force_retaddr
23524 + ret
23525 +ENDPROC(pax_erase_kstack)
23526 +#endif
23527
23528 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23529 #ifdef CONFIG_TRACE_IRQFLAGS
23530 @@ -117,7 +544,7 @@ ENDPROC(native_usergs_sysret64)
23531 .endm
23532
23533 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23534 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23535 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23536 jnc 1f
23537 TRACE_IRQS_ON_DEBUG
23538 1:
23539 @@ -155,27 +582,6 @@ ENDPROC(native_usergs_sysret64)
23540 movq \tmp,R11+\offset(%rsp)
23541 .endm
23542
23543 - .macro FAKE_STACK_FRAME child_rip
23544 - /* push in order ss, rsp, eflags, cs, rip */
23545 - xorl %eax, %eax
23546 - pushq_cfi $__KERNEL_DS /* ss */
23547 - /*CFI_REL_OFFSET ss,0*/
23548 - pushq_cfi %rax /* rsp */
23549 - CFI_REL_OFFSET rsp,0
23550 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23551 - /*CFI_REL_OFFSET rflags,0*/
23552 - pushq_cfi $__KERNEL_CS /* cs */
23553 - /*CFI_REL_OFFSET cs,0*/
23554 - pushq_cfi \child_rip /* rip */
23555 - CFI_REL_OFFSET rip,0
23556 - pushq_cfi %rax /* orig rax */
23557 - .endm
23558 -
23559 - .macro UNFAKE_STACK_FRAME
23560 - addq $8*6, %rsp
23561 - CFI_ADJUST_CFA_OFFSET -(6*8)
23562 - .endm
23563 -
23564 /*
23565 * initial frame state for interrupts (and exceptions without error code)
23566 */
23567 @@ -241,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23568 /* save partial stack frame */
23569 .macro SAVE_ARGS_IRQ
23570 cld
23571 - /* start from rbp in pt_regs and jump over */
23572 - movq_cfi rdi, (RDI-RBP)
23573 - movq_cfi rsi, (RSI-RBP)
23574 - movq_cfi rdx, (RDX-RBP)
23575 - movq_cfi rcx, (RCX-RBP)
23576 - movq_cfi rax, (RAX-RBP)
23577 - movq_cfi r8, (R8-RBP)
23578 - movq_cfi r9, (R9-RBP)
23579 - movq_cfi r10, (R10-RBP)
23580 - movq_cfi r11, (R11-RBP)
23581 + /* start from r15 in pt_regs and jump over */
23582 + movq_cfi rdi, RDI
23583 + movq_cfi rsi, RSI
23584 + movq_cfi rdx, RDX
23585 + movq_cfi rcx, RCX
23586 + movq_cfi rax, RAX
23587 + movq_cfi r8, R8
23588 + movq_cfi r9, R9
23589 + movq_cfi r10, R10
23590 + movq_cfi r11, R11
23591 + movq_cfi r12, R12
23592
23593 /* Save rbp so that we can unwind from get_irq_regs() */
23594 - movq_cfi rbp, 0
23595 + movq_cfi rbp, RBP
23596
23597 /* Save previous stack value */
23598 movq %rsp, %rsi
23599
23600 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23601 - testl $3, CS-RBP(%rsi)
23602 + movq %rsp,%rdi /* arg1 for handler */
23603 + testb $3, CS(%rsi)
23604 je 1f
23605 SWAPGS
23606 /*
23607 @@ -279,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23608 0x06 /* DW_OP_deref */, \
23609 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23610 0x22 /* DW_OP_plus */
23611 +
23612 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23613 + testb $3, CS(%rdi)
23614 + jnz 1f
23615 + pax_enter_kernel
23616 + jmp 2f
23617 +1: pax_enter_kernel_user
23618 +2:
23619 +#else
23620 + pax_enter_kernel
23621 +#endif
23622 +
23623 /* We entered an interrupt context - irqs are off: */
23624 TRACE_IRQS_OFF
23625 .endm
23626 @@ -308,9 +727,52 @@ ENTRY(save_paranoid)
23627 js 1f /* negative -> in kernel */
23628 SWAPGS
23629 xorl %ebx,%ebx
23630 -1: ret
23631 +1:
23632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23633 + testb $3, CS+8(%rsp)
23634 + jnz 1f
23635 + pax_enter_kernel
23636 + jmp 2f
23637 +1: pax_enter_kernel_user
23638 +2:
23639 +#else
23640 + pax_enter_kernel
23641 +#endif
23642 + pax_force_retaddr
23643 + ret
23644 CFI_ENDPROC
23645 -END(save_paranoid)
23646 +ENDPROC(save_paranoid)
23647 +
23648 +ENTRY(save_paranoid_nmi)
23649 + XCPT_FRAME 1 RDI+8
23650 + cld
23651 + movq_cfi rdi, RDI+8
23652 + movq_cfi rsi, RSI+8
23653 + movq_cfi rdx, RDX+8
23654 + movq_cfi rcx, RCX+8
23655 + movq_cfi rax, RAX+8
23656 + movq_cfi r8, R8+8
23657 + movq_cfi r9, R9+8
23658 + movq_cfi r10, R10+8
23659 + movq_cfi r11, R11+8
23660 + movq_cfi rbx, RBX+8
23661 + movq_cfi rbp, RBP+8
23662 + movq_cfi r12, R12+8
23663 + movq_cfi r13, R13+8
23664 + movq_cfi r14, R14+8
23665 + movq_cfi r15, R15+8
23666 + movl $1,%ebx
23667 + movl $MSR_GS_BASE,%ecx
23668 + rdmsr
23669 + testl %edx,%edx
23670 + js 1f /* negative -> in kernel */
23671 + SWAPGS
23672 + xorl %ebx,%ebx
23673 +1: pax_enter_kernel_nmi
23674 + pax_force_retaddr
23675 + ret
23676 + CFI_ENDPROC
23677 +ENDPROC(save_paranoid_nmi)
23678
23679 /*
23680 * A newly forked process directly context switches into this address.
23681 @@ -331,7 +793,7 @@ ENTRY(ret_from_fork)
23682
23683 RESTORE_REST
23684
23685 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23686 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23687 jz 1f
23688
23689 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23690 @@ -341,15 +803,13 @@ ENTRY(ret_from_fork)
23691 jmp ret_from_sys_call # go to the SYSRET fastpath
23692
23693 1:
23694 - subq $REST_SKIP, %rsp # leave space for volatiles
23695 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23696 movq %rbp, %rdi
23697 call *%rbx
23698 movl $0, RAX(%rsp)
23699 RESTORE_REST
23700 jmp int_ret_from_sys_call
23701 CFI_ENDPROC
23702 -END(ret_from_fork)
23703 +ENDPROC(ret_from_fork)
23704
23705 /*
23706 * System call entry. Up to 6 arguments in registers are supported.
23707 @@ -386,7 +846,7 @@ END(ret_from_fork)
23708 ENTRY(system_call)
23709 CFI_STARTPROC simple
23710 CFI_SIGNAL_FRAME
23711 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23712 + CFI_DEF_CFA rsp,0
23713 CFI_REGISTER rip,rcx
23714 /*CFI_REGISTER rflags,r11*/
23715 SWAPGS_UNSAFE_STACK
23716 @@ -399,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23717
23718 movq %rsp,PER_CPU_VAR(old_rsp)
23719 movq PER_CPU_VAR(kernel_stack),%rsp
23720 + SAVE_ARGS 8*6, 0, rax_enosys=1
23721 + pax_enter_kernel_user
23722 +
23723 +#ifdef CONFIG_PAX_RANDKSTACK
23724 + pax_erase_kstack
23725 +#endif
23726 +
23727 /*
23728 * No need to follow this irqs off/on section - it's straight
23729 * and short:
23730 */
23731 ENABLE_INTERRUPTS(CLBR_NONE)
23732 - SAVE_ARGS 8, 0, rax_enosys=1
23733 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23734 movq %rcx,RIP-ARGOFFSET(%rsp)
23735 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23736 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23737 + GET_THREAD_INFO(%rcx)
23738 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23739 jnz tracesys
23740 system_call_fastpath:
23741 #if __SYSCALL_MASK == ~0
23742 @@ -432,10 +899,13 @@ sysret_check:
23743 LOCKDEP_SYS_EXIT
23744 DISABLE_INTERRUPTS(CLBR_NONE)
23745 TRACE_IRQS_OFF
23746 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23747 + GET_THREAD_INFO(%rcx)
23748 + movl TI_flags(%rcx),%edx
23749 andl %edi,%edx
23750 jnz sysret_careful
23751 CFI_REMEMBER_STATE
23752 + pax_exit_kernel_user
23753 + pax_erase_kstack
23754 /*
23755 * sysretq will re-enable interrupts:
23756 */
23757 @@ -494,12 +964,15 @@ sysret_audit:
23758
23759 /* Do syscall tracing */
23760 tracesys:
23761 - leaq -REST_SKIP(%rsp), %rdi
23762 + movq %rsp, %rdi
23763 movq $AUDIT_ARCH_X86_64, %rsi
23764 call syscall_trace_enter_phase1
23765 test %rax, %rax
23766 jnz tracesys_phase2 /* if needed, run the slow path */
23767 - LOAD_ARGS 0 /* else restore clobbered regs */
23768 +
23769 + pax_erase_kstack
23770 +
23771 + LOAD_ARGS /* else restore clobbered regs */
23772 jmp system_call_fastpath /* and return to the fast path */
23773
23774 tracesys_phase2:
23775 @@ -510,12 +983,14 @@ tracesys_phase2:
23776 movq %rax,%rdx
23777 call syscall_trace_enter_phase2
23778
23779 + pax_erase_kstack
23780 +
23781 /*
23782 * Reload arg registers from stack in case ptrace changed them.
23783 * We don't reload %rax because syscall_trace_entry_phase2() returned
23784 * the value it wants us to use in the table lookup.
23785 */
23786 - LOAD_ARGS ARGOFFSET, 1
23787 + LOAD_ARGS 1
23788 RESTORE_REST
23789 #if __SYSCALL_MASK == ~0
23790 cmpq $__NR_syscall_max,%rax
23791 @@ -545,7 +1020,9 @@ GLOBAL(int_with_check)
23792 andl %edi,%edx
23793 jnz int_careful
23794 andl $~TS_COMPAT,TI_status(%rcx)
23795 - jmp retint_swapgs
23796 + pax_exit_kernel_user
23797 + pax_erase_kstack
23798 + jmp retint_swapgs_pax
23799
23800 /* Either reschedule or signal or syscall exit tracking needed. */
23801 /* First do a reschedule test. */
23802 @@ -591,7 +1068,7 @@ int_restore_rest:
23803 TRACE_IRQS_OFF
23804 jmp int_with_check
23805 CFI_ENDPROC
23806 -END(system_call)
23807 +ENDPROC(system_call)
23808
23809 .macro FORK_LIKE func
23810 ENTRY(stub_\func)
23811 @@ -604,9 +1081,10 @@ ENTRY(stub_\func)
23812 DEFAULT_FRAME 0 8 /* offset 8: return address */
23813 call sys_\func
23814 RESTORE_TOP_OF_STACK %r11, 8
23815 - ret $REST_SKIP /* pop extended registers */
23816 + pax_force_retaddr
23817 + ret
23818 CFI_ENDPROC
23819 -END(stub_\func)
23820 +ENDPROC(stub_\func)
23821 .endm
23822
23823 .macro FIXED_FRAME label,func
23824 @@ -616,9 +1094,10 @@ ENTRY(\label)
23825 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23826 call \func
23827 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23828 + pax_force_retaddr
23829 ret
23830 CFI_ENDPROC
23831 -END(\label)
23832 +ENDPROC(\label)
23833 .endm
23834
23835 FORK_LIKE clone
23836 @@ -626,19 +1105,6 @@ END(\label)
23837 FORK_LIKE vfork
23838 FIXED_FRAME stub_iopl, sys_iopl
23839
23840 -ENTRY(ptregscall_common)
23841 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23842 - RESTORE_TOP_OF_STACK %r11, 8
23843 - movq_cfi_restore R15+8, r15
23844 - movq_cfi_restore R14+8, r14
23845 - movq_cfi_restore R13+8, r13
23846 - movq_cfi_restore R12+8, r12
23847 - movq_cfi_restore RBP+8, rbp
23848 - movq_cfi_restore RBX+8, rbx
23849 - ret $REST_SKIP /* pop extended registers */
23850 - CFI_ENDPROC
23851 -END(ptregscall_common)
23852 -
23853 ENTRY(stub_execve)
23854 CFI_STARTPROC
23855 addq $8, %rsp
23856 @@ -650,7 +1116,7 @@ ENTRY(stub_execve)
23857 RESTORE_REST
23858 jmp int_ret_from_sys_call
23859 CFI_ENDPROC
23860 -END(stub_execve)
23861 +ENDPROC(stub_execve)
23862
23863 /*
23864 * sigreturn is special because it needs to restore all registers on return.
23865 @@ -667,7 +1133,7 @@ ENTRY(stub_rt_sigreturn)
23866 RESTORE_REST
23867 jmp int_ret_from_sys_call
23868 CFI_ENDPROC
23869 -END(stub_rt_sigreturn)
23870 +ENDPROC(stub_rt_sigreturn)
23871
23872 #ifdef CONFIG_X86_X32_ABI
23873 ENTRY(stub_x32_rt_sigreturn)
23874 @@ -681,7 +1147,7 @@ ENTRY(stub_x32_rt_sigreturn)
23875 RESTORE_REST
23876 jmp int_ret_from_sys_call
23877 CFI_ENDPROC
23878 -END(stub_x32_rt_sigreturn)
23879 +ENDPROC(stub_x32_rt_sigreturn)
23880
23881 ENTRY(stub_x32_execve)
23882 CFI_STARTPROC
23883 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_execve)
23884 RESTORE_REST
23885 jmp int_ret_from_sys_call
23886 CFI_ENDPROC
23887 -END(stub_x32_execve)
23888 +ENDPROC(stub_x32_execve)
23889
23890 #endif
23891
23892 @@ -732,7 +1198,7 @@ vector=vector+1
23893 2: jmp common_interrupt
23894 .endr
23895 CFI_ENDPROC
23896 -END(irq_entries_start)
23897 +ENDPROC(irq_entries_start)
23898
23899 .previous
23900 END(interrupt)
23901 @@ -749,8 +1215,8 @@ END(interrupt)
23902 /* 0(%rsp): ~(interrupt number) */
23903 .macro interrupt func
23904 /* reserve pt_regs for scratch regs and rbp */
23905 - subq $ORIG_RAX-RBP, %rsp
23906 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23907 + subq $ORIG_RAX, %rsp
23908 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23909 SAVE_ARGS_IRQ
23910 call \func
23911 .endm
23912 @@ -773,14 +1239,14 @@ ret_from_intr:
23913
23914 /* Restore saved previous stack */
23915 popq %rsi
23916 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23917 - leaq ARGOFFSET-RBP(%rsi), %rsp
23918 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23919 + movq %rsi, %rsp
23920 CFI_DEF_CFA_REGISTER rsp
23921 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23922 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23923
23924 exit_intr:
23925 GET_THREAD_INFO(%rcx)
23926 - testl $3,CS-ARGOFFSET(%rsp)
23927 + testb $3,CS-ARGOFFSET(%rsp)
23928 je retint_kernel
23929
23930 /* Interrupt came from user space */
23931 @@ -802,12 +1268,35 @@ retint_swapgs: /* return to user-space */
23932 * The iretq could re-enable interrupts:
23933 */
23934 DISABLE_INTERRUPTS(CLBR_ANY)
23935 + pax_exit_kernel_user
23936 +retint_swapgs_pax:
23937 TRACE_IRQS_IRETQ
23938 SWAPGS
23939 jmp restore_args
23940
23941 retint_restore_args: /* return to kernel space */
23942 DISABLE_INTERRUPTS(CLBR_ANY)
23943 + pax_exit_kernel
23944 +
23945 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23946 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23947 + * namely calling EFI runtime services with a phys mapping. We're
23948 + * starting off with NOPs and patch in the real instrumentation
23949 + * (BTS/OR) before starting any userland process; even before starting
23950 + * up the APs.
23951 + */
23952 + .pushsection .altinstr_replacement, "a"
23953 + 601: pax_force_retaddr (RIP-ARGOFFSET)
23954 + 602:
23955 + .popsection
23956 + 603: .fill 602b-601b, 1, 0x90
23957 + .pushsection .altinstructions, "a"
23958 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23959 + .popsection
23960 +#else
23961 + pax_force_retaddr (RIP-ARGOFFSET)
23962 +#endif
23963 +
23964 /*
23965 * The iretq could re-enable interrupts:
23966 */
23967 @@ -845,15 +1334,15 @@ native_irq_return_ldt:
23968 SWAPGS
23969 movq PER_CPU_VAR(espfix_waddr),%rdi
23970 movq %rax,(0*8)(%rdi) /* RAX */
23971 - movq (2*8)(%rsp),%rax /* RIP */
23972 + movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23973 movq %rax,(1*8)(%rdi)
23974 - movq (3*8)(%rsp),%rax /* CS */
23975 + movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23976 movq %rax,(2*8)(%rdi)
23977 - movq (4*8)(%rsp),%rax /* RFLAGS */
23978 + movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23979 movq %rax,(3*8)(%rdi)
23980 - movq (6*8)(%rsp),%rax /* SS */
23981 + movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23982 movq %rax,(5*8)(%rdi)
23983 - movq (5*8)(%rsp),%rax /* RSP */
23984 + movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23985 movq %rax,(4*8)(%rdi)
23986 andl $0xffff0000,%eax
23987 popq_cfi %rdi
23988 @@ -907,7 +1396,7 @@ ENTRY(retint_kernel)
23989 jmp exit_intr
23990 #endif
23991 CFI_ENDPROC
23992 -END(common_interrupt)
23993 +ENDPROC(common_interrupt)
23994
23995 /*
23996 * APIC interrupts.
23997 @@ -921,7 +1410,7 @@ ENTRY(\sym)
23998 interrupt \do_sym
23999 jmp ret_from_intr
24000 CFI_ENDPROC
24001 -END(\sym)
24002 +ENDPROC(\sym)
24003 .endm
24004
24005 #ifdef CONFIG_TRACING
24006 @@ -994,7 +1483,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24007 /*
24008 * Exception entry points.
24009 */
24010 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24011 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24012
24013 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24014 ENTRY(\sym)
24015 @@ -1045,6 +1534,12 @@ ENTRY(\sym)
24016 .endif
24017
24018 .if \shift_ist != -1
24019 +#ifdef CONFIG_SMP
24020 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24021 + lea init_tss(%r13), %r13
24022 +#else
24023 + lea init_tss(%rip), %r13
24024 +#endif
24025 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24026 .endif
24027
24028 @@ -1061,7 +1556,7 @@ ENTRY(\sym)
24029 .endif
24030
24031 CFI_ENDPROC
24032 -END(\sym)
24033 +ENDPROC(\sym)
24034 .endm
24035
24036 #ifdef CONFIG_TRACING
24037 @@ -1102,9 +1597,10 @@ gs_change:
24038 2: mfence /* workaround */
24039 SWAPGS
24040 popfq_cfi
24041 + pax_force_retaddr
24042 ret
24043 CFI_ENDPROC
24044 -END(native_load_gs_index)
24045 +ENDPROC(native_load_gs_index)
24046
24047 _ASM_EXTABLE(gs_change,bad_gs)
24048 .section .fixup,"ax"
24049 @@ -1132,9 +1628,10 @@ ENTRY(do_softirq_own_stack)
24050 CFI_DEF_CFA_REGISTER rsp
24051 CFI_ADJUST_CFA_OFFSET -8
24052 decl PER_CPU_VAR(irq_count)
24053 + pax_force_retaddr
24054 ret
24055 CFI_ENDPROC
24056 -END(do_softirq_own_stack)
24057 +ENDPROC(do_softirq_own_stack)
24058
24059 #ifdef CONFIG_XEN
24060 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24061 @@ -1172,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24062 decl PER_CPU_VAR(irq_count)
24063 jmp error_exit
24064 CFI_ENDPROC
24065 -END(xen_do_hypervisor_callback)
24066 +ENDPROC(xen_do_hypervisor_callback)
24067
24068 /*
24069 * Hypervisor uses this for application faults while it executes.
24070 @@ -1231,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
24071 SAVE_ALL
24072 jmp error_exit
24073 CFI_ENDPROC
24074 -END(xen_failsafe_callback)
24075 +ENDPROC(xen_failsafe_callback)
24076
24077 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24078 xen_hvm_callback_vector xen_evtchn_do_upcall
24079 @@ -1278,18 +1775,33 @@ ENTRY(paranoid_exit)
24080 DEFAULT_FRAME
24081 DISABLE_INTERRUPTS(CLBR_NONE)
24082 TRACE_IRQS_OFF_DEBUG
24083 - testl %ebx,%ebx /* swapgs needed? */
24084 + testl $1,%ebx /* swapgs needed? */
24085 jnz paranoid_restore
24086 - testl $3,CS(%rsp)
24087 + testb $3,CS(%rsp)
24088 jnz paranoid_userspace
24089 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24090 + pax_exit_kernel
24091 + TRACE_IRQS_IRETQ 0
24092 + SWAPGS_UNSAFE_STACK
24093 + RESTORE_ALL 8
24094 + pax_force_retaddr_bts
24095 + jmp irq_return
24096 +#endif
24097 paranoid_swapgs:
24098 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24099 + pax_exit_kernel_user
24100 +#else
24101 + pax_exit_kernel
24102 +#endif
24103 TRACE_IRQS_IRETQ 0
24104 SWAPGS_UNSAFE_STACK
24105 RESTORE_ALL 8
24106 jmp irq_return
24107 paranoid_restore:
24108 + pax_exit_kernel
24109 TRACE_IRQS_IRETQ_DEBUG 0
24110 RESTORE_ALL 8
24111 + pax_force_retaddr_bts
24112 jmp irq_return
24113 paranoid_userspace:
24114 GET_THREAD_INFO(%rcx)
24115 @@ -1318,7 +1830,7 @@ paranoid_schedule:
24116 TRACE_IRQS_OFF
24117 jmp paranoid_userspace
24118 CFI_ENDPROC
24119 -END(paranoid_exit)
24120 +ENDPROC(paranoid_exit)
24121
24122 /*
24123 * Exception entry point. This expects an error code/orig_rax on the stack.
24124 @@ -1345,12 +1857,23 @@ ENTRY(error_entry)
24125 movq %r14, R14+8(%rsp)
24126 movq %r15, R15+8(%rsp)
24127 xorl %ebx,%ebx
24128 - testl $3,CS+8(%rsp)
24129 + testb $3,CS+8(%rsp)
24130 je error_kernelspace
24131 error_swapgs:
24132 SWAPGS
24133 error_sti:
24134 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24135 + testb $3, CS+8(%rsp)
24136 + jnz 1f
24137 + pax_enter_kernel
24138 + jmp 2f
24139 +1: pax_enter_kernel_user
24140 +2:
24141 +#else
24142 + pax_enter_kernel
24143 +#endif
24144 TRACE_IRQS_OFF
24145 + pax_force_retaddr
24146 ret
24147
24148 /*
24149 @@ -1385,7 +1908,7 @@ error_bad_iret:
24150 decl %ebx /* Return to usergs */
24151 jmp error_sti
24152 CFI_ENDPROC
24153 -END(error_entry)
24154 +ENDPROC(error_entry)
24155
24156
24157 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24158 @@ -1396,7 +1919,7 @@ ENTRY(error_exit)
24159 DISABLE_INTERRUPTS(CLBR_NONE)
24160 TRACE_IRQS_OFF
24161 GET_THREAD_INFO(%rcx)
24162 - testl %eax,%eax
24163 + testl $1,%eax
24164 jne retint_kernel
24165 LOCKDEP_SYS_EXIT_IRQ
24166 movl TI_flags(%rcx),%edx
24167 @@ -1405,7 +1928,7 @@ ENTRY(error_exit)
24168 jnz retint_careful
24169 jmp retint_swapgs
24170 CFI_ENDPROC
24171 -END(error_exit)
24172 +ENDPROC(error_exit)
24173
24174 /*
24175 * Test if a given stack is an NMI stack or not.
24176 @@ -1463,9 +1986,11 @@ ENTRY(nmi)
24177 * If %cs was not the kernel segment, then the NMI triggered in user
24178 * space, which means it is definitely not nested.
24179 */
24180 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24181 + je 1f
24182 cmpl $__KERNEL_CS, 16(%rsp)
24183 jne first_nmi
24184 -
24185 +1:
24186 /*
24187 * Check the special variable on the stack to see if NMIs are
24188 * executing.
24189 @@ -1499,8 +2024,7 @@ nested_nmi:
24190
24191 1:
24192 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24193 - leaq -1*8(%rsp), %rdx
24194 - movq %rdx, %rsp
24195 + subq $8, %rsp
24196 CFI_ADJUST_CFA_OFFSET 1*8
24197 leaq -10*8(%rsp), %rdx
24198 pushq_cfi $__KERNEL_DS
24199 @@ -1518,6 +2042,7 @@ nested_nmi_out:
24200 CFI_RESTORE rdx
24201
24202 /* No need to check faults here */
24203 +# pax_force_retaddr_bts
24204 INTERRUPT_RETURN
24205
24206 CFI_RESTORE_STATE
24207 @@ -1614,13 +2139,13 @@ end_repeat_nmi:
24208 subq $ORIG_RAX-R15, %rsp
24209 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24210 /*
24211 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24212 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24213 * as we should not be calling schedule in NMI context.
24214 * Even with normal interrupts enabled. An NMI should not be
24215 * setting NEED_RESCHED or anything that normal interrupts and
24216 * exceptions might do.
24217 */
24218 - call save_paranoid
24219 + call save_paranoid_nmi
24220 DEFAULT_FRAME 0
24221
24222 /*
24223 @@ -1630,9 +2155,9 @@ end_repeat_nmi:
24224 * NMI itself takes a page fault, the page fault that was preempted
24225 * will read the information from the NMI page fault and not the
24226 * origin fault. Save it off and restore it if it changes.
24227 - * Use the r12 callee-saved register.
24228 + * Use the r13 callee-saved register.
24229 */
24230 - movq %cr2, %r12
24231 + movq %cr2, %r13
24232
24233 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24234 movq %rsp,%rdi
24235 @@ -1641,29 +2166,34 @@ end_repeat_nmi:
24236
24237 /* Did the NMI take a page fault? Restore cr2 if it did */
24238 movq %cr2, %rcx
24239 - cmpq %rcx, %r12
24240 + cmpq %rcx, %r13
24241 je 1f
24242 - movq %r12, %cr2
24243 + movq %r13, %cr2
24244 1:
24245
24246 - testl %ebx,%ebx /* swapgs needed? */
24247 + testl $1,%ebx /* swapgs needed? */
24248 jnz nmi_restore
24249 nmi_swapgs:
24250 SWAPGS_UNSAFE_STACK
24251 nmi_restore:
24252 + pax_exit_kernel_nmi
24253 /* Pop the extra iret frame at once */
24254 RESTORE_ALL 6*8
24255 + testb $3, 8(%rsp)
24256 + jnz 1f
24257 + pax_force_retaddr_bts
24258 +1:
24259
24260 /* Clear the NMI executing stack variable */
24261 movq $0, 5*8(%rsp)
24262 jmp irq_return
24263 CFI_ENDPROC
24264 -END(nmi)
24265 +ENDPROC(nmi)
24266
24267 ENTRY(ignore_sysret)
24268 CFI_STARTPROC
24269 mov $-ENOSYS,%eax
24270 sysret
24271 CFI_ENDPROC
24272 -END(ignore_sysret)
24273 +ENDPROC(ignore_sysret)
24274
24275 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24276 index 94d857f..5bce89c 100644
24277 --- a/arch/x86/kernel/espfix_64.c
24278 +++ b/arch/x86/kernel/espfix_64.c
24279 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24280 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24281 static void *espfix_pages[ESPFIX_MAX_PAGES];
24282
24283 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24284 - __aligned(PAGE_SIZE);
24285 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24286
24287 static unsigned int page_random, slot_random;
24288
24289 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
24290 void __init init_espfix_bsp(void)
24291 {
24292 pgd_t *pgd_p;
24293 - pteval_t ptemask;
24294 -
24295 - ptemask = __supported_pte_mask;
24296 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24297
24298 /* Install the espfix pud into the kernel page directory */
24299 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24300 + pgd_p = &init_level4_pgt[index];
24301 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24302
24303 +#ifdef CONFIG_PAX_PER_CPU_PGD
24304 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24305 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24306 +#endif
24307 +
24308 /* Randomize the locations */
24309 init_espfix_random();
24310
24311 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
24312 set_pte(&pte_p[n*PTE_STRIDE], pte);
24313
24314 /* Job is done for this CPU and any CPU which shares this page */
24315 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24316 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24317
24318 unlock_done:
24319 mutex_unlock(&espfix_init_mutex);
24320 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24321 index 3386dc9..28bdf81 100644
24322 --- a/arch/x86/kernel/ftrace.c
24323 +++ b/arch/x86/kernel/ftrace.c
24324 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24325 * kernel identity mapping to modify code.
24326 */
24327 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24328 - ip = (unsigned long)__va(__pa_symbol(ip));
24329 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24330
24331 return ip;
24332 }
24333 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24334 {
24335 unsigned char replaced[MCOUNT_INSN_SIZE];
24336
24337 + ip = ktla_ktva(ip);
24338 +
24339 /*
24340 * Note: Due to modules and __init, code can
24341 * disappear and change, we need to protect against faulting
24342 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24343 unsigned char old[MCOUNT_INSN_SIZE];
24344 int ret;
24345
24346 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24347 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24348
24349 ftrace_update_func = ip;
24350 /* Make sure the breakpoints see the ftrace_update_func update */
24351 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24352 unsigned char replaced[MCOUNT_INSN_SIZE];
24353 unsigned char brk = BREAKPOINT_INSTRUCTION;
24354
24355 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24356 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24357 return -EFAULT;
24358
24359 /* Make sure it is what we expect it to be */
24360 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24361 index eda1a86..8f6df48 100644
24362 --- a/arch/x86/kernel/head64.c
24363 +++ b/arch/x86/kernel/head64.c
24364 @@ -67,12 +67,12 @@ again:
24365 pgd = *pgd_p;
24366
24367 /*
24368 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24369 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24370 + * The use of __early_va rather than __va here is critical:
24371 + * __va would point us back into the dynamic
24372 * range and we might end up looping forever...
24373 */
24374 if (pgd)
24375 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24376 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24377 else {
24378 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24379 reset_early_page_tables();
24380 @@ -82,13 +82,13 @@ again:
24381 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24382 for (i = 0; i < PTRS_PER_PUD; i++)
24383 pud_p[i] = 0;
24384 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24385 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24386 }
24387 pud_p += pud_index(address);
24388 pud = *pud_p;
24389
24390 if (pud)
24391 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24392 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24393 else {
24394 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24395 reset_early_page_tables();
24396 @@ -98,7 +98,7 @@ again:
24397 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24398 for (i = 0; i < PTRS_PER_PMD; i++)
24399 pmd_p[i] = 0;
24400 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24401 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24402 }
24403 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24404 pmd_p[pmd_index(address)] = pmd;
24405 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24406 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24407 early_printk("Kernel alive\n");
24408
24409 - clear_page(init_level4_pgt);
24410 /* set init_level4_pgt kernel high mapping*/
24411 init_level4_pgt[511] = early_level4_pgt[511];
24412
24413 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24414 index f36bd42..0ab4474 100644
24415 --- a/arch/x86/kernel/head_32.S
24416 +++ b/arch/x86/kernel/head_32.S
24417 @@ -26,6 +26,12 @@
24418 /* Physical address */
24419 #define pa(X) ((X) - __PAGE_OFFSET)
24420
24421 +#ifdef CONFIG_PAX_KERNEXEC
24422 +#define ta(X) (X)
24423 +#else
24424 +#define ta(X) ((X) - __PAGE_OFFSET)
24425 +#endif
24426 +
24427 /*
24428 * References to members of the new_cpu_data structure.
24429 */
24430 @@ -55,11 +61,7 @@
24431 * and small than max_low_pfn, otherwise will waste some page table entries
24432 */
24433
24434 -#if PTRS_PER_PMD > 1
24435 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24436 -#else
24437 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24438 -#endif
24439 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24440
24441 /* Number of possible pages in the lowmem region */
24442 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24443 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24444 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24445
24446 /*
24447 + * Real beginning of normal "text" segment
24448 + */
24449 +ENTRY(stext)
24450 +ENTRY(_stext)
24451 +
24452 +/*
24453 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24454 * %esi points to the real-mode code as a 32-bit pointer.
24455 * CS and DS must be 4 GB flat segments, but we don't depend on
24456 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24457 * can.
24458 */
24459 __HEAD
24460 +
24461 +#ifdef CONFIG_PAX_KERNEXEC
24462 + jmp startup_32
24463 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24464 +.fill PAGE_SIZE-5,1,0xcc
24465 +#endif
24466 +
24467 ENTRY(startup_32)
24468 movl pa(stack_start),%ecx
24469
24470 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24471 2:
24472 leal -__PAGE_OFFSET(%ecx),%esp
24473
24474 +#ifdef CONFIG_SMP
24475 + movl $pa(cpu_gdt_table),%edi
24476 + movl $__per_cpu_load,%eax
24477 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24478 + rorl $16,%eax
24479 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24480 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24481 + movl $__per_cpu_end - 1,%eax
24482 + subl $__per_cpu_start,%eax
24483 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24484 +#endif
24485 +
24486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24487 + movl $NR_CPUS,%ecx
24488 + movl $pa(cpu_gdt_table),%edi
24489 +1:
24490 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24491 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24492 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24493 + addl $PAGE_SIZE_asm,%edi
24494 + loop 1b
24495 +#endif
24496 +
24497 +#ifdef CONFIG_PAX_KERNEXEC
24498 + movl $pa(boot_gdt),%edi
24499 + movl $__LOAD_PHYSICAL_ADDR,%eax
24500 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24501 + rorl $16,%eax
24502 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24503 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24504 + rorl $16,%eax
24505 +
24506 + ljmp $(__BOOT_CS),$1f
24507 +1:
24508 +
24509 + movl $NR_CPUS,%ecx
24510 + movl $pa(cpu_gdt_table),%edi
24511 + addl $__PAGE_OFFSET,%eax
24512 +1:
24513 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24514 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24515 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24516 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24517 + rorl $16,%eax
24518 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24519 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24520 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24521 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24522 + rorl $16,%eax
24523 + addl $PAGE_SIZE_asm,%edi
24524 + loop 1b
24525 +#endif
24526 +
24527 /*
24528 * Clear BSS first so that there are no surprises...
24529 */
24530 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24531 movl %eax, pa(max_pfn_mapped)
24532
24533 /* Do early initialization of the fixmap area */
24534 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24535 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24536 +#ifdef CONFIG_COMPAT_VDSO
24537 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24538 +#else
24539 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24540 +#endif
24541 #else /* Not PAE */
24542
24543 page_pde_offset = (__PAGE_OFFSET >> 20);
24544 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24545 movl %eax, pa(max_pfn_mapped)
24546
24547 /* Do early initialization of the fixmap area */
24548 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24549 - movl %eax,pa(initial_page_table+0xffc)
24550 +#ifdef CONFIG_COMPAT_VDSO
24551 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24552 +#else
24553 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24554 +#endif
24555 #endif
24556
24557 #ifdef CONFIG_PARAVIRT
24558 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24559 cmpl $num_subarch_entries, %eax
24560 jae bad_subarch
24561
24562 - movl pa(subarch_entries)(,%eax,4), %eax
24563 - subl $__PAGE_OFFSET, %eax
24564 - jmp *%eax
24565 + jmp *pa(subarch_entries)(,%eax,4)
24566
24567 bad_subarch:
24568 WEAK(lguest_entry)
24569 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24570 __INITDATA
24571
24572 subarch_entries:
24573 - .long default_entry /* normal x86/PC */
24574 - .long lguest_entry /* lguest hypervisor */
24575 - .long xen_entry /* Xen hypervisor */
24576 - .long default_entry /* Moorestown MID */
24577 + .long ta(default_entry) /* normal x86/PC */
24578 + .long ta(lguest_entry) /* lguest hypervisor */
24579 + .long ta(xen_entry) /* Xen hypervisor */
24580 + .long ta(default_entry) /* Moorestown MID */
24581 num_subarch_entries = (. - subarch_entries) / 4
24582 .previous
24583 #else
24584 @@ -354,6 +426,7 @@ default_entry:
24585 movl pa(mmu_cr4_features),%eax
24586 movl %eax,%cr4
24587
24588 +#ifdef CONFIG_X86_PAE
24589 testb $X86_CR4_PAE, %al # check if PAE is enabled
24590 jz enable_paging
24591
24592 @@ -382,6 +455,9 @@ default_entry:
24593 /* Make changes effective */
24594 wrmsr
24595
24596 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24597 +#endif
24598 +
24599 enable_paging:
24600
24601 /*
24602 @@ -449,14 +525,20 @@ is486:
24603 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24604 movl %eax,%ss # after changing gdt.
24605
24606 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24607 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24608 movl %eax,%ds
24609 movl %eax,%es
24610
24611 movl $(__KERNEL_PERCPU), %eax
24612 movl %eax,%fs # set this cpu's percpu
24613
24614 +#ifdef CONFIG_CC_STACKPROTECTOR
24615 movl $(__KERNEL_STACK_CANARY),%eax
24616 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24617 + movl $(__USER_DS),%eax
24618 +#else
24619 + xorl %eax,%eax
24620 +#endif
24621 movl %eax,%gs
24622
24623 xorl %eax,%eax # Clear LDT
24624 @@ -512,8 +594,11 @@ setup_once:
24625 * relocation. Manually set base address in stack canary
24626 * segment descriptor.
24627 */
24628 - movl $gdt_page,%eax
24629 + movl $cpu_gdt_table,%eax
24630 movl $stack_canary,%ecx
24631 +#ifdef CONFIG_SMP
24632 + addl $__per_cpu_load,%ecx
24633 +#endif
24634 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24635 shrl $16, %ecx
24636 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24637 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24638 cmpl $2,(%esp) # X86_TRAP_NMI
24639 je is_nmi # Ignore NMI
24640
24641 - cmpl $2,%ss:early_recursion_flag
24642 + cmpl $1,%ss:early_recursion_flag
24643 je hlt_loop
24644 incl %ss:early_recursion_flag
24645
24646 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24647 pushl (20+6*4)(%esp) /* trapno */
24648 pushl $fault_msg
24649 call printk
24650 -#endif
24651 call dump_stack
24652 +#endif
24653 hlt_loop:
24654 hlt
24655 jmp hlt_loop
24656 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24657 /* This is the default interrupt "handler" :-) */
24658 ALIGN
24659 ignore_int:
24660 - cld
24661 #ifdef CONFIG_PRINTK
24662 + cmpl $2,%ss:early_recursion_flag
24663 + je hlt_loop
24664 + incl %ss:early_recursion_flag
24665 + cld
24666 pushl %eax
24667 pushl %ecx
24668 pushl %edx
24669 @@ -617,9 +705,6 @@ ignore_int:
24670 movl $(__KERNEL_DS),%eax
24671 movl %eax,%ds
24672 movl %eax,%es
24673 - cmpl $2,early_recursion_flag
24674 - je hlt_loop
24675 - incl early_recursion_flag
24676 pushl 16(%esp)
24677 pushl 24(%esp)
24678 pushl 32(%esp)
24679 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24680 /*
24681 * BSS section
24682 */
24683 -__PAGE_ALIGNED_BSS
24684 - .align PAGE_SIZE
24685 #ifdef CONFIG_X86_PAE
24686 +.section .initial_pg_pmd,"a",@progbits
24687 initial_pg_pmd:
24688 .fill 1024*KPMDS,4,0
24689 #else
24690 +.section .initial_page_table,"a",@progbits
24691 ENTRY(initial_page_table)
24692 .fill 1024,4,0
24693 #endif
24694 +.section .initial_pg_fixmap,"a",@progbits
24695 initial_pg_fixmap:
24696 .fill 1024,4,0
24697 +.section .empty_zero_page,"a",@progbits
24698 ENTRY(empty_zero_page)
24699 .fill 4096,1,0
24700 +.section .swapper_pg_dir,"a",@progbits
24701 ENTRY(swapper_pg_dir)
24702 +#ifdef CONFIG_X86_PAE
24703 + .fill 4,8,0
24704 +#else
24705 .fill 1024,4,0
24706 +#endif
24707
24708 /*
24709 * This starts the data section.
24710 */
24711 #ifdef CONFIG_X86_PAE
24712 -__PAGE_ALIGNED_DATA
24713 - /* Page-aligned for the benefit of paravirt? */
24714 - .align PAGE_SIZE
24715 +.section .initial_page_table,"a",@progbits
24716 ENTRY(initial_page_table)
24717 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24718 # if KPMDS == 3
24719 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24720 # error "Kernel PMDs should be 1, 2 or 3"
24721 # endif
24722 .align PAGE_SIZE /* needs to be page-sized too */
24723 +
24724 +#ifdef CONFIG_PAX_PER_CPU_PGD
24725 +ENTRY(cpu_pgd)
24726 + .rept 2*NR_CPUS
24727 + .fill 4,8,0
24728 + .endr
24729 +#endif
24730 +
24731 #endif
24732
24733 .data
24734 .balign 4
24735 ENTRY(stack_start)
24736 - .long init_thread_union+THREAD_SIZE
24737 + .long init_thread_union+THREAD_SIZE-8
24738
24739 __INITRODATA
24740 int_msg:
24741 @@ -727,7 +825,7 @@ fault_msg:
24742 * segment size, and 32-bit linear address value:
24743 */
24744
24745 - .data
24746 +.section .rodata,"a",@progbits
24747 .globl boot_gdt_descr
24748 .globl idt_descr
24749
24750 @@ -736,7 +834,7 @@ fault_msg:
24751 .word 0 # 32 bit align gdt_desc.address
24752 boot_gdt_descr:
24753 .word __BOOT_DS+7
24754 - .long boot_gdt - __PAGE_OFFSET
24755 + .long pa(boot_gdt)
24756
24757 .word 0 # 32-bit align idt_desc.address
24758 idt_descr:
24759 @@ -747,7 +845,7 @@ idt_descr:
24760 .word 0 # 32 bit align gdt_desc.address
24761 ENTRY(early_gdt_descr)
24762 .word GDT_ENTRIES*8-1
24763 - .long gdt_page /* Overwritten for secondary CPUs */
24764 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24765
24766 /*
24767 * The boot_gdt must mirror the equivalent in setup.S and is
24768 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24769 .align L1_CACHE_BYTES
24770 ENTRY(boot_gdt)
24771 .fill GDT_ENTRY_BOOT_CS,8,0
24772 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24773 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24774 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24775 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24776 +
24777 + .align PAGE_SIZE_asm
24778 +ENTRY(cpu_gdt_table)
24779 + .rept NR_CPUS
24780 + .quad 0x0000000000000000 /* NULL descriptor */
24781 + .quad 0x0000000000000000 /* 0x0b reserved */
24782 + .quad 0x0000000000000000 /* 0x13 reserved */
24783 + .quad 0x0000000000000000 /* 0x1b reserved */
24784 +
24785 +#ifdef CONFIG_PAX_KERNEXEC
24786 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24787 +#else
24788 + .quad 0x0000000000000000 /* 0x20 unused */
24789 +#endif
24790 +
24791 + .quad 0x0000000000000000 /* 0x28 unused */
24792 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24793 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24794 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24795 + .quad 0x0000000000000000 /* 0x4b reserved */
24796 + .quad 0x0000000000000000 /* 0x53 reserved */
24797 + .quad 0x0000000000000000 /* 0x5b reserved */
24798 +
24799 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24800 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24801 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24802 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24803 +
24804 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24805 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24806 +
24807 + /*
24808 + * Segments used for calling PnP BIOS have byte granularity.
24809 + * The code segments and data segments have fixed 64k limits,
24810 + * the transfer segment sizes are set at run time.
24811 + */
24812 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24813 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24814 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24815 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24816 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24817 +
24818 + /*
24819 + * The APM segments have byte granularity and their bases
24820 + * are set at run time. All have 64k limits.
24821 + */
24822 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24823 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24824 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24825 +
24826 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24827 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24828 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24829 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24830 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24831 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24832 +
24833 + /* Be sure this is zeroed to avoid false validations in Xen */
24834 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24835 + .endr
24836 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24837 index a468c0a..8b5a879 100644
24838 --- a/arch/x86/kernel/head_64.S
24839 +++ b/arch/x86/kernel/head_64.S
24840 @@ -20,6 +20,8 @@
24841 #include <asm/processor-flags.h>
24842 #include <asm/percpu.h>
24843 #include <asm/nops.h>
24844 +#include <asm/cpufeature.h>
24845 +#include <asm/alternative-asm.h>
24846
24847 #ifdef CONFIG_PARAVIRT
24848 #include <asm/asm-offsets.h>
24849 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24850 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24851 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24852 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24853 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24854 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24855 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24856 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24857 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24858 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24859
24860 .text
24861 __HEAD
24862 @@ -89,11 +97,24 @@ startup_64:
24863 * Fixup the physical addresses in the page table
24864 */
24865 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24866 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24867 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24868 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24869 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24870 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24871
24872 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24873 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24874 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24875 +#ifndef CONFIG_XEN
24876 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24877 +#endif
24878 +
24879 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24880 +
24881 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24882 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24883
24884 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24885 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24886
24887 /*
24888 * Set up the identity mapping for the switchover. These
24889 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24890 * after the boot processor executes this code.
24891 */
24892
24893 + orq $-1, %rbp
24894 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24895 1:
24896
24897 - /* Enable PAE mode and PGE */
24898 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24899 + /* Enable PAE mode and PSE/PGE */
24900 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24901 movq %rcx, %cr4
24902
24903 /* Setup early boot stage 4 level pagetables. */
24904 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24905 movl $MSR_EFER, %ecx
24906 rdmsr
24907 btsl $_EFER_SCE, %eax /* Enable System Call */
24908 - btl $20,%edi /* No Execute supported? */
24909 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24910 jnc 1f
24911 btsl $_EFER_NX, %eax
24912 + cmpq $-1, %rbp
24913 + je 1f
24914 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24915 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24916 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24917 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24918 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24919 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24920 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24921 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24922 1: wrmsr /* Make changes effective */
24923
24924 /* Setup cr0 */
24925 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24926 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24927 * address given in m16:64.
24928 */
24929 + pax_set_fptr_mask
24930 movq initial_code(%rip),%rax
24931 pushq $0 # fake return address to stop unwinder
24932 pushq $__KERNEL_CS # set correct cs
24933 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24934 .quad INIT_PER_CPU_VAR(irq_stack_union)
24935
24936 GLOBAL(stack_start)
24937 - .quad init_thread_union+THREAD_SIZE-8
24938 + .quad init_thread_union+THREAD_SIZE-16
24939 .word 0
24940 __FINITDATA
24941
24942 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24943 call dump_stack
24944 #ifdef CONFIG_KALLSYMS
24945 leaq early_idt_ripmsg(%rip),%rdi
24946 - movq 40(%rsp),%rsi # %rip again
24947 + movq 88(%rsp),%rsi # %rip again
24948 call __print_symbol
24949 #endif
24950 #endif /* EARLY_PRINTK */
24951 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24952 early_recursion_flag:
24953 .long 0
24954
24955 + .section .rodata,"a",@progbits
24956 #ifdef CONFIG_EARLY_PRINTK
24957 early_idt_msg:
24958 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24959 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24960 NEXT_PAGE(early_dynamic_pgts)
24961 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24962
24963 - .data
24964 + .section .rodata,"a",@progbits
24965
24966 -#ifndef CONFIG_XEN
24967 NEXT_PAGE(init_level4_pgt)
24968 - .fill 512,8,0
24969 -#else
24970 -NEXT_PAGE(init_level4_pgt)
24971 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24972 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24973 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24974 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24975 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24976 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24977 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24978 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24979 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24980 .org init_level4_pgt + L4_START_KERNEL*8, 0
24981 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24982 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24983
24984 +#ifdef CONFIG_PAX_PER_CPU_PGD
24985 +NEXT_PAGE(cpu_pgd)
24986 + .rept 2*NR_CPUS
24987 + .fill 512,8,0
24988 + .endr
24989 +#endif
24990 +
24991 NEXT_PAGE(level3_ident_pgt)
24992 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24993 +#ifdef CONFIG_XEN
24994 .fill 511, 8, 0
24995 +#else
24996 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24997 + .fill 510,8,0
24998 +#endif
24999 +
25000 +NEXT_PAGE(level3_vmalloc_start_pgt)
25001 + .fill 512,8,0
25002 +
25003 +NEXT_PAGE(level3_vmalloc_end_pgt)
25004 + .fill 512,8,0
25005 +
25006 +NEXT_PAGE(level3_vmemmap_pgt)
25007 + .fill L3_VMEMMAP_START,8,0
25008 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25009 +
25010 NEXT_PAGE(level2_ident_pgt)
25011 - /* Since I easily can, map the first 1G.
25012 + /* Since I easily can, map the first 2G.
25013 * Don't set NX because code runs from these pages.
25014 */
25015 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25016 -#endif
25017 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25018
25019 NEXT_PAGE(level3_kernel_pgt)
25020 .fill L3_START_KERNEL,8,0
25021 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25022 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25023 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25024
25025 +NEXT_PAGE(level2_vmemmap_pgt)
25026 + .fill 512,8,0
25027 +
25028 NEXT_PAGE(level2_kernel_pgt)
25029 /*
25030 * 512 MB kernel mapping. We spend a full page on this pagetable
25031 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25032 NEXT_PAGE(level2_fixmap_pgt)
25033 .fill 506,8,0
25034 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25035 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25036 - .fill 5,8,0
25037 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25038 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25039 + .fill 4,8,0
25040
25041 NEXT_PAGE(level1_fixmap_pgt)
25042 .fill 512,8,0
25043
25044 +NEXT_PAGE(level1_vsyscall_pgt)
25045 + .fill 512,8,0
25046 +
25047 #undef PMDS
25048
25049 - .data
25050 + .align PAGE_SIZE
25051 +ENTRY(cpu_gdt_table)
25052 + .rept NR_CPUS
25053 + .quad 0x0000000000000000 /* NULL descriptor */
25054 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25055 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25056 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25057 + .quad 0x00cffb000000ffff /* __USER32_CS */
25058 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25059 + .quad 0x00affb000000ffff /* __USER_CS */
25060 +
25061 +#ifdef CONFIG_PAX_KERNEXEC
25062 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25063 +#else
25064 + .quad 0x0 /* unused */
25065 +#endif
25066 +
25067 + .quad 0,0 /* TSS */
25068 + .quad 0,0 /* LDT */
25069 + .quad 0,0,0 /* three TLS descriptors */
25070 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25071 + /* asm/segment.h:GDT_ENTRIES must match this */
25072 +
25073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25074 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25075 +#else
25076 + .quad 0x0 /* unused */
25077 +#endif
25078 +
25079 + /* zero the remaining page */
25080 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25081 + .endr
25082 +
25083 .align 16
25084 .globl early_gdt_descr
25085 early_gdt_descr:
25086 .word GDT_ENTRIES*8-1
25087 early_gdt_descr_base:
25088 - .quad INIT_PER_CPU_VAR(gdt_page)
25089 + .quad cpu_gdt_table
25090
25091 ENTRY(phys_base)
25092 /* This must match the first entry in level2_kernel_pgt */
25093 .quad 0x0000000000000000
25094
25095 #include "../../x86/xen/xen-head.S"
25096 -
25097 - __PAGE_ALIGNED_BSS
25098 +
25099 + .section .rodata,"a",@progbits
25100 NEXT_PAGE(empty_zero_page)
25101 .skip PAGE_SIZE
25102 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25103 index 05fd74f..c3548b1 100644
25104 --- a/arch/x86/kernel/i386_ksyms_32.c
25105 +++ b/arch/x86/kernel/i386_ksyms_32.c
25106 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25107 EXPORT_SYMBOL(cmpxchg8b_emu);
25108 #endif
25109
25110 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25111 +
25112 /* Networking helper routines. */
25113 EXPORT_SYMBOL(csum_partial_copy_generic);
25114 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25115 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25116
25117 EXPORT_SYMBOL(__get_user_1);
25118 EXPORT_SYMBOL(__get_user_2);
25119 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25120 EXPORT_SYMBOL(___preempt_schedule_context);
25121 #endif
25122 #endif
25123 +
25124 +#ifdef CONFIG_PAX_KERNEXEC
25125 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25126 +#endif
25127 +
25128 +#ifdef CONFIG_PAX_PER_CPU_PGD
25129 +EXPORT_SYMBOL(cpu_pgd);
25130 +#endif
25131 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25132 index a9a4229..6f4d476 100644
25133 --- a/arch/x86/kernel/i387.c
25134 +++ b/arch/x86/kernel/i387.c
25135 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25136 static inline bool interrupted_user_mode(void)
25137 {
25138 struct pt_regs *regs = get_irq_regs();
25139 - return regs && user_mode_vm(regs);
25140 + return regs && user_mode(regs);
25141 }
25142
25143 /*
25144 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25145 index e7cc537..67d7372 100644
25146 --- a/arch/x86/kernel/i8259.c
25147 +++ b/arch/x86/kernel/i8259.c
25148 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25149 static void make_8259A_irq(unsigned int irq)
25150 {
25151 disable_irq_nosync(irq);
25152 - io_apic_irqs &= ~(1<<irq);
25153 + io_apic_irqs &= ~(1UL<<irq);
25154 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25155 enable_irq(irq);
25156 }
25157 @@ -208,7 +208,7 @@ spurious_8259A_irq:
25158 "spurious 8259A interrupt: IRQ%d.\n", irq);
25159 spurious_irq_mask |= irqmask;
25160 }
25161 - atomic_inc(&irq_err_count);
25162 + atomic_inc_unchecked(&irq_err_count);
25163 /*
25164 * Theoretically we do not have to handle this IRQ,
25165 * but in Linux this does not cause problems and is
25166 @@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25167 /* (slave's support for AEOI in flat mode is to be investigated) */
25168 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25169
25170 + pax_open_kernel();
25171 if (auto_eoi)
25172 /*
25173 * In AEOI mode we just have to mask the interrupt
25174 * when acking.
25175 */
25176 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25177 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25178 else
25179 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25180 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25181 + pax_close_kernel();
25182
25183 udelay(100); /* wait for 8259A to initialize */
25184
25185 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25186 index a979b5b..1d6db75 100644
25187 --- a/arch/x86/kernel/io_delay.c
25188 +++ b/arch/x86/kernel/io_delay.c
25189 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25190 * Quirk table for systems that misbehave (lock up, etc.) if port
25191 * 0x80 is used:
25192 */
25193 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25194 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25195 {
25196 .callback = dmi_io_delay_0xed_port,
25197 .ident = "Compaq Presario V6000",
25198 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25199 index 4ddaf66..49d5c18 100644
25200 --- a/arch/x86/kernel/ioport.c
25201 +++ b/arch/x86/kernel/ioport.c
25202 @@ -6,6 +6,7 @@
25203 #include <linux/sched.h>
25204 #include <linux/kernel.h>
25205 #include <linux/capability.h>
25206 +#include <linux/security.h>
25207 #include <linux/errno.h>
25208 #include <linux/types.h>
25209 #include <linux/ioport.h>
25210 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25211 return -EINVAL;
25212 if (turn_on && !capable(CAP_SYS_RAWIO))
25213 return -EPERM;
25214 +#ifdef CONFIG_GRKERNSEC_IO
25215 + if (turn_on && grsec_disable_privio) {
25216 + gr_handle_ioperm();
25217 + return -ENODEV;
25218 + }
25219 +#endif
25220
25221 /*
25222 * If it's the first ioperm() call in this thread's lifetime, set the
25223 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25224 * because the ->io_bitmap_max value must match the bitmap
25225 * contents:
25226 */
25227 - tss = &per_cpu(init_tss, get_cpu());
25228 + tss = init_tss + get_cpu();
25229
25230 if (turn_on)
25231 bitmap_clear(t->io_bitmap_ptr, from, num);
25232 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25233 if (level > old) {
25234 if (!capable(CAP_SYS_RAWIO))
25235 return -EPERM;
25236 +#ifdef CONFIG_GRKERNSEC_IO
25237 + if (grsec_disable_privio) {
25238 + gr_handle_iopl();
25239 + return -ENODEV;
25240 + }
25241 +#endif
25242 }
25243 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25244 t->iopl = level << 12;
25245 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25246 index 3790775..53717dc 100644
25247 --- a/arch/x86/kernel/irq.c
25248 +++ b/arch/x86/kernel/irq.c
25249 @@ -22,7 +22,7 @@
25250 #define CREATE_TRACE_POINTS
25251 #include <asm/trace/irq_vectors.h>
25252
25253 -atomic_t irq_err_count;
25254 +atomic_unchecked_t irq_err_count;
25255
25256 /* Function pointer for generic interrupt vector handling */
25257 void (*x86_platform_ipi_callback)(void) = NULL;
25258 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25259 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25260 seq_printf(p, " Hypervisor callback interrupts\n");
25261 #endif
25262 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25263 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25264 #if defined(CONFIG_X86_IO_APIC)
25265 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25266 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25267 #endif
25268 return 0;
25269 }
25270 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25271
25272 u64 arch_irq_stat(void)
25273 {
25274 - u64 sum = atomic_read(&irq_err_count);
25275 + u64 sum = atomic_read_unchecked(&irq_err_count);
25276 return sum;
25277 }
25278
25279 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25280 index 63ce838..2ea3e06 100644
25281 --- a/arch/x86/kernel/irq_32.c
25282 +++ b/arch/x86/kernel/irq_32.c
25283 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25284
25285 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25286
25287 +extern void gr_handle_kernel_exploit(void);
25288 +
25289 int sysctl_panic_on_stackoverflow __read_mostly;
25290
25291 /* Debugging check for stack overflow: is there less than 1KB free? */
25292 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25293 __asm__ __volatile__("andl %%esp,%0" :
25294 "=r" (sp) : "0" (THREAD_SIZE - 1));
25295
25296 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25297 + return sp < STACK_WARN;
25298 }
25299
25300 static void print_stack_overflow(void)
25301 {
25302 printk(KERN_WARNING "low stack detected by irq handler\n");
25303 dump_stack();
25304 + gr_handle_kernel_exploit();
25305 if (sysctl_panic_on_stackoverflow)
25306 panic("low stack detected by irq handler - check messages\n");
25307 }
25308 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25309 static inline int
25310 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25311 {
25312 - struct irq_stack *curstk, *irqstk;
25313 + struct irq_stack *irqstk;
25314 u32 *isp, *prev_esp, arg1, arg2;
25315
25316 - curstk = (struct irq_stack *) current_stack();
25317 irqstk = __this_cpu_read(hardirq_stack);
25318
25319 /*
25320 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25321 * handler) we can't do that and just have to keep using the
25322 * current stack (which is the irq stack already after all)
25323 */
25324 - if (unlikely(curstk == irqstk))
25325 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25326 return 0;
25327
25328 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25329 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25330
25331 /* Save the next esp at the bottom of the stack */
25332 prev_esp = (u32 *)irqstk;
25333 *prev_esp = current_stack_pointer;
25334
25335 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25336 + __set_fs(MAKE_MM_SEG(0));
25337 +#endif
25338 +
25339 if (unlikely(overflow))
25340 call_on_stack(print_stack_overflow, isp);
25341
25342 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25343 : "0" (irq), "1" (desc), "2" (isp),
25344 "D" (desc->handle_irq)
25345 : "memory", "cc", "ecx");
25346 +
25347 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25348 + __set_fs(current_thread_info()->addr_limit);
25349 +#endif
25350 +
25351 return 1;
25352 }
25353
25354 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25355 */
25356 void irq_ctx_init(int cpu)
25357 {
25358 - struct irq_stack *irqstk;
25359 -
25360 if (per_cpu(hardirq_stack, cpu))
25361 return;
25362
25363 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25364 - THREADINFO_GFP,
25365 - THREAD_SIZE_ORDER));
25366 - per_cpu(hardirq_stack, cpu) = irqstk;
25367 -
25368 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25369 - THREADINFO_GFP,
25370 - THREAD_SIZE_ORDER));
25371 - per_cpu(softirq_stack, cpu) = irqstk;
25372 -
25373 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25374 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25375 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25376 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25377 }
25378
25379 void do_softirq_own_stack(void)
25380 {
25381 - struct thread_info *curstk;
25382 struct irq_stack *irqstk;
25383 u32 *isp, *prev_esp;
25384
25385 - curstk = current_stack();
25386 irqstk = __this_cpu_read(softirq_stack);
25387
25388 /* build the stack frame on the softirq stack */
25389 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25390 prev_esp = (u32 *)irqstk;
25391 *prev_esp = current_stack_pointer;
25392
25393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25394 + __set_fs(MAKE_MM_SEG(0));
25395 +#endif
25396 +
25397 call_on_stack(__do_softirq, isp);
25398 +
25399 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25400 + __set_fs(current_thread_info()->addr_limit);
25401 +#endif
25402 +
25403 }
25404
25405 bool handle_irq(unsigned irq, struct pt_regs *regs)
25406 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25407 if (unlikely(!desc))
25408 return false;
25409
25410 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25411 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25412 if (unlikely(overflow))
25413 print_stack_overflow();
25414 desc->handle_irq(irq, desc);
25415 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25416 index e4b503d..824fce8 100644
25417 --- a/arch/x86/kernel/irq_64.c
25418 +++ b/arch/x86/kernel/irq_64.c
25419 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25420 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25421 EXPORT_PER_CPU_SYMBOL(irq_regs);
25422
25423 +extern void gr_handle_kernel_exploit(void);
25424 +
25425 int sysctl_panic_on_stackoverflow;
25426
25427 /*
25428 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25429 u64 estack_top, estack_bottom;
25430 u64 curbase = (u64)task_stack_page(current);
25431
25432 - if (user_mode_vm(regs))
25433 + if (user_mode(regs))
25434 return;
25435
25436 if (regs->sp >= curbase + sizeof(struct thread_info) +
25437 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25438 irq_stack_top, irq_stack_bottom,
25439 estack_top, estack_bottom);
25440
25441 + gr_handle_kernel_exploit();
25442 +
25443 if (sysctl_panic_on_stackoverflow)
25444 panic("low stack detected by irq handler - check messages\n");
25445 #endif
25446 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25447 index 26d5a55..a01160a 100644
25448 --- a/arch/x86/kernel/jump_label.c
25449 +++ b/arch/x86/kernel/jump_label.c
25450 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25451 * Jump label is enabled for the first time.
25452 * So we expect a default_nop...
25453 */
25454 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25455 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25456 != 0))
25457 bug_at((void *)entry->code, __LINE__);
25458 } else {
25459 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25460 * ...otherwise expect an ideal_nop. Otherwise
25461 * something went horribly wrong.
25462 */
25463 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25464 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25465 != 0))
25466 bug_at((void *)entry->code, __LINE__);
25467 }
25468 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25469 * are converting the default nop to the ideal nop.
25470 */
25471 if (init) {
25472 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25473 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25474 bug_at((void *)entry->code, __LINE__);
25475 } else {
25476 code.jump = 0xe9;
25477 code.offset = entry->target -
25478 (entry->code + JUMP_LABEL_NOP_SIZE);
25479 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25480 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25481 bug_at((void *)entry->code, __LINE__);
25482 }
25483 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25484 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25485 index 7ec1d5f..5a7d130 100644
25486 --- a/arch/x86/kernel/kgdb.c
25487 +++ b/arch/x86/kernel/kgdb.c
25488 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25489 #ifdef CONFIG_X86_32
25490 switch (regno) {
25491 case GDB_SS:
25492 - if (!user_mode_vm(regs))
25493 + if (!user_mode(regs))
25494 *(unsigned long *)mem = __KERNEL_DS;
25495 break;
25496 case GDB_SP:
25497 - if (!user_mode_vm(regs))
25498 + if (!user_mode(regs))
25499 *(unsigned long *)mem = kernel_stack_pointer(regs);
25500 break;
25501 case GDB_GS:
25502 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25503 bp->attr.bp_addr = breakinfo[breakno].addr;
25504 bp->attr.bp_len = breakinfo[breakno].len;
25505 bp->attr.bp_type = breakinfo[breakno].type;
25506 - info->address = breakinfo[breakno].addr;
25507 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25508 + info->address = ktla_ktva(breakinfo[breakno].addr);
25509 + else
25510 + info->address = breakinfo[breakno].addr;
25511 info->len = breakinfo[breakno].len;
25512 info->type = breakinfo[breakno].type;
25513 val = arch_install_hw_breakpoint(bp);
25514 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25515 case 'k':
25516 /* clear the trace bit */
25517 linux_regs->flags &= ~X86_EFLAGS_TF;
25518 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25519 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25520
25521 /* set the trace bit if we're stepping */
25522 if (remcomInBuffer[0] == 's') {
25523 linux_regs->flags |= X86_EFLAGS_TF;
25524 - atomic_set(&kgdb_cpu_doing_single_step,
25525 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25526 raw_smp_processor_id());
25527 }
25528
25529 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25530
25531 switch (cmd) {
25532 case DIE_DEBUG:
25533 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25534 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25535 if (user_mode(regs))
25536 return single_step_cont(regs, args);
25537 break;
25538 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25539 #endif /* CONFIG_DEBUG_RODATA */
25540
25541 bpt->type = BP_BREAKPOINT;
25542 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25543 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25544 BREAK_INSTR_SIZE);
25545 if (err)
25546 return err;
25547 - err = probe_kernel_write((char *)bpt->bpt_addr,
25548 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25549 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25550 #ifdef CONFIG_DEBUG_RODATA
25551 if (!err)
25552 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25553 return -EBUSY;
25554 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25555 BREAK_INSTR_SIZE);
25556 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25557 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25558 if (err)
25559 return err;
25560 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25561 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25562 if (mutex_is_locked(&text_mutex))
25563 goto knl_write;
25564 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25565 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25566 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25567 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25568 goto knl_write;
25569 return err;
25570 knl_write:
25571 #endif /* CONFIG_DEBUG_RODATA */
25572 - return probe_kernel_write((char *)bpt->bpt_addr,
25573 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25574 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25575 }
25576
25577 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25578 index 93d2c04..36d0e94 100644
25579 --- a/arch/x86/kernel/kprobes/core.c
25580 +++ b/arch/x86/kernel/kprobes/core.c
25581 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25582 s32 raddr;
25583 } __packed *insn;
25584
25585 - insn = (struct __arch_relative_insn *)from;
25586 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25587 +
25588 + pax_open_kernel();
25589 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25590 insn->op = op;
25591 + pax_close_kernel();
25592 }
25593
25594 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25595 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25596 kprobe_opcode_t opcode;
25597 kprobe_opcode_t *orig_opcodes = opcodes;
25598
25599 - if (search_exception_tables((unsigned long)opcodes))
25600 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25601 return 0; /* Page fault may occur on this address. */
25602
25603 retry:
25604 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25605 * for the first byte, we can recover the original instruction
25606 * from it and kp->opcode.
25607 */
25608 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25609 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25610 buf[0] = kp->opcode;
25611 - return (unsigned long)buf;
25612 + return ktva_ktla((unsigned long)buf);
25613 }
25614
25615 /*
25616 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25617 /* Another subsystem puts a breakpoint, failed to recover */
25618 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25619 return 0;
25620 + pax_open_kernel();
25621 memcpy(dest, insn.kaddr, insn.length);
25622 + pax_close_kernel();
25623
25624 #ifdef CONFIG_X86_64
25625 if (insn_rip_relative(&insn)) {
25626 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25627 return 0;
25628 }
25629 disp = (u8 *) dest + insn_offset_displacement(&insn);
25630 + pax_open_kernel();
25631 *(s32 *) disp = (s32) newdisp;
25632 + pax_close_kernel();
25633 }
25634 #endif
25635 return insn.length;
25636 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25637 * nor set current_kprobe, because it doesn't use single
25638 * stepping.
25639 */
25640 - regs->ip = (unsigned long)p->ainsn.insn;
25641 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25642 preempt_enable_no_resched();
25643 return;
25644 }
25645 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25646 regs->flags &= ~X86_EFLAGS_IF;
25647 /* single step inline if the instruction is an int3 */
25648 if (p->opcode == BREAKPOINT_INSTRUCTION)
25649 - regs->ip = (unsigned long)p->addr;
25650 + regs->ip = ktla_ktva((unsigned long)p->addr);
25651 else
25652 - regs->ip = (unsigned long)p->ainsn.insn;
25653 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25654 }
25655 NOKPROBE_SYMBOL(setup_singlestep);
25656
25657 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25658 struct kprobe *p;
25659 struct kprobe_ctlblk *kcb;
25660
25661 - if (user_mode_vm(regs))
25662 + if (user_mode(regs))
25663 return 0;
25664
25665 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25666 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25667 setup_singlestep(p, regs, kcb, 0);
25668 return 1;
25669 }
25670 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25671 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25672 /*
25673 * The breakpoint instruction was removed right
25674 * after we hit it. Another cpu has removed
25675 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25676 " movq %rax, 152(%rsp)\n"
25677 RESTORE_REGS_STRING
25678 " popfq\n"
25679 +#ifdef KERNEXEC_PLUGIN
25680 + " btsq $63,(%rsp)\n"
25681 +#endif
25682 #else
25683 " pushf\n"
25684 SAVE_REGS_STRING
25685 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25686 struct kprobe_ctlblk *kcb)
25687 {
25688 unsigned long *tos = stack_addr(regs);
25689 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25690 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25691 unsigned long orig_ip = (unsigned long)p->addr;
25692 kprobe_opcode_t *insn = p->ainsn.insn;
25693
25694 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25695 struct die_args *args = data;
25696 int ret = NOTIFY_DONE;
25697
25698 - if (args->regs && user_mode_vm(args->regs))
25699 + if (args->regs && user_mode(args->regs))
25700 return ret;
25701
25702 if (val == DIE_GPF) {
25703 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25704 index f1314d0..15f3154 100644
25705 --- a/arch/x86/kernel/kprobes/opt.c
25706 +++ b/arch/x86/kernel/kprobes/opt.c
25707 @@ -79,6 +79,7 @@ found:
25708 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25709 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25710 {
25711 + pax_open_kernel();
25712 #ifdef CONFIG_X86_64
25713 *addr++ = 0x48;
25714 *addr++ = 0xbf;
25715 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25716 *addr++ = 0xb8;
25717 #endif
25718 *(unsigned long *)addr = val;
25719 + pax_close_kernel();
25720 }
25721
25722 asm (
25723 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25724 * Verify if the address gap is in 2GB range, because this uses
25725 * a relative jump.
25726 */
25727 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25728 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25729 if (abs(rel) > 0x7fffffff) {
25730 __arch_remove_optimized_kprobe(op, 0);
25731 return -ERANGE;
25732 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25733 op->optinsn.size = ret;
25734
25735 /* Copy arch-dep-instance from template */
25736 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25737 + pax_open_kernel();
25738 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25739 + pax_close_kernel();
25740
25741 /* Set probe information */
25742 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25743
25744 /* Set probe function call */
25745 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25746 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25747
25748 /* Set returning jmp instruction at the tail of out-of-line buffer */
25749 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25750 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25751 (u8 *)op->kp.addr + op->optinsn.size);
25752
25753 flush_icache_range((unsigned long) buf,
25754 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25755 WARN_ON(kprobe_disabled(&op->kp));
25756
25757 /* Backup instructions which will be replaced by jump address */
25758 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25759 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25760 RELATIVE_ADDR_SIZE);
25761
25762 insn_buf[0] = RELATIVEJUMP_OPCODE;
25763 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25764 /* This kprobe is really able to run optimized path. */
25765 op = container_of(p, struct optimized_kprobe, kp);
25766 /* Detour through copied instructions */
25767 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25768 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25769 if (!reenter)
25770 reset_current_kprobe();
25771 preempt_enable_no_resched();
25772 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25773 index c2bedae..25e7ab60 100644
25774 --- a/arch/x86/kernel/ksysfs.c
25775 +++ b/arch/x86/kernel/ksysfs.c
25776 @@ -184,7 +184,7 @@ out:
25777
25778 static struct kobj_attribute type_attr = __ATTR_RO(type);
25779
25780 -static struct bin_attribute data_attr = {
25781 +static bin_attribute_no_const data_attr __read_only = {
25782 .attr = {
25783 .name = "data",
25784 .mode = S_IRUGO,
25785 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25786 index c37886d..d851d32 100644
25787 --- a/arch/x86/kernel/ldt.c
25788 +++ b/arch/x86/kernel/ldt.c
25789 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25790 if (reload) {
25791 #ifdef CONFIG_SMP
25792 preempt_disable();
25793 - load_LDT(pc);
25794 + load_LDT_nolock(pc);
25795 if (!cpumask_equal(mm_cpumask(current->mm),
25796 cpumask_of(smp_processor_id())))
25797 smp_call_function(flush_ldt, current->mm, 1);
25798 preempt_enable();
25799 #else
25800 - load_LDT(pc);
25801 + load_LDT_nolock(pc);
25802 #endif
25803 }
25804 if (oldsize) {
25805 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25806 return err;
25807
25808 for (i = 0; i < old->size; i++)
25809 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25810 + write_ldt_entry(new->ldt, i, old->ldt + i);
25811 return 0;
25812 }
25813
25814 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25815 retval = copy_ldt(&mm->context, &old_mm->context);
25816 mutex_unlock(&old_mm->context.lock);
25817 }
25818 +
25819 + if (tsk == current) {
25820 + mm->context.vdso = 0;
25821 +
25822 +#ifdef CONFIG_X86_32
25823 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25824 + mm->context.user_cs_base = 0UL;
25825 + mm->context.user_cs_limit = ~0UL;
25826 +
25827 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25828 + cpus_clear(mm->context.cpu_user_cs_mask);
25829 +#endif
25830 +
25831 +#endif
25832 +#endif
25833 +
25834 + }
25835 +
25836 return retval;
25837 }
25838
25839 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25840 }
25841 }
25842
25843 +#ifdef CONFIG_PAX_SEGMEXEC
25844 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25845 + error = -EINVAL;
25846 + goto out_unlock;
25847 + }
25848 +#endif
25849 +
25850 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25851 error = -EINVAL;
25852 goto out_unlock;
25853 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25854 index 72e8e31..f2f1605 100644
25855 --- a/arch/x86/kernel/machine_kexec_32.c
25856 +++ b/arch/x86/kernel/machine_kexec_32.c
25857 @@ -25,7 +25,7 @@
25858 #include <asm/cacheflush.h>
25859 #include <asm/debugreg.h>
25860
25861 -static void set_idt(void *newidt, __u16 limit)
25862 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25863 {
25864 struct desc_ptr curidt;
25865
25866 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25867 }
25868
25869
25870 -static void set_gdt(void *newgdt, __u16 limit)
25871 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25872 {
25873 struct desc_ptr curgdt;
25874
25875 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25876 }
25877
25878 control_page = page_address(image->control_code_page);
25879 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25880 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25881
25882 relocate_kernel_ptr = control_page;
25883 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25884 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25885 index c73aecf..4c63630 100644
25886 --- a/arch/x86/kernel/mcount_64.S
25887 +++ b/arch/x86/kernel/mcount_64.S
25888 @@ -7,7 +7,7 @@
25889 #include <linux/linkage.h>
25890 #include <asm/ptrace.h>
25891 #include <asm/ftrace.h>
25892 -
25893 +#include <asm/alternative-asm.h>
25894
25895 .code64
25896 .section .entry.text, "ax"
25897 @@ -24,8 +24,9 @@
25898 #ifdef CONFIG_DYNAMIC_FTRACE
25899
25900 ENTRY(function_hook)
25901 + pax_force_retaddr
25902 retq
25903 -END(function_hook)
25904 +ENDPROC(function_hook)
25905
25906 /* skip is set if stack has been adjusted */
25907 .macro ftrace_caller_setup skip=0
25908 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25909 #endif
25910
25911 GLOBAL(ftrace_stub)
25912 + pax_force_retaddr
25913 retq
25914 -END(ftrace_caller)
25915 +ENDPROC(ftrace_caller)
25916
25917 ENTRY(ftrace_regs_caller)
25918 /* Save the current flags before compare (in SS location)*/
25919 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25920 popfq
25921 jmp ftrace_stub
25922
25923 -END(ftrace_regs_caller)
25924 +ENDPROC(ftrace_regs_caller)
25925
25926
25927 #else /* ! CONFIG_DYNAMIC_FTRACE */
25928 @@ -145,6 +147,7 @@ ENTRY(function_hook)
25929 #endif
25930
25931 GLOBAL(ftrace_stub)
25932 + pax_force_retaddr
25933 retq
25934
25935 trace:
25936 @@ -158,12 +161,13 @@ trace:
25937 #endif
25938 subq $MCOUNT_INSN_SIZE, %rdi
25939
25940 + pax_force_fptr ftrace_trace_function
25941 call *ftrace_trace_function
25942
25943 MCOUNT_RESTORE_FRAME
25944
25945 jmp ftrace_stub
25946 -END(function_hook)
25947 +ENDPROC(function_hook)
25948 #endif /* CONFIG_DYNAMIC_FTRACE */
25949 #endif /* CONFIG_FUNCTION_TRACER */
25950
25951 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25952
25953 MCOUNT_RESTORE_FRAME
25954
25955 + pax_force_retaddr
25956 retq
25957 -END(ftrace_graph_caller)
25958 +ENDPROC(ftrace_graph_caller)
25959
25960 GLOBAL(return_to_handler)
25961 subq $24, %rsp
25962 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25963 movq 8(%rsp), %rdx
25964 movq (%rsp), %rax
25965 addq $24, %rsp
25966 + pax_force_fptr %rdi
25967 jmp *%rdi
25968 +ENDPROC(return_to_handler)
25969 #endif
25970 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25971 index e69f988..da078ea 100644
25972 --- a/arch/x86/kernel/module.c
25973 +++ b/arch/x86/kernel/module.c
25974 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25975 }
25976 #endif
25977
25978 -void *module_alloc(unsigned long size)
25979 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25980 {
25981 - if (PAGE_ALIGN(size) > MODULES_LEN)
25982 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25983 return NULL;
25984 return __vmalloc_node_range(size, 1,
25985 MODULES_VADDR + get_module_load_offset(),
25986 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25987 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25988 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25989 + prot, NUMA_NO_NODE,
25990 __builtin_return_address(0));
25991 }
25992
25993 +void *module_alloc(unsigned long size)
25994 +{
25995 +
25996 +#ifdef CONFIG_PAX_KERNEXEC
25997 + return __module_alloc(size, PAGE_KERNEL);
25998 +#else
25999 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26000 +#endif
26001 +
26002 +}
26003 +
26004 +#ifdef CONFIG_PAX_KERNEXEC
26005 +#ifdef CONFIG_X86_32
26006 +void *module_alloc_exec(unsigned long size)
26007 +{
26008 + struct vm_struct *area;
26009 +
26010 + if (size == 0)
26011 + return NULL;
26012 +
26013 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26014 +return area ? area->addr : NULL;
26015 +}
26016 +EXPORT_SYMBOL(module_alloc_exec);
26017 +
26018 +void module_free_exec(struct module *mod, void *module_region)
26019 +{
26020 + vunmap(module_region);
26021 +}
26022 +EXPORT_SYMBOL(module_free_exec);
26023 +#else
26024 +void module_free_exec(struct module *mod, void *module_region)
26025 +{
26026 + module_free(mod, module_region);
26027 +}
26028 +EXPORT_SYMBOL(module_free_exec);
26029 +
26030 +void *module_alloc_exec(unsigned long size)
26031 +{
26032 + return __module_alloc(size, PAGE_KERNEL_RX);
26033 +}
26034 +EXPORT_SYMBOL(module_alloc_exec);
26035 +#endif
26036 +#endif
26037 +
26038 #ifdef CONFIG_X86_32
26039 int apply_relocate(Elf32_Shdr *sechdrs,
26040 const char *strtab,
26041 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26042 unsigned int i;
26043 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26044 Elf32_Sym *sym;
26045 - uint32_t *location;
26046 + uint32_t *plocation, location;
26047
26048 DEBUGP("Applying relocate section %u to %u\n",
26049 relsec, sechdrs[relsec].sh_info);
26050 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26051 /* This is where to make the change */
26052 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26053 - + rel[i].r_offset;
26054 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26055 + location = (uint32_t)plocation;
26056 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26057 + plocation = ktla_ktva((void *)plocation);
26058 /* This is the symbol it is referring to. Note that all
26059 undefined symbols have been resolved. */
26060 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26061 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26062 switch (ELF32_R_TYPE(rel[i].r_info)) {
26063 case R_386_32:
26064 /* We add the value into the location given */
26065 - *location += sym->st_value;
26066 + pax_open_kernel();
26067 + *plocation += sym->st_value;
26068 + pax_close_kernel();
26069 break;
26070 case R_386_PC32:
26071 /* Add the value, subtract its position */
26072 - *location += sym->st_value - (uint32_t)location;
26073 + pax_open_kernel();
26074 + *plocation += sym->st_value - location;
26075 + pax_close_kernel();
26076 break;
26077 default:
26078 pr_err("%s: Unknown relocation: %u\n",
26079 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26080 case R_X86_64_NONE:
26081 break;
26082 case R_X86_64_64:
26083 + pax_open_kernel();
26084 *(u64 *)loc = val;
26085 + pax_close_kernel();
26086 break;
26087 case R_X86_64_32:
26088 + pax_open_kernel();
26089 *(u32 *)loc = val;
26090 + pax_close_kernel();
26091 if (val != *(u32 *)loc)
26092 goto overflow;
26093 break;
26094 case R_X86_64_32S:
26095 + pax_open_kernel();
26096 *(s32 *)loc = val;
26097 + pax_close_kernel();
26098 if ((s64)val != *(s32 *)loc)
26099 goto overflow;
26100 break;
26101 case R_X86_64_PC32:
26102 val -= (u64)loc;
26103 + pax_open_kernel();
26104 *(u32 *)loc = val;
26105 + pax_close_kernel();
26106 +
26107 #if 0
26108 if ((s64)val != *(s32 *)loc)
26109 goto overflow;
26110 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26111 index c9603ac..9f88728 100644
26112 --- a/arch/x86/kernel/msr.c
26113 +++ b/arch/x86/kernel/msr.c
26114 @@ -37,6 +37,7 @@
26115 #include <linux/notifier.h>
26116 #include <linux/uaccess.h>
26117 #include <linux/gfp.h>
26118 +#include <linux/grsecurity.h>
26119
26120 #include <asm/processor.h>
26121 #include <asm/msr.h>
26122 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26123 int err = 0;
26124 ssize_t bytes = 0;
26125
26126 +#ifdef CONFIG_GRKERNSEC_KMEM
26127 + gr_handle_msr_write();
26128 + return -EPERM;
26129 +#endif
26130 +
26131 if (count % 8)
26132 return -EINVAL; /* Invalid chunk size */
26133
26134 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26135 err = -EBADF;
26136 break;
26137 }
26138 +#ifdef CONFIG_GRKERNSEC_KMEM
26139 + gr_handle_msr_write();
26140 + return -EPERM;
26141 +#endif
26142 if (copy_from_user(&regs, uregs, sizeof regs)) {
26143 err = -EFAULT;
26144 break;
26145 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26146 return notifier_from_errno(err);
26147 }
26148
26149 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26150 +static struct notifier_block msr_class_cpu_notifier = {
26151 .notifier_call = msr_class_cpu_callback,
26152 };
26153
26154 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26155 index c3e985d..110a36a 100644
26156 --- a/arch/x86/kernel/nmi.c
26157 +++ b/arch/x86/kernel/nmi.c
26158 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26159
26160 static void nmi_max_handler(struct irq_work *w)
26161 {
26162 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26163 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26164 int remainder_ns, decimal_msecs;
26165 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26166 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26167
26168 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26169 decimal_msecs = remainder_ns / 1000;
26170
26171 printk_ratelimited(KERN_INFO
26172 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26173 - a->handler, whole_msecs, decimal_msecs);
26174 + n->action->handler, whole_msecs, decimal_msecs);
26175 }
26176
26177 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26178 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26179 delta = sched_clock() - delta;
26180 trace_nmi_handler(a->handler, (int)delta, thishandled);
26181
26182 - if (delta < nmi_longest_ns || delta < a->max_duration)
26183 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26184 continue;
26185
26186 - a->max_duration = delta;
26187 - irq_work_queue(&a->irq_work);
26188 + a->work->max_duration = delta;
26189 + irq_work_queue(&a->work->irq_work);
26190 }
26191
26192 rcu_read_unlock();
26193 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26194 }
26195 NOKPROBE_SYMBOL(nmi_handle);
26196
26197 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26198 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26199 {
26200 struct nmi_desc *desc = nmi_to_desc(type);
26201 unsigned long flags;
26202 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26203 if (!action->handler)
26204 return -EINVAL;
26205
26206 - init_irq_work(&action->irq_work, nmi_max_handler);
26207 + action->work->action = action;
26208 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26209
26210 spin_lock_irqsave(&desc->lock, flags);
26211
26212 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26213 * event confuses some handlers (kdump uses this flag)
26214 */
26215 if (action->flags & NMI_FLAG_FIRST)
26216 - list_add_rcu(&action->list, &desc->head);
26217 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26218 else
26219 - list_add_tail_rcu(&action->list, &desc->head);
26220 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26221
26222 spin_unlock_irqrestore(&desc->lock, flags);
26223 return 0;
26224 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26225 if (!strcmp(n->name, name)) {
26226 WARN(in_nmi(),
26227 "Trying to free NMI (%s) from NMI context!\n", n->name);
26228 - list_del_rcu(&n->list);
26229 + pax_list_del_rcu((struct list_head *)&n->list);
26230 break;
26231 }
26232 }
26233 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26234 dotraplinkage notrace void
26235 do_nmi(struct pt_regs *regs, long error_code)
26236 {
26237 +
26238 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26239 + if (!user_mode(regs)) {
26240 + unsigned long cs = regs->cs & 0xFFFF;
26241 + unsigned long ip = ktva_ktla(regs->ip);
26242 +
26243 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26244 + regs->ip = ip;
26245 + }
26246 +#endif
26247 +
26248 nmi_nesting_preprocess(regs);
26249
26250 nmi_enter();
26251 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26252 index 6d9582e..f746287 100644
26253 --- a/arch/x86/kernel/nmi_selftest.c
26254 +++ b/arch/x86/kernel/nmi_selftest.c
26255 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26256 {
26257 /* trap all the unknown NMIs we may generate */
26258 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26259 - __initdata);
26260 + __initconst);
26261 }
26262
26263 static void __init cleanup_nmi_testsuite(void)
26264 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26265 unsigned long timeout;
26266
26267 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26268 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26269 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26270 nmi_fail = FAILURE;
26271 return;
26272 }
26273 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26274 index bbb6c73..24a58ef 100644
26275 --- a/arch/x86/kernel/paravirt-spinlocks.c
26276 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26277 @@ -8,7 +8,7 @@
26278
26279 #include <asm/paravirt.h>
26280
26281 -struct pv_lock_ops pv_lock_ops = {
26282 +struct pv_lock_ops pv_lock_ops __read_only = {
26283 #ifdef CONFIG_SMP
26284 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26285 .unlock_kick = paravirt_nop,
26286 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26287 index 548d25f..f8fb99c 100644
26288 --- a/arch/x86/kernel/paravirt.c
26289 +++ b/arch/x86/kernel/paravirt.c
26290 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26291 {
26292 return x;
26293 }
26294 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26295 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26296 +#endif
26297
26298 void __init default_banner(void)
26299 {
26300 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26301
26302 if (opfunc == NULL)
26303 /* If there's no function, patch it with a ud2a (BUG) */
26304 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26305 - else if (opfunc == _paravirt_nop)
26306 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26307 + else if (opfunc == (void *)_paravirt_nop)
26308 /* If the operation is a nop, then nop the callsite */
26309 ret = paravirt_patch_nop();
26310
26311 /* identity functions just return their single argument */
26312 - else if (opfunc == _paravirt_ident_32)
26313 + else if (opfunc == (void *)_paravirt_ident_32)
26314 ret = paravirt_patch_ident_32(insnbuf, len);
26315 - else if (opfunc == _paravirt_ident_64)
26316 + else if (opfunc == (void *)_paravirt_ident_64)
26317 ret = paravirt_patch_ident_64(insnbuf, len);
26318 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26319 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26320 + ret = paravirt_patch_ident_64(insnbuf, len);
26321 +#endif
26322
26323 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26324 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26325 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26326 if (insn_len > len || start == NULL)
26327 insn_len = len;
26328 else
26329 - memcpy(insnbuf, start, insn_len);
26330 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26331
26332 return insn_len;
26333 }
26334 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26335 return this_cpu_read(paravirt_lazy_mode);
26336 }
26337
26338 -struct pv_info pv_info = {
26339 +struct pv_info pv_info __read_only = {
26340 .name = "bare hardware",
26341 .paravirt_enabled = 0,
26342 .kernel_rpl = 0,
26343 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26344 #endif
26345 };
26346
26347 -struct pv_init_ops pv_init_ops = {
26348 +struct pv_init_ops pv_init_ops __read_only = {
26349 .patch = native_patch,
26350 };
26351
26352 -struct pv_time_ops pv_time_ops = {
26353 +struct pv_time_ops pv_time_ops __read_only = {
26354 .sched_clock = native_sched_clock,
26355 .steal_clock = native_steal_clock,
26356 };
26357
26358 -__visible struct pv_irq_ops pv_irq_ops = {
26359 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26360 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26361 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26362 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26363 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26364 #endif
26365 };
26366
26367 -__visible struct pv_cpu_ops pv_cpu_ops = {
26368 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26369 .cpuid = native_cpuid,
26370 .get_debugreg = native_get_debugreg,
26371 .set_debugreg = native_set_debugreg,
26372 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26373 NOKPROBE_SYMBOL(native_set_debugreg);
26374 NOKPROBE_SYMBOL(native_load_idt);
26375
26376 -struct pv_apic_ops pv_apic_ops = {
26377 +struct pv_apic_ops pv_apic_ops __read_only= {
26378 #ifdef CONFIG_X86_LOCAL_APIC
26379 .startup_ipi_hook = paravirt_nop,
26380 #endif
26381 };
26382
26383 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26384 +#ifdef CONFIG_X86_32
26385 +#ifdef CONFIG_X86_PAE
26386 +/* 64-bit pagetable entries */
26387 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26388 +#else
26389 /* 32-bit pagetable entries */
26390 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26391 +#endif
26392 #else
26393 /* 64-bit pagetable entries */
26394 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26395 #endif
26396
26397 -struct pv_mmu_ops pv_mmu_ops = {
26398 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26399
26400 .read_cr2 = native_read_cr2,
26401 .write_cr2 = native_write_cr2,
26402 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26403 .make_pud = PTE_IDENT,
26404
26405 .set_pgd = native_set_pgd,
26406 + .set_pgd_batched = native_set_pgd_batched,
26407 #endif
26408 #endif /* PAGETABLE_LEVELS >= 3 */
26409
26410 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26411 },
26412
26413 .set_fixmap = native_set_fixmap,
26414 +
26415 +#ifdef CONFIG_PAX_KERNEXEC
26416 + .pax_open_kernel = native_pax_open_kernel,
26417 + .pax_close_kernel = native_pax_close_kernel,
26418 +#endif
26419 +
26420 };
26421
26422 EXPORT_SYMBOL_GPL(pv_time_ops);
26423 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26424 index a1da673..b6f5831 100644
26425 --- a/arch/x86/kernel/paravirt_patch_64.c
26426 +++ b/arch/x86/kernel/paravirt_patch_64.c
26427 @@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26428 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26429 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26430 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26431 +
26432 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26433 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26434 +#endif
26435 +
26436 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26437 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26438
26439 @@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26440 PATCH_SITE(pv_mmu_ops, read_cr3);
26441 PATCH_SITE(pv_mmu_ops, write_cr3);
26442 PATCH_SITE(pv_cpu_ops, clts);
26443 +
26444 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26445 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26446 +#endif
26447 +
26448 PATCH_SITE(pv_cpu_ops, wbinvd);
26449
26450 patch_site:
26451 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26452 index 0497f71..7186c0d 100644
26453 --- a/arch/x86/kernel/pci-calgary_64.c
26454 +++ b/arch/x86/kernel/pci-calgary_64.c
26455 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26456 tce_space = be64_to_cpu(readq(target));
26457 tce_space = tce_space & TAR_SW_BITS;
26458
26459 - tce_space = tce_space & (~specified_table_size);
26460 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26461 info->tce_space = (u64 *)__va(tce_space);
26462 }
26463 }
26464 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26465 index 35ccf75..7a15747 100644
26466 --- a/arch/x86/kernel/pci-iommu_table.c
26467 +++ b/arch/x86/kernel/pci-iommu_table.c
26468 @@ -2,7 +2,7 @@
26469 #include <asm/iommu_table.h>
26470 #include <linux/string.h>
26471 #include <linux/kallsyms.h>
26472 -
26473 +#include <linux/sched.h>
26474
26475 #define DEBUG 1
26476
26477 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26478 index 77dd0ad..9ec4723 100644
26479 --- a/arch/x86/kernel/pci-swiotlb.c
26480 +++ b/arch/x86/kernel/pci-swiotlb.c
26481 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26482 struct dma_attrs *attrs)
26483 {
26484 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26485 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26486 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26487 else
26488 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26489 }
26490 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26491 index e127dda..94e384d 100644
26492 --- a/arch/x86/kernel/process.c
26493 +++ b/arch/x86/kernel/process.c
26494 @@ -36,7 +36,8 @@
26495 * section. Since TSS's are completely CPU-local, we want them
26496 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26497 */
26498 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26499 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26500 +EXPORT_SYMBOL(init_tss);
26501
26502 #ifdef CONFIG_X86_64
26503 static DEFINE_PER_CPU(unsigned char, is_idle);
26504 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26505 task_xstate_cachep =
26506 kmem_cache_create("task_xstate", xstate_size,
26507 __alignof__(union thread_xstate),
26508 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26509 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26510 setup_xstate_comp();
26511 }
26512
26513 @@ -108,7 +109,7 @@ void exit_thread(void)
26514 unsigned long *bp = t->io_bitmap_ptr;
26515
26516 if (bp) {
26517 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26518 + struct tss_struct *tss = init_tss + get_cpu();
26519
26520 t->io_bitmap_ptr = NULL;
26521 clear_thread_flag(TIF_IO_BITMAP);
26522 @@ -128,6 +129,9 @@ void flush_thread(void)
26523 {
26524 struct task_struct *tsk = current;
26525
26526 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26527 + loadsegment(gs, 0);
26528 +#endif
26529 flush_ptrace_hw_breakpoint(tsk);
26530 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26531 drop_init_fpu(tsk);
26532 @@ -274,7 +278,7 @@ static void __exit_idle(void)
26533 void exit_idle(void)
26534 {
26535 /* idle loop has pid 0 */
26536 - if (current->pid)
26537 + if (task_pid_nr(current))
26538 return;
26539 __exit_idle();
26540 }
26541 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26542 return ret;
26543 }
26544 #endif
26545 -void stop_this_cpu(void *dummy)
26546 +__noreturn void stop_this_cpu(void *dummy)
26547 {
26548 local_irq_disable();
26549 /*
26550 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26551 }
26552 early_param("idle", idle_setup);
26553
26554 -unsigned long arch_align_stack(unsigned long sp)
26555 +#ifdef CONFIG_PAX_RANDKSTACK
26556 +void pax_randomize_kstack(struct pt_regs *regs)
26557 {
26558 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26559 - sp -= get_random_int() % 8192;
26560 - return sp & ~0xf;
26561 -}
26562 + struct thread_struct *thread = &current->thread;
26563 + unsigned long time;
26564
26565 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26566 -{
26567 - unsigned long range_end = mm->brk + 0x02000000;
26568 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26569 -}
26570 + if (!randomize_va_space)
26571 + return;
26572 +
26573 + if (v8086_mode(regs))
26574 + return;
26575
26576 + rdtscl(time);
26577 +
26578 + /* P4 seems to return a 0 LSB, ignore it */
26579 +#ifdef CONFIG_MPENTIUM4
26580 + time &= 0x3EUL;
26581 + time <<= 2;
26582 +#elif defined(CONFIG_X86_64)
26583 + time &= 0xFUL;
26584 + time <<= 4;
26585 +#else
26586 + time &= 0x1FUL;
26587 + time <<= 3;
26588 +#endif
26589 +
26590 + thread->sp0 ^= time;
26591 + load_sp0(init_tss + smp_processor_id(), thread);
26592 +
26593 +#ifdef CONFIG_X86_64
26594 + this_cpu_write(kernel_stack, thread->sp0);
26595 +#endif
26596 +}
26597 +#endif
26598 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26599 index 8f3ebfe..cbc731b 100644
26600 --- a/arch/x86/kernel/process_32.c
26601 +++ b/arch/x86/kernel/process_32.c
26602 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26603 unsigned long thread_saved_pc(struct task_struct *tsk)
26604 {
26605 return ((unsigned long *)tsk->thread.sp)[3];
26606 +//XXX return tsk->thread.eip;
26607 }
26608
26609 void __show_regs(struct pt_regs *regs, int all)
26610 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26611 unsigned long sp;
26612 unsigned short ss, gs;
26613
26614 - if (user_mode_vm(regs)) {
26615 + if (user_mode(regs)) {
26616 sp = regs->sp;
26617 ss = regs->ss & 0xffff;
26618 - gs = get_user_gs(regs);
26619 } else {
26620 sp = kernel_stack_pointer(regs);
26621 savesegment(ss, ss);
26622 - savesegment(gs, gs);
26623 }
26624 + gs = get_user_gs(regs);
26625
26626 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26627 (u16)regs->cs, regs->ip, regs->flags,
26628 - smp_processor_id());
26629 + raw_smp_processor_id());
26630 print_symbol("EIP is at %s\n", regs->ip);
26631
26632 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26633 @@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26634 int copy_thread(unsigned long clone_flags, unsigned long sp,
26635 unsigned long arg, struct task_struct *p)
26636 {
26637 - struct pt_regs *childregs = task_pt_regs(p);
26638 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26639 struct task_struct *tsk;
26640 int err;
26641
26642 p->thread.sp = (unsigned long) childregs;
26643 p->thread.sp0 = (unsigned long) (childregs+1);
26644 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26645 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26646
26647 if (unlikely(p->flags & PF_KTHREAD)) {
26648 /* kernel thread */
26649 memset(childregs, 0, sizeof(struct pt_regs));
26650 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26651 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26652 - childregs->ds = __USER_DS;
26653 - childregs->es = __USER_DS;
26654 + savesegment(gs, childregs->gs);
26655 + childregs->ds = __KERNEL_DS;
26656 + childregs->es = __KERNEL_DS;
26657 childregs->fs = __KERNEL_PERCPU;
26658 childregs->bx = sp; /* function */
26659 childregs->bp = arg;
26660 @@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26661 struct thread_struct *prev = &prev_p->thread,
26662 *next = &next_p->thread;
26663 int cpu = smp_processor_id();
26664 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26665 + struct tss_struct *tss = init_tss + cpu;
26666 fpu_switch_t fpu;
26667
26668 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26669 @@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26670 */
26671 lazy_save_gs(prev->gs);
26672
26673 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26674 + __set_fs(task_thread_info(next_p)->addr_limit);
26675 +#endif
26676 +
26677 /*
26678 * Load the per-thread Thread-Local Storage descriptor.
26679 */
26680 @@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26681 */
26682 arch_end_context_switch(next_p);
26683
26684 - this_cpu_write(kernel_stack,
26685 - (unsigned long)task_stack_page(next_p) +
26686 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26687 + this_cpu_write(current_task, next_p);
26688 + this_cpu_write(current_tinfo, &next_p->tinfo);
26689 + this_cpu_write(kernel_stack, next->sp0);
26690
26691 /*
26692 * Restore %gs if needed (which is common)
26693 @@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26694
26695 switch_fpu_finish(next_p, fpu);
26696
26697 - this_cpu_write(current_task, next_p);
26698 -
26699 return prev_p;
26700 }
26701
26702 @@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26703 } while (count++ < 16);
26704 return 0;
26705 }
26706 -
26707 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26708 index 5a2c029..ec8611d 100644
26709 --- a/arch/x86/kernel/process_64.c
26710 +++ b/arch/x86/kernel/process_64.c
26711 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26712 struct pt_regs *childregs;
26713 struct task_struct *me = current;
26714
26715 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26716 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26717 childregs = task_pt_regs(p);
26718 p->thread.sp = (unsigned long) childregs;
26719 p->thread.usersp = me->thread.usersp;
26720 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26721 set_tsk_thread_flag(p, TIF_FORK);
26722 p->thread.io_bitmap_ptr = NULL;
26723
26724 @@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26725 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26726 savesegment(es, p->thread.es);
26727 savesegment(ds, p->thread.ds);
26728 + savesegment(ss, p->thread.ss);
26729 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26730 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26731
26732 if (unlikely(p->flags & PF_KTHREAD)) {
26733 @@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26734 struct thread_struct *prev = &prev_p->thread;
26735 struct thread_struct *next = &next_p->thread;
26736 int cpu = smp_processor_id();
26737 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26738 + struct tss_struct *tss = init_tss + cpu;
26739 unsigned fsindex, gsindex;
26740 fpu_switch_t fpu;
26741
26742 @@ -331,6 +334,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26743 if (unlikely(next->ds | prev->ds))
26744 loadsegment(ds, next->ds);
26745
26746 + savesegment(ss, prev->ss);
26747 + if (unlikely(next->ss != prev->ss))
26748 + loadsegment(ss, next->ss);
26749 +
26750 /*
26751 * Switch FS and GS.
26752 *
26753 @@ -404,6 +411,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26754 prev->usersp = this_cpu_read(old_rsp);
26755 this_cpu_write(old_rsp, next->usersp);
26756 this_cpu_write(current_task, next_p);
26757 + this_cpu_write(current_tinfo, &next_p->tinfo);
26758
26759 /*
26760 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26761 @@ -413,9 +421,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26762 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26763 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26764
26765 - this_cpu_write(kernel_stack,
26766 - (unsigned long)task_stack_page(next_p) +
26767 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26768 + this_cpu_write(kernel_stack, next->sp0);
26769
26770 /*
26771 * Now maybe reload the debug registers and handle I/O bitmaps
26772 @@ -485,12 +491,11 @@ unsigned long get_wchan(struct task_struct *p)
26773 if (!p || p == current || p->state == TASK_RUNNING)
26774 return 0;
26775 stack = (unsigned long)task_stack_page(p);
26776 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26777 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26778 return 0;
26779 fp = *(u64 *)(p->thread.sp);
26780 do {
26781 - if (fp < (unsigned long)stack ||
26782 - fp >= (unsigned long)stack+THREAD_SIZE)
26783 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26784 return 0;
26785 ip = *(u64 *)(fp+8);
26786 if (!in_sched_functions(ip))
26787 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26788 index e510618..5165ac0 100644
26789 --- a/arch/x86/kernel/ptrace.c
26790 +++ b/arch/x86/kernel/ptrace.c
26791 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26792 unsigned long sp = (unsigned long)&regs->sp;
26793 u32 *prev_esp;
26794
26795 - if (context == (sp & ~(THREAD_SIZE - 1)))
26796 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26797 return sp;
26798
26799 - prev_esp = (u32 *)(context);
26800 + prev_esp = *(u32 **)(context);
26801 if (prev_esp)
26802 return (unsigned long)prev_esp;
26803
26804 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26805 if (child->thread.gs != value)
26806 return do_arch_prctl(child, ARCH_SET_GS, value);
26807 return 0;
26808 +
26809 + case offsetof(struct user_regs_struct,ip):
26810 + /*
26811 + * Protect against any attempt to set ip to an
26812 + * impossible address. There are dragons lurking if the
26813 + * address is noncanonical. (This explicitly allows
26814 + * setting ip to TASK_SIZE_MAX, because user code can do
26815 + * that all by itself by running off the end of its
26816 + * address space.
26817 + */
26818 + if (value > TASK_SIZE_MAX)
26819 + return -EIO;
26820 + break;
26821 +
26822 #endif
26823 }
26824
26825 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26826 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26827 {
26828 int i;
26829 - int dr7 = 0;
26830 + unsigned long dr7 = 0;
26831 struct arch_hw_breakpoint *info;
26832
26833 for (i = 0; i < HBP_NUM; i++) {
26834 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26835 unsigned long addr, unsigned long data)
26836 {
26837 int ret;
26838 - unsigned long __user *datap = (unsigned long __user *)data;
26839 + unsigned long __user *datap = (__force unsigned long __user *)data;
26840
26841 switch (request) {
26842 /* read the word at location addr in the USER area. */
26843 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26844 if ((int) addr < 0)
26845 return -EIO;
26846 ret = do_get_thread_area(child, addr,
26847 - (struct user_desc __user *)data);
26848 + (__force struct user_desc __user *) data);
26849 break;
26850
26851 case PTRACE_SET_THREAD_AREA:
26852 if ((int) addr < 0)
26853 return -EIO;
26854 ret = do_set_thread_area(child, addr,
26855 - (struct user_desc __user *)data, 0);
26856 + (__force struct user_desc __user *) data, 0);
26857 break;
26858 #endif
26859
26860 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26861
26862 #ifdef CONFIG_X86_64
26863
26864 -static struct user_regset x86_64_regsets[] __read_mostly = {
26865 +static user_regset_no_const x86_64_regsets[] __read_only = {
26866 [REGSET_GENERAL] = {
26867 .core_note_type = NT_PRSTATUS,
26868 .n = sizeof(struct user_regs_struct) / sizeof(long),
26869 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26870 #endif /* CONFIG_X86_64 */
26871
26872 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26873 -static struct user_regset x86_32_regsets[] __read_mostly = {
26874 +static user_regset_no_const x86_32_regsets[] __read_only = {
26875 [REGSET_GENERAL] = {
26876 .core_note_type = NT_PRSTATUS,
26877 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26878 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26879 */
26880 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26881
26882 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26883 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26884 {
26885 #ifdef CONFIG_X86_64
26886 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26887 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26888 memset(info, 0, sizeof(*info));
26889 info->si_signo = SIGTRAP;
26890 info->si_code = si_code;
26891 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26892 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26893 }
26894
26895 void user_single_step_siginfo(struct task_struct *tsk,
26896 @@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26897 }
26898 }
26899
26900 +#ifdef CONFIG_GRKERNSEC_SETXID
26901 +extern void gr_delayed_cred_worker(void);
26902 +#endif
26903 +
26904 /*
26905 * We can return 0 to resume the syscall or anything else to go to phase
26906 * 2. If we resume the syscall, we need to put something appropriate in
26907 @@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26908
26909 BUG_ON(regs != task_pt_regs(current));
26910
26911 +#ifdef CONFIG_GRKERNSEC_SETXID
26912 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26913 + gr_delayed_cred_worker();
26914 +#endif
26915 +
26916 /*
26917 * If we stepped into a sysenter/syscall insn, it trapped in
26918 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26919 @@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26920 */
26921 user_exit();
26922
26923 +#ifdef CONFIG_GRKERNSEC_SETXID
26924 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26925 + gr_delayed_cred_worker();
26926 +#endif
26927 +
26928 audit_syscall_exit(regs);
26929
26930 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26931 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26932 index 2f355d2..e75ed0a 100644
26933 --- a/arch/x86/kernel/pvclock.c
26934 +++ b/arch/x86/kernel/pvclock.c
26935 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26936 reset_hung_task_detector();
26937 }
26938
26939 -static atomic64_t last_value = ATOMIC64_INIT(0);
26940 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26941
26942 void pvclock_resume(void)
26943 {
26944 - atomic64_set(&last_value, 0);
26945 + atomic64_set_unchecked(&last_value, 0);
26946 }
26947
26948 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26949 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26950 * updating at the same time, and one of them could be slightly behind,
26951 * making the assumption that last_value always go forward fail to hold.
26952 */
26953 - last = atomic64_read(&last_value);
26954 + last = atomic64_read_unchecked(&last_value);
26955 do {
26956 if (ret < last)
26957 return last;
26958 - last = atomic64_cmpxchg(&last_value, last, ret);
26959 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26960 } while (unlikely(last != ret));
26961
26962 return ret;
26963 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26964 index 17962e6..47f55db 100644
26965 --- a/arch/x86/kernel/reboot.c
26966 +++ b/arch/x86/kernel/reboot.c
26967 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26968
26969 void __noreturn machine_real_restart(unsigned int type)
26970 {
26971 +
26972 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26973 + struct desc_struct *gdt;
26974 +#endif
26975 +
26976 local_irq_disable();
26977
26978 /*
26979 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26980
26981 /* Jump to the identity-mapped low memory code */
26982 #ifdef CONFIG_X86_32
26983 - asm volatile("jmpl *%0" : :
26984 +
26985 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26986 + gdt = get_cpu_gdt_table(smp_processor_id());
26987 + pax_open_kernel();
26988 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26989 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26990 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26991 + loadsegment(ds, __KERNEL_DS);
26992 + loadsegment(es, __KERNEL_DS);
26993 + loadsegment(ss, __KERNEL_DS);
26994 +#endif
26995 +#ifdef CONFIG_PAX_KERNEXEC
26996 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26997 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26998 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26999 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27000 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27001 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27002 +#endif
27003 + pax_close_kernel();
27004 +#endif
27005 +
27006 + asm volatile("ljmpl *%0" : :
27007 "rm" (real_mode_header->machine_real_restart_asm),
27008 "a" (type));
27009 #else
27010 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27011 * This means that this function can never return, it can misbehave
27012 * by not rebooting properly and hanging.
27013 */
27014 -static void native_machine_emergency_restart(void)
27015 +static void __noreturn native_machine_emergency_restart(void)
27016 {
27017 int i;
27018 int attempt = 0;
27019 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27020 #endif
27021 }
27022
27023 -static void __machine_emergency_restart(int emergency)
27024 +static void __noreturn __machine_emergency_restart(int emergency)
27025 {
27026 reboot_emergency = emergency;
27027 machine_ops.emergency_restart();
27028 }
27029
27030 -static void native_machine_restart(char *__unused)
27031 +static void __noreturn native_machine_restart(char *__unused)
27032 {
27033 pr_notice("machine restart\n");
27034
27035 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27036 __machine_emergency_restart(0);
27037 }
27038
27039 -static void native_machine_halt(void)
27040 +static void __noreturn native_machine_halt(void)
27041 {
27042 /* Stop other cpus and apics */
27043 machine_shutdown();
27044 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27045 stop_this_cpu(NULL);
27046 }
27047
27048 -static void native_machine_power_off(void)
27049 +static void __noreturn native_machine_power_off(void)
27050 {
27051 if (pm_power_off) {
27052 if (!reboot_force)
27053 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27054 }
27055 /* A fallback in case there is no PM info available */
27056 tboot_shutdown(TB_SHUTDOWN_HALT);
27057 + unreachable();
27058 }
27059
27060 -struct machine_ops machine_ops = {
27061 +struct machine_ops machine_ops __read_only = {
27062 .power_off = native_machine_power_off,
27063 .shutdown = native_machine_shutdown,
27064 .emergency_restart = native_machine_emergency_restart,
27065 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27066 index c8e41e9..64049ef 100644
27067 --- a/arch/x86/kernel/reboot_fixups_32.c
27068 +++ b/arch/x86/kernel/reboot_fixups_32.c
27069 @@ -57,7 +57,7 @@ struct device_fixup {
27070 unsigned int vendor;
27071 unsigned int device;
27072 void (*reboot_fixup)(struct pci_dev *);
27073 -};
27074 +} __do_const;
27075
27076 /*
27077 * PCI ids solely used for fixups_table go here
27078 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27079 index 3fd2c69..a444264 100644
27080 --- a/arch/x86/kernel/relocate_kernel_64.S
27081 +++ b/arch/x86/kernel/relocate_kernel_64.S
27082 @@ -96,8 +96,7 @@ relocate_kernel:
27083
27084 /* jump to identity mapped page */
27085 addq $(identity_mapped - relocate_kernel), %r8
27086 - pushq %r8
27087 - ret
27088 + jmp *%r8
27089
27090 identity_mapped:
27091 /* set return address to 0 if not preserving context */
27092 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27093 index ab08aa2..6d74a3a 100644
27094 --- a/arch/x86/kernel/setup.c
27095 +++ b/arch/x86/kernel/setup.c
27096 @@ -110,6 +110,7 @@
27097 #include <asm/mce.h>
27098 #include <asm/alternative.h>
27099 #include <asm/prom.h>
27100 +#include <asm/boot.h>
27101
27102 /*
27103 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27104 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27105 #endif
27106
27107
27108 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27109 -__visible unsigned long mmu_cr4_features;
27110 +#ifdef CONFIG_X86_64
27111 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27112 +#elif defined(CONFIG_X86_PAE)
27113 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27114 #else
27115 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27116 +__visible unsigned long mmu_cr4_features __read_only;
27117 #endif
27118
27119 +void set_in_cr4(unsigned long mask)
27120 +{
27121 + unsigned long cr4 = read_cr4();
27122 +
27123 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27124 + return;
27125 +
27126 + pax_open_kernel();
27127 + mmu_cr4_features |= mask;
27128 + pax_close_kernel();
27129 +
27130 + if (trampoline_cr4_features)
27131 + *trampoline_cr4_features = mmu_cr4_features;
27132 + cr4 |= mask;
27133 + write_cr4(cr4);
27134 +}
27135 +EXPORT_SYMBOL(set_in_cr4);
27136 +
27137 +void clear_in_cr4(unsigned long mask)
27138 +{
27139 + unsigned long cr4 = read_cr4();
27140 +
27141 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27142 + return;
27143 +
27144 + pax_open_kernel();
27145 + mmu_cr4_features &= ~mask;
27146 + pax_close_kernel();
27147 +
27148 + if (trampoline_cr4_features)
27149 + *trampoline_cr4_features = mmu_cr4_features;
27150 + cr4 &= ~mask;
27151 + write_cr4(cr4);
27152 +}
27153 +EXPORT_SYMBOL(clear_in_cr4);
27154 +
27155 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27156 int bootloader_type, bootloader_version;
27157
27158 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27159 * area (640->1Mb) as ram even though it is not.
27160 * take them out.
27161 */
27162 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27163 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27164
27165 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27166 }
27167 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27168 /* called before trim_bios_range() to spare extra sanitize */
27169 static void __init e820_add_kernel_range(void)
27170 {
27171 - u64 start = __pa_symbol(_text);
27172 + u64 start = __pa_symbol(ktla_ktva(_text));
27173 u64 size = __pa_symbol(_end) - start;
27174
27175 /*
27176 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27177
27178 void __init setup_arch(char **cmdline_p)
27179 {
27180 +#ifdef CONFIG_X86_32
27181 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27182 +#else
27183 memblock_reserve(__pa_symbol(_text),
27184 (unsigned long)__bss_stop - (unsigned long)_text);
27185 +#endif
27186
27187 early_reserve_initrd();
27188
27189 @@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27190
27191 if (!boot_params.hdr.root_flags)
27192 root_mountflags &= ~MS_RDONLY;
27193 - init_mm.start_code = (unsigned long) _text;
27194 - init_mm.end_code = (unsigned long) _etext;
27195 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27196 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27197 init_mm.end_data = (unsigned long) _edata;
27198 init_mm.brk = _brk_end;
27199
27200 - code_resource.start = __pa_symbol(_text);
27201 - code_resource.end = __pa_symbol(_etext)-1;
27202 - data_resource.start = __pa_symbol(_etext);
27203 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27204 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27205 + data_resource.start = __pa_symbol(_sdata);
27206 data_resource.end = __pa_symbol(_edata)-1;
27207 bss_resource.start = __pa_symbol(__bss_start);
27208 bss_resource.end = __pa_symbol(__bss_stop)-1;
27209 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27210 index 5cdff03..80fa283 100644
27211 --- a/arch/x86/kernel/setup_percpu.c
27212 +++ b/arch/x86/kernel/setup_percpu.c
27213 @@ -21,19 +21,17 @@
27214 #include <asm/cpu.h>
27215 #include <asm/stackprotector.h>
27216
27217 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27218 +#ifdef CONFIG_SMP
27219 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27220 EXPORT_PER_CPU_SYMBOL(cpu_number);
27221 +#endif
27222
27223 -#ifdef CONFIG_X86_64
27224 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27225 -#else
27226 -#define BOOT_PERCPU_OFFSET 0
27227 -#endif
27228
27229 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27230 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27231
27232 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27233 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27234 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27235 };
27236 EXPORT_SYMBOL(__per_cpu_offset);
27237 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27238 {
27239 #ifdef CONFIG_NEED_MULTIPLE_NODES
27240 pg_data_t *last = NULL;
27241 - unsigned int cpu;
27242 + int cpu;
27243
27244 for_each_possible_cpu(cpu) {
27245 int node = early_cpu_to_node(cpu);
27246 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27247 {
27248 #ifdef CONFIG_X86_32
27249 struct desc_struct gdt;
27250 + unsigned long base = per_cpu_offset(cpu);
27251
27252 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27253 - 0x2 | DESCTYPE_S, 0x8);
27254 - gdt.s = 1;
27255 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27256 + 0x83 | DESCTYPE_S, 0xC);
27257 write_gdt_entry(get_cpu_gdt_table(cpu),
27258 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27259 #endif
27260 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27261 /* alrighty, percpu areas up and running */
27262 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27263 for_each_possible_cpu(cpu) {
27264 +#ifdef CONFIG_CC_STACKPROTECTOR
27265 +#ifdef CONFIG_X86_32
27266 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27267 +#endif
27268 +#endif
27269 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27270 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27271 per_cpu(cpu_number, cpu) = cpu;
27272 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27273 */
27274 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27275 #endif
27276 +#ifdef CONFIG_CC_STACKPROTECTOR
27277 +#ifdef CONFIG_X86_32
27278 + if (!cpu)
27279 + per_cpu(stack_canary.canary, cpu) = canary;
27280 +#endif
27281 +#endif
27282 /*
27283 * Up to this point, the boot CPU has been using .init.data
27284 * area. Reload any changed state for the boot CPU.
27285 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27286 index ed37a76..39f936e 100644
27287 --- a/arch/x86/kernel/signal.c
27288 +++ b/arch/x86/kernel/signal.c
27289 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27290 * Align the stack pointer according to the i386 ABI,
27291 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27292 */
27293 - sp = ((sp + 4) & -16ul) - 4;
27294 + sp = ((sp - 12) & -16ul) - 4;
27295 #else /* !CONFIG_X86_32 */
27296 sp = round_down(sp, 16) - 8;
27297 #endif
27298 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27299 }
27300
27301 if (current->mm->context.vdso)
27302 - restorer = current->mm->context.vdso +
27303 - selected_vdso32->sym___kernel_sigreturn;
27304 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27305 else
27306 - restorer = &frame->retcode;
27307 + restorer = (void __user *)&frame->retcode;
27308 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27309 restorer = ksig->ka.sa.sa_restorer;
27310
27311 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27312 * reasons and because gdb uses it as a signature to notice
27313 * signal handler stack frames.
27314 */
27315 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27316 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27317
27318 if (err)
27319 return -EFAULT;
27320 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27321 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27322
27323 /* Set up to return from userspace. */
27324 - restorer = current->mm->context.vdso +
27325 - selected_vdso32->sym___kernel_rt_sigreturn;
27326 + if (current->mm->context.vdso)
27327 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27328 + else
27329 + restorer = (void __user *)&frame->retcode;
27330 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27331 restorer = ksig->ka.sa.sa_restorer;
27332 put_user_ex(restorer, &frame->pretcode);
27333 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27334 * reasons and because gdb uses it as a signature to notice
27335 * signal handler stack frames.
27336 */
27337 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27338 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27339 } put_user_catch(err);
27340
27341 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27342 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27343 {
27344 int usig = signr_convert(ksig->sig);
27345 sigset_t *set = sigmask_to_save();
27346 - compat_sigset_t *cset = (compat_sigset_t *) set;
27347 + sigset_t sigcopy;
27348 + compat_sigset_t *cset;
27349 +
27350 + sigcopy = *set;
27351 +
27352 + cset = (compat_sigset_t *) &sigcopy;
27353
27354 /* Set up the stack frame */
27355 if (is_ia32_frame()) {
27356 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27357 } else if (is_x32_frame()) {
27358 return x32_setup_rt_frame(ksig, cset, regs);
27359 } else {
27360 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27361 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27362 }
27363 }
27364
27365 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27366 index be8e1bd..a3d93fa 100644
27367 --- a/arch/x86/kernel/smp.c
27368 +++ b/arch/x86/kernel/smp.c
27369 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27370
27371 __setup("nonmi_ipi", nonmi_ipi_setup);
27372
27373 -struct smp_ops smp_ops = {
27374 +struct smp_ops smp_ops __read_only = {
27375 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27376 .smp_prepare_cpus = native_smp_prepare_cpus,
27377 .smp_cpus_done = native_smp_cpus_done,
27378 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27379 index 668d8f2..84a9d54 100644
27380 --- a/arch/x86/kernel/smpboot.c
27381 +++ b/arch/x86/kernel/smpboot.c
27382 @@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27383
27384 enable_start_cpu0 = 0;
27385
27386 -#ifdef CONFIG_X86_32
27387 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27388 + barrier();
27389 +
27390 /* switch away from the initial page table */
27391 +#ifdef CONFIG_PAX_PER_CPU_PGD
27392 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27393 +#else
27394 load_cr3(swapper_pg_dir);
27395 +#endif
27396 __flush_tlb_all();
27397 -#endif
27398
27399 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27400 - barrier();
27401 /*
27402 * Check TSC synchronization with the BP:
27403 */
27404 @@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27405 alternatives_enable_smp();
27406
27407 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27408 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27409 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27410 per_cpu(current_task, cpu) = idle;
27411 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27412
27413 #ifdef CONFIG_X86_32
27414 /* Stack for startup_32 can be just as for start_secondary onwards */
27415 @@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27416 clear_tsk_thread_flag(idle, TIF_FORK);
27417 initial_gs = per_cpu_offset(cpu);
27418 #endif
27419 - per_cpu(kernel_stack, cpu) =
27420 - (unsigned long)task_stack_page(idle) -
27421 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27422 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27423 + pax_open_kernel();
27424 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27425 + pax_close_kernel();
27426 initial_code = (unsigned long)start_secondary;
27427 stack_start = idle->thread.sp;
27428
27429 @@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27430 /* the FPU context is blank, nobody can own it */
27431 __cpu_disable_lazy_restore(cpu);
27432
27433 +#ifdef CONFIG_PAX_PER_CPU_PGD
27434 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27435 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27436 + KERNEL_PGD_PTRS);
27437 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27438 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27439 + KERNEL_PGD_PTRS);
27440 +#endif
27441 +
27442 err = do_boot_cpu(apicid, cpu, tidle);
27443 if (err) {
27444 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27445 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27446 index 9b4d51d..5d28b58 100644
27447 --- a/arch/x86/kernel/step.c
27448 +++ b/arch/x86/kernel/step.c
27449 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27450 struct desc_struct *desc;
27451 unsigned long base;
27452
27453 - seg &= ~7UL;
27454 + seg >>= 3;
27455
27456 mutex_lock(&child->mm->context.lock);
27457 - if (unlikely((seg >> 3) >= child->mm->context.size))
27458 + if (unlikely(seg >= child->mm->context.size))
27459 addr = -1L; /* bogus selector, access would fault */
27460 else {
27461 desc = child->mm->context.ldt + seg;
27462 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27463 addr += base;
27464 }
27465 mutex_unlock(&child->mm->context.lock);
27466 - }
27467 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27468 + addr = ktla_ktva(addr);
27469
27470 return addr;
27471 }
27472 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27473 unsigned char opcode[15];
27474 unsigned long addr = convert_ip_to_linear(child, regs);
27475
27476 + if (addr == -EINVAL)
27477 + return 0;
27478 +
27479 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27480 for (i = 0; i < copied; i++) {
27481 switch (opcode[i]) {
27482 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27483 new file mode 100644
27484 index 0000000..5877189
27485 --- /dev/null
27486 +++ b/arch/x86/kernel/sys_i386_32.c
27487 @@ -0,0 +1,189 @@
27488 +/*
27489 + * This file contains various random system calls that
27490 + * have a non-standard calling sequence on the Linux/i386
27491 + * platform.
27492 + */
27493 +
27494 +#include <linux/errno.h>
27495 +#include <linux/sched.h>
27496 +#include <linux/mm.h>
27497 +#include <linux/fs.h>
27498 +#include <linux/smp.h>
27499 +#include <linux/sem.h>
27500 +#include <linux/msg.h>
27501 +#include <linux/shm.h>
27502 +#include <linux/stat.h>
27503 +#include <linux/syscalls.h>
27504 +#include <linux/mman.h>
27505 +#include <linux/file.h>
27506 +#include <linux/utsname.h>
27507 +#include <linux/ipc.h>
27508 +#include <linux/elf.h>
27509 +
27510 +#include <linux/uaccess.h>
27511 +#include <linux/unistd.h>
27512 +
27513 +#include <asm/syscalls.h>
27514 +
27515 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27516 +{
27517 + unsigned long pax_task_size = TASK_SIZE;
27518 +
27519 +#ifdef CONFIG_PAX_SEGMEXEC
27520 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27521 + pax_task_size = SEGMEXEC_TASK_SIZE;
27522 +#endif
27523 +
27524 + if (flags & MAP_FIXED)
27525 + if (len > pax_task_size || addr > pax_task_size - len)
27526 + return -EINVAL;
27527 +
27528 + return 0;
27529 +}
27530 +
27531 +/*
27532 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27533 + */
27534 +static unsigned long get_align_mask(void)
27535 +{
27536 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27537 + return 0;
27538 +
27539 + if (!(current->flags & PF_RANDOMIZE))
27540 + return 0;
27541 +
27542 + return va_align.mask;
27543 +}
27544 +
27545 +unsigned long
27546 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27547 + unsigned long len, unsigned long pgoff, unsigned long flags)
27548 +{
27549 + struct mm_struct *mm = current->mm;
27550 + struct vm_area_struct *vma;
27551 + unsigned long pax_task_size = TASK_SIZE;
27552 + struct vm_unmapped_area_info info;
27553 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27554 +
27555 +#ifdef CONFIG_PAX_SEGMEXEC
27556 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27557 + pax_task_size = SEGMEXEC_TASK_SIZE;
27558 +#endif
27559 +
27560 + pax_task_size -= PAGE_SIZE;
27561 +
27562 + if (len > pax_task_size)
27563 + return -ENOMEM;
27564 +
27565 + if (flags & MAP_FIXED)
27566 + return addr;
27567 +
27568 +#ifdef CONFIG_PAX_RANDMMAP
27569 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27570 +#endif
27571 +
27572 + if (addr) {
27573 + addr = PAGE_ALIGN(addr);
27574 + if (pax_task_size - len >= addr) {
27575 + vma = find_vma(mm, addr);
27576 + if (check_heap_stack_gap(vma, addr, len, offset))
27577 + return addr;
27578 + }
27579 + }
27580 +
27581 + info.flags = 0;
27582 + info.length = len;
27583 + info.align_mask = filp ? get_align_mask() : 0;
27584 + info.align_offset = pgoff << PAGE_SHIFT;
27585 + info.threadstack_offset = offset;
27586 +
27587 +#ifdef CONFIG_PAX_PAGEEXEC
27588 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27589 + info.low_limit = 0x00110000UL;
27590 + info.high_limit = mm->start_code;
27591 +
27592 +#ifdef CONFIG_PAX_RANDMMAP
27593 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27594 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27595 +#endif
27596 +
27597 + if (info.low_limit < info.high_limit) {
27598 + addr = vm_unmapped_area(&info);
27599 + if (!IS_ERR_VALUE(addr))
27600 + return addr;
27601 + }
27602 + } else
27603 +#endif
27604 +
27605 + info.low_limit = mm->mmap_base;
27606 + info.high_limit = pax_task_size;
27607 +
27608 + return vm_unmapped_area(&info);
27609 +}
27610 +
27611 +unsigned long
27612 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27613 + const unsigned long len, const unsigned long pgoff,
27614 + const unsigned long flags)
27615 +{
27616 + struct vm_area_struct *vma;
27617 + struct mm_struct *mm = current->mm;
27618 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27619 + struct vm_unmapped_area_info info;
27620 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27621 +
27622 +#ifdef CONFIG_PAX_SEGMEXEC
27623 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27624 + pax_task_size = SEGMEXEC_TASK_SIZE;
27625 +#endif
27626 +
27627 + pax_task_size -= PAGE_SIZE;
27628 +
27629 + /* requested length too big for entire address space */
27630 + if (len > pax_task_size)
27631 + return -ENOMEM;
27632 +
27633 + if (flags & MAP_FIXED)
27634 + return addr;
27635 +
27636 +#ifdef CONFIG_PAX_PAGEEXEC
27637 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27638 + goto bottomup;
27639 +#endif
27640 +
27641 +#ifdef CONFIG_PAX_RANDMMAP
27642 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27643 +#endif
27644 +
27645 + /* requesting a specific address */
27646 + if (addr) {
27647 + addr = PAGE_ALIGN(addr);
27648 + if (pax_task_size - len >= addr) {
27649 + vma = find_vma(mm, addr);
27650 + if (check_heap_stack_gap(vma, addr, len, offset))
27651 + return addr;
27652 + }
27653 + }
27654 +
27655 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27656 + info.length = len;
27657 + info.low_limit = PAGE_SIZE;
27658 + info.high_limit = mm->mmap_base;
27659 + info.align_mask = filp ? get_align_mask() : 0;
27660 + info.align_offset = pgoff << PAGE_SHIFT;
27661 + info.threadstack_offset = offset;
27662 +
27663 + addr = vm_unmapped_area(&info);
27664 + if (!(addr & ~PAGE_MASK))
27665 + return addr;
27666 + VM_BUG_ON(addr != -ENOMEM);
27667 +
27668 +bottomup:
27669 + /*
27670 + * A failed mmap() very likely causes application failure,
27671 + * so fall back to the bottom-up function here. This scenario
27672 + * can happen with large stack limits and large mmap()
27673 + * allocations.
27674 + */
27675 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27676 +}
27677 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27678 index 30277e2..5664a29 100644
27679 --- a/arch/x86/kernel/sys_x86_64.c
27680 +++ b/arch/x86/kernel/sys_x86_64.c
27681 @@ -81,8 +81,8 @@ out:
27682 return error;
27683 }
27684
27685 -static void find_start_end(unsigned long flags, unsigned long *begin,
27686 - unsigned long *end)
27687 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27688 + unsigned long *begin, unsigned long *end)
27689 {
27690 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27691 unsigned long new_begin;
27692 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27693 *begin = new_begin;
27694 }
27695 } else {
27696 - *begin = current->mm->mmap_legacy_base;
27697 + *begin = mm->mmap_legacy_base;
27698 *end = TASK_SIZE;
27699 }
27700 }
27701 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27702 struct vm_area_struct *vma;
27703 struct vm_unmapped_area_info info;
27704 unsigned long begin, end;
27705 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27706
27707 if (flags & MAP_FIXED)
27708 return addr;
27709
27710 - find_start_end(flags, &begin, &end);
27711 + find_start_end(mm, flags, &begin, &end);
27712
27713 if (len > end)
27714 return -ENOMEM;
27715
27716 +#ifdef CONFIG_PAX_RANDMMAP
27717 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27718 +#endif
27719 +
27720 if (addr) {
27721 addr = PAGE_ALIGN(addr);
27722 vma = find_vma(mm, addr);
27723 - if (end - len >= addr &&
27724 - (!vma || addr + len <= vma->vm_start))
27725 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27726 return addr;
27727 }
27728
27729 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27730 info.high_limit = end;
27731 info.align_mask = filp ? get_align_mask() : 0;
27732 info.align_offset = pgoff << PAGE_SHIFT;
27733 + info.threadstack_offset = offset;
27734 return vm_unmapped_area(&info);
27735 }
27736
27737 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27738 struct mm_struct *mm = current->mm;
27739 unsigned long addr = addr0;
27740 struct vm_unmapped_area_info info;
27741 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27742
27743 /* requested length too big for entire address space */
27744 if (len > TASK_SIZE)
27745 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27746 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27747 goto bottomup;
27748
27749 +#ifdef CONFIG_PAX_RANDMMAP
27750 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27751 +#endif
27752 +
27753 /* requesting a specific address */
27754 if (addr) {
27755 addr = PAGE_ALIGN(addr);
27756 vma = find_vma(mm, addr);
27757 - if (TASK_SIZE - len >= addr &&
27758 - (!vma || addr + len <= vma->vm_start))
27759 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27760 return addr;
27761 }
27762
27763 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27764 info.high_limit = mm->mmap_base;
27765 info.align_mask = filp ? get_align_mask() : 0;
27766 info.align_offset = pgoff << PAGE_SHIFT;
27767 + info.threadstack_offset = offset;
27768 addr = vm_unmapped_area(&info);
27769 if (!(addr & ~PAGE_MASK))
27770 return addr;
27771 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27772 index 91a4496..bb87552 100644
27773 --- a/arch/x86/kernel/tboot.c
27774 +++ b/arch/x86/kernel/tboot.c
27775 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27776
27777 void tboot_shutdown(u32 shutdown_type)
27778 {
27779 - void (*shutdown)(void);
27780 + void (* __noreturn shutdown)(void);
27781
27782 if (!tboot_enabled())
27783 return;
27784 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27785
27786 switch_to_tboot_pt();
27787
27788 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27789 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27790 shutdown();
27791
27792 /* should not reach here */
27793 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27794 return -ENODEV;
27795 }
27796
27797 -static atomic_t ap_wfs_count;
27798 +static atomic_unchecked_t ap_wfs_count;
27799
27800 static int tboot_wait_for_aps(int num_aps)
27801 {
27802 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27803 {
27804 switch (action) {
27805 case CPU_DYING:
27806 - atomic_inc(&ap_wfs_count);
27807 + atomic_inc_unchecked(&ap_wfs_count);
27808 if (num_online_cpus() == 1)
27809 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27810 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27811 return NOTIFY_BAD;
27812 break;
27813 }
27814 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27815
27816 tboot_create_trampoline();
27817
27818 - atomic_set(&ap_wfs_count, 0);
27819 + atomic_set_unchecked(&ap_wfs_count, 0);
27820 register_hotcpu_notifier(&tboot_cpu_notifier);
27821
27822 #ifdef CONFIG_DEBUG_FS
27823 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27824 index 0fa2960..91eabbe 100644
27825 --- a/arch/x86/kernel/time.c
27826 +++ b/arch/x86/kernel/time.c
27827 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27828 {
27829 unsigned long pc = instruction_pointer(regs);
27830
27831 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27832 + if (!user_mode(regs) && in_lock_functions(pc)) {
27833 #ifdef CONFIG_FRAME_POINTER
27834 - return *(unsigned long *)(regs->bp + sizeof(long));
27835 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27836 #else
27837 unsigned long *sp =
27838 (unsigned long *)kernel_stack_pointer(regs);
27839 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27840 * or above a saved flags. Eflags has bits 22-31 zero,
27841 * kernel addresses don't.
27842 */
27843 +
27844 +#ifdef CONFIG_PAX_KERNEXEC
27845 + return ktla_ktva(sp[0]);
27846 +#else
27847 if (sp[0] >> 22)
27848 return sp[0];
27849 if (sp[1] >> 22)
27850 return sp[1];
27851 #endif
27852 +
27853 +#endif
27854 }
27855 return pc;
27856 }
27857 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27858 index 7fc5e84..c6e445a 100644
27859 --- a/arch/x86/kernel/tls.c
27860 +++ b/arch/x86/kernel/tls.c
27861 @@ -139,6 +139,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27862 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27863 return -EINVAL;
27864
27865 +#ifdef CONFIG_PAX_SEGMEXEC
27866 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27867 + return -EINVAL;
27868 +#endif
27869 +
27870 set_tls_desc(p, idx, &info, 1);
27871
27872 return 0;
27873 @@ -256,7 +261,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27874
27875 if (kbuf)
27876 info = kbuf;
27877 - else if (__copy_from_user(infobuf, ubuf, count))
27878 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27879 return -EFAULT;
27880 else
27881 info = infobuf;
27882 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27883 index 1c113db..287b42e 100644
27884 --- a/arch/x86/kernel/tracepoint.c
27885 +++ b/arch/x86/kernel/tracepoint.c
27886 @@ -9,11 +9,11 @@
27887 #include <linux/atomic.h>
27888
27889 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27890 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27891 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27892 (unsigned long) trace_idt_table };
27893
27894 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27895 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27896 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27897
27898 static int trace_irq_vector_refcount;
27899 static DEFINE_MUTEX(irq_vector_mutex);
27900 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27901 index 07ab8e9..99c8456 100644
27902 --- a/arch/x86/kernel/traps.c
27903 +++ b/arch/x86/kernel/traps.c
27904 @@ -67,7 +67,7 @@
27905 #include <asm/proto.h>
27906
27907 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27908 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27909 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27910 #else
27911 #include <asm/processor-flags.h>
27912 #include <asm/setup.h>
27913 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27914 #endif
27915
27916 /* Must be page-aligned because the real IDT is used in a fixmap. */
27917 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27918 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27919
27920 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27921 EXPORT_SYMBOL_GPL(used_vectors);
27922 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27923 }
27924
27925 static nokprobe_inline int
27926 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27927 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27928 struct pt_regs *regs, long error_code)
27929 {
27930 #ifdef CONFIG_X86_32
27931 - if (regs->flags & X86_VM_MASK) {
27932 + if (v8086_mode(regs)) {
27933 /*
27934 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27935 * On nmi (interrupt 2), do_trap should not be called.
27936 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27937 return -1;
27938 }
27939 #endif
27940 - if (!user_mode(regs)) {
27941 + if (!user_mode_novm(regs)) {
27942 if (!fixup_exception(regs)) {
27943 tsk->thread.error_code = error_code;
27944 tsk->thread.trap_nr = trapnr;
27945 +
27946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27947 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27948 + str = "PAX: suspicious stack segment fault";
27949 +#endif
27950 +
27951 die(str, regs, error_code);
27952 }
27953 +
27954 +#ifdef CONFIG_PAX_REFCOUNT
27955 + if (trapnr == X86_TRAP_OF)
27956 + pax_report_refcount_overflow(regs);
27957 +#endif
27958 +
27959 return 0;
27960 }
27961
27962 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27963 }
27964
27965 static void
27966 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27967 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27968 long error_code, siginfo_t *info)
27969 {
27970 struct task_struct *tsk = current;
27971 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27972 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27973 printk_ratelimit()) {
27974 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27975 - tsk->comm, tsk->pid, str,
27976 + tsk->comm, task_pid_nr(tsk), str,
27977 regs->ip, regs->sp, error_code);
27978 print_vma_addr(" in ", regs->ip);
27979 pr_cont("\n");
27980 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27981 tsk->thread.error_code = error_code;
27982 tsk->thread.trap_nr = X86_TRAP_DF;
27983
27984 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27985 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27986 + die("grsec: kernel stack overflow detected", regs, error_code);
27987 +#endif
27988 +
27989 #ifdef CONFIG_DOUBLEFAULT
27990 df_debug(regs, error_code);
27991 #endif
27992 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27993 conditional_sti(regs);
27994
27995 #ifdef CONFIG_X86_32
27996 - if (regs->flags & X86_VM_MASK) {
27997 + if (v8086_mode(regs)) {
27998 local_irq_enable();
27999 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28000 goto exit;
28001 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28002 #endif
28003
28004 tsk = current;
28005 - if (!user_mode(regs)) {
28006 + if (!user_mode_novm(regs)) {
28007 if (fixup_exception(regs))
28008 goto exit;
28009
28010 tsk->thread.error_code = error_code;
28011 tsk->thread.trap_nr = X86_TRAP_GP;
28012 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28013 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28014 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28015 +
28016 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28017 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28018 + die("PAX: suspicious general protection fault", regs, error_code);
28019 + else
28020 +#endif
28021 +
28022 die("general protection fault", regs, error_code);
28023 + }
28024 goto exit;
28025 }
28026
28027 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28028 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28029 + struct mm_struct *mm = tsk->mm;
28030 + unsigned long limit;
28031 +
28032 + down_write(&mm->mmap_sem);
28033 + limit = mm->context.user_cs_limit;
28034 + if (limit < TASK_SIZE) {
28035 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28036 + up_write(&mm->mmap_sem);
28037 + return;
28038 + }
28039 + up_write(&mm->mmap_sem);
28040 + }
28041 +#endif
28042 +
28043 tsk->thread.error_code = error_code;
28044 tsk->thread.trap_nr = X86_TRAP_GP;
28045
28046 @@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28047 container_of(task_pt_regs(current),
28048 struct bad_iret_stack, regs);
28049
28050 + if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28051 + new_stack = s;
28052 +
28053 /* Copy the IRET target to the new stack. */
28054 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28055
28056 /* Copy the remainder of the stack from the current stack. */
28057 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28058
28059 - BUG_ON(!user_mode_vm(&new_stack->regs));
28060 + BUG_ON(!user_mode(&new_stack->regs));
28061 return new_stack;
28062 }
28063 NOKPROBE_SYMBOL(fixup_bad_iret);
28064 @@ -519,7 +563,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28065 /* It's safe to allow irq's after DR6 has been saved */
28066 preempt_conditional_sti(regs);
28067
28068 - if (regs->flags & X86_VM_MASK) {
28069 + if (v8086_mode(regs)) {
28070 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28071 X86_TRAP_DB);
28072 preempt_conditional_cli(regs);
28073 @@ -534,7 +578,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28074 * We already checked v86 mode above, so we can check for kernel mode
28075 * by just checking the CPL of CS.
28076 */
28077 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28078 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28079 tsk->thread.debugreg6 &= ~DR_STEP;
28080 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28081 regs->flags &= ~X86_EFLAGS_TF;
28082 @@ -567,7 +611,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28083 return;
28084 conditional_sti(regs);
28085
28086 - if (!user_mode_vm(regs))
28087 + if (!user_mode(regs))
28088 {
28089 if (!fixup_exception(regs)) {
28090 task->thread.error_code = error_code;
28091 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28092 index 5054497..139f8f8 100644
28093 --- a/arch/x86/kernel/tsc.c
28094 +++ b/arch/x86/kernel/tsc.c
28095 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28096 */
28097 smp_wmb();
28098
28099 - ACCESS_ONCE(c2n->head) = data;
28100 + ACCESS_ONCE_RW(c2n->head) = data;
28101 }
28102
28103 /*
28104 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28105 index 5d1cbfe..2a21feb 100644
28106 --- a/arch/x86/kernel/uprobes.c
28107 +++ b/arch/x86/kernel/uprobes.c
28108 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28109 int ret = NOTIFY_DONE;
28110
28111 /* We are only interested in userspace traps */
28112 - if (regs && !user_mode_vm(regs))
28113 + if (regs && !user_mode(regs))
28114 return NOTIFY_DONE;
28115
28116 switch (val) {
28117 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28118
28119 if (nleft != rasize) {
28120 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28121 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28122 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28123
28124 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28125 }
28126 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28127 index b9242ba..50c5edd 100644
28128 --- a/arch/x86/kernel/verify_cpu.S
28129 +++ b/arch/x86/kernel/verify_cpu.S
28130 @@ -20,6 +20,7 @@
28131 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28132 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28133 * arch/x86/kernel/head_32.S: processor startup
28134 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28135 *
28136 * verify_cpu, returns the status of longmode and SSE in register %eax.
28137 * 0: Success 1: Failure
28138 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28139 index e8edcf5..27f9344 100644
28140 --- a/arch/x86/kernel/vm86_32.c
28141 +++ b/arch/x86/kernel/vm86_32.c
28142 @@ -44,6 +44,7 @@
28143 #include <linux/ptrace.h>
28144 #include <linux/audit.h>
28145 #include <linux/stddef.h>
28146 +#include <linux/grsecurity.h>
28147
28148 #include <asm/uaccess.h>
28149 #include <asm/io.h>
28150 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28151 do_exit(SIGSEGV);
28152 }
28153
28154 - tss = &per_cpu(init_tss, get_cpu());
28155 + tss = init_tss + get_cpu();
28156 current->thread.sp0 = current->thread.saved_sp0;
28157 current->thread.sysenter_cs = __KERNEL_CS;
28158 load_sp0(tss, &current->thread);
28159 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28160
28161 if (tsk->thread.saved_sp0)
28162 return -EPERM;
28163 +
28164 +#ifdef CONFIG_GRKERNSEC_VM86
28165 + if (!capable(CAP_SYS_RAWIO)) {
28166 + gr_handle_vm86();
28167 + return -EPERM;
28168 + }
28169 +#endif
28170 +
28171 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28172 offsetof(struct kernel_vm86_struct, vm86plus) -
28173 sizeof(info.regs));
28174 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28175 int tmp;
28176 struct vm86plus_struct __user *v86;
28177
28178 +#ifdef CONFIG_GRKERNSEC_VM86
28179 + if (!capable(CAP_SYS_RAWIO)) {
28180 + gr_handle_vm86();
28181 + return -EPERM;
28182 + }
28183 +#endif
28184 +
28185 tsk = current;
28186 switch (cmd) {
28187 case VM86_REQUEST_IRQ:
28188 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28189 tsk->thread.saved_fs = info->regs32->fs;
28190 tsk->thread.saved_gs = get_user_gs(info->regs32);
28191
28192 - tss = &per_cpu(init_tss, get_cpu());
28193 + tss = init_tss + get_cpu();
28194 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28195 if (cpu_has_sep)
28196 tsk->thread.sysenter_cs = 0;
28197 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28198 goto cannot_handle;
28199 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28200 goto cannot_handle;
28201 - intr_ptr = (unsigned long __user *) (i << 2);
28202 + intr_ptr = (__force unsigned long __user *) (i << 2);
28203 if (get_user(segoffs, intr_ptr))
28204 goto cannot_handle;
28205 if ((segoffs >> 16) == BIOSSEG)
28206 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28207 index 49edf2d..c0d1362 100644
28208 --- a/arch/x86/kernel/vmlinux.lds.S
28209 +++ b/arch/x86/kernel/vmlinux.lds.S
28210 @@ -26,6 +26,13 @@
28211 #include <asm/page_types.h>
28212 #include <asm/cache.h>
28213 #include <asm/boot.h>
28214 +#include <asm/segment.h>
28215 +
28216 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28217 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28218 +#else
28219 +#define __KERNEL_TEXT_OFFSET 0
28220 +#endif
28221
28222 #undef i386 /* in case the preprocessor is a 32bit one */
28223
28224 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28225
28226 PHDRS {
28227 text PT_LOAD FLAGS(5); /* R_E */
28228 +#ifdef CONFIG_X86_32
28229 + module PT_LOAD FLAGS(5); /* R_E */
28230 +#endif
28231 +#ifdef CONFIG_XEN
28232 + rodata PT_LOAD FLAGS(5); /* R_E */
28233 +#else
28234 + rodata PT_LOAD FLAGS(4); /* R__ */
28235 +#endif
28236 data PT_LOAD FLAGS(6); /* RW_ */
28237 -#ifdef CONFIG_X86_64
28238 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28239 #ifdef CONFIG_SMP
28240 percpu PT_LOAD FLAGS(6); /* RW_ */
28241 #endif
28242 + text.init PT_LOAD FLAGS(5); /* R_E */
28243 + text.exit PT_LOAD FLAGS(5); /* R_E */
28244 init PT_LOAD FLAGS(7); /* RWE */
28245 -#endif
28246 note PT_NOTE FLAGS(0); /* ___ */
28247 }
28248
28249 SECTIONS
28250 {
28251 #ifdef CONFIG_X86_32
28252 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28253 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28254 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28255 #else
28256 - . = __START_KERNEL;
28257 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28258 + . = __START_KERNEL;
28259 #endif
28260
28261 /* Text and read-only data */
28262 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28263 - _text = .;
28264 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28265 /* bootstrapping code */
28266 +#ifdef CONFIG_X86_32
28267 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28268 +#else
28269 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28270 +#endif
28271 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28272 + _text = .;
28273 HEAD_TEXT
28274 . = ALIGN(8);
28275 _stext = .;
28276 @@ -104,13 +124,47 @@ SECTIONS
28277 IRQENTRY_TEXT
28278 *(.fixup)
28279 *(.gnu.warning)
28280 - /* End of text section */
28281 - _etext = .;
28282 } :text = 0x9090
28283
28284 - NOTES :text :note
28285 + . += __KERNEL_TEXT_OFFSET;
28286
28287 - EXCEPTION_TABLE(16) :text = 0x9090
28288 +#ifdef CONFIG_X86_32
28289 + . = ALIGN(PAGE_SIZE);
28290 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28291 +
28292 +#ifdef CONFIG_PAX_KERNEXEC
28293 + MODULES_EXEC_VADDR = .;
28294 + BYTE(0)
28295 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28296 + . = ALIGN(HPAGE_SIZE) - 1;
28297 + MODULES_EXEC_END = .;
28298 +#endif
28299 +
28300 + } :module
28301 +#endif
28302 +
28303 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28304 + /* End of text section */
28305 + BYTE(0)
28306 + _etext = . - __KERNEL_TEXT_OFFSET;
28307 + }
28308 +
28309 +#ifdef CONFIG_X86_32
28310 + . = ALIGN(PAGE_SIZE);
28311 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28312 + . = ALIGN(PAGE_SIZE);
28313 + *(.empty_zero_page)
28314 + *(.initial_pg_fixmap)
28315 + *(.initial_pg_pmd)
28316 + *(.initial_page_table)
28317 + *(.swapper_pg_dir)
28318 + } :rodata
28319 +#endif
28320 +
28321 + . = ALIGN(PAGE_SIZE);
28322 + NOTES :rodata :note
28323 +
28324 + EXCEPTION_TABLE(16) :rodata
28325
28326 #if defined(CONFIG_DEBUG_RODATA)
28327 /* .text should occupy whole number of pages */
28328 @@ -122,16 +176,20 @@ SECTIONS
28329
28330 /* Data */
28331 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28332 +
28333 +#ifdef CONFIG_PAX_KERNEXEC
28334 + . = ALIGN(HPAGE_SIZE);
28335 +#else
28336 + . = ALIGN(PAGE_SIZE);
28337 +#endif
28338 +
28339 /* Start of data section */
28340 _sdata = .;
28341
28342 /* init_task */
28343 INIT_TASK_DATA(THREAD_SIZE)
28344
28345 -#ifdef CONFIG_X86_32
28346 - /* 32 bit has nosave before _edata */
28347 NOSAVE_DATA
28348 -#endif
28349
28350 PAGE_ALIGNED_DATA(PAGE_SIZE)
28351
28352 @@ -174,12 +232,19 @@ SECTIONS
28353 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28354
28355 /* Init code and data - will be freed after init */
28356 - . = ALIGN(PAGE_SIZE);
28357 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28358 + BYTE(0)
28359 +
28360 +#ifdef CONFIG_PAX_KERNEXEC
28361 + . = ALIGN(HPAGE_SIZE);
28362 +#else
28363 + . = ALIGN(PAGE_SIZE);
28364 +#endif
28365 +
28366 __init_begin = .; /* paired with __init_end */
28367 - }
28368 + } :init.begin
28369
28370 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28371 +#ifdef CONFIG_SMP
28372 /*
28373 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28374 * output PHDR, so the next output section - .init.text - should
28375 @@ -188,12 +253,27 @@ SECTIONS
28376 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28377 #endif
28378
28379 - INIT_TEXT_SECTION(PAGE_SIZE)
28380 -#ifdef CONFIG_X86_64
28381 - :init
28382 -#endif
28383 + . = ALIGN(PAGE_SIZE);
28384 + init_begin = .;
28385 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28386 + VMLINUX_SYMBOL(_sinittext) = .;
28387 + INIT_TEXT
28388 + VMLINUX_SYMBOL(_einittext) = .;
28389 + . = ALIGN(PAGE_SIZE);
28390 + } :text.init
28391
28392 - INIT_DATA_SECTION(16)
28393 + /*
28394 + * .exit.text is discard at runtime, not link time, to deal with
28395 + * references from .altinstructions and .eh_frame
28396 + */
28397 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28398 + EXIT_TEXT
28399 + . = ALIGN(16);
28400 + } :text.exit
28401 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28402 +
28403 + . = ALIGN(PAGE_SIZE);
28404 + INIT_DATA_SECTION(16) :init
28405
28406 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28407 __x86_cpu_dev_start = .;
28408 @@ -264,19 +344,12 @@ SECTIONS
28409 }
28410
28411 . = ALIGN(8);
28412 - /*
28413 - * .exit.text is discard at runtime, not link time, to deal with
28414 - * references from .altinstructions and .eh_frame
28415 - */
28416 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28417 - EXIT_TEXT
28418 - }
28419
28420 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28421 EXIT_DATA
28422 }
28423
28424 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28425 +#ifndef CONFIG_SMP
28426 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28427 #endif
28428
28429 @@ -295,16 +368,10 @@ SECTIONS
28430 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28431 __smp_locks = .;
28432 *(.smp_locks)
28433 - . = ALIGN(PAGE_SIZE);
28434 __smp_locks_end = .;
28435 + . = ALIGN(PAGE_SIZE);
28436 }
28437
28438 -#ifdef CONFIG_X86_64
28439 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28440 - NOSAVE_DATA
28441 - }
28442 -#endif
28443 -
28444 /* BSS */
28445 . = ALIGN(PAGE_SIZE);
28446 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28447 @@ -320,6 +387,7 @@ SECTIONS
28448 __brk_base = .;
28449 . += 64 * 1024; /* 64k alignment slop space */
28450 *(.brk_reservation) /* areas brk users have reserved */
28451 + . = ALIGN(HPAGE_SIZE);
28452 __brk_limit = .;
28453 }
28454
28455 @@ -346,13 +414,12 @@ SECTIONS
28456 * for the boot processor.
28457 */
28458 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28459 -INIT_PER_CPU(gdt_page);
28460 INIT_PER_CPU(irq_stack_union);
28461
28462 /*
28463 * Build-time check on the image size:
28464 */
28465 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28466 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28467 "kernel image bigger than KERNEL_IMAGE_SIZE");
28468
28469 #ifdef CONFIG_SMP
28470 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28471 index 957779f..74e405c 100644
28472 --- a/arch/x86/kernel/vsyscall_64.c
28473 +++ b/arch/x86/kernel/vsyscall_64.c
28474 @@ -54,15 +54,13 @@
28475
28476 DEFINE_VVAR(int, vgetcpu_mode);
28477
28478 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28479 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28480
28481 static int __init vsyscall_setup(char *str)
28482 {
28483 if (str) {
28484 if (!strcmp("emulate", str))
28485 vsyscall_mode = EMULATE;
28486 - else if (!strcmp("native", str))
28487 - vsyscall_mode = NATIVE;
28488 else if (!strcmp("none", str))
28489 vsyscall_mode = NONE;
28490 else
28491 @@ -279,8 +277,7 @@ do_ret:
28492 return true;
28493
28494 sigsegv:
28495 - force_sig(SIGSEGV, current);
28496 - return true;
28497 + do_group_exit(SIGKILL);
28498 }
28499
28500 /*
28501 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28502 extern char __vsyscall_page;
28503 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28504
28505 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28506 - vsyscall_mode == NATIVE
28507 - ? PAGE_KERNEL_VSYSCALL
28508 - : PAGE_KERNEL_VVAR);
28509 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28510 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28511 (unsigned long)VSYSCALL_ADDR);
28512 }
28513 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28514 index 04068192..4d75aa6 100644
28515 --- a/arch/x86/kernel/x8664_ksyms_64.c
28516 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28517 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28518 EXPORT_SYMBOL(copy_user_generic_unrolled);
28519 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28520 EXPORT_SYMBOL(__copy_user_nocache);
28521 -EXPORT_SYMBOL(_copy_from_user);
28522 -EXPORT_SYMBOL(_copy_to_user);
28523
28524 EXPORT_SYMBOL(copy_page);
28525 EXPORT_SYMBOL(clear_page);
28526 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28527 EXPORT_SYMBOL(___preempt_schedule_context);
28528 #endif
28529 #endif
28530 +
28531 +#ifdef CONFIG_PAX_PER_CPU_PGD
28532 +EXPORT_SYMBOL(cpu_pgd);
28533 +#endif
28534 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28535 index e48b674..a451dd9 100644
28536 --- a/arch/x86/kernel/x86_init.c
28537 +++ b/arch/x86/kernel/x86_init.c
28538 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28539 static void default_nmi_init(void) { };
28540 static int default_i8042_detect(void) { return 1; };
28541
28542 -struct x86_platform_ops x86_platform = {
28543 +struct x86_platform_ops x86_platform __read_only = {
28544 .calibrate_tsc = native_calibrate_tsc,
28545 .get_wallclock = mach_get_cmos_time,
28546 .set_wallclock = mach_set_rtc_mmss,
28547 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28548 EXPORT_SYMBOL_GPL(x86_platform);
28549
28550 #if defined(CONFIG_PCI_MSI)
28551 -struct x86_msi_ops x86_msi = {
28552 +struct x86_msi_ops x86_msi __read_only = {
28553 .setup_msi_irqs = native_setup_msi_irqs,
28554 .compose_msi_msg = native_compose_msi_msg,
28555 .teardown_msi_irq = native_teardown_msi_irq,
28556 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28557 }
28558 #endif
28559
28560 -struct x86_io_apic_ops x86_io_apic_ops = {
28561 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28562 .init = native_io_apic_init_mappings,
28563 .read = native_io_apic_read,
28564 .write = native_io_apic_write,
28565 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28566 index 0de1fae..298d037 100644
28567 --- a/arch/x86/kernel/xsave.c
28568 +++ b/arch/x86/kernel/xsave.c
28569 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28570
28571 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28572 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28573 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28574 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28575
28576 if (!use_xsave())
28577 return err;
28578
28579 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28580 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28581
28582 /*
28583 * Read the xstate_bv which we copied (directly from the cpu or
28584 * from the state in task struct) to the user buffers.
28585 */
28586 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28587 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28588
28589 /*
28590 * For legacy compatible, we always set FP/SSE bits in the bit
28591 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28592 */
28593 xstate_bv |= XSTATE_FPSSE;
28594
28595 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28596 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28597
28598 return err;
28599 }
28600 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28601 {
28602 int err;
28603
28604 + buf = (struct xsave_struct __user *)____m(buf);
28605 if (use_xsave())
28606 err = xsave_user(buf);
28607 else if (use_fxsr())
28608 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28609 */
28610 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28611 {
28612 + buf = (void __user *)____m(buf);
28613 if (use_xsave()) {
28614 if ((unsigned long)buf % 64 || fx_only) {
28615 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28616 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28617 index 88f9201..0e7f1a3 100644
28618 --- a/arch/x86/kvm/cpuid.c
28619 +++ b/arch/x86/kvm/cpuid.c
28620 @@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28621 struct kvm_cpuid2 *cpuid,
28622 struct kvm_cpuid_entry2 __user *entries)
28623 {
28624 - int r;
28625 + int r, i;
28626
28627 r = -E2BIG;
28628 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28629 goto out;
28630 r = -EFAULT;
28631 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28632 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28633 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28634 goto out;
28635 + for (i = 0; i < cpuid->nent; ++i) {
28636 + struct kvm_cpuid_entry2 cpuid_entry;
28637 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28638 + goto out;
28639 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28640 + }
28641 vcpu->arch.cpuid_nent = cpuid->nent;
28642 kvm_apic_set_version(vcpu);
28643 kvm_x86_ops->cpuid_update(vcpu);
28644 @@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28645 struct kvm_cpuid2 *cpuid,
28646 struct kvm_cpuid_entry2 __user *entries)
28647 {
28648 - int r;
28649 + int r, i;
28650
28651 r = -E2BIG;
28652 if (cpuid->nent < vcpu->arch.cpuid_nent)
28653 goto out;
28654 r = -EFAULT;
28655 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28656 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28657 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28658 goto out;
28659 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28660 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28661 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28662 + goto out;
28663 + }
28664 return 0;
28665
28666 out:
28667 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28668 index c7327a7..c3e2419 100644
28669 --- a/arch/x86/kvm/emulate.c
28670 +++ b/arch/x86/kvm/emulate.c
28671 @@ -3508,7 +3508,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28672 int cr = ctxt->modrm_reg;
28673 u64 efer = 0;
28674
28675 - static u64 cr_reserved_bits[] = {
28676 + static const u64 cr_reserved_bits[] = {
28677 0xffffffff00000000ULL,
28678 0, 0, 0, /* CR3 checked later */
28679 CR4_RESERVED_BITS,
28680 @@ -3543,7 +3543,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28681
28682 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28683 if (efer & EFER_LMA)
28684 - rsvd = CR3_L_MODE_RESERVED_BITS;
28685 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28686
28687 if (new_val & rsvd)
28688 return emulate_gp(ctxt, 0);
28689 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28690 index b8345dd..f225d71 100644
28691 --- a/arch/x86/kvm/lapic.c
28692 +++ b/arch/x86/kvm/lapic.c
28693 @@ -55,7 +55,7 @@
28694 #define APIC_BUS_CYCLE_NS 1
28695
28696 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28697 -#define apic_debug(fmt, arg...)
28698 +#define apic_debug(fmt, arg...) do {} while (0)
28699
28700 #define APIC_LVT_NUM 6
28701 /* 14 is the version for Xeon and Pentium 8.4.8*/
28702 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28703 index fd49c86..77e1aa0 100644
28704 --- a/arch/x86/kvm/paging_tmpl.h
28705 +++ b/arch/x86/kvm/paging_tmpl.h
28706 @@ -343,7 +343,7 @@ retry_walk:
28707 if (unlikely(kvm_is_error_hva(host_addr)))
28708 goto error;
28709
28710 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28711 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28712 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28713 goto error;
28714 walker->ptep_user[walker->level - 1] = ptep_user;
28715 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28716 index 7527cef..c63a838e 100644
28717 --- a/arch/x86/kvm/svm.c
28718 +++ b/arch/x86/kvm/svm.c
28719 @@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28720 int cpu = raw_smp_processor_id();
28721
28722 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28723 +
28724 + pax_open_kernel();
28725 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28726 + pax_close_kernel();
28727 +
28728 load_TR_desc();
28729 }
28730
28731 @@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28732 #endif
28733 #endif
28734
28735 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28736 + __set_fs(current_thread_info()->addr_limit);
28737 +#endif
28738 +
28739 reload_tss(vcpu);
28740
28741 local_irq_disable();
28742 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28743 index ed70394..c629a68 100644
28744 --- a/arch/x86/kvm/vmx.c
28745 +++ b/arch/x86/kvm/vmx.c
28746 @@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28747 #endif
28748 }
28749
28750 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28751 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28752 {
28753 vmcs_writel(field, vmcs_readl(field) & ~mask);
28754 }
28755
28756 -static void vmcs_set_bits(unsigned long field, u32 mask)
28757 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28758 {
28759 vmcs_writel(field, vmcs_readl(field) | mask);
28760 }
28761 @@ -1631,7 +1631,11 @@ static void reload_tss(void)
28762 struct desc_struct *descs;
28763
28764 descs = (void *)gdt->address;
28765 +
28766 + pax_open_kernel();
28767 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28768 + pax_close_kernel();
28769 +
28770 load_TR_desc();
28771 }
28772
28773 @@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28774 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28775 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28776
28777 +#ifdef CONFIG_PAX_PER_CPU_PGD
28778 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28779 +#endif
28780 +
28781 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28782 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28783 vmx->loaded_vmcs->cpu = cpu;
28784 @@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28785 * reads and returns guest's timestamp counter "register"
28786 * guest_tsc = host_tsc + tsc_offset -- 21.3
28787 */
28788 -static u64 guest_read_tsc(void)
28789 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28790 {
28791 u64 host_tsc, tsc_offset;
28792
28793 @@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28794 * page upon invalidation. No need to do anything if the
28795 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28796 */
28797 - kvm_x86_ops->set_apic_access_page_addr = NULL;
28798 + pax_open_kernel();
28799 + *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28800 + pax_close_kernel();
28801 }
28802
28803 - if (!cpu_has_vmx_tpr_shadow())
28804 - kvm_x86_ops->update_cr8_intercept = NULL;
28805 + if (!cpu_has_vmx_tpr_shadow()) {
28806 + pax_open_kernel();
28807 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28808 + pax_close_kernel();
28809 + }
28810
28811 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28812 kvm_disable_largepages();
28813 @@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28814 if (!cpu_has_vmx_apicv())
28815 enable_apicv = 0;
28816
28817 + pax_open_kernel();
28818 if (enable_apicv)
28819 - kvm_x86_ops->update_cr8_intercept = NULL;
28820 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28821 else {
28822 - kvm_x86_ops->hwapic_irr_update = NULL;
28823 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28824 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28825 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28826 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28827 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28828 }
28829 + pax_close_kernel();
28830
28831 if (nested)
28832 nested_vmx_setup_ctls_msrs();
28833 @@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28834 unsigned long cr4;
28835
28836 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28837 +
28838 +#ifndef CONFIG_PAX_PER_CPU_PGD
28839 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28840 +#endif
28841
28842 /* Save the most likely value for this task's CR4 in the VMCS. */
28843 cr4 = read_cr4();
28844 @@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28845 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28846 vmx->host_idt_base = dt.address;
28847
28848 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28849 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28850
28851 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28852 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28853 @@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28854 "jmp 2f \n\t"
28855 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28856 "2: "
28857 +
28858 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28859 + "ljmp %[cs],$3f\n\t"
28860 + "3: "
28861 +#endif
28862 +
28863 /* Save guest registers, load host registers, keep flags */
28864 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28865 "pop %0 \n\t"
28866 @@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28867 #endif
28868 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28869 [wordsize]"i"(sizeof(ulong))
28870 +
28871 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28872 + ,[cs]"i"(__KERNEL_CS)
28873 +#endif
28874 +
28875 : "cc", "memory"
28876 #ifdef CONFIG_X86_64
28877 , "rax", "rbx", "rdi", "rsi"
28878 @@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28879 if (debugctlmsr)
28880 update_debugctlmsr(debugctlmsr);
28881
28882 -#ifndef CONFIG_X86_64
28883 +#ifdef CONFIG_X86_32
28884 /*
28885 * The sysexit path does not restore ds/es, so we must set them to
28886 * a reasonable value ourselves.
28887 @@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28888 * may be executed in interrupt context, which saves and restore segments
28889 * around it, nullifying its effect.
28890 */
28891 - loadsegment(ds, __USER_DS);
28892 - loadsegment(es, __USER_DS);
28893 + loadsegment(ds, __KERNEL_DS);
28894 + loadsegment(es, __KERNEL_DS);
28895 + loadsegment(ss, __KERNEL_DS);
28896 +
28897 +#ifdef CONFIG_PAX_KERNEXEC
28898 + loadsegment(fs, __KERNEL_PERCPU);
28899 +#endif
28900 +
28901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28902 + __set_fs(current_thread_info()->addr_limit);
28903 +#endif
28904 +
28905 #endif
28906
28907 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28908 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28909 index 506488c..f8df17e 100644
28910 --- a/arch/x86/kvm/x86.c
28911 +++ b/arch/x86/kvm/x86.c
28912 @@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28913
28914 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28915 {
28916 + cr3 &= ~CR3_PCID_INVD;
28917 +
28918 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28919 kvm_mmu_sync_roots(vcpu);
28920 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28921 @@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28922 {
28923 struct kvm *kvm = vcpu->kvm;
28924 int lm = is_long_mode(vcpu);
28925 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28926 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28927 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28928 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28929 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28930 : kvm->arch.xen_hvm_config.blob_size_32;
28931 u32 page_num = data & ~PAGE_MASK;
28932 @@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28933 if (n < msr_list.nmsrs)
28934 goto out;
28935 r = -EFAULT;
28936 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28937 + goto out;
28938 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28939 num_msrs_to_save * sizeof(u32)))
28940 goto out;
28941 @@ -5743,7 +5747,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28942 };
28943 #endif
28944
28945 -int kvm_arch_init(void *opaque)
28946 +int kvm_arch_init(const void *opaque)
28947 {
28948 int r;
28949 struct kvm_x86_ops *ops = opaque;
28950 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28951 index aae9413..d11e829 100644
28952 --- a/arch/x86/lguest/boot.c
28953 +++ b/arch/x86/lguest/boot.c
28954 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28955 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28956 * Launcher to reboot us.
28957 */
28958 -static void lguest_restart(char *reason)
28959 +static __noreturn void lguest_restart(char *reason)
28960 {
28961 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28962 + BUG();
28963 }
28964
28965 /*G:050
28966 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28967 index 00933d5..3a64af9 100644
28968 --- a/arch/x86/lib/atomic64_386_32.S
28969 +++ b/arch/x86/lib/atomic64_386_32.S
28970 @@ -48,6 +48,10 @@ BEGIN(read)
28971 movl (v), %eax
28972 movl 4(v), %edx
28973 RET_ENDP
28974 +BEGIN(read_unchecked)
28975 + movl (v), %eax
28976 + movl 4(v), %edx
28977 +RET_ENDP
28978 #undef v
28979
28980 #define v %esi
28981 @@ -55,6 +59,10 @@ BEGIN(set)
28982 movl %ebx, (v)
28983 movl %ecx, 4(v)
28984 RET_ENDP
28985 +BEGIN(set_unchecked)
28986 + movl %ebx, (v)
28987 + movl %ecx, 4(v)
28988 +RET_ENDP
28989 #undef v
28990
28991 #define v %esi
28992 @@ -70,6 +78,20 @@ RET_ENDP
28993 BEGIN(add)
28994 addl %eax, (v)
28995 adcl %edx, 4(v)
28996 +
28997 +#ifdef CONFIG_PAX_REFCOUNT
28998 + jno 0f
28999 + subl %eax, (v)
29000 + sbbl %edx, 4(v)
29001 + int $4
29002 +0:
29003 + _ASM_EXTABLE(0b, 0b)
29004 +#endif
29005 +
29006 +RET_ENDP
29007 +BEGIN(add_unchecked)
29008 + addl %eax, (v)
29009 + adcl %edx, 4(v)
29010 RET_ENDP
29011 #undef v
29012
29013 @@ -77,6 +99,24 @@ RET_ENDP
29014 BEGIN(add_return)
29015 addl (v), %eax
29016 adcl 4(v), %edx
29017 +
29018 +#ifdef CONFIG_PAX_REFCOUNT
29019 + into
29020 +1234:
29021 + _ASM_EXTABLE(1234b, 2f)
29022 +#endif
29023 +
29024 + movl %eax, (v)
29025 + movl %edx, 4(v)
29026 +
29027 +#ifdef CONFIG_PAX_REFCOUNT
29028 +2:
29029 +#endif
29030 +
29031 +RET_ENDP
29032 +BEGIN(add_return_unchecked)
29033 + addl (v), %eax
29034 + adcl 4(v), %edx
29035 movl %eax, (v)
29036 movl %edx, 4(v)
29037 RET_ENDP
29038 @@ -86,6 +126,20 @@ RET_ENDP
29039 BEGIN(sub)
29040 subl %eax, (v)
29041 sbbl %edx, 4(v)
29042 +
29043 +#ifdef CONFIG_PAX_REFCOUNT
29044 + jno 0f
29045 + addl %eax, (v)
29046 + adcl %edx, 4(v)
29047 + int $4
29048 +0:
29049 + _ASM_EXTABLE(0b, 0b)
29050 +#endif
29051 +
29052 +RET_ENDP
29053 +BEGIN(sub_unchecked)
29054 + subl %eax, (v)
29055 + sbbl %edx, 4(v)
29056 RET_ENDP
29057 #undef v
29058
29059 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29060 sbbl $0, %edx
29061 addl (v), %eax
29062 adcl 4(v), %edx
29063 +
29064 +#ifdef CONFIG_PAX_REFCOUNT
29065 + into
29066 +1234:
29067 + _ASM_EXTABLE(1234b, 2f)
29068 +#endif
29069 +
29070 + movl %eax, (v)
29071 + movl %edx, 4(v)
29072 +
29073 +#ifdef CONFIG_PAX_REFCOUNT
29074 +2:
29075 +#endif
29076 +
29077 +RET_ENDP
29078 +BEGIN(sub_return_unchecked)
29079 + negl %edx
29080 + negl %eax
29081 + sbbl $0, %edx
29082 + addl (v), %eax
29083 + adcl 4(v), %edx
29084 movl %eax, (v)
29085 movl %edx, 4(v)
29086 RET_ENDP
29087 @@ -105,6 +180,20 @@ RET_ENDP
29088 BEGIN(inc)
29089 addl $1, (v)
29090 adcl $0, 4(v)
29091 +
29092 +#ifdef CONFIG_PAX_REFCOUNT
29093 + jno 0f
29094 + subl $1, (v)
29095 + sbbl $0, 4(v)
29096 + int $4
29097 +0:
29098 + _ASM_EXTABLE(0b, 0b)
29099 +#endif
29100 +
29101 +RET_ENDP
29102 +BEGIN(inc_unchecked)
29103 + addl $1, (v)
29104 + adcl $0, 4(v)
29105 RET_ENDP
29106 #undef v
29107
29108 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29109 movl 4(v), %edx
29110 addl $1, %eax
29111 adcl $0, %edx
29112 +
29113 +#ifdef CONFIG_PAX_REFCOUNT
29114 + into
29115 +1234:
29116 + _ASM_EXTABLE(1234b, 2f)
29117 +#endif
29118 +
29119 + movl %eax, (v)
29120 + movl %edx, 4(v)
29121 +
29122 +#ifdef CONFIG_PAX_REFCOUNT
29123 +2:
29124 +#endif
29125 +
29126 +RET_ENDP
29127 +BEGIN(inc_return_unchecked)
29128 + movl (v), %eax
29129 + movl 4(v), %edx
29130 + addl $1, %eax
29131 + adcl $0, %edx
29132 movl %eax, (v)
29133 movl %edx, 4(v)
29134 RET_ENDP
29135 @@ -123,6 +232,20 @@ RET_ENDP
29136 BEGIN(dec)
29137 subl $1, (v)
29138 sbbl $0, 4(v)
29139 +
29140 +#ifdef CONFIG_PAX_REFCOUNT
29141 + jno 0f
29142 + addl $1, (v)
29143 + adcl $0, 4(v)
29144 + int $4
29145 +0:
29146 + _ASM_EXTABLE(0b, 0b)
29147 +#endif
29148 +
29149 +RET_ENDP
29150 +BEGIN(dec_unchecked)
29151 + subl $1, (v)
29152 + sbbl $0, 4(v)
29153 RET_ENDP
29154 #undef v
29155
29156 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29157 movl 4(v), %edx
29158 subl $1, %eax
29159 sbbl $0, %edx
29160 +
29161 +#ifdef CONFIG_PAX_REFCOUNT
29162 + into
29163 +1234:
29164 + _ASM_EXTABLE(1234b, 2f)
29165 +#endif
29166 +
29167 + movl %eax, (v)
29168 + movl %edx, 4(v)
29169 +
29170 +#ifdef CONFIG_PAX_REFCOUNT
29171 +2:
29172 +#endif
29173 +
29174 +RET_ENDP
29175 +BEGIN(dec_return_unchecked)
29176 + movl (v), %eax
29177 + movl 4(v), %edx
29178 + subl $1, %eax
29179 + sbbl $0, %edx
29180 movl %eax, (v)
29181 movl %edx, 4(v)
29182 RET_ENDP
29183 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29184 adcl %edx, %edi
29185 addl (v), %eax
29186 adcl 4(v), %edx
29187 +
29188 +#ifdef CONFIG_PAX_REFCOUNT
29189 + into
29190 +1234:
29191 + _ASM_EXTABLE(1234b, 2f)
29192 +#endif
29193 +
29194 cmpl %eax, %ecx
29195 je 3f
29196 1:
29197 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29198 1:
29199 addl $1, %eax
29200 adcl $0, %edx
29201 +
29202 +#ifdef CONFIG_PAX_REFCOUNT
29203 + into
29204 +1234:
29205 + _ASM_EXTABLE(1234b, 2f)
29206 +#endif
29207 +
29208 movl %eax, (v)
29209 movl %edx, 4(v)
29210 movl $1, %eax
29211 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29212 movl 4(v), %edx
29213 subl $1, %eax
29214 sbbl $0, %edx
29215 +
29216 +#ifdef CONFIG_PAX_REFCOUNT
29217 + into
29218 +1234:
29219 + _ASM_EXTABLE(1234b, 1f)
29220 +#endif
29221 +
29222 js 1f
29223 movl %eax, (v)
29224 movl %edx, 4(v)
29225 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29226 index f5cc9eb..51fa319 100644
29227 --- a/arch/x86/lib/atomic64_cx8_32.S
29228 +++ b/arch/x86/lib/atomic64_cx8_32.S
29229 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29230 CFI_STARTPROC
29231
29232 read64 %ecx
29233 + pax_force_retaddr
29234 ret
29235 CFI_ENDPROC
29236 ENDPROC(atomic64_read_cx8)
29237
29238 +ENTRY(atomic64_read_unchecked_cx8)
29239 + CFI_STARTPROC
29240 +
29241 + read64 %ecx
29242 + pax_force_retaddr
29243 + ret
29244 + CFI_ENDPROC
29245 +ENDPROC(atomic64_read_unchecked_cx8)
29246 +
29247 ENTRY(atomic64_set_cx8)
29248 CFI_STARTPROC
29249
29250 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29251 cmpxchg8b (%esi)
29252 jne 1b
29253
29254 + pax_force_retaddr
29255 ret
29256 CFI_ENDPROC
29257 ENDPROC(atomic64_set_cx8)
29258
29259 +ENTRY(atomic64_set_unchecked_cx8)
29260 + CFI_STARTPROC
29261 +
29262 +1:
29263 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29264 + * are atomic on 586 and newer */
29265 + cmpxchg8b (%esi)
29266 + jne 1b
29267 +
29268 + pax_force_retaddr
29269 + ret
29270 + CFI_ENDPROC
29271 +ENDPROC(atomic64_set_unchecked_cx8)
29272 +
29273 ENTRY(atomic64_xchg_cx8)
29274 CFI_STARTPROC
29275
29276 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29277 cmpxchg8b (%esi)
29278 jne 1b
29279
29280 + pax_force_retaddr
29281 ret
29282 CFI_ENDPROC
29283 ENDPROC(atomic64_xchg_cx8)
29284
29285 -.macro addsub_return func ins insc
29286 -ENTRY(atomic64_\func\()_return_cx8)
29287 +.macro addsub_return func ins insc unchecked=""
29288 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29289 CFI_STARTPROC
29290 SAVE ebp
29291 SAVE ebx
29292 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29293 movl %edx, %ecx
29294 \ins\()l %esi, %ebx
29295 \insc\()l %edi, %ecx
29296 +
29297 +.ifb \unchecked
29298 +#ifdef CONFIG_PAX_REFCOUNT
29299 + into
29300 +2:
29301 + _ASM_EXTABLE(2b, 3f)
29302 +#endif
29303 +.endif
29304 +
29305 LOCK_PREFIX
29306 cmpxchg8b (%ebp)
29307 jne 1b
29308 -
29309 -10:
29310 movl %ebx, %eax
29311 movl %ecx, %edx
29312 +
29313 +.ifb \unchecked
29314 +#ifdef CONFIG_PAX_REFCOUNT
29315 +3:
29316 +#endif
29317 +.endif
29318 +
29319 RESTORE edi
29320 RESTORE esi
29321 RESTORE ebx
29322 RESTORE ebp
29323 + pax_force_retaddr
29324 ret
29325 CFI_ENDPROC
29326 -ENDPROC(atomic64_\func\()_return_cx8)
29327 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29328 .endm
29329
29330 addsub_return add add adc
29331 addsub_return sub sub sbb
29332 +addsub_return add add adc _unchecked
29333 +addsub_return sub sub sbb _unchecked
29334
29335 -.macro incdec_return func ins insc
29336 -ENTRY(atomic64_\func\()_return_cx8)
29337 +.macro incdec_return func ins insc unchecked=""
29338 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29339 CFI_STARTPROC
29340 SAVE ebx
29341
29342 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29343 movl %edx, %ecx
29344 \ins\()l $1, %ebx
29345 \insc\()l $0, %ecx
29346 +
29347 +.ifb \unchecked
29348 +#ifdef CONFIG_PAX_REFCOUNT
29349 + into
29350 +2:
29351 + _ASM_EXTABLE(2b, 3f)
29352 +#endif
29353 +.endif
29354 +
29355 LOCK_PREFIX
29356 cmpxchg8b (%esi)
29357 jne 1b
29358
29359 -10:
29360 movl %ebx, %eax
29361 movl %ecx, %edx
29362 +
29363 +.ifb \unchecked
29364 +#ifdef CONFIG_PAX_REFCOUNT
29365 +3:
29366 +#endif
29367 +.endif
29368 +
29369 RESTORE ebx
29370 + pax_force_retaddr
29371 ret
29372 CFI_ENDPROC
29373 -ENDPROC(atomic64_\func\()_return_cx8)
29374 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29375 .endm
29376
29377 incdec_return inc add adc
29378 incdec_return dec sub sbb
29379 +incdec_return inc add adc _unchecked
29380 +incdec_return dec sub sbb _unchecked
29381
29382 ENTRY(atomic64_dec_if_positive_cx8)
29383 CFI_STARTPROC
29384 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29385 movl %edx, %ecx
29386 subl $1, %ebx
29387 sbb $0, %ecx
29388 +
29389 +#ifdef CONFIG_PAX_REFCOUNT
29390 + into
29391 +1234:
29392 + _ASM_EXTABLE(1234b, 2f)
29393 +#endif
29394 +
29395 js 2f
29396 LOCK_PREFIX
29397 cmpxchg8b (%esi)
29398 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29399 movl %ebx, %eax
29400 movl %ecx, %edx
29401 RESTORE ebx
29402 + pax_force_retaddr
29403 ret
29404 CFI_ENDPROC
29405 ENDPROC(atomic64_dec_if_positive_cx8)
29406 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29407 movl %edx, %ecx
29408 addl %ebp, %ebx
29409 adcl %edi, %ecx
29410 +
29411 +#ifdef CONFIG_PAX_REFCOUNT
29412 + into
29413 +1234:
29414 + _ASM_EXTABLE(1234b, 3f)
29415 +#endif
29416 +
29417 LOCK_PREFIX
29418 cmpxchg8b (%esi)
29419 jne 1b
29420 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29421 CFI_ADJUST_CFA_OFFSET -8
29422 RESTORE ebx
29423 RESTORE ebp
29424 + pax_force_retaddr
29425 ret
29426 4:
29427 cmpl %edx, 4(%esp)
29428 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29429 xorl %ecx, %ecx
29430 addl $1, %ebx
29431 adcl %edx, %ecx
29432 +
29433 +#ifdef CONFIG_PAX_REFCOUNT
29434 + into
29435 +1234:
29436 + _ASM_EXTABLE(1234b, 3f)
29437 +#endif
29438 +
29439 LOCK_PREFIX
29440 cmpxchg8b (%esi)
29441 jne 1b
29442 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29443 movl $1, %eax
29444 3:
29445 RESTORE ebx
29446 + pax_force_retaddr
29447 ret
29448 CFI_ENDPROC
29449 ENDPROC(atomic64_inc_not_zero_cx8)
29450 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29451 index e78b8eee..7e173a8 100644
29452 --- a/arch/x86/lib/checksum_32.S
29453 +++ b/arch/x86/lib/checksum_32.S
29454 @@ -29,7 +29,8 @@
29455 #include <asm/dwarf2.h>
29456 #include <asm/errno.h>
29457 #include <asm/asm.h>
29458 -
29459 +#include <asm/segment.h>
29460 +
29461 /*
29462 * computes a partial checksum, e.g. for TCP/UDP fragments
29463 */
29464 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29465
29466 #define ARGBASE 16
29467 #define FP 12
29468 -
29469 -ENTRY(csum_partial_copy_generic)
29470 +
29471 +ENTRY(csum_partial_copy_generic_to_user)
29472 CFI_STARTPROC
29473 +
29474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29475 + pushl_cfi %gs
29476 + popl_cfi %es
29477 + jmp csum_partial_copy_generic
29478 +#endif
29479 +
29480 +ENTRY(csum_partial_copy_generic_from_user)
29481 +
29482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29483 + pushl_cfi %gs
29484 + popl_cfi %ds
29485 +#endif
29486 +
29487 +ENTRY(csum_partial_copy_generic)
29488 subl $4,%esp
29489 CFI_ADJUST_CFA_OFFSET 4
29490 pushl_cfi %edi
29491 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29492 jmp 4f
29493 SRC(1: movw (%esi), %bx )
29494 addl $2, %esi
29495 -DST( movw %bx, (%edi) )
29496 +DST( movw %bx, %es:(%edi) )
29497 addl $2, %edi
29498 addw %bx, %ax
29499 adcl $0, %eax
29500 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29501 SRC(1: movl (%esi), %ebx )
29502 SRC( movl 4(%esi), %edx )
29503 adcl %ebx, %eax
29504 -DST( movl %ebx, (%edi) )
29505 +DST( movl %ebx, %es:(%edi) )
29506 adcl %edx, %eax
29507 -DST( movl %edx, 4(%edi) )
29508 +DST( movl %edx, %es:4(%edi) )
29509
29510 SRC( movl 8(%esi), %ebx )
29511 SRC( movl 12(%esi), %edx )
29512 adcl %ebx, %eax
29513 -DST( movl %ebx, 8(%edi) )
29514 +DST( movl %ebx, %es:8(%edi) )
29515 adcl %edx, %eax
29516 -DST( movl %edx, 12(%edi) )
29517 +DST( movl %edx, %es:12(%edi) )
29518
29519 SRC( movl 16(%esi), %ebx )
29520 SRC( movl 20(%esi), %edx )
29521 adcl %ebx, %eax
29522 -DST( movl %ebx, 16(%edi) )
29523 +DST( movl %ebx, %es:16(%edi) )
29524 adcl %edx, %eax
29525 -DST( movl %edx, 20(%edi) )
29526 +DST( movl %edx, %es:20(%edi) )
29527
29528 SRC( movl 24(%esi), %ebx )
29529 SRC( movl 28(%esi), %edx )
29530 adcl %ebx, %eax
29531 -DST( movl %ebx, 24(%edi) )
29532 +DST( movl %ebx, %es:24(%edi) )
29533 adcl %edx, %eax
29534 -DST( movl %edx, 28(%edi) )
29535 +DST( movl %edx, %es:28(%edi) )
29536
29537 lea 32(%esi), %esi
29538 lea 32(%edi), %edi
29539 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29540 shrl $2, %edx # This clears CF
29541 SRC(3: movl (%esi), %ebx )
29542 adcl %ebx, %eax
29543 -DST( movl %ebx, (%edi) )
29544 +DST( movl %ebx, %es:(%edi) )
29545 lea 4(%esi), %esi
29546 lea 4(%edi), %edi
29547 dec %edx
29548 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29549 jb 5f
29550 SRC( movw (%esi), %cx )
29551 leal 2(%esi), %esi
29552 -DST( movw %cx, (%edi) )
29553 +DST( movw %cx, %es:(%edi) )
29554 leal 2(%edi), %edi
29555 je 6f
29556 shll $16,%ecx
29557 SRC(5: movb (%esi), %cl )
29558 -DST( movb %cl, (%edi) )
29559 +DST( movb %cl, %es:(%edi) )
29560 6: addl %ecx, %eax
29561 adcl $0, %eax
29562 7:
29563 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29564
29565 6001:
29566 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29567 - movl $-EFAULT, (%ebx)
29568 + movl $-EFAULT, %ss:(%ebx)
29569
29570 # zero the complete destination - computing the rest
29571 # is too much work
29572 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29573
29574 6002:
29575 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29576 - movl $-EFAULT,(%ebx)
29577 + movl $-EFAULT,%ss:(%ebx)
29578 jmp 5000b
29579
29580 .previous
29581
29582 + pushl_cfi %ss
29583 + popl_cfi %ds
29584 + pushl_cfi %ss
29585 + popl_cfi %es
29586 popl_cfi %ebx
29587 CFI_RESTORE ebx
29588 popl_cfi %esi
29589 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29590 popl_cfi %ecx # equivalent to addl $4,%esp
29591 ret
29592 CFI_ENDPROC
29593 -ENDPROC(csum_partial_copy_generic)
29594 +ENDPROC(csum_partial_copy_generic_to_user)
29595
29596 #else
29597
29598 /* Version for PentiumII/PPro */
29599
29600 #define ROUND1(x) \
29601 + nop; nop; nop; \
29602 SRC(movl x(%esi), %ebx ) ; \
29603 addl %ebx, %eax ; \
29604 - DST(movl %ebx, x(%edi) ) ;
29605 + DST(movl %ebx, %es:x(%edi)) ;
29606
29607 #define ROUND(x) \
29608 + nop; nop; nop; \
29609 SRC(movl x(%esi), %ebx ) ; \
29610 adcl %ebx, %eax ; \
29611 - DST(movl %ebx, x(%edi) ) ;
29612 + DST(movl %ebx, %es:x(%edi)) ;
29613
29614 #define ARGBASE 12
29615 -
29616 -ENTRY(csum_partial_copy_generic)
29617 +
29618 +ENTRY(csum_partial_copy_generic_to_user)
29619 CFI_STARTPROC
29620 +
29621 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29622 + pushl_cfi %gs
29623 + popl_cfi %es
29624 + jmp csum_partial_copy_generic
29625 +#endif
29626 +
29627 +ENTRY(csum_partial_copy_generic_from_user)
29628 +
29629 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29630 + pushl_cfi %gs
29631 + popl_cfi %ds
29632 +#endif
29633 +
29634 +ENTRY(csum_partial_copy_generic)
29635 pushl_cfi %ebx
29636 CFI_REL_OFFSET ebx, 0
29637 pushl_cfi %edi
29638 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29639 subl %ebx, %edi
29640 lea -1(%esi),%edx
29641 andl $-32,%edx
29642 - lea 3f(%ebx,%ebx), %ebx
29643 + lea 3f(%ebx,%ebx,2), %ebx
29644 testl %esi, %esi
29645 jmp *%ebx
29646 1: addl $64,%esi
29647 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29648 jb 5f
29649 SRC( movw (%esi), %dx )
29650 leal 2(%esi), %esi
29651 -DST( movw %dx, (%edi) )
29652 +DST( movw %dx, %es:(%edi) )
29653 leal 2(%edi), %edi
29654 je 6f
29655 shll $16,%edx
29656 5:
29657 SRC( movb (%esi), %dl )
29658 -DST( movb %dl, (%edi) )
29659 +DST( movb %dl, %es:(%edi) )
29660 6: addl %edx, %eax
29661 adcl $0, %eax
29662 7:
29663 .section .fixup, "ax"
29664 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29665 - movl $-EFAULT, (%ebx)
29666 + movl $-EFAULT, %ss:(%ebx)
29667 # zero the complete destination (computing the rest is too much work)
29668 movl ARGBASE+8(%esp),%edi # dst
29669 movl ARGBASE+12(%esp),%ecx # len
29670 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29671 rep; stosb
29672 jmp 7b
29673 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29674 - movl $-EFAULT, (%ebx)
29675 + movl $-EFAULT, %ss:(%ebx)
29676 jmp 7b
29677 .previous
29678
29679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29680 + pushl_cfi %ss
29681 + popl_cfi %ds
29682 + pushl_cfi %ss
29683 + popl_cfi %es
29684 +#endif
29685 +
29686 popl_cfi %esi
29687 CFI_RESTORE esi
29688 popl_cfi %edi
29689 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29690 CFI_RESTORE ebx
29691 ret
29692 CFI_ENDPROC
29693 -ENDPROC(csum_partial_copy_generic)
29694 +ENDPROC(csum_partial_copy_generic_to_user)
29695
29696 #undef ROUND
29697 #undef ROUND1
29698 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29699 index f2145cf..cea889d 100644
29700 --- a/arch/x86/lib/clear_page_64.S
29701 +++ b/arch/x86/lib/clear_page_64.S
29702 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29703 movl $4096/8,%ecx
29704 xorl %eax,%eax
29705 rep stosq
29706 + pax_force_retaddr
29707 ret
29708 CFI_ENDPROC
29709 ENDPROC(clear_page_c)
29710 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29711 movl $4096,%ecx
29712 xorl %eax,%eax
29713 rep stosb
29714 + pax_force_retaddr
29715 ret
29716 CFI_ENDPROC
29717 ENDPROC(clear_page_c_e)
29718 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29719 leaq 64(%rdi),%rdi
29720 jnz .Lloop
29721 nop
29722 + pax_force_retaddr
29723 ret
29724 CFI_ENDPROC
29725 .Lclear_page_end:
29726 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29727
29728 #include <asm/cpufeature.h>
29729
29730 - .section .altinstr_replacement,"ax"
29731 + .section .altinstr_replacement,"a"
29732 1: .byte 0xeb /* jmp <disp8> */
29733 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29734 2: .byte 0xeb /* jmp <disp8> */
29735 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29736 index 40a1725..5d12ac4 100644
29737 --- a/arch/x86/lib/cmpxchg16b_emu.S
29738 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29739 @@ -8,6 +8,7 @@
29740 #include <linux/linkage.h>
29741 #include <asm/dwarf2.h>
29742 #include <asm/percpu.h>
29743 +#include <asm/alternative-asm.h>
29744
29745 .text
29746
29747 @@ -46,12 +47,14 @@ CFI_STARTPROC
29748 CFI_REMEMBER_STATE
29749 popfq_cfi
29750 mov $1, %al
29751 + pax_force_retaddr
29752 ret
29753
29754 CFI_RESTORE_STATE
29755 .Lnot_same:
29756 popfq_cfi
29757 xor %al,%al
29758 + pax_force_retaddr
29759 ret
29760
29761 CFI_ENDPROC
29762 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29763 index 176cca6..e0d658e 100644
29764 --- a/arch/x86/lib/copy_page_64.S
29765 +++ b/arch/x86/lib/copy_page_64.S
29766 @@ -9,6 +9,7 @@ copy_page_rep:
29767 CFI_STARTPROC
29768 movl $4096/8, %ecx
29769 rep movsq
29770 + pax_force_retaddr
29771 ret
29772 CFI_ENDPROC
29773 ENDPROC(copy_page_rep)
29774 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29775 CFI_ADJUST_CFA_OFFSET 2*8
29776 movq %rbx, (%rsp)
29777 CFI_REL_OFFSET rbx, 0
29778 - movq %r12, 1*8(%rsp)
29779 - CFI_REL_OFFSET r12, 1*8
29780 + movq %r13, 1*8(%rsp)
29781 + CFI_REL_OFFSET r13, 1*8
29782
29783 movl $(4096/64)-5, %ecx
29784 .p2align 4
29785 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29786 movq 0x8*4(%rsi), %r9
29787 movq 0x8*5(%rsi), %r10
29788 movq 0x8*6(%rsi), %r11
29789 - movq 0x8*7(%rsi), %r12
29790 + movq 0x8*7(%rsi), %r13
29791
29792 prefetcht0 5*64(%rsi)
29793
29794 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29795 movq %r9, 0x8*4(%rdi)
29796 movq %r10, 0x8*5(%rdi)
29797 movq %r11, 0x8*6(%rdi)
29798 - movq %r12, 0x8*7(%rdi)
29799 + movq %r13, 0x8*7(%rdi)
29800
29801 leaq 64 (%rsi), %rsi
29802 leaq 64 (%rdi), %rdi
29803 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29804 movq 0x8*4(%rsi), %r9
29805 movq 0x8*5(%rsi), %r10
29806 movq 0x8*6(%rsi), %r11
29807 - movq 0x8*7(%rsi), %r12
29808 + movq 0x8*7(%rsi), %r13
29809
29810 movq %rax, 0x8*0(%rdi)
29811 movq %rbx, 0x8*1(%rdi)
29812 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29813 movq %r9, 0x8*4(%rdi)
29814 movq %r10, 0x8*5(%rdi)
29815 movq %r11, 0x8*6(%rdi)
29816 - movq %r12, 0x8*7(%rdi)
29817 + movq %r13, 0x8*7(%rdi)
29818
29819 leaq 64(%rdi), %rdi
29820 leaq 64(%rsi), %rsi
29821 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29822
29823 movq (%rsp), %rbx
29824 CFI_RESTORE rbx
29825 - movq 1*8(%rsp), %r12
29826 - CFI_RESTORE r12
29827 + movq 1*8(%rsp), %r13
29828 + CFI_RESTORE r13
29829 addq $2*8, %rsp
29830 CFI_ADJUST_CFA_OFFSET -2*8
29831 + pax_force_retaddr
29832 ret
29833 .Lcopy_page_end:
29834 CFI_ENDPROC
29835 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29836
29837 #include <asm/cpufeature.h>
29838
29839 - .section .altinstr_replacement,"ax"
29840 + .section .altinstr_replacement,"a"
29841 1: .byte 0xeb /* jmp <disp8> */
29842 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29843 2:
29844 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29845 index dee945d..a84067b 100644
29846 --- a/arch/x86/lib/copy_user_64.S
29847 +++ b/arch/x86/lib/copy_user_64.S
29848 @@ -18,31 +18,7 @@
29849 #include <asm/alternative-asm.h>
29850 #include <asm/asm.h>
29851 #include <asm/smap.h>
29852 -
29853 -/*
29854 - * By placing feature2 after feature1 in altinstructions section, we logically
29855 - * implement:
29856 - * If CPU has feature2, jmp to alt2 is used
29857 - * else if CPU has feature1, jmp to alt1 is used
29858 - * else jmp to orig is used.
29859 - */
29860 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29861 -0:
29862 - .byte 0xe9 /* 32bit jump */
29863 - .long \orig-1f /* by default jump to orig */
29864 -1:
29865 - .section .altinstr_replacement,"ax"
29866 -2: .byte 0xe9 /* near jump with 32bit immediate */
29867 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29868 -3: .byte 0xe9 /* near jump with 32bit immediate */
29869 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29870 - .previous
29871 -
29872 - .section .altinstructions,"a"
29873 - altinstruction_entry 0b,2b,\feature1,5,5
29874 - altinstruction_entry 0b,3b,\feature2,5,5
29875 - .previous
29876 - .endm
29877 +#include <asm/pgtable.h>
29878
29879 .macro ALIGN_DESTINATION
29880 #ifdef FIX_ALIGNMENT
29881 @@ -70,52 +46,6 @@
29882 #endif
29883 .endm
29884
29885 -/* Standard copy_to_user with segment limit checking */
29886 -ENTRY(_copy_to_user)
29887 - CFI_STARTPROC
29888 - GET_THREAD_INFO(%rax)
29889 - movq %rdi,%rcx
29890 - addq %rdx,%rcx
29891 - jc bad_to_user
29892 - cmpq TI_addr_limit(%rax),%rcx
29893 - ja bad_to_user
29894 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29895 - copy_user_generic_unrolled,copy_user_generic_string, \
29896 - copy_user_enhanced_fast_string
29897 - CFI_ENDPROC
29898 -ENDPROC(_copy_to_user)
29899 -
29900 -/* Standard copy_from_user with segment limit checking */
29901 -ENTRY(_copy_from_user)
29902 - CFI_STARTPROC
29903 - GET_THREAD_INFO(%rax)
29904 - movq %rsi,%rcx
29905 - addq %rdx,%rcx
29906 - jc bad_from_user
29907 - cmpq TI_addr_limit(%rax),%rcx
29908 - ja bad_from_user
29909 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29910 - copy_user_generic_unrolled,copy_user_generic_string, \
29911 - copy_user_enhanced_fast_string
29912 - CFI_ENDPROC
29913 -ENDPROC(_copy_from_user)
29914 -
29915 - .section .fixup,"ax"
29916 - /* must zero dest */
29917 -ENTRY(bad_from_user)
29918 -bad_from_user:
29919 - CFI_STARTPROC
29920 - movl %edx,%ecx
29921 - xorl %eax,%eax
29922 - rep
29923 - stosb
29924 -bad_to_user:
29925 - movl %edx,%eax
29926 - ret
29927 - CFI_ENDPROC
29928 -ENDPROC(bad_from_user)
29929 - .previous
29930 -
29931 /*
29932 * copy_user_generic_unrolled - memory copy with exception handling.
29933 * This version is for CPUs like P4 that don't have efficient micro
29934 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29935 */
29936 ENTRY(copy_user_generic_unrolled)
29937 CFI_STARTPROC
29938 + ASM_PAX_OPEN_USERLAND
29939 ASM_STAC
29940 cmpl $8,%edx
29941 jb 20f /* less then 8 bytes, go to byte copy loop */
29942 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29943 jnz 21b
29944 23: xor %eax,%eax
29945 ASM_CLAC
29946 + ASM_PAX_CLOSE_USERLAND
29947 + pax_force_retaddr
29948 ret
29949
29950 .section .fixup,"ax"
29951 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29952 */
29953 ENTRY(copy_user_generic_string)
29954 CFI_STARTPROC
29955 + ASM_PAX_OPEN_USERLAND
29956 ASM_STAC
29957 cmpl $8,%edx
29958 jb 2f /* less than 8 bytes, go to byte copy loop */
29959 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29960 movsb
29961 xorl %eax,%eax
29962 ASM_CLAC
29963 + ASM_PAX_CLOSE_USERLAND
29964 + pax_force_retaddr
29965 ret
29966
29967 .section .fixup,"ax"
29968 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29969 */
29970 ENTRY(copy_user_enhanced_fast_string)
29971 CFI_STARTPROC
29972 + ASM_PAX_OPEN_USERLAND
29973 ASM_STAC
29974 movl %edx,%ecx
29975 1: rep
29976 movsb
29977 xorl %eax,%eax
29978 ASM_CLAC
29979 + ASM_PAX_CLOSE_USERLAND
29980 + pax_force_retaddr
29981 ret
29982
29983 .section .fixup,"ax"
29984 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29985 index 6a4f43c..c70fb52 100644
29986 --- a/arch/x86/lib/copy_user_nocache_64.S
29987 +++ b/arch/x86/lib/copy_user_nocache_64.S
29988 @@ -8,6 +8,7 @@
29989
29990 #include <linux/linkage.h>
29991 #include <asm/dwarf2.h>
29992 +#include <asm/alternative-asm.h>
29993
29994 #define FIX_ALIGNMENT 1
29995
29996 @@ -16,6 +17,7 @@
29997 #include <asm/thread_info.h>
29998 #include <asm/asm.h>
29999 #include <asm/smap.h>
30000 +#include <asm/pgtable.h>
30001
30002 .macro ALIGN_DESTINATION
30003 #ifdef FIX_ALIGNMENT
30004 @@ -49,6 +51,16 @@
30005 */
30006 ENTRY(__copy_user_nocache)
30007 CFI_STARTPROC
30008 +
30009 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30010 + mov pax_user_shadow_base,%rcx
30011 + cmp %rcx,%rsi
30012 + jae 1f
30013 + add %rcx,%rsi
30014 +1:
30015 +#endif
30016 +
30017 + ASM_PAX_OPEN_USERLAND
30018 ASM_STAC
30019 cmpl $8,%edx
30020 jb 20f /* less then 8 bytes, go to byte copy loop */
30021 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30022 jnz 21b
30023 23: xorl %eax,%eax
30024 ASM_CLAC
30025 + ASM_PAX_CLOSE_USERLAND
30026 sfence
30027 + pax_force_retaddr
30028 ret
30029
30030 .section .fixup,"ax"
30031 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30032 index 2419d5f..fe52d0e 100644
30033 --- a/arch/x86/lib/csum-copy_64.S
30034 +++ b/arch/x86/lib/csum-copy_64.S
30035 @@ -9,6 +9,7 @@
30036 #include <asm/dwarf2.h>
30037 #include <asm/errno.h>
30038 #include <asm/asm.h>
30039 +#include <asm/alternative-asm.h>
30040
30041 /*
30042 * Checksum copy with exception handling.
30043 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30044 CFI_ADJUST_CFA_OFFSET 7*8
30045 movq %rbx, 2*8(%rsp)
30046 CFI_REL_OFFSET rbx, 2*8
30047 - movq %r12, 3*8(%rsp)
30048 - CFI_REL_OFFSET r12, 3*8
30049 + movq %r15, 3*8(%rsp)
30050 + CFI_REL_OFFSET r15, 3*8
30051 movq %r14, 4*8(%rsp)
30052 CFI_REL_OFFSET r14, 4*8
30053 movq %r13, 5*8(%rsp)
30054 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30055 movl %edx, %ecx
30056
30057 xorl %r9d, %r9d
30058 - movq %rcx, %r12
30059 + movq %rcx, %r15
30060
30061 - shrq $6, %r12
30062 + shrq $6, %r15
30063 jz .Lhandle_tail /* < 64 */
30064
30065 clc
30066
30067 /* main loop. clear in 64 byte blocks */
30068 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30069 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30070 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30071 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30072 .p2align 4
30073 .Lloop:
30074 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30075 adcq %r14, %rax
30076 adcq %r13, %rax
30077
30078 - decl %r12d
30079 + decl %r15d
30080
30081 dest
30082 movq %rbx, (%rsi)
30083 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30084 .Lende:
30085 movq 2*8(%rsp), %rbx
30086 CFI_RESTORE rbx
30087 - movq 3*8(%rsp), %r12
30088 - CFI_RESTORE r12
30089 + movq 3*8(%rsp), %r15
30090 + CFI_RESTORE r15
30091 movq 4*8(%rsp), %r14
30092 CFI_RESTORE r14
30093 movq 5*8(%rsp), %r13
30094 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30095 CFI_RESTORE rbp
30096 addq $7*8, %rsp
30097 CFI_ADJUST_CFA_OFFSET -7*8
30098 + pax_force_retaddr
30099 ret
30100 CFI_RESTORE_STATE
30101
30102 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30103 index 1318f75..44c30fd 100644
30104 --- a/arch/x86/lib/csum-wrappers_64.c
30105 +++ b/arch/x86/lib/csum-wrappers_64.c
30106 @@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30107 len -= 2;
30108 }
30109 }
30110 + pax_open_userland();
30111 stac();
30112 - isum = csum_partial_copy_generic((__force const void *)src,
30113 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30114 dst, len, isum, errp, NULL);
30115 clac();
30116 + pax_close_userland();
30117 if (unlikely(*errp))
30118 goto out_err;
30119
30120 @@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30121 }
30122
30123 *errp = 0;
30124 + pax_open_userland();
30125 stac();
30126 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30127 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30128 len, isum, NULL, errp);
30129 clac();
30130 + pax_close_userland();
30131 return ret;
30132 }
30133 EXPORT_SYMBOL(csum_partial_copy_to_user);
30134 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30135 index a451235..1daa956 100644
30136 --- a/arch/x86/lib/getuser.S
30137 +++ b/arch/x86/lib/getuser.S
30138 @@ -33,17 +33,40 @@
30139 #include <asm/thread_info.h>
30140 #include <asm/asm.h>
30141 #include <asm/smap.h>
30142 +#include <asm/segment.h>
30143 +#include <asm/pgtable.h>
30144 +#include <asm/alternative-asm.h>
30145 +
30146 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30147 +#define __copyuser_seg gs;
30148 +#else
30149 +#define __copyuser_seg
30150 +#endif
30151
30152 .text
30153 ENTRY(__get_user_1)
30154 CFI_STARTPROC
30155 +
30156 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30157 GET_THREAD_INFO(%_ASM_DX)
30158 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30159 jae bad_get_user
30160 ASM_STAC
30161 -1: movzbl (%_ASM_AX),%edx
30162 +
30163 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30164 + mov pax_user_shadow_base,%_ASM_DX
30165 + cmp %_ASM_DX,%_ASM_AX
30166 + jae 1234f
30167 + add %_ASM_DX,%_ASM_AX
30168 +1234:
30169 +#endif
30170 +
30171 +#endif
30172 +
30173 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30174 xor %eax,%eax
30175 ASM_CLAC
30176 + pax_force_retaddr
30177 ret
30178 CFI_ENDPROC
30179 ENDPROC(__get_user_1)
30180 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30181 ENTRY(__get_user_2)
30182 CFI_STARTPROC
30183 add $1,%_ASM_AX
30184 +
30185 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30186 jc bad_get_user
30187 GET_THREAD_INFO(%_ASM_DX)
30188 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30189 jae bad_get_user
30190 ASM_STAC
30191 -2: movzwl -1(%_ASM_AX),%edx
30192 +
30193 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30194 + mov pax_user_shadow_base,%_ASM_DX
30195 + cmp %_ASM_DX,%_ASM_AX
30196 + jae 1234f
30197 + add %_ASM_DX,%_ASM_AX
30198 +1234:
30199 +#endif
30200 +
30201 +#endif
30202 +
30203 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30204 xor %eax,%eax
30205 ASM_CLAC
30206 + pax_force_retaddr
30207 ret
30208 CFI_ENDPROC
30209 ENDPROC(__get_user_2)
30210 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30211 ENTRY(__get_user_4)
30212 CFI_STARTPROC
30213 add $3,%_ASM_AX
30214 +
30215 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30216 jc bad_get_user
30217 GET_THREAD_INFO(%_ASM_DX)
30218 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30219 jae bad_get_user
30220 ASM_STAC
30221 -3: movl -3(%_ASM_AX),%edx
30222 +
30223 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30224 + mov pax_user_shadow_base,%_ASM_DX
30225 + cmp %_ASM_DX,%_ASM_AX
30226 + jae 1234f
30227 + add %_ASM_DX,%_ASM_AX
30228 +1234:
30229 +#endif
30230 +
30231 +#endif
30232 +
30233 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30234 xor %eax,%eax
30235 ASM_CLAC
30236 + pax_force_retaddr
30237 ret
30238 CFI_ENDPROC
30239 ENDPROC(__get_user_4)
30240 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30241 GET_THREAD_INFO(%_ASM_DX)
30242 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30243 jae bad_get_user
30244 +
30245 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30246 + mov pax_user_shadow_base,%_ASM_DX
30247 + cmp %_ASM_DX,%_ASM_AX
30248 + jae 1234f
30249 + add %_ASM_DX,%_ASM_AX
30250 +1234:
30251 +#endif
30252 +
30253 ASM_STAC
30254 4: movq -7(%_ASM_AX),%rdx
30255 xor %eax,%eax
30256 ASM_CLAC
30257 + pax_force_retaddr
30258 ret
30259 #else
30260 add $7,%_ASM_AX
30261 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30262 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30263 jae bad_get_user_8
30264 ASM_STAC
30265 -4: movl -7(%_ASM_AX),%edx
30266 -5: movl -3(%_ASM_AX),%ecx
30267 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30268 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30269 xor %eax,%eax
30270 ASM_CLAC
30271 + pax_force_retaddr
30272 ret
30273 #endif
30274 CFI_ENDPROC
30275 @@ -113,6 +175,7 @@ bad_get_user:
30276 xor %edx,%edx
30277 mov $(-EFAULT),%_ASM_AX
30278 ASM_CLAC
30279 + pax_force_retaddr
30280 ret
30281 CFI_ENDPROC
30282 END(bad_get_user)
30283 @@ -124,6 +187,7 @@ bad_get_user_8:
30284 xor %ecx,%ecx
30285 mov $(-EFAULT),%_ASM_AX
30286 ASM_CLAC
30287 + pax_force_retaddr
30288 ret
30289 CFI_ENDPROC
30290 END(bad_get_user_8)
30291 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30292 index 54fcffe..7be149e 100644
30293 --- a/arch/x86/lib/insn.c
30294 +++ b/arch/x86/lib/insn.c
30295 @@ -20,8 +20,10 @@
30296
30297 #ifdef __KERNEL__
30298 #include <linux/string.h>
30299 +#include <asm/pgtable_types.h>
30300 #else
30301 #include <string.h>
30302 +#define ktla_ktva(addr) addr
30303 #endif
30304 #include <asm/inat.h>
30305 #include <asm/insn.h>
30306 @@ -53,8 +55,8 @@
30307 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30308 {
30309 memset(insn, 0, sizeof(*insn));
30310 - insn->kaddr = kaddr;
30311 - insn->next_byte = kaddr;
30312 + insn->kaddr = ktla_ktva(kaddr);
30313 + insn->next_byte = ktla_ktva(kaddr);
30314 insn->x86_64 = x86_64 ? 1 : 0;
30315 insn->opnd_bytes = 4;
30316 if (x86_64)
30317 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30318 index 05a95e7..326f2fa 100644
30319 --- a/arch/x86/lib/iomap_copy_64.S
30320 +++ b/arch/x86/lib/iomap_copy_64.S
30321 @@ -17,6 +17,7 @@
30322
30323 #include <linux/linkage.h>
30324 #include <asm/dwarf2.h>
30325 +#include <asm/alternative-asm.h>
30326
30327 /*
30328 * override generic version in lib/iomap_copy.c
30329 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30330 CFI_STARTPROC
30331 movl %edx,%ecx
30332 rep movsd
30333 + pax_force_retaddr
30334 ret
30335 CFI_ENDPROC
30336 ENDPROC(__iowrite32_copy)
30337 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30338 index 56313a3..0db417e 100644
30339 --- a/arch/x86/lib/memcpy_64.S
30340 +++ b/arch/x86/lib/memcpy_64.S
30341 @@ -24,7 +24,7 @@
30342 * This gets patched over the unrolled variant (below) via the
30343 * alternative instructions framework:
30344 */
30345 - .section .altinstr_replacement, "ax", @progbits
30346 + .section .altinstr_replacement, "a", @progbits
30347 .Lmemcpy_c:
30348 movq %rdi, %rax
30349 movq %rdx, %rcx
30350 @@ -33,6 +33,7 @@
30351 rep movsq
30352 movl %edx, %ecx
30353 rep movsb
30354 + pax_force_retaddr
30355 ret
30356 .Lmemcpy_e:
30357 .previous
30358 @@ -44,11 +45,12 @@
30359 * This gets patched over the unrolled variant (below) via the
30360 * alternative instructions framework:
30361 */
30362 - .section .altinstr_replacement, "ax", @progbits
30363 + .section .altinstr_replacement, "a", @progbits
30364 .Lmemcpy_c_e:
30365 movq %rdi, %rax
30366 movq %rdx, %rcx
30367 rep movsb
30368 + pax_force_retaddr
30369 ret
30370 .Lmemcpy_e_e:
30371 .previous
30372 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30373 movq %r9, 1*8(%rdi)
30374 movq %r10, -2*8(%rdi, %rdx)
30375 movq %r11, -1*8(%rdi, %rdx)
30376 + pax_force_retaddr
30377 retq
30378 .p2align 4
30379 .Lless_16bytes:
30380 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30381 movq -1*8(%rsi, %rdx), %r9
30382 movq %r8, 0*8(%rdi)
30383 movq %r9, -1*8(%rdi, %rdx)
30384 + pax_force_retaddr
30385 retq
30386 .p2align 4
30387 .Lless_8bytes:
30388 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30389 movl -4(%rsi, %rdx), %r8d
30390 movl %ecx, (%rdi)
30391 movl %r8d, -4(%rdi, %rdx)
30392 + pax_force_retaddr
30393 retq
30394 .p2align 4
30395 .Lless_3bytes:
30396 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30397 movb %cl, (%rdi)
30398
30399 .Lend:
30400 + pax_force_retaddr
30401 retq
30402 CFI_ENDPROC
30403 ENDPROC(memcpy)
30404 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30405 index 65268a6..dd1de11 100644
30406 --- a/arch/x86/lib/memmove_64.S
30407 +++ b/arch/x86/lib/memmove_64.S
30408 @@ -202,14 +202,16 @@ ENTRY(memmove)
30409 movb (%rsi), %r11b
30410 movb %r11b, (%rdi)
30411 13:
30412 + pax_force_retaddr
30413 retq
30414 CFI_ENDPROC
30415
30416 - .section .altinstr_replacement,"ax"
30417 + .section .altinstr_replacement,"a"
30418 .Lmemmove_begin_forward_efs:
30419 /* Forward moving data. */
30420 movq %rdx, %rcx
30421 rep movsb
30422 + pax_force_retaddr
30423 retq
30424 .Lmemmove_end_forward_efs:
30425 .previous
30426 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30427 index 2dcb380..2eb79fe 100644
30428 --- a/arch/x86/lib/memset_64.S
30429 +++ b/arch/x86/lib/memset_64.S
30430 @@ -16,7 +16,7 @@
30431 *
30432 * rax original destination
30433 */
30434 - .section .altinstr_replacement, "ax", @progbits
30435 + .section .altinstr_replacement, "a", @progbits
30436 .Lmemset_c:
30437 movq %rdi,%r9
30438 movq %rdx,%rcx
30439 @@ -30,6 +30,7 @@
30440 movl %edx,%ecx
30441 rep stosb
30442 movq %r9,%rax
30443 + pax_force_retaddr
30444 ret
30445 .Lmemset_e:
30446 .previous
30447 @@ -45,13 +46,14 @@
30448 *
30449 * rax original destination
30450 */
30451 - .section .altinstr_replacement, "ax", @progbits
30452 + .section .altinstr_replacement, "a", @progbits
30453 .Lmemset_c_e:
30454 movq %rdi,%r9
30455 movb %sil,%al
30456 movq %rdx,%rcx
30457 rep stosb
30458 movq %r9,%rax
30459 + pax_force_retaddr
30460 ret
30461 .Lmemset_e_e:
30462 .previous
30463 @@ -118,6 +120,7 @@ ENTRY(__memset)
30464
30465 .Lende:
30466 movq %r10,%rax
30467 + pax_force_retaddr
30468 ret
30469
30470 CFI_RESTORE_STATE
30471 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30472 index c9f2d9b..e7fd2c0 100644
30473 --- a/arch/x86/lib/mmx_32.c
30474 +++ b/arch/x86/lib/mmx_32.c
30475 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30476 {
30477 void *p;
30478 int i;
30479 + unsigned long cr0;
30480
30481 if (unlikely(in_interrupt()))
30482 return __memcpy(to, from, len);
30483 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30484 kernel_fpu_begin();
30485
30486 __asm__ __volatile__ (
30487 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30488 - " prefetch 64(%0)\n"
30489 - " prefetch 128(%0)\n"
30490 - " prefetch 192(%0)\n"
30491 - " prefetch 256(%0)\n"
30492 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30493 + " prefetch 64(%1)\n"
30494 + " prefetch 128(%1)\n"
30495 + " prefetch 192(%1)\n"
30496 + " prefetch 256(%1)\n"
30497 "2: \n"
30498 ".section .fixup, \"ax\"\n"
30499 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30500 + "3: \n"
30501 +
30502 +#ifdef CONFIG_PAX_KERNEXEC
30503 + " movl %%cr0, %0\n"
30504 + " movl %0, %%eax\n"
30505 + " andl $0xFFFEFFFF, %%eax\n"
30506 + " movl %%eax, %%cr0\n"
30507 +#endif
30508 +
30509 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30510 +
30511 +#ifdef CONFIG_PAX_KERNEXEC
30512 + " movl %0, %%cr0\n"
30513 +#endif
30514 +
30515 " jmp 2b\n"
30516 ".previous\n"
30517 _ASM_EXTABLE(1b, 3b)
30518 - : : "r" (from));
30519 + : "=&r" (cr0) : "r" (from) : "ax");
30520
30521 for ( ; i > 5; i--) {
30522 __asm__ __volatile__ (
30523 - "1: prefetch 320(%0)\n"
30524 - "2: movq (%0), %%mm0\n"
30525 - " movq 8(%0), %%mm1\n"
30526 - " movq 16(%0), %%mm2\n"
30527 - " movq 24(%0), %%mm3\n"
30528 - " movq %%mm0, (%1)\n"
30529 - " movq %%mm1, 8(%1)\n"
30530 - " movq %%mm2, 16(%1)\n"
30531 - " movq %%mm3, 24(%1)\n"
30532 - " movq 32(%0), %%mm0\n"
30533 - " movq 40(%0), %%mm1\n"
30534 - " movq 48(%0), %%mm2\n"
30535 - " movq 56(%0), %%mm3\n"
30536 - " movq %%mm0, 32(%1)\n"
30537 - " movq %%mm1, 40(%1)\n"
30538 - " movq %%mm2, 48(%1)\n"
30539 - " movq %%mm3, 56(%1)\n"
30540 + "1: prefetch 320(%1)\n"
30541 + "2: movq (%1), %%mm0\n"
30542 + " movq 8(%1), %%mm1\n"
30543 + " movq 16(%1), %%mm2\n"
30544 + " movq 24(%1), %%mm3\n"
30545 + " movq %%mm0, (%2)\n"
30546 + " movq %%mm1, 8(%2)\n"
30547 + " movq %%mm2, 16(%2)\n"
30548 + " movq %%mm3, 24(%2)\n"
30549 + " movq 32(%1), %%mm0\n"
30550 + " movq 40(%1), %%mm1\n"
30551 + " movq 48(%1), %%mm2\n"
30552 + " movq 56(%1), %%mm3\n"
30553 + " movq %%mm0, 32(%2)\n"
30554 + " movq %%mm1, 40(%2)\n"
30555 + " movq %%mm2, 48(%2)\n"
30556 + " movq %%mm3, 56(%2)\n"
30557 ".section .fixup, \"ax\"\n"
30558 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30559 + "3:\n"
30560 +
30561 +#ifdef CONFIG_PAX_KERNEXEC
30562 + " movl %%cr0, %0\n"
30563 + " movl %0, %%eax\n"
30564 + " andl $0xFFFEFFFF, %%eax\n"
30565 + " movl %%eax, %%cr0\n"
30566 +#endif
30567 +
30568 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30569 +
30570 +#ifdef CONFIG_PAX_KERNEXEC
30571 + " movl %0, %%cr0\n"
30572 +#endif
30573 +
30574 " jmp 2b\n"
30575 ".previous\n"
30576 _ASM_EXTABLE(1b, 3b)
30577 - : : "r" (from), "r" (to) : "memory");
30578 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30579
30580 from += 64;
30581 to += 64;
30582 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30583 static void fast_copy_page(void *to, void *from)
30584 {
30585 int i;
30586 + unsigned long cr0;
30587
30588 kernel_fpu_begin();
30589
30590 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30591 * but that is for later. -AV
30592 */
30593 __asm__ __volatile__(
30594 - "1: prefetch (%0)\n"
30595 - " prefetch 64(%0)\n"
30596 - " prefetch 128(%0)\n"
30597 - " prefetch 192(%0)\n"
30598 - " prefetch 256(%0)\n"
30599 + "1: prefetch (%1)\n"
30600 + " prefetch 64(%1)\n"
30601 + " prefetch 128(%1)\n"
30602 + " prefetch 192(%1)\n"
30603 + " prefetch 256(%1)\n"
30604 "2: \n"
30605 ".section .fixup, \"ax\"\n"
30606 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30607 + "3: \n"
30608 +
30609 +#ifdef CONFIG_PAX_KERNEXEC
30610 + " movl %%cr0, %0\n"
30611 + " movl %0, %%eax\n"
30612 + " andl $0xFFFEFFFF, %%eax\n"
30613 + " movl %%eax, %%cr0\n"
30614 +#endif
30615 +
30616 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30617 +
30618 +#ifdef CONFIG_PAX_KERNEXEC
30619 + " movl %0, %%cr0\n"
30620 +#endif
30621 +
30622 " jmp 2b\n"
30623 ".previous\n"
30624 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30625 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30626
30627 for (i = 0; i < (4096-320)/64; i++) {
30628 __asm__ __volatile__ (
30629 - "1: prefetch 320(%0)\n"
30630 - "2: movq (%0), %%mm0\n"
30631 - " movntq %%mm0, (%1)\n"
30632 - " movq 8(%0), %%mm1\n"
30633 - " movntq %%mm1, 8(%1)\n"
30634 - " movq 16(%0), %%mm2\n"
30635 - " movntq %%mm2, 16(%1)\n"
30636 - " movq 24(%0), %%mm3\n"
30637 - " movntq %%mm3, 24(%1)\n"
30638 - " movq 32(%0), %%mm4\n"
30639 - " movntq %%mm4, 32(%1)\n"
30640 - " movq 40(%0), %%mm5\n"
30641 - " movntq %%mm5, 40(%1)\n"
30642 - " movq 48(%0), %%mm6\n"
30643 - " movntq %%mm6, 48(%1)\n"
30644 - " movq 56(%0), %%mm7\n"
30645 - " movntq %%mm7, 56(%1)\n"
30646 + "1: prefetch 320(%1)\n"
30647 + "2: movq (%1), %%mm0\n"
30648 + " movntq %%mm0, (%2)\n"
30649 + " movq 8(%1), %%mm1\n"
30650 + " movntq %%mm1, 8(%2)\n"
30651 + " movq 16(%1), %%mm2\n"
30652 + " movntq %%mm2, 16(%2)\n"
30653 + " movq 24(%1), %%mm3\n"
30654 + " movntq %%mm3, 24(%2)\n"
30655 + " movq 32(%1), %%mm4\n"
30656 + " movntq %%mm4, 32(%2)\n"
30657 + " movq 40(%1), %%mm5\n"
30658 + " movntq %%mm5, 40(%2)\n"
30659 + " movq 48(%1), %%mm6\n"
30660 + " movntq %%mm6, 48(%2)\n"
30661 + " movq 56(%1), %%mm7\n"
30662 + " movntq %%mm7, 56(%2)\n"
30663 ".section .fixup, \"ax\"\n"
30664 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30665 + "3:\n"
30666 +
30667 +#ifdef CONFIG_PAX_KERNEXEC
30668 + " movl %%cr0, %0\n"
30669 + " movl %0, %%eax\n"
30670 + " andl $0xFFFEFFFF, %%eax\n"
30671 + " movl %%eax, %%cr0\n"
30672 +#endif
30673 +
30674 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30675 +
30676 +#ifdef CONFIG_PAX_KERNEXEC
30677 + " movl %0, %%cr0\n"
30678 +#endif
30679 +
30680 " jmp 2b\n"
30681 ".previous\n"
30682 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30683 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30684
30685 from += 64;
30686 to += 64;
30687 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30688 static void fast_copy_page(void *to, void *from)
30689 {
30690 int i;
30691 + unsigned long cr0;
30692
30693 kernel_fpu_begin();
30694
30695 __asm__ __volatile__ (
30696 - "1: prefetch (%0)\n"
30697 - " prefetch 64(%0)\n"
30698 - " prefetch 128(%0)\n"
30699 - " prefetch 192(%0)\n"
30700 - " prefetch 256(%0)\n"
30701 + "1: prefetch (%1)\n"
30702 + " prefetch 64(%1)\n"
30703 + " prefetch 128(%1)\n"
30704 + " prefetch 192(%1)\n"
30705 + " prefetch 256(%1)\n"
30706 "2: \n"
30707 ".section .fixup, \"ax\"\n"
30708 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30709 + "3: \n"
30710 +
30711 +#ifdef CONFIG_PAX_KERNEXEC
30712 + " movl %%cr0, %0\n"
30713 + " movl %0, %%eax\n"
30714 + " andl $0xFFFEFFFF, %%eax\n"
30715 + " movl %%eax, %%cr0\n"
30716 +#endif
30717 +
30718 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30719 +
30720 +#ifdef CONFIG_PAX_KERNEXEC
30721 + " movl %0, %%cr0\n"
30722 +#endif
30723 +
30724 " jmp 2b\n"
30725 ".previous\n"
30726 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30727 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30728
30729 for (i = 0; i < 4096/64; i++) {
30730 __asm__ __volatile__ (
30731 - "1: prefetch 320(%0)\n"
30732 - "2: movq (%0), %%mm0\n"
30733 - " movq 8(%0), %%mm1\n"
30734 - " movq 16(%0), %%mm2\n"
30735 - " movq 24(%0), %%mm3\n"
30736 - " movq %%mm0, (%1)\n"
30737 - " movq %%mm1, 8(%1)\n"
30738 - " movq %%mm2, 16(%1)\n"
30739 - " movq %%mm3, 24(%1)\n"
30740 - " movq 32(%0), %%mm0\n"
30741 - " movq 40(%0), %%mm1\n"
30742 - " movq 48(%0), %%mm2\n"
30743 - " movq 56(%0), %%mm3\n"
30744 - " movq %%mm0, 32(%1)\n"
30745 - " movq %%mm1, 40(%1)\n"
30746 - " movq %%mm2, 48(%1)\n"
30747 - " movq %%mm3, 56(%1)\n"
30748 + "1: prefetch 320(%1)\n"
30749 + "2: movq (%1), %%mm0\n"
30750 + " movq 8(%1), %%mm1\n"
30751 + " movq 16(%1), %%mm2\n"
30752 + " movq 24(%1), %%mm3\n"
30753 + " movq %%mm0, (%2)\n"
30754 + " movq %%mm1, 8(%2)\n"
30755 + " movq %%mm2, 16(%2)\n"
30756 + " movq %%mm3, 24(%2)\n"
30757 + " movq 32(%1), %%mm0\n"
30758 + " movq 40(%1), %%mm1\n"
30759 + " movq 48(%1), %%mm2\n"
30760 + " movq 56(%1), %%mm3\n"
30761 + " movq %%mm0, 32(%2)\n"
30762 + " movq %%mm1, 40(%2)\n"
30763 + " movq %%mm2, 48(%2)\n"
30764 + " movq %%mm3, 56(%2)\n"
30765 ".section .fixup, \"ax\"\n"
30766 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30767 + "3:\n"
30768 +
30769 +#ifdef CONFIG_PAX_KERNEXEC
30770 + " movl %%cr0, %0\n"
30771 + " movl %0, %%eax\n"
30772 + " andl $0xFFFEFFFF, %%eax\n"
30773 + " movl %%eax, %%cr0\n"
30774 +#endif
30775 +
30776 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30777 +
30778 +#ifdef CONFIG_PAX_KERNEXEC
30779 + " movl %0, %%cr0\n"
30780 +#endif
30781 +
30782 " jmp 2b\n"
30783 ".previous\n"
30784 _ASM_EXTABLE(1b, 3b)
30785 - : : "r" (from), "r" (to) : "memory");
30786 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30787
30788 from += 64;
30789 to += 64;
30790 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30791 index f6d13ee..d789440 100644
30792 --- a/arch/x86/lib/msr-reg.S
30793 +++ b/arch/x86/lib/msr-reg.S
30794 @@ -3,6 +3,7 @@
30795 #include <asm/dwarf2.h>
30796 #include <asm/asm.h>
30797 #include <asm/msr.h>
30798 +#include <asm/alternative-asm.h>
30799
30800 #ifdef CONFIG_X86_64
30801 /*
30802 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30803 movl %edi, 28(%r10)
30804 popq_cfi %rbp
30805 popq_cfi %rbx
30806 + pax_force_retaddr
30807 ret
30808 3:
30809 CFI_RESTORE_STATE
30810 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30811 index fc6ba17..d4d989d 100644
30812 --- a/arch/x86/lib/putuser.S
30813 +++ b/arch/x86/lib/putuser.S
30814 @@ -16,7 +16,9 @@
30815 #include <asm/errno.h>
30816 #include <asm/asm.h>
30817 #include <asm/smap.h>
30818 -
30819 +#include <asm/segment.h>
30820 +#include <asm/pgtable.h>
30821 +#include <asm/alternative-asm.h>
30822
30823 /*
30824 * __put_user_X
30825 @@ -30,57 +32,125 @@
30826 * as they get called from within inline assembly.
30827 */
30828
30829 -#define ENTER CFI_STARTPROC ; \
30830 - GET_THREAD_INFO(%_ASM_BX)
30831 -#define EXIT ASM_CLAC ; \
30832 - ret ; \
30833 +#define ENTER CFI_STARTPROC
30834 +#define EXIT ASM_CLAC ; \
30835 + pax_force_retaddr ; \
30836 + ret ; \
30837 CFI_ENDPROC
30838
30839 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30840 +#define _DEST %_ASM_CX,%_ASM_BX
30841 +#else
30842 +#define _DEST %_ASM_CX
30843 +#endif
30844 +
30845 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30846 +#define __copyuser_seg gs;
30847 +#else
30848 +#define __copyuser_seg
30849 +#endif
30850 +
30851 .text
30852 ENTRY(__put_user_1)
30853 ENTER
30854 +
30855 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30856 + GET_THREAD_INFO(%_ASM_BX)
30857 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30858 jae bad_put_user
30859 ASM_STAC
30860 -1: movb %al,(%_ASM_CX)
30861 +
30862 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30863 + mov pax_user_shadow_base,%_ASM_BX
30864 + cmp %_ASM_BX,%_ASM_CX
30865 + jb 1234f
30866 + xor %ebx,%ebx
30867 +1234:
30868 +#endif
30869 +
30870 +#endif
30871 +
30872 +1: __copyuser_seg movb %al,(_DEST)
30873 xor %eax,%eax
30874 EXIT
30875 ENDPROC(__put_user_1)
30876
30877 ENTRY(__put_user_2)
30878 ENTER
30879 +
30880 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30881 + GET_THREAD_INFO(%_ASM_BX)
30882 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30883 sub $1,%_ASM_BX
30884 cmp %_ASM_BX,%_ASM_CX
30885 jae bad_put_user
30886 ASM_STAC
30887 -2: movw %ax,(%_ASM_CX)
30888 +
30889 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30890 + mov pax_user_shadow_base,%_ASM_BX
30891 + cmp %_ASM_BX,%_ASM_CX
30892 + jb 1234f
30893 + xor %ebx,%ebx
30894 +1234:
30895 +#endif
30896 +
30897 +#endif
30898 +
30899 +2: __copyuser_seg movw %ax,(_DEST)
30900 xor %eax,%eax
30901 EXIT
30902 ENDPROC(__put_user_2)
30903
30904 ENTRY(__put_user_4)
30905 ENTER
30906 +
30907 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30908 + GET_THREAD_INFO(%_ASM_BX)
30909 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30910 sub $3,%_ASM_BX
30911 cmp %_ASM_BX,%_ASM_CX
30912 jae bad_put_user
30913 ASM_STAC
30914 -3: movl %eax,(%_ASM_CX)
30915 +
30916 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30917 + mov pax_user_shadow_base,%_ASM_BX
30918 + cmp %_ASM_BX,%_ASM_CX
30919 + jb 1234f
30920 + xor %ebx,%ebx
30921 +1234:
30922 +#endif
30923 +
30924 +#endif
30925 +
30926 +3: __copyuser_seg movl %eax,(_DEST)
30927 xor %eax,%eax
30928 EXIT
30929 ENDPROC(__put_user_4)
30930
30931 ENTRY(__put_user_8)
30932 ENTER
30933 +
30934 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30935 + GET_THREAD_INFO(%_ASM_BX)
30936 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30937 sub $7,%_ASM_BX
30938 cmp %_ASM_BX,%_ASM_CX
30939 jae bad_put_user
30940 ASM_STAC
30941 -4: mov %_ASM_AX,(%_ASM_CX)
30942 +
30943 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30944 + mov pax_user_shadow_base,%_ASM_BX
30945 + cmp %_ASM_BX,%_ASM_CX
30946 + jb 1234f
30947 + xor %ebx,%ebx
30948 +1234:
30949 +#endif
30950 +
30951 +#endif
30952 +
30953 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30954 #ifdef CONFIG_X86_32
30955 -5: movl %edx,4(%_ASM_CX)
30956 +5: __copyuser_seg movl %edx,4(_DEST)
30957 #endif
30958 xor %eax,%eax
30959 EXIT
30960 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30961 index 5dff5f0..cadebf4 100644
30962 --- a/arch/x86/lib/rwsem.S
30963 +++ b/arch/x86/lib/rwsem.S
30964 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30965 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30966 CFI_RESTORE __ASM_REG(dx)
30967 restore_common_regs
30968 + pax_force_retaddr
30969 ret
30970 CFI_ENDPROC
30971 ENDPROC(call_rwsem_down_read_failed)
30972 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30973 movq %rax,%rdi
30974 call rwsem_down_write_failed
30975 restore_common_regs
30976 + pax_force_retaddr
30977 ret
30978 CFI_ENDPROC
30979 ENDPROC(call_rwsem_down_write_failed)
30980 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30981 movq %rax,%rdi
30982 call rwsem_wake
30983 restore_common_regs
30984 -1: ret
30985 +1: pax_force_retaddr
30986 + ret
30987 CFI_ENDPROC
30988 ENDPROC(call_rwsem_wake)
30989
30990 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30991 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30992 CFI_RESTORE __ASM_REG(dx)
30993 restore_common_regs
30994 + pax_force_retaddr
30995 ret
30996 CFI_ENDPROC
30997 ENDPROC(call_rwsem_downgrade_wake)
30998 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30999 index b30b5eb..2b57052 100644
31000 --- a/arch/x86/lib/thunk_64.S
31001 +++ b/arch/x86/lib/thunk_64.S
31002 @@ -9,6 +9,7 @@
31003 #include <asm/dwarf2.h>
31004 #include <asm/calling.h>
31005 #include <asm/asm.h>
31006 +#include <asm/alternative-asm.h>
31007
31008 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31009 .macro THUNK name, func, put_ret_addr_in_rdi=0
31010 @@ -16,11 +17,11 @@
31011 \name:
31012 CFI_STARTPROC
31013
31014 - /* this one pushes 9 elems, the next one would be %rIP */
31015 - SAVE_ARGS
31016 + /* this one pushes 15+1 elems, the next one would be %rIP */
31017 + SAVE_ARGS 8
31018
31019 .if \put_ret_addr_in_rdi
31020 - movq_cfi_restore 9*8, rdi
31021 + movq_cfi_restore RIP, rdi
31022 .endif
31023
31024 call \func
31025 @@ -47,9 +48,10 @@
31026
31027 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31028 CFI_STARTPROC
31029 - SAVE_ARGS
31030 + SAVE_ARGS 8
31031 restore:
31032 - RESTORE_ARGS
31033 + RESTORE_ARGS 1,8
31034 + pax_force_retaddr
31035 ret
31036 CFI_ENDPROC
31037 _ASM_NOKPROBE(restore)
31038 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31039 index e2f5e21..4b22130 100644
31040 --- a/arch/x86/lib/usercopy_32.c
31041 +++ b/arch/x86/lib/usercopy_32.c
31042 @@ -42,11 +42,13 @@ do { \
31043 int __d0; \
31044 might_fault(); \
31045 __asm__ __volatile__( \
31046 + __COPYUSER_SET_ES \
31047 ASM_STAC "\n" \
31048 "0: rep; stosl\n" \
31049 " movl %2,%0\n" \
31050 "1: rep; stosb\n" \
31051 "2: " ASM_CLAC "\n" \
31052 + __COPYUSER_RESTORE_ES \
31053 ".section .fixup,\"ax\"\n" \
31054 "3: lea 0(%2,%0,4),%0\n" \
31055 " jmp 2b\n" \
31056 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31057
31058 #ifdef CONFIG_X86_INTEL_USERCOPY
31059 static unsigned long
31060 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31061 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31062 {
31063 int d0, d1;
31064 __asm__ __volatile__(
31065 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31066 " .align 2,0x90\n"
31067 "3: movl 0(%4), %%eax\n"
31068 "4: movl 4(%4), %%edx\n"
31069 - "5: movl %%eax, 0(%3)\n"
31070 - "6: movl %%edx, 4(%3)\n"
31071 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31072 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31073 "7: movl 8(%4), %%eax\n"
31074 "8: movl 12(%4),%%edx\n"
31075 - "9: movl %%eax, 8(%3)\n"
31076 - "10: movl %%edx, 12(%3)\n"
31077 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31078 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31079 "11: movl 16(%4), %%eax\n"
31080 "12: movl 20(%4), %%edx\n"
31081 - "13: movl %%eax, 16(%3)\n"
31082 - "14: movl %%edx, 20(%3)\n"
31083 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31084 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31085 "15: movl 24(%4), %%eax\n"
31086 "16: movl 28(%4), %%edx\n"
31087 - "17: movl %%eax, 24(%3)\n"
31088 - "18: movl %%edx, 28(%3)\n"
31089 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31090 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31091 "19: movl 32(%4), %%eax\n"
31092 "20: movl 36(%4), %%edx\n"
31093 - "21: movl %%eax, 32(%3)\n"
31094 - "22: movl %%edx, 36(%3)\n"
31095 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31096 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31097 "23: movl 40(%4), %%eax\n"
31098 "24: movl 44(%4), %%edx\n"
31099 - "25: movl %%eax, 40(%3)\n"
31100 - "26: movl %%edx, 44(%3)\n"
31101 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31102 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31103 "27: movl 48(%4), %%eax\n"
31104 "28: movl 52(%4), %%edx\n"
31105 - "29: movl %%eax, 48(%3)\n"
31106 - "30: movl %%edx, 52(%3)\n"
31107 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31108 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31109 "31: movl 56(%4), %%eax\n"
31110 "32: movl 60(%4), %%edx\n"
31111 - "33: movl %%eax, 56(%3)\n"
31112 - "34: movl %%edx, 60(%3)\n"
31113 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31114 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31115 " addl $-64, %0\n"
31116 " addl $64, %4\n"
31117 " addl $64, %3\n"
31118 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31119 " shrl $2, %0\n"
31120 " andl $3, %%eax\n"
31121 " cld\n"
31122 + __COPYUSER_SET_ES
31123 "99: rep; movsl\n"
31124 "36: movl %%eax, %0\n"
31125 "37: rep; movsb\n"
31126 "100:\n"
31127 + __COPYUSER_RESTORE_ES
31128 + ".section .fixup,\"ax\"\n"
31129 + "101: lea 0(%%eax,%0,4),%0\n"
31130 + " jmp 100b\n"
31131 + ".previous\n"
31132 + _ASM_EXTABLE(1b,100b)
31133 + _ASM_EXTABLE(2b,100b)
31134 + _ASM_EXTABLE(3b,100b)
31135 + _ASM_EXTABLE(4b,100b)
31136 + _ASM_EXTABLE(5b,100b)
31137 + _ASM_EXTABLE(6b,100b)
31138 + _ASM_EXTABLE(7b,100b)
31139 + _ASM_EXTABLE(8b,100b)
31140 + _ASM_EXTABLE(9b,100b)
31141 + _ASM_EXTABLE(10b,100b)
31142 + _ASM_EXTABLE(11b,100b)
31143 + _ASM_EXTABLE(12b,100b)
31144 + _ASM_EXTABLE(13b,100b)
31145 + _ASM_EXTABLE(14b,100b)
31146 + _ASM_EXTABLE(15b,100b)
31147 + _ASM_EXTABLE(16b,100b)
31148 + _ASM_EXTABLE(17b,100b)
31149 + _ASM_EXTABLE(18b,100b)
31150 + _ASM_EXTABLE(19b,100b)
31151 + _ASM_EXTABLE(20b,100b)
31152 + _ASM_EXTABLE(21b,100b)
31153 + _ASM_EXTABLE(22b,100b)
31154 + _ASM_EXTABLE(23b,100b)
31155 + _ASM_EXTABLE(24b,100b)
31156 + _ASM_EXTABLE(25b,100b)
31157 + _ASM_EXTABLE(26b,100b)
31158 + _ASM_EXTABLE(27b,100b)
31159 + _ASM_EXTABLE(28b,100b)
31160 + _ASM_EXTABLE(29b,100b)
31161 + _ASM_EXTABLE(30b,100b)
31162 + _ASM_EXTABLE(31b,100b)
31163 + _ASM_EXTABLE(32b,100b)
31164 + _ASM_EXTABLE(33b,100b)
31165 + _ASM_EXTABLE(34b,100b)
31166 + _ASM_EXTABLE(35b,100b)
31167 + _ASM_EXTABLE(36b,100b)
31168 + _ASM_EXTABLE(37b,100b)
31169 + _ASM_EXTABLE(99b,101b)
31170 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31171 + : "1"(to), "2"(from), "0"(size)
31172 + : "eax", "edx", "memory");
31173 + return size;
31174 +}
31175 +
31176 +static unsigned long
31177 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31178 +{
31179 + int d0, d1;
31180 + __asm__ __volatile__(
31181 + " .align 2,0x90\n"
31182 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31183 + " cmpl $67, %0\n"
31184 + " jbe 3f\n"
31185 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31186 + " .align 2,0x90\n"
31187 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31188 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31189 + "5: movl %%eax, 0(%3)\n"
31190 + "6: movl %%edx, 4(%3)\n"
31191 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31192 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31193 + "9: movl %%eax, 8(%3)\n"
31194 + "10: movl %%edx, 12(%3)\n"
31195 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31196 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31197 + "13: movl %%eax, 16(%3)\n"
31198 + "14: movl %%edx, 20(%3)\n"
31199 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31200 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31201 + "17: movl %%eax, 24(%3)\n"
31202 + "18: movl %%edx, 28(%3)\n"
31203 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31204 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31205 + "21: movl %%eax, 32(%3)\n"
31206 + "22: movl %%edx, 36(%3)\n"
31207 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31208 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31209 + "25: movl %%eax, 40(%3)\n"
31210 + "26: movl %%edx, 44(%3)\n"
31211 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31212 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31213 + "29: movl %%eax, 48(%3)\n"
31214 + "30: movl %%edx, 52(%3)\n"
31215 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31216 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31217 + "33: movl %%eax, 56(%3)\n"
31218 + "34: movl %%edx, 60(%3)\n"
31219 + " addl $-64, %0\n"
31220 + " addl $64, %4\n"
31221 + " addl $64, %3\n"
31222 + " cmpl $63, %0\n"
31223 + " ja 1b\n"
31224 + "35: movl %0, %%eax\n"
31225 + " shrl $2, %0\n"
31226 + " andl $3, %%eax\n"
31227 + " cld\n"
31228 + "99: rep; "__copyuser_seg" movsl\n"
31229 + "36: movl %%eax, %0\n"
31230 + "37: rep; "__copyuser_seg" movsb\n"
31231 + "100:\n"
31232 ".section .fixup,\"ax\"\n"
31233 "101: lea 0(%%eax,%0,4),%0\n"
31234 " jmp 100b\n"
31235 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31236 int d0, d1;
31237 __asm__ __volatile__(
31238 " .align 2,0x90\n"
31239 - "0: movl 32(%4), %%eax\n"
31240 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31241 " cmpl $67, %0\n"
31242 " jbe 2f\n"
31243 - "1: movl 64(%4), %%eax\n"
31244 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31245 " .align 2,0x90\n"
31246 - "2: movl 0(%4), %%eax\n"
31247 - "21: movl 4(%4), %%edx\n"
31248 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31249 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31250 " movl %%eax, 0(%3)\n"
31251 " movl %%edx, 4(%3)\n"
31252 - "3: movl 8(%4), %%eax\n"
31253 - "31: movl 12(%4),%%edx\n"
31254 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31255 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31256 " movl %%eax, 8(%3)\n"
31257 " movl %%edx, 12(%3)\n"
31258 - "4: movl 16(%4), %%eax\n"
31259 - "41: movl 20(%4), %%edx\n"
31260 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31261 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31262 " movl %%eax, 16(%3)\n"
31263 " movl %%edx, 20(%3)\n"
31264 - "10: movl 24(%4), %%eax\n"
31265 - "51: movl 28(%4), %%edx\n"
31266 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31267 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31268 " movl %%eax, 24(%3)\n"
31269 " movl %%edx, 28(%3)\n"
31270 - "11: movl 32(%4), %%eax\n"
31271 - "61: movl 36(%4), %%edx\n"
31272 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31273 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31274 " movl %%eax, 32(%3)\n"
31275 " movl %%edx, 36(%3)\n"
31276 - "12: movl 40(%4), %%eax\n"
31277 - "71: movl 44(%4), %%edx\n"
31278 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31279 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31280 " movl %%eax, 40(%3)\n"
31281 " movl %%edx, 44(%3)\n"
31282 - "13: movl 48(%4), %%eax\n"
31283 - "81: movl 52(%4), %%edx\n"
31284 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31285 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31286 " movl %%eax, 48(%3)\n"
31287 " movl %%edx, 52(%3)\n"
31288 - "14: movl 56(%4), %%eax\n"
31289 - "91: movl 60(%4), %%edx\n"
31290 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31291 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31292 " movl %%eax, 56(%3)\n"
31293 " movl %%edx, 60(%3)\n"
31294 " addl $-64, %0\n"
31295 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31296 " shrl $2, %0\n"
31297 " andl $3, %%eax\n"
31298 " cld\n"
31299 - "6: rep; movsl\n"
31300 + "6: rep; "__copyuser_seg" movsl\n"
31301 " movl %%eax,%0\n"
31302 - "7: rep; movsb\n"
31303 + "7: rep; "__copyuser_seg" movsb\n"
31304 "8:\n"
31305 ".section .fixup,\"ax\"\n"
31306 "9: lea 0(%%eax,%0,4),%0\n"
31307 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31308
31309 __asm__ __volatile__(
31310 " .align 2,0x90\n"
31311 - "0: movl 32(%4), %%eax\n"
31312 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31313 " cmpl $67, %0\n"
31314 " jbe 2f\n"
31315 - "1: movl 64(%4), %%eax\n"
31316 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31317 " .align 2,0x90\n"
31318 - "2: movl 0(%4), %%eax\n"
31319 - "21: movl 4(%4), %%edx\n"
31320 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31321 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31322 " movnti %%eax, 0(%3)\n"
31323 " movnti %%edx, 4(%3)\n"
31324 - "3: movl 8(%4), %%eax\n"
31325 - "31: movl 12(%4),%%edx\n"
31326 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31327 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31328 " movnti %%eax, 8(%3)\n"
31329 " movnti %%edx, 12(%3)\n"
31330 - "4: movl 16(%4), %%eax\n"
31331 - "41: movl 20(%4), %%edx\n"
31332 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31333 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31334 " movnti %%eax, 16(%3)\n"
31335 " movnti %%edx, 20(%3)\n"
31336 - "10: movl 24(%4), %%eax\n"
31337 - "51: movl 28(%4), %%edx\n"
31338 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31339 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31340 " movnti %%eax, 24(%3)\n"
31341 " movnti %%edx, 28(%3)\n"
31342 - "11: movl 32(%4), %%eax\n"
31343 - "61: movl 36(%4), %%edx\n"
31344 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31345 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31346 " movnti %%eax, 32(%3)\n"
31347 " movnti %%edx, 36(%3)\n"
31348 - "12: movl 40(%4), %%eax\n"
31349 - "71: movl 44(%4), %%edx\n"
31350 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31351 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31352 " movnti %%eax, 40(%3)\n"
31353 " movnti %%edx, 44(%3)\n"
31354 - "13: movl 48(%4), %%eax\n"
31355 - "81: movl 52(%4), %%edx\n"
31356 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31357 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31358 " movnti %%eax, 48(%3)\n"
31359 " movnti %%edx, 52(%3)\n"
31360 - "14: movl 56(%4), %%eax\n"
31361 - "91: movl 60(%4), %%edx\n"
31362 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31363 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31364 " movnti %%eax, 56(%3)\n"
31365 " movnti %%edx, 60(%3)\n"
31366 " addl $-64, %0\n"
31367 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31368 " shrl $2, %0\n"
31369 " andl $3, %%eax\n"
31370 " cld\n"
31371 - "6: rep; movsl\n"
31372 + "6: rep; "__copyuser_seg" movsl\n"
31373 " movl %%eax,%0\n"
31374 - "7: rep; movsb\n"
31375 + "7: rep; "__copyuser_seg" movsb\n"
31376 "8:\n"
31377 ".section .fixup,\"ax\"\n"
31378 "9: lea 0(%%eax,%0,4),%0\n"
31379 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31380
31381 __asm__ __volatile__(
31382 " .align 2,0x90\n"
31383 - "0: movl 32(%4), %%eax\n"
31384 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31385 " cmpl $67, %0\n"
31386 " jbe 2f\n"
31387 - "1: movl 64(%4), %%eax\n"
31388 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31389 " .align 2,0x90\n"
31390 - "2: movl 0(%4), %%eax\n"
31391 - "21: movl 4(%4), %%edx\n"
31392 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31393 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31394 " movnti %%eax, 0(%3)\n"
31395 " movnti %%edx, 4(%3)\n"
31396 - "3: movl 8(%4), %%eax\n"
31397 - "31: movl 12(%4),%%edx\n"
31398 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31399 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31400 " movnti %%eax, 8(%3)\n"
31401 " movnti %%edx, 12(%3)\n"
31402 - "4: movl 16(%4), %%eax\n"
31403 - "41: movl 20(%4), %%edx\n"
31404 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31405 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31406 " movnti %%eax, 16(%3)\n"
31407 " movnti %%edx, 20(%3)\n"
31408 - "10: movl 24(%4), %%eax\n"
31409 - "51: movl 28(%4), %%edx\n"
31410 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31411 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31412 " movnti %%eax, 24(%3)\n"
31413 " movnti %%edx, 28(%3)\n"
31414 - "11: movl 32(%4), %%eax\n"
31415 - "61: movl 36(%4), %%edx\n"
31416 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31417 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31418 " movnti %%eax, 32(%3)\n"
31419 " movnti %%edx, 36(%3)\n"
31420 - "12: movl 40(%4), %%eax\n"
31421 - "71: movl 44(%4), %%edx\n"
31422 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31423 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31424 " movnti %%eax, 40(%3)\n"
31425 " movnti %%edx, 44(%3)\n"
31426 - "13: movl 48(%4), %%eax\n"
31427 - "81: movl 52(%4), %%edx\n"
31428 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31429 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31430 " movnti %%eax, 48(%3)\n"
31431 " movnti %%edx, 52(%3)\n"
31432 - "14: movl 56(%4), %%eax\n"
31433 - "91: movl 60(%4), %%edx\n"
31434 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31435 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31436 " movnti %%eax, 56(%3)\n"
31437 " movnti %%edx, 60(%3)\n"
31438 " addl $-64, %0\n"
31439 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31440 " shrl $2, %0\n"
31441 " andl $3, %%eax\n"
31442 " cld\n"
31443 - "6: rep; movsl\n"
31444 + "6: rep; "__copyuser_seg" movsl\n"
31445 " movl %%eax,%0\n"
31446 - "7: rep; movsb\n"
31447 + "7: rep; "__copyuser_seg" movsb\n"
31448 "8:\n"
31449 ".section .fixup,\"ax\"\n"
31450 "9: lea 0(%%eax,%0,4),%0\n"
31451 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31452 */
31453 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31454 unsigned long size);
31455 -unsigned long __copy_user_intel(void __user *to, const void *from,
31456 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31457 + unsigned long size);
31458 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31459 unsigned long size);
31460 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31461 const void __user *from, unsigned long size);
31462 #endif /* CONFIG_X86_INTEL_USERCOPY */
31463
31464 /* Generic arbitrary sized copy. */
31465 -#define __copy_user(to, from, size) \
31466 +#define __copy_user(to, from, size, prefix, set, restore) \
31467 do { \
31468 int __d0, __d1, __d2; \
31469 __asm__ __volatile__( \
31470 + set \
31471 " cmp $7,%0\n" \
31472 " jbe 1f\n" \
31473 " movl %1,%0\n" \
31474 " negl %0\n" \
31475 " andl $7,%0\n" \
31476 " subl %0,%3\n" \
31477 - "4: rep; movsb\n" \
31478 + "4: rep; "prefix"movsb\n" \
31479 " movl %3,%0\n" \
31480 " shrl $2,%0\n" \
31481 " andl $3,%3\n" \
31482 " .align 2,0x90\n" \
31483 - "0: rep; movsl\n" \
31484 + "0: rep; "prefix"movsl\n" \
31485 " movl %3,%0\n" \
31486 - "1: rep; movsb\n" \
31487 + "1: rep; "prefix"movsb\n" \
31488 "2:\n" \
31489 + restore \
31490 ".section .fixup,\"ax\"\n" \
31491 "5: addl %3,%0\n" \
31492 " jmp 2b\n" \
31493 @@ -538,14 +650,14 @@ do { \
31494 " negl %0\n" \
31495 " andl $7,%0\n" \
31496 " subl %0,%3\n" \
31497 - "4: rep; movsb\n" \
31498 + "4: rep; "__copyuser_seg"movsb\n" \
31499 " movl %3,%0\n" \
31500 " shrl $2,%0\n" \
31501 " andl $3,%3\n" \
31502 " .align 2,0x90\n" \
31503 - "0: rep; movsl\n" \
31504 + "0: rep; "__copyuser_seg"movsl\n" \
31505 " movl %3,%0\n" \
31506 - "1: rep; movsb\n" \
31507 + "1: rep; "__copyuser_seg"movsb\n" \
31508 "2:\n" \
31509 ".section .fixup,\"ax\"\n" \
31510 "5: addl %3,%0\n" \
31511 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31512 {
31513 stac();
31514 if (movsl_is_ok(to, from, n))
31515 - __copy_user(to, from, n);
31516 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31517 else
31518 - n = __copy_user_intel(to, from, n);
31519 + n = __generic_copy_to_user_intel(to, from, n);
31520 clac();
31521 return n;
31522 }
31523 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31524 {
31525 stac();
31526 if (movsl_is_ok(to, from, n))
31527 - __copy_user(to, from, n);
31528 + __copy_user(to, from, n, __copyuser_seg, "", "");
31529 else
31530 - n = __copy_user_intel((void __user *)to,
31531 - (const void *)from, n);
31532 + n = __generic_copy_from_user_intel(to, from, n);
31533 clac();
31534 return n;
31535 }
31536 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31537 if (n > 64 && cpu_has_xmm2)
31538 n = __copy_user_intel_nocache(to, from, n);
31539 else
31540 - __copy_user(to, from, n);
31541 + __copy_user(to, from, n, __copyuser_seg, "", "");
31542 #else
31543 - __copy_user(to, from, n);
31544 + __copy_user(to, from, n, __copyuser_seg, "", "");
31545 #endif
31546 clac();
31547 return n;
31548 }
31549 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31550
31551 -/**
31552 - * copy_to_user: - Copy a block of data into user space.
31553 - * @to: Destination address, in user space.
31554 - * @from: Source address, in kernel space.
31555 - * @n: Number of bytes to copy.
31556 - *
31557 - * Context: User context only. This function may sleep.
31558 - *
31559 - * Copy data from kernel space to user space.
31560 - *
31561 - * Returns number of bytes that could not be copied.
31562 - * On success, this will be zero.
31563 - */
31564 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31566 +void __set_fs(mm_segment_t x)
31567 {
31568 - if (access_ok(VERIFY_WRITE, to, n))
31569 - n = __copy_to_user(to, from, n);
31570 - return n;
31571 + switch (x.seg) {
31572 + case 0:
31573 + loadsegment(gs, 0);
31574 + break;
31575 + case TASK_SIZE_MAX:
31576 + loadsegment(gs, __USER_DS);
31577 + break;
31578 + case -1UL:
31579 + loadsegment(gs, __KERNEL_DS);
31580 + break;
31581 + default:
31582 + BUG();
31583 + }
31584 }
31585 -EXPORT_SYMBOL(_copy_to_user);
31586 +EXPORT_SYMBOL(__set_fs);
31587
31588 -/**
31589 - * copy_from_user: - Copy a block of data from user space.
31590 - * @to: Destination address, in kernel space.
31591 - * @from: Source address, in user space.
31592 - * @n: Number of bytes to copy.
31593 - *
31594 - * Context: User context only. This function may sleep.
31595 - *
31596 - * Copy data from user space to kernel space.
31597 - *
31598 - * Returns number of bytes that could not be copied.
31599 - * On success, this will be zero.
31600 - *
31601 - * If some data could not be copied, this function will pad the copied
31602 - * data to the requested size using zero bytes.
31603 - */
31604 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31605 +void set_fs(mm_segment_t x)
31606 {
31607 - if (access_ok(VERIFY_READ, from, n))
31608 - n = __copy_from_user(to, from, n);
31609 - else
31610 - memset(to, 0, n);
31611 - return n;
31612 + current_thread_info()->addr_limit = x;
31613 + __set_fs(x);
31614 }
31615 -EXPORT_SYMBOL(_copy_from_user);
31616 +EXPORT_SYMBOL(set_fs);
31617 +#endif
31618 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31619 index c905e89..01ab928 100644
31620 --- a/arch/x86/lib/usercopy_64.c
31621 +++ b/arch/x86/lib/usercopy_64.c
31622 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31623 might_fault();
31624 /* no memory constraint because it doesn't change any memory gcc knows
31625 about */
31626 + pax_open_userland();
31627 stac();
31628 asm volatile(
31629 " testq %[size8],%[size8]\n"
31630 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31631 _ASM_EXTABLE(0b,3b)
31632 _ASM_EXTABLE(1b,2b)
31633 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31634 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31635 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31636 [zero] "r" (0UL), [eight] "r" (8UL));
31637 clac();
31638 + pax_close_userland();
31639 return size;
31640 }
31641 EXPORT_SYMBOL(__clear_user);
31642 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31643 }
31644 EXPORT_SYMBOL(clear_user);
31645
31646 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31647 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31648 {
31649 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31650 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31651 - }
31652 - return len;
31653 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31654 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31655 + return len;
31656 }
31657 EXPORT_SYMBOL(copy_in_user);
31658
31659 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31660 * it is not necessary to optimize tail handling.
31661 */
31662 __visible unsigned long
31663 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31664 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31665 {
31666 char c;
31667 unsigned zero_len;
31668
31669 + clac();
31670 + pax_close_userland();
31671 for (; len; --len, to++) {
31672 if (__get_user_nocheck(c, from++, sizeof(char)))
31673 break;
31674 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31675 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31676 if (__put_user_nocheck(c, to++, sizeof(char)))
31677 break;
31678 - clac();
31679 return len;
31680 }
31681 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31682 index 6a19ad9..1c48f9a 100644
31683 --- a/arch/x86/mm/Makefile
31684 +++ b/arch/x86/mm/Makefile
31685 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31686 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31687
31688 obj-$(CONFIG_MEMTEST) += memtest.o
31689 +
31690 +quote:="
31691 +obj-$(CONFIG_X86_64) += uderef_64.o
31692 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31693 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31694 index 903ec1e..c4166b2 100644
31695 --- a/arch/x86/mm/extable.c
31696 +++ b/arch/x86/mm/extable.c
31697 @@ -6,12 +6,24 @@
31698 static inline unsigned long
31699 ex_insn_addr(const struct exception_table_entry *x)
31700 {
31701 - return (unsigned long)&x->insn + x->insn;
31702 + unsigned long reloc = 0;
31703 +
31704 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31705 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31706 +#endif
31707 +
31708 + return (unsigned long)&x->insn + x->insn + reloc;
31709 }
31710 static inline unsigned long
31711 ex_fixup_addr(const struct exception_table_entry *x)
31712 {
31713 - return (unsigned long)&x->fixup + x->fixup;
31714 + unsigned long reloc = 0;
31715 +
31716 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31717 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31718 +#endif
31719 +
31720 + return (unsigned long)&x->fixup + x->fixup + reloc;
31721 }
31722
31723 int fixup_exception(struct pt_regs *regs)
31724 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31725 unsigned long new_ip;
31726
31727 #ifdef CONFIG_PNPBIOS
31728 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31729 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31730 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31731 extern u32 pnp_bios_is_utter_crap;
31732 pnp_bios_is_utter_crap = 1;
31733 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31734 i += 4;
31735 p->fixup -= i;
31736 i += 4;
31737 +
31738 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31739 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31740 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31741 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31742 +#endif
31743 +
31744 }
31745 }
31746
31747 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31748 index d973e61..fb868e9 100644
31749 --- a/arch/x86/mm/fault.c
31750 +++ b/arch/x86/mm/fault.c
31751 @@ -13,12 +13,19 @@
31752 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31753 #include <linux/prefetch.h> /* prefetchw */
31754 #include <linux/context_tracking.h> /* exception_enter(), ... */
31755 +#include <linux/unistd.h>
31756 +#include <linux/compiler.h>
31757
31758 #include <asm/traps.h> /* dotraplinkage, ... */
31759 #include <asm/pgalloc.h> /* pgd_*(), ... */
31760 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31761 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31762 #include <asm/vsyscall.h> /* emulate_vsyscall */
31763 +#include <asm/tlbflush.h>
31764 +
31765 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31766 +#include <asm/stacktrace.h>
31767 +#endif
31768
31769 #define CREATE_TRACE_POINTS
31770 #include <asm/trace/exceptions.h>
31771 @@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31772 int ret = 0;
31773
31774 /* kprobe_running() needs smp_processor_id() */
31775 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31776 + if (kprobes_built_in() && !user_mode(regs)) {
31777 preempt_disable();
31778 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31779 ret = 1;
31780 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31781 return !instr_lo || (instr_lo>>1) == 1;
31782 case 0x00:
31783 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31784 - if (probe_kernel_address(instr, opcode))
31785 + if (user_mode(regs)) {
31786 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31787 + return 0;
31788 + } else if (probe_kernel_address(instr, opcode))
31789 return 0;
31790
31791 *prefetch = (instr_lo == 0xF) &&
31792 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31793 while (instr < max_instr) {
31794 unsigned char opcode;
31795
31796 - if (probe_kernel_address(instr, opcode))
31797 + if (user_mode(regs)) {
31798 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31799 + break;
31800 + } else if (probe_kernel_address(instr, opcode))
31801 break;
31802
31803 instr++;
31804 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31805 force_sig_info(si_signo, &info, tsk);
31806 }
31807
31808 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31809 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31810 +#endif
31811 +
31812 +#ifdef CONFIG_PAX_EMUTRAMP
31813 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31814 +#endif
31815 +
31816 +#ifdef CONFIG_PAX_PAGEEXEC
31817 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31818 +{
31819 + pgd_t *pgd;
31820 + pud_t *pud;
31821 + pmd_t *pmd;
31822 +
31823 + pgd = pgd_offset(mm, address);
31824 + if (!pgd_present(*pgd))
31825 + return NULL;
31826 + pud = pud_offset(pgd, address);
31827 + if (!pud_present(*pud))
31828 + return NULL;
31829 + pmd = pmd_offset(pud, address);
31830 + if (!pmd_present(*pmd))
31831 + return NULL;
31832 + return pmd;
31833 +}
31834 +#endif
31835 +
31836 DEFINE_SPINLOCK(pgd_lock);
31837 LIST_HEAD(pgd_list);
31838
31839 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31840 for (address = VMALLOC_START & PMD_MASK;
31841 address >= TASK_SIZE && address < FIXADDR_TOP;
31842 address += PMD_SIZE) {
31843 +
31844 +#ifdef CONFIG_PAX_PER_CPU_PGD
31845 + unsigned long cpu;
31846 +#else
31847 struct page *page;
31848 +#endif
31849
31850 spin_lock(&pgd_lock);
31851 +
31852 +#ifdef CONFIG_PAX_PER_CPU_PGD
31853 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31854 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31855 + pmd_t *ret;
31856 +
31857 + ret = vmalloc_sync_one(pgd, address);
31858 + if (!ret)
31859 + break;
31860 + pgd = get_cpu_pgd(cpu, kernel);
31861 +#else
31862 list_for_each_entry(page, &pgd_list, lru) {
31863 + pgd_t *pgd;
31864 spinlock_t *pgt_lock;
31865 pmd_t *ret;
31866
31867 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31868 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31869
31870 spin_lock(pgt_lock);
31871 - ret = vmalloc_sync_one(page_address(page), address);
31872 + pgd = page_address(page);
31873 +#endif
31874 +
31875 + ret = vmalloc_sync_one(pgd, address);
31876 +
31877 +#ifndef CONFIG_PAX_PER_CPU_PGD
31878 spin_unlock(pgt_lock);
31879 +#endif
31880
31881 if (!ret)
31882 break;
31883 @@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31884 * an interrupt in the middle of a task switch..
31885 */
31886 pgd_paddr = read_cr3();
31887 +
31888 +#ifdef CONFIG_PAX_PER_CPU_PGD
31889 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31890 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31891 +#endif
31892 +
31893 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31894 if (!pmd_k)
31895 return -1;
31896 @@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31897 * happen within a race in page table update. In the later
31898 * case just flush:
31899 */
31900 - pgd = pgd_offset(current->active_mm, address);
31901 +
31902 pgd_ref = pgd_offset_k(address);
31903 if (pgd_none(*pgd_ref))
31904 return -1;
31905
31906 +#ifdef CONFIG_PAX_PER_CPU_PGD
31907 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31908 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31909 + if (pgd_none(*pgd)) {
31910 + set_pgd(pgd, *pgd_ref);
31911 + arch_flush_lazy_mmu_mode();
31912 + } else {
31913 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31914 + }
31915 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31916 +#else
31917 + pgd = pgd_offset(current->active_mm, address);
31918 +#endif
31919 +
31920 if (pgd_none(*pgd)) {
31921 set_pgd(pgd, *pgd_ref);
31922 arch_flush_lazy_mmu_mode();
31923 @@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31924 static int is_errata100(struct pt_regs *regs, unsigned long address)
31925 {
31926 #ifdef CONFIG_X86_64
31927 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31928 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31929 return 1;
31930 #endif
31931 return 0;
31932 @@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31933 }
31934
31935 static const char nx_warning[] = KERN_CRIT
31936 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31937 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31938 static const char smep_warning[] = KERN_CRIT
31939 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
31940 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31941
31942 static void
31943 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31944 @@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31945 if (!oops_may_print())
31946 return;
31947
31948 - if (error_code & PF_INSTR) {
31949 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31950 unsigned int level;
31951 pgd_t *pgd;
31952 pte_t *pte;
31953 @@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31954 pte = lookup_address_in_pgd(pgd, address, &level);
31955
31956 if (pte && pte_present(*pte) && !pte_exec(*pte))
31957 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31958 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31959 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31960 (pgd_flags(*pgd) & _PAGE_USER) &&
31961 (read_cr4() & X86_CR4_SMEP))
31962 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31963 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31964 }
31965
31966 +#ifdef CONFIG_PAX_KERNEXEC
31967 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31968 + if (current->signal->curr_ip)
31969 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31970 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31971 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31972 + else
31973 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31974 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31975 + }
31976 +#endif
31977 +
31978 printk(KERN_ALERT "BUG: unable to handle kernel ");
31979 if (address < PAGE_SIZE)
31980 printk(KERN_CONT "NULL pointer dereference");
31981 @@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31982 return;
31983 }
31984 #endif
31985 +
31986 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31987 + if (pax_is_fetch_fault(regs, error_code, address)) {
31988 +
31989 +#ifdef CONFIG_PAX_EMUTRAMP
31990 + switch (pax_handle_fetch_fault(regs)) {
31991 + case 2:
31992 + return;
31993 + }
31994 +#endif
31995 +
31996 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31997 + do_group_exit(SIGKILL);
31998 + }
31999 +#endif
32000 +
32001 /* Kernel addresses are always protection faults: */
32002 if (address >= TASK_SIZE)
32003 error_code |= PF_PROT;
32004 @@ -867,7 +979,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32005 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32006 printk(KERN_ERR
32007 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32008 - tsk->comm, tsk->pid, address);
32009 + tsk->comm, task_pid_nr(tsk), address);
32010 code = BUS_MCEERR_AR;
32011 }
32012 #endif
32013 @@ -921,6 +1033,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32014 return 1;
32015 }
32016
32017 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32018 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32019 +{
32020 + pte_t *pte;
32021 + pmd_t *pmd;
32022 + spinlock_t *ptl;
32023 + unsigned char pte_mask;
32024 +
32025 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32026 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32027 + return 0;
32028 +
32029 + /* PaX: it's our fault, let's handle it if we can */
32030 +
32031 + /* PaX: take a look at read faults before acquiring any locks */
32032 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32033 + /* instruction fetch attempt from a protected page in user mode */
32034 + up_read(&mm->mmap_sem);
32035 +
32036 +#ifdef CONFIG_PAX_EMUTRAMP
32037 + switch (pax_handle_fetch_fault(regs)) {
32038 + case 2:
32039 + return 1;
32040 + }
32041 +#endif
32042 +
32043 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32044 + do_group_exit(SIGKILL);
32045 + }
32046 +
32047 + pmd = pax_get_pmd(mm, address);
32048 + if (unlikely(!pmd))
32049 + return 0;
32050 +
32051 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32052 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32053 + pte_unmap_unlock(pte, ptl);
32054 + return 0;
32055 + }
32056 +
32057 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32058 + /* write attempt to a protected page in user mode */
32059 + pte_unmap_unlock(pte, ptl);
32060 + return 0;
32061 + }
32062 +
32063 +#ifdef CONFIG_SMP
32064 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32065 +#else
32066 + if (likely(address > get_limit(regs->cs)))
32067 +#endif
32068 + {
32069 + set_pte(pte, pte_mkread(*pte));
32070 + __flush_tlb_one(address);
32071 + pte_unmap_unlock(pte, ptl);
32072 + up_read(&mm->mmap_sem);
32073 + return 1;
32074 + }
32075 +
32076 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32077 +
32078 + /*
32079 + * PaX: fill DTLB with user rights and retry
32080 + */
32081 + __asm__ __volatile__ (
32082 + "orb %2,(%1)\n"
32083 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32084 +/*
32085 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32086 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32087 + * page fault when examined during a TLB load attempt. this is true not only
32088 + * for PTEs holding a non-present entry but also present entries that will
32089 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32090 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32091 + * for our target pages since their PTEs are simply not in the TLBs at all.
32092 +
32093 + * the best thing in omitting it is that we gain around 15-20% speed in the
32094 + * fast path of the page fault handler and can get rid of tracing since we
32095 + * can no longer flush unintended entries.
32096 + */
32097 + "invlpg (%0)\n"
32098 +#endif
32099 + __copyuser_seg"testb $0,(%0)\n"
32100 + "xorb %3,(%1)\n"
32101 + :
32102 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32103 + : "memory", "cc");
32104 + pte_unmap_unlock(pte, ptl);
32105 + up_read(&mm->mmap_sem);
32106 + return 1;
32107 +}
32108 +#endif
32109 +
32110 /*
32111 * Handle a spurious fault caused by a stale TLB entry.
32112 *
32113 @@ -1006,6 +1211,9 @@ int show_unhandled_signals = 1;
32114 static inline int
32115 access_error(unsigned long error_code, struct vm_area_struct *vma)
32116 {
32117 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32118 + return 1;
32119 +
32120 if (error_code & PF_WRITE) {
32121 /* write, present and write, not present: */
32122 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32123 @@ -1040,7 +1248,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32124 if (error_code & PF_USER)
32125 return false;
32126
32127 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32128 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32129 return false;
32130
32131 return true;
32132 @@ -1068,6 +1276,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32133 tsk = current;
32134 mm = tsk->mm;
32135
32136 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32137 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32138 + if (!search_exception_tables(regs->ip)) {
32139 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32140 + bad_area_nosemaphore(regs, error_code, address);
32141 + return;
32142 + }
32143 + if (address < pax_user_shadow_base) {
32144 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32145 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32146 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32147 + } else
32148 + address -= pax_user_shadow_base;
32149 + }
32150 +#endif
32151 +
32152 /*
32153 * Detect and handle instructions that would cause a page fault for
32154 * both a tracked kernel page and a userspace page.
32155 @@ -1145,7 +1369,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32156 * User-mode registers count as a user access even for any
32157 * potential system fault or CPU buglet:
32158 */
32159 - if (user_mode_vm(regs)) {
32160 + if (user_mode(regs)) {
32161 local_irq_enable();
32162 error_code |= PF_USER;
32163 flags |= FAULT_FLAG_USER;
32164 @@ -1192,6 +1416,11 @@ retry:
32165 might_sleep();
32166 }
32167
32168 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32169 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32170 + return;
32171 +#endif
32172 +
32173 vma = find_vma(mm, address);
32174 if (unlikely(!vma)) {
32175 bad_area(regs, error_code, address);
32176 @@ -1203,18 +1432,24 @@ retry:
32177 bad_area(regs, error_code, address);
32178 return;
32179 }
32180 - if (error_code & PF_USER) {
32181 - /*
32182 - * Accessing the stack below %sp is always a bug.
32183 - * The large cushion allows instructions like enter
32184 - * and pusha to work. ("enter $65535, $31" pushes
32185 - * 32 pointers and then decrements %sp by 65535.)
32186 - */
32187 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32188 - bad_area(regs, error_code, address);
32189 - return;
32190 - }
32191 + /*
32192 + * Accessing the stack below %sp is always a bug.
32193 + * The large cushion allows instructions like enter
32194 + * and pusha to work. ("enter $65535, $31" pushes
32195 + * 32 pointers and then decrements %sp by 65535.)
32196 + */
32197 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32198 + bad_area(regs, error_code, address);
32199 + return;
32200 }
32201 +
32202 +#ifdef CONFIG_PAX_SEGMEXEC
32203 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32204 + bad_area(regs, error_code, address);
32205 + return;
32206 + }
32207 +#endif
32208 +
32209 if (unlikely(expand_stack(vma, address))) {
32210 bad_area(regs, error_code, address);
32211 return;
32212 @@ -1331,3 +1566,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32213 }
32214 NOKPROBE_SYMBOL(trace_do_page_fault);
32215 #endif /* CONFIG_TRACING */
32216 +
32217 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32218 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32219 +{
32220 + struct mm_struct *mm = current->mm;
32221 + unsigned long ip = regs->ip;
32222 +
32223 + if (v8086_mode(regs))
32224 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32225 +
32226 +#ifdef CONFIG_PAX_PAGEEXEC
32227 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32228 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32229 + return true;
32230 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32231 + return true;
32232 + return false;
32233 + }
32234 +#endif
32235 +
32236 +#ifdef CONFIG_PAX_SEGMEXEC
32237 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32238 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32239 + return true;
32240 + return false;
32241 + }
32242 +#endif
32243 +
32244 + return false;
32245 +}
32246 +#endif
32247 +
32248 +#ifdef CONFIG_PAX_EMUTRAMP
32249 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32250 +{
32251 + int err;
32252 +
32253 + do { /* PaX: libffi trampoline emulation */
32254 + unsigned char mov, jmp;
32255 + unsigned int addr1, addr2;
32256 +
32257 +#ifdef CONFIG_X86_64
32258 + if ((regs->ip + 9) >> 32)
32259 + break;
32260 +#endif
32261 +
32262 + err = get_user(mov, (unsigned char __user *)regs->ip);
32263 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32264 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32265 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32266 +
32267 + if (err)
32268 + break;
32269 +
32270 + if (mov == 0xB8 && jmp == 0xE9) {
32271 + regs->ax = addr1;
32272 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32273 + return 2;
32274 + }
32275 + } while (0);
32276 +
32277 + do { /* PaX: gcc trampoline emulation #1 */
32278 + unsigned char mov1, mov2;
32279 + unsigned short jmp;
32280 + unsigned int addr1, addr2;
32281 +
32282 +#ifdef CONFIG_X86_64
32283 + if ((regs->ip + 11) >> 32)
32284 + break;
32285 +#endif
32286 +
32287 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32288 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32289 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32290 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32291 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32292 +
32293 + if (err)
32294 + break;
32295 +
32296 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32297 + regs->cx = addr1;
32298 + regs->ax = addr2;
32299 + regs->ip = addr2;
32300 + return 2;
32301 + }
32302 + } while (0);
32303 +
32304 + do { /* PaX: gcc trampoline emulation #2 */
32305 + unsigned char mov, jmp;
32306 + unsigned int addr1, addr2;
32307 +
32308 +#ifdef CONFIG_X86_64
32309 + if ((regs->ip + 9) >> 32)
32310 + break;
32311 +#endif
32312 +
32313 + err = get_user(mov, (unsigned char __user *)regs->ip);
32314 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32315 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32316 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32317 +
32318 + if (err)
32319 + break;
32320 +
32321 + if (mov == 0xB9 && jmp == 0xE9) {
32322 + regs->cx = addr1;
32323 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32324 + return 2;
32325 + }
32326 + } while (0);
32327 +
32328 + return 1; /* PaX in action */
32329 +}
32330 +
32331 +#ifdef CONFIG_X86_64
32332 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32333 +{
32334 + int err;
32335 +
32336 + do { /* PaX: libffi trampoline emulation */
32337 + unsigned short mov1, mov2, jmp1;
32338 + unsigned char stcclc, jmp2;
32339 + unsigned long addr1, addr2;
32340 +
32341 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32342 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32343 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32344 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32345 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32346 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32347 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32348 +
32349 + if (err)
32350 + break;
32351 +
32352 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32353 + regs->r11 = addr1;
32354 + regs->r10 = addr2;
32355 + if (stcclc == 0xF8)
32356 + regs->flags &= ~X86_EFLAGS_CF;
32357 + else
32358 + regs->flags |= X86_EFLAGS_CF;
32359 + regs->ip = addr1;
32360 + return 2;
32361 + }
32362 + } while (0);
32363 +
32364 + do { /* PaX: gcc trampoline emulation #1 */
32365 + unsigned short mov1, mov2, jmp1;
32366 + unsigned char jmp2;
32367 + unsigned int addr1;
32368 + unsigned long addr2;
32369 +
32370 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32371 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32372 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32373 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32374 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32375 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32376 +
32377 + if (err)
32378 + break;
32379 +
32380 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32381 + regs->r11 = addr1;
32382 + regs->r10 = addr2;
32383 + regs->ip = addr1;
32384 + return 2;
32385 + }
32386 + } while (0);
32387 +
32388 + do { /* PaX: gcc trampoline emulation #2 */
32389 + unsigned short mov1, mov2, jmp1;
32390 + unsigned char jmp2;
32391 + unsigned long addr1, addr2;
32392 +
32393 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32394 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32395 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32396 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32397 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32398 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32399 +
32400 + if (err)
32401 + break;
32402 +
32403 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32404 + regs->r11 = addr1;
32405 + regs->r10 = addr2;
32406 + regs->ip = addr1;
32407 + return 2;
32408 + }
32409 + } while (0);
32410 +
32411 + return 1; /* PaX in action */
32412 +}
32413 +#endif
32414 +
32415 +/*
32416 + * PaX: decide what to do with offenders (regs->ip = fault address)
32417 + *
32418 + * returns 1 when task should be killed
32419 + * 2 when gcc trampoline was detected
32420 + */
32421 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32422 +{
32423 + if (v8086_mode(regs))
32424 + return 1;
32425 +
32426 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32427 + return 1;
32428 +
32429 +#ifdef CONFIG_X86_32
32430 + return pax_handle_fetch_fault_32(regs);
32431 +#else
32432 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32433 + return pax_handle_fetch_fault_32(regs);
32434 + else
32435 + return pax_handle_fetch_fault_64(regs);
32436 +#endif
32437 +}
32438 +#endif
32439 +
32440 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32441 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32442 +{
32443 + long i;
32444 +
32445 + printk(KERN_ERR "PAX: bytes at PC: ");
32446 + for (i = 0; i < 20; i++) {
32447 + unsigned char c;
32448 + if (get_user(c, (unsigned char __force_user *)pc+i))
32449 + printk(KERN_CONT "?? ");
32450 + else
32451 + printk(KERN_CONT "%02x ", c);
32452 + }
32453 + printk("\n");
32454 +
32455 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32456 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32457 + unsigned long c;
32458 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32459 +#ifdef CONFIG_X86_32
32460 + printk(KERN_CONT "???????? ");
32461 +#else
32462 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32463 + printk(KERN_CONT "???????? ???????? ");
32464 + else
32465 + printk(KERN_CONT "???????????????? ");
32466 +#endif
32467 + } else {
32468 +#ifdef CONFIG_X86_64
32469 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32470 + printk(KERN_CONT "%08x ", (unsigned int)c);
32471 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32472 + } else
32473 +#endif
32474 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32475 + }
32476 + }
32477 + printk("\n");
32478 +}
32479 +#endif
32480 +
32481 +/**
32482 + * probe_kernel_write(): safely attempt to write to a location
32483 + * @dst: address to write to
32484 + * @src: pointer to the data that shall be written
32485 + * @size: size of the data chunk
32486 + *
32487 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32488 + * happens, handle that and return -EFAULT.
32489 + */
32490 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32491 +{
32492 + long ret;
32493 + mm_segment_t old_fs = get_fs();
32494 +
32495 + set_fs(KERNEL_DS);
32496 + pagefault_disable();
32497 + pax_open_kernel();
32498 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32499 + pax_close_kernel();
32500 + pagefault_enable();
32501 + set_fs(old_fs);
32502 +
32503 + return ret ? -EFAULT : 0;
32504 +}
32505 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32506 index 207d9aef..69030980 100644
32507 --- a/arch/x86/mm/gup.c
32508 +++ b/arch/x86/mm/gup.c
32509 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32510 addr = start;
32511 len = (unsigned long) nr_pages << PAGE_SHIFT;
32512 end = start + len;
32513 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32514 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32515 (void __user *)start, len)))
32516 return 0;
32517
32518 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32519 goto slow_irqon;
32520 #endif
32521
32522 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32523 + (void __user *)start, len)))
32524 + return 0;
32525 +
32526 /*
32527 * XXX: batch / limit 'nr', to avoid large irq off latency
32528 * needs some instrumenting to determine the common sizes used by
32529 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32530 index 4500142..53a363c 100644
32531 --- a/arch/x86/mm/highmem_32.c
32532 +++ b/arch/x86/mm/highmem_32.c
32533 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32534 idx = type + KM_TYPE_NR*smp_processor_id();
32535 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32536 BUG_ON(!pte_none(*(kmap_pte-idx)));
32537 +
32538 + pax_open_kernel();
32539 set_pte(kmap_pte-idx, mk_pte(page, prot));
32540 + pax_close_kernel();
32541 +
32542 arch_flush_lazy_mmu_mode();
32543
32544 return (void *)vaddr;
32545 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32546 index 8b977eb..4732c33 100644
32547 --- a/arch/x86/mm/hugetlbpage.c
32548 +++ b/arch/x86/mm/hugetlbpage.c
32549 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32550 #ifdef CONFIG_HUGETLB_PAGE
32551 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32552 unsigned long addr, unsigned long len,
32553 - unsigned long pgoff, unsigned long flags)
32554 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32555 {
32556 struct hstate *h = hstate_file(file);
32557 struct vm_unmapped_area_info info;
32558 -
32559 +
32560 info.flags = 0;
32561 info.length = len;
32562 info.low_limit = current->mm->mmap_legacy_base;
32563 info.high_limit = TASK_SIZE;
32564 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32565 info.align_offset = 0;
32566 + info.threadstack_offset = offset;
32567 return vm_unmapped_area(&info);
32568 }
32569
32570 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32571 unsigned long addr0, unsigned long len,
32572 - unsigned long pgoff, unsigned long flags)
32573 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32574 {
32575 struct hstate *h = hstate_file(file);
32576 struct vm_unmapped_area_info info;
32577 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32578 info.high_limit = current->mm->mmap_base;
32579 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32580 info.align_offset = 0;
32581 + info.threadstack_offset = offset;
32582 addr = vm_unmapped_area(&info);
32583
32584 /*
32585 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32586 VM_BUG_ON(addr != -ENOMEM);
32587 info.flags = 0;
32588 info.low_limit = TASK_UNMAPPED_BASE;
32589 +
32590 +#ifdef CONFIG_PAX_RANDMMAP
32591 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32592 + info.low_limit += current->mm->delta_mmap;
32593 +#endif
32594 +
32595 info.high_limit = TASK_SIZE;
32596 addr = vm_unmapped_area(&info);
32597 }
32598 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32599 struct hstate *h = hstate_file(file);
32600 struct mm_struct *mm = current->mm;
32601 struct vm_area_struct *vma;
32602 + unsigned long pax_task_size = TASK_SIZE;
32603 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32604
32605 if (len & ~huge_page_mask(h))
32606 return -EINVAL;
32607 - if (len > TASK_SIZE)
32608 +
32609 +#ifdef CONFIG_PAX_SEGMEXEC
32610 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32611 + pax_task_size = SEGMEXEC_TASK_SIZE;
32612 +#endif
32613 +
32614 + pax_task_size -= PAGE_SIZE;
32615 +
32616 + if (len > pax_task_size)
32617 return -ENOMEM;
32618
32619 if (flags & MAP_FIXED) {
32620 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32621 return addr;
32622 }
32623
32624 +#ifdef CONFIG_PAX_RANDMMAP
32625 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32626 +#endif
32627 +
32628 if (addr) {
32629 addr = ALIGN(addr, huge_page_size(h));
32630 vma = find_vma(mm, addr);
32631 - if (TASK_SIZE - len >= addr &&
32632 - (!vma || addr + len <= vma->vm_start))
32633 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32634 return addr;
32635 }
32636 if (mm->get_unmapped_area == arch_get_unmapped_area)
32637 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32638 - pgoff, flags);
32639 + pgoff, flags, offset);
32640 else
32641 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32642 - pgoff, flags);
32643 + pgoff, flags, offset);
32644 }
32645 #endif /* CONFIG_HUGETLB_PAGE */
32646
32647 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32648 index 66dba36..f8082ec 100644
32649 --- a/arch/x86/mm/init.c
32650 +++ b/arch/x86/mm/init.c
32651 @@ -4,6 +4,7 @@
32652 #include <linux/swap.h>
32653 #include <linux/memblock.h>
32654 #include <linux/bootmem.h> /* for max_low_pfn */
32655 +#include <linux/tboot.h>
32656
32657 #include <asm/cacheflush.h>
32658 #include <asm/e820.h>
32659 @@ -17,6 +18,8 @@
32660 #include <asm/proto.h>
32661 #include <asm/dma.h> /* for MAX_DMA_PFN */
32662 #include <asm/microcode.h>
32663 +#include <asm/desc.h>
32664 +#include <asm/bios_ebda.h>
32665
32666 /*
32667 * We need to define the tracepoints somewhere, and tlb.c
32668 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32669 early_ioremap_page_table_range_init();
32670 #endif
32671
32672 +#ifdef CONFIG_PAX_PER_CPU_PGD
32673 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32674 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32675 + KERNEL_PGD_PTRS);
32676 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32677 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32678 + KERNEL_PGD_PTRS);
32679 + load_cr3(get_cpu_pgd(0, kernel));
32680 +#else
32681 load_cr3(swapper_pg_dir);
32682 +#endif
32683 +
32684 __flush_tlb_all();
32685
32686 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32687 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32688 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32689 * mmio resources as well as potential bios/acpi data regions.
32690 */
32691 +
32692 +#ifdef CONFIG_GRKERNSEC_KMEM
32693 +static unsigned int ebda_start __read_only;
32694 +static unsigned int ebda_end __read_only;
32695 +#endif
32696 +
32697 int devmem_is_allowed(unsigned long pagenr)
32698 {
32699 - if (pagenr < 256)
32700 +#ifdef CONFIG_GRKERNSEC_KMEM
32701 + /* allow BDA */
32702 + if (!pagenr)
32703 return 1;
32704 + /* allow EBDA */
32705 + if (pagenr >= ebda_start && pagenr < ebda_end)
32706 + return 1;
32707 + /* if tboot is in use, allow access to its hardcoded serial log range */
32708 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32709 + return 1;
32710 +#else
32711 + if (!pagenr)
32712 + return 1;
32713 +#ifdef CONFIG_VM86
32714 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32715 + return 1;
32716 +#endif
32717 +#endif
32718 +
32719 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32720 + return 1;
32721 +#ifdef CONFIG_GRKERNSEC_KMEM
32722 + /* throw out everything else below 1MB */
32723 + if (pagenr <= 256)
32724 + return 0;
32725 +#endif
32726 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32727 return 0;
32728 if (!page_is_ram(pagenr))
32729 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32730 #endif
32731 }
32732
32733 +#ifdef CONFIG_GRKERNSEC_KMEM
32734 +static inline void gr_init_ebda(void)
32735 +{
32736 + unsigned int ebda_addr;
32737 + unsigned int ebda_size = 0;
32738 +
32739 + ebda_addr = get_bios_ebda();
32740 + if (ebda_addr) {
32741 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32742 + ebda_size <<= 10;
32743 + }
32744 + if (ebda_addr && ebda_size) {
32745 + ebda_start = ebda_addr >> PAGE_SHIFT;
32746 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32747 + } else {
32748 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32749 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32750 + }
32751 +}
32752 +#else
32753 +static inline void gr_init_ebda(void) { }
32754 +#endif
32755 +
32756 void free_initmem(void)
32757 {
32758 +#ifdef CONFIG_PAX_KERNEXEC
32759 +#ifdef CONFIG_X86_32
32760 + /* PaX: limit KERNEL_CS to actual size */
32761 + unsigned long addr, limit;
32762 + struct desc_struct d;
32763 + int cpu;
32764 +#else
32765 + pgd_t *pgd;
32766 + pud_t *pud;
32767 + pmd_t *pmd;
32768 + unsigned long addr, end;
32769 +#endif
32770 +#endif
32771 +
32772 + gr_init_ebda();
32773 +
32774 +#ifdef CONFIG_PAX_KERNEXEC
32775 +#ifdef CONFIG_X86_32
32776 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32777 + limit = (limit - 1UL) >> PAGE_SHIFT;
32778 +
32779 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32780 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32781 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32782 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32783 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32784 + }
32785 +
32786 + /* PaX: make KERNEL_CS read-only */
32787 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32788 + if (!paravirt_enabled())
32789 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32790 +/*
32791 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32792 + pgd = pgd_offset_k(addr);
32793 + pud = pud_offset(pgd, addr);
32794 + pmd = pmd_offset(pud, addr);
32795 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32796 + }
32797 +*/
32798 +#ifdef CONFIG_X86_PAE
32799 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32800 +/*
32801 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32802 + pgd = pgd_offset_k(addr);
32803 + pud = pud_offset(pgd, addr);
32804 + pmd = pmd_offset(pud, addr);
32805 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32806 + }
32807 +*/
32808 +#endif
32809 +
32810 +#ifdef CONFIG_MODULES
32811 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32812 +#endif
32813 +
32814 +#else
32815 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32816 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32817 + pgd = pgd_offset_k(addr);
32818 + pud = pud_offset(pgd, addr);
32819 + pmd = pmd_offset(pud, addr);
32820 + if (!pmd_present(*pmd))
32821 + continue;
32822 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32823 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32824 + else
32825 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32826 + }
32827 +
32828 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32829 + end = addr + KERNEL_IMAGE_SIZE;
32830 + for (; addr < end; addr += PMD_SIZE) {
32831 + pgd = pgd_offset_k(addr);
32832 + pud = pud_offset(pgd, addr);
32833 + pmd = pmd_offset(pud, addr);
32834 + if (!pmd_present(*pmd))
32835 + continue;
32836 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32837 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32838 + }
32839 +#endif
32840 +
32841 + flush_tlb_all();
32842 +#endif
32843 +
32844 free_init_pages("unused kernel",
32845 (unsigned long)(&__init_begin),
32846 (unsigned long)(&__init_end));
32847 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32848 index c8140e1..59257fc 100644
32849 --- a/arch/x86/mm/init_32.c
32850 +++ b/arch/x86/mm/init_32.c
32851 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32852 bool __read_mostly __vmalloc_start_set = false;
32853
32854 /*
32855 - * Creates a middle page table and puts a pointer to it in the
32856 - * given global directory entry. This only returns the gd entry
32857 - * in non-PAE compilation mode, since the middle layer is folded.
32858 - */
32859 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32860 -{
32861 - pud_t *pud;
32862 - pmd_t *pmd_table;
32863 -
32864 -#ifdef CONFIG_X86_PAE
32865 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32866 - pmd_table = (pmd_t *)alloc_low_page();
32867 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32868 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32869 - pud = pud_offset(pgd, 0);
32870 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32871 -
32872 - return pmd_table;
32873 - }
32874 -#endif
32875 - pud = pud_offset(pgd, 0);
32876 - pmd_table = pmd_offset(pud, 0);
32877 -
32878 - return pmd_table;
32879 -}
32880 -
32881 -/*
32882 * Create a page table and place a pointer to it in a middle page
32883 * directory entry:
32884 */
32885 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32886 pte_t *page_table = (pte_t *)alloc_low_page();
32887
32888 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32889 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32890 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32891 +#else
32892 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32893 +#endif
32894 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32895 }
32896
32897 return pte_offset_kernel(pmd, 0);
32898 }
32899
32900 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32901 +{
32902 + pud_t *pud;
32903 + pmd_t *pmd_table;
32904 +
32905 + pud = pud_offset(pgd, 0);
32906 + pmd_table = pmd_offset(pud, 0);
32907 +
32908 + return pmd_table;
32909 +}
32910 +
32911 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32912 {
32913 int pgd_idx = pgd_index(vaddr);
32914 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32915 int pgd_idx, pmd_idx;
32916 unsigned long vaddr;
32917 pgd_t *pgd;
32918 + pud_t *pud;
32919 pmd_t *pmd;
32920 pte_t *pte = NULL;
32921 unsigned long count = page_table_range_init_count(start, end);
32922 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32923 pgd = pgd_base + pgd_idx;
32924
32925 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32926 - pmd = one_md_table_init(pgd);
32927 - pmd = pmd + pmd_index(vaddr);
32928 + pud = pud_offset(pgd, vaddr);
32929 + pmd = pmd_offset(pud, vaddr);
32930 +
32931 +#ifdef CONFIG_X86_PAE
32932 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32933 +#endif
32934 +
32935 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32936 pmd++, pmd_idx++) {
32937 pte = page_table_kmap_check(one_page_table_init(pmd),
32938 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32939 }
32940 }
32941
32942 -static inline int is_kernel_text(unsigned long addr)
32943 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32944 {
32945 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32946 - return 1;
32947 - return 0;
32948 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32949 + end <= ktla_ktva((unsigned long)_stext)) &&
32950 + (start >= ktla_ktva((unsigned long)_einittext) ||
32951 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32952 +
32953 +#ifdef CONFIG_ACPI_SLEEP
32954 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32955 +#endif
32956 +
32957 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32958 + return 0;
32959 + return 1;
32960 }
32961
32962 /*
32963 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32964 unsigned long last_map_addr = end;
32965 unsigned long start_pfn, end_pfn;
32966 pgd_t *pgd_base = swapper_pg_dir;
32967 - int pgd_idx, pmd_idx, pte_ofs;
32968 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32969 unsigned long pfn;
32970 pgd_t *pgd;
32971 + pud_t *pud;
32972 pmd_t *pmd;
32973 pte_t *pte;
32974 unsigned pages_2m, pages_4k;
32975 @@ -291,8 +295,13 @@ repeat:
32976 pfn = start_pfn;
32977 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32978 pgd = pgd_base + pgd_idx;
32979 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32980 - pmd = one_md_table_init(pgd);
32981 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32982 + pud = pud_offset(pgd, 0);
32983 + pmd = pmd_offset(pud, 0);
32984 +
32985 +#ifdef CONFIG_X86_PAE
32986 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32987 +#endif
32988
32989 if (pfn >= end_pfn)
32990 continue;
32991 @@ -304,14 +313,13 @@ repeat:
32992 #endif
32993 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32994 pmd++, pmd_idx++) {
32995 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32996 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32997
32998 /*
32999 * Map with big pages if possible, otherwise
33000 * create normal page tables:
33001 */
33002 if (use_pse) {
33003 - unsigned int addr2;
33004 pgprot_t prot = PAGE_KERNEL_LARGE;
33005 /*
33006 * first pass will use the same initial
33007 @@ -322,11 +330,7 @@ repeat:
33008 _PAGE_PSE);
33009
33010 pfn &= PMD_MASK >> PAGE_SHIFT;
33011 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33012 - PAGE_OFFSET + PAGE_SIZE-1;
33013 -
33014 - if (is_kernel_text(addr) ||
33015 - is_kernel_text(addr2))
33016 + if (is_kernel_text(address, address + PMD_SIZE))
33017 prot = PAGE_KERNEL_LARGE_EXEC;
33018
33019 pages_2m++;
33020 @@ -343,7 +347,7 @@ repeat:
33021 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33022 pte += pte_ofs;
33023 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33024 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33025 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33026 pgprot_t prot = PAGE_KERNEL;
33027 /*
33028 * first pass will use the same initial
33029 @@ -351,7 +355,7 @@ repeat:
33030 */
33031 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33032
33033 - if (is_kernel_text(addr))
33034 + if (is_kernel_text(address, address + PAGE_SIZE))
33035 prot = PAGE_KERNEL_EXEC;
33036
33037 pages_4k++;
33038 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33039
33040 pud = pud_offset(pgd, va);
33041 pmd = pmd_offset(pud, va);
33042 - if (!pmd_present(*pmd))
33043 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33044 break;
33045
33046 /* should not be large page here */
33047 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33048
33049 static void __init pagetable_init(void)
33050 {
33051 - pgd_t *pgd_base = swapper_pg_dir;
33052 -
33053 - permanent_kmaps_init(pgd_base);
33054 + permanent_kmaps_init(swapper_pg_dir);
33055 }
33056
33057 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33058 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33059 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33060
33061 /* user-defined highmem size */
33062 @@ -787,10 +789,10 @@ void __init mem_init(void)
33063 ((unsigned long)&__init_end -
33064 (unsigned long)&__init_begin) >> 10,
33065
33066 - (unsigned long)&_etext, (unsigned long)&_edata,
33067 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33068 + (unsigned long)&_sdata, (unsigned long)&_edata,
33069 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33070
33071 - (unsigned long)&_text, (unsigned long)&_etext,
33072 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33073 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33074
33075 /*
33076 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33077 if (!kernel_set_to_readonly)
33078 return;
33079
33080 + start = ktla_ktva(start);
33081 pr_debug("Set kernel text: %lx - %lx for read write\n",
33082 start, start+size);
33083
33084 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33085 if (!kernel_set_to_readonly)
33086 return;
33087
33088 + start = ktla_ktva(start);
33089 pr_debug("Set kernel text: %lx - %lx for read only\n",
33090 start, start+size);
33091
33092 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33093 unsigned long start = PFN_ALIGN(_text);
33094 unsigned long size = PFN_ALIGN(_etext) - start;
33095
33096 + start = ktla_ktva(start);
33097 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33098 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33099 size >> 10);
33100 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33101 index 4e5dfec..6fd6dc5 100644
33102 --- a/arch/x86/mm/init_64.c
33103 +++ b/arch/x86/mm/init_64.c
33104 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33105 * around without checking the pgd every time.
33106 */
33107
33108 -pteval_t __supported_pte_mask __read_mostly = ~0;
33109 +pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33110 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33111
33112 int force_personality32;
33113 @@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33114
33115 for (address = start; address <= end; address += PGDIR_SIZE) {
33116 const pgd_t *pgd_ref = pgd_offset_k(address);
33117 +
33118 +#ifdef CONFIG_PAX_PER_CPU_PGD
33119 + unsigned long cpu;
33120 +#else
33121 struct page *page;
33122 +#endif
33123
33124 /*
33125 * When it is called after memory hot remove, pgd_none()
33126 @@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33127 continue;
33128
33129 spin_lock(&pgd_lock);
33130 +
33131 +#ifdef CONFIG_PAX_PER_CPU_PGD
33132 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33133 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33134 +
33135 + if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33136 + BUG_ON(pgd_page_vaddr(*pgd)
33137 + != pgd_page_vaddr(*pgd_ref));
33138 +
33139 + if (removed) {
33140 + if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33141 + pgd_clear(pgd);
33142 + } else {
33143 + if (pgd_none(*pgd))
33144 + set_pgd(pgd, *pgd_ref);
33145 + }
33146 +
33147 + pgd = pgd_offset_cpu(cpu, kernel, address);
33148 +#else
33149 list_for_each_entry(page, &pgd_list, lru) {
33150 pgd_t *pgd;
33151 spinlock_t *pgt_lock;
33152 @@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33153 /* the pgt_lock only for Xen */
33154 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33155 spin_lock(pgt_lock);
33156 +#endif
33157
33158 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33159 BUG_ON(pgd_page_vaddr(*pgd)
33160 @@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33161 set_pgd(pgd, *pgd_ref);
33162 }
33163
33164 +#ifndef CONFIG_PAX_PER_CPU_PGD
33165 spin_unlock(pgt_lock);
33166 +#endif
33167 +
33168 }
33169 spin_unlock(&pgd_lock);
33170 }
33171 @@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33172 {
33173 if (pgd_none(*pgd)) {
33174 pud_t *pud = (pud_t *)spp_getpage();
33175 - pgd_populate(&init_mm, pgd, pud);
33176 + pgd_populate_kernel(&init_mm, pgd, pud);
33177 if (pud != pud_offset(pgd, 0))
33178 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33179 pud, pud_offset(pgd, 0));
33180 @@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33181 {
33182 if (pud_none(*pud)) {
33183 pmd_t *pmd = (pmd_t *) spp_getpage();
33184 - pud_populate(&init_mm, pud, pmd);
33185 + pud_populate_kernel(&init_mm, pud, pmd);
33186 if (pmd != pmd_offset(pud, 0))
33187 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33188 pmd, pmd_offset(pud, 0));
33189 @@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33190 pmd = fill_pmd(pud, vaddr);
33191 pte = fill_pte(pmd, vaddr);
33192
33193 + pax_open_kernel();
33194 set_pte(pte, new_pte);
33195 + pax_close_kernel();
33196
33197 /*
33198 * It's enough to flush this one mapping.
33199 @@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33200 pgd = pgd_offset_k((unsigned long)__va(phys));
33201 if (pgd_none(*pgd)) {
33202 pud = (pud_t *) spp_getpage();
33203 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33204 - _PAGE_USER));
33205 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33206 }
33207 pud = pud_offset(pgd, (unsigned long)__va(phys));
33208 if (pud_none(*pud)) {
33209 pmd = (pmd_t *) spp_getpage();
33210 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33211 - _PAGE_USER));
33212 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33213 }
33214 pmd = pmd_offset(pud, phys);
33215 BUG_ON(!pmd_none(*pmd));
33216 @@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33217 prot);
33218
33219 spin_lock(&init_mm.page_table_lock);
33220 - pud_populate(&init_mm, pud, pmd);
33221 + pud_populate_kernel(&init_mm, pud, pmd);
33222 spin_unlock(&init_mm.page_table_lock);
33223 }
33224 __flush_tlb_all();
33225 @@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33226 page_size_mask);
33227
33228 spin_lock(&init_mm.page_table_lock);
33229 - pgd_populate(&init_mm, pgd, pud);
33230 + pgd_populate_kernel(&init_mm, pgd, pud);
33231 spin_unlock(&init_mm.page_table_lock);
33232 pgd_changed = true;
33233 }
33234 @@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33235 static struct vm_area_struct gate_vma = {
33236 .vm_start = VSYSCALL_ADDR,
33237 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33238 - .vm_page_prot = PAGE_READONLY_EXEC,
33239 - .vm_flags = VM_READ | VM_EXEC,
33240 + .vm_page_prot = PAGE_READONLY,
33241 + .vm_flags = VM_READ,
33242 .vm_ops = &gate_vma_ops,
33243 };
33244
33245 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33246 index 7b179b49..6bd17777 100644
33247 --- a/arch/x86/mm/iomap_32.c
33248 +++ b/arch/x86/mm/iomap_32.c
33249 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33250 type = kmap_atomic_idx_push();
33251 idx = type + KM_TYPE_NR * smp_processor_id();
33252 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33253 +
33254 + pax_open_kernel();
33255 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33256 + pax_close_kernel();
33257 +
33258 arch_flush_lazy_mmu_mode();
33259
33260 return (void *)vaddr;
33261 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33262 index af78e50..0790b03 100644
33263 --- a/arch/x86/mm/ioremap.c
33264 +++ b/arch/x86/mm/ioremap.c
33265 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33266 unsigned long i;
33267
33268 for (i = 0; i < nr_pages; ++i)
33269 - if (pfn_valid(start_pfn + i) &&
33270 - !PageReserved(pfn_to_page(start_pfn + i)))
33271 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33272 + !PageReserved(pfn_to_page(start_pfn + i))))
33273 return 1;
33274
33275 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33276 @@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33277 *
33278 * Caller must ensure there is only one unmapping for the same pointer.
33279 */
33280 -void iounmap(volatile void __iomem *addr)
33281 +void iounmap(const volatile void __iomem *addr)
33282 {
33283 struct vm_struct *p, *o;
33284
33285 @@ -334,6 +334,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33286
33287 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33288 if (page_is_ram(start >> PAGE_SHIFT))
33289 +#ifdef CONFIG_HIGHMEM
33290 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33291 +#endif
33292 return __va(phys);
33293
33294 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33295 @@ -346,13 +349,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33296 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33297 {
33298 if (page_is_ram(phys >> PAGE_SHIFT))
33299 +#ifdef CONFIG_HIGHMEM
33300 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33301 +#endif
33302 return;
33303
33304 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33305 return;
33306 }
33307
33308 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33309 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33310
33311 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33312 {
33313 @@ -388,8 +394,7 @@ void __init early_ioremap_init(void)
33314 early_ioremap_setup();
33315
33316 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33317 - memset(bm_pte, 0, sizeof(bm_pte));
33318 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33319 + pmd_populate_user(&init_mm, pmd, bm_pte);
33320
33321 /*
33322 * The boot-ioremap range spans multiple pmds, for which
33323 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33324 index b4f2e7e..96c9c3e 100644
33325 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33326 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33327 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33328 * memory (e.g. tracked pages)? For now, we need this to avoid
33329 * invoking kmemcheck for PnP BIOS calls.
33330 */
33331 - if (regs->flags & X86_VM_MASK)
33332 + if (v8086_mode(regs))
33333 return false;
33334 - if (regs->cs != __KERNEL_CS)
33335 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33336 return false;
33337
33338 pte = kmemcheck_pte_lookup(address);
33339 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33340 index 919b912..9267313 100644
33341 --- a/arch/x86/mm/mmap.c
33342 +++ b/arch/x86/mm/mmap.c
33343 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33344 * Leave an at least ~128 MB hole with possible stack randomization.
33345 */
33346 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33347 -#define MAX_GAP (TASK_SIZE/6*5)
33348 +#define MAX_GAP (pax_task_size/6*5)
33349
33350 static int mmap_is_legacy(void)
33351 {
33352 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33353 return rnd << PAGE_SHIFT;
33354 }
33355
33356 -static unsigned long mmap_base(void)
33357 +static unsigned long mmap_base(struct mm_struct *mm)
33358 {
33359 unsigned long gap = rlimit(RLIMIT_STACK);
33360 + unsigned long pax_task_size = TASK_SIZE;
33361 +
33362 +#ifdef CONFIG_PAX_SEGMEXEC
33363 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33364 + pax_task_size = SEGMEXEC_TASK_SIZE;
33365 +#endif
33366
33367 if (gap < MIN_GAP)
33368 gap = MIN_GAP;
33369 else if (gap > MAX_GAP)
33370 gap = MAX_GAP;
33371
33372 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33373 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33374 }
33375
33376 /*
33377 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33378 * does, but not when emulating X86_32
33379 */
33380 -static unsigned long mmap_legacy_base(void)
33381 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33382 {
33383 - if (mmap_is_ia32())
33384 + if (mmap_is_ia32()) {
33385 +
33386 +#ifdef CONFIG_PAX_SEGMEXEC
33387 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33388 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33389 + else
33390 +#endif
33391 +
33392 return TASK_UNMAPPED_BASE;
33393 - else
33394 + } else
33395 return TASK_UNMAPPED_BASE + mmap_rnd();
33396 }
33397
33398 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33399 */
33400 void arch_pick_mmap_layout(struct mm_struct *mm)
33401 {
33402 - mm->mmap_legacy_base = mmap_legacy_base();
33403 - mm->mmap_base = mmap_base();
33404 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33405 + mm->mmap_base = mmap_base(mm);
33406 +
33407 +#ifdef CONFIG_PAX_RANDMMAP
33408 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33409 + mm->mmap_legacy_base += mm->delta_mmap;
33410 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33411 + }
33412 +#endif
33413
33414 if (mmap_is_legacy()) {
33415 mm->mmap_base = mm->mmap_legacy_base;
33416 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33417 index 0057a7a..95c7edd 100644
33418 --- a/arch/x86/mm/mmio-mod.c
33419 +++ b/arch/x86/mm/mmio-mod.c
33420 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33421 break;
33422 default:
33423 {
33424 - unsigned char *ip = (unsigned char *)instptr;
33425 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33426 my_trace->opcode = MMIO_UNKNOWN_OP;
33427 my_trace->width = 0;
33428 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33429 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33430 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33431 void __iomem *addr)
33432 {
33433 - static atomic_t next_id;
33434 + static atomic_unchecked_t next_id;
33435 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33436 /* These are page-unaligned. */
33437 struct mmiotrace_map map = {
33438 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33439 .private = trace
33440 },
33441 .phys = offset,
33442 - .id = atomic_inc_return(&next_id)
33443 + .id = atomic_inc_return_unchecked(&next_id)
33444 };
33445 map.map_id = trace->id;
33446
33447 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33448 ioremap_trace_core(offset, size, addr);
33449 }
33450
33451 -static void iounmap_trace_core(volatile void __iomem *addr)
33452 +static void iounmap_trace_core(const volatile void __iomem *addr)
33453 {
33454 struct mmiotrace_map map = {
33455 .phys = 0,
33456 @@ -328,7 +328,7 @@ not_enabled:
33457 }
33458 }
33459
33460 -void mmiotrace_iounmap(volatile void __iomem *addr)
33461 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33462 {
33463 might_sleep();
33464 if (is_enabled()) /* recheck and proper locking in *_core() */
33465 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33466 index 1a88370..3f598b5 100644
33467 --- a/arch/x86/mm/numa.c
33468 +++ b/arch/x86/mm/numa.c
33469 @@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33470 }
33471 }
33472
33473 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33474 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33475 {
33476 unsigned long uninitialized_var(pfn_align);
33477 int i, nid;
33478 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33479 index 36de293..b820ddc 100644
33480 --- a/arch/x86/mm/pageattr.c
33481 +++ b/arch/x86/mm/pageattr.c
33482 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33483 */
33484 #ifdef CONFIG_PCI_BIOS
33485 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33486 - pgprot_val(forbidden) |= _PAGE_NX;
33487 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33488 #endif
33489
33490 /*
33491 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33492 * Does not cover __inittext since that is gone later on. On
33493 * 64bit we do not enforce !NX on the low mapping
33494 */
33495 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33496 - pgprot_val(forbidden) |= _PAGE_NX;
33497 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33498 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33499
33500 +#ifdef CONFIG_DEBUG_RODATA
33501 /*
33502 * The .rodata section needs to be read-only. Using the pfn
33503 * catches all aliases.
33504 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33505 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33506 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33507 pgprot_val(forbidden) |= _PAGE_RW;
33508 +#endif
33509
33510 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33511 /*
33512 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33513 }
33514 #endif
33515
33516 +#ifdef CONFIG_PAX_KERNEXEC
33517 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33518 + pgprot_val(forbidden) |= _PAGE_RW;
33519 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33520 + }
33521 +#endif
33522 +
33523 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33524
33525 return prot;
33526 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33527 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33528 {
33529 /* change init_mm */
33530 + pax_open_kernel();
33531 set_pte_atomic(kpte, pte);
33532 +
33533 #ifdef CONFIG_X86_32
33534 if (!SHARED_KERNEL_PMD) {
33535 +
33536 +#ifdef CONFIG_PAX_PER_CPU_PGD
33537 + unsigned long cpu;
33538 +#else
33539 struct page *page;
33540 +#endif
33541
33542 +#ifdef CONFIG_PAX_PER_CPU_PGD
33543 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33544 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33545 +#else
33546 list_for_each_entry(page, &pgd_list, lru) {
33547 - pgd_t *pgd;
33548 + pgd_t *pgd = (pgd_t *)page_address(page);
33549 +#endif
33550 +
33551 pud_t *pud;
33552 pmd_t *pmd;
33553
33554 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33555 + pgd += pgd_index(address);
33556 pud = pud_offset(pgd, address);
33557 pmd = pmd_offset(pud, address);
33558 set_pte_atomic((pte_t *)pmd, pte);
33559 }
33560 }
33561 #endif
33562 + pax_close_kernel();
33563 }
33564
33565 static int
33566 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33567 index 6574388..87e9bef 100644
33568 --- a/arch/x86/mm/pat.c
33569 +++ b/arch/x86/mm/pat.c
33570 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33571
33572 if (!entry) {
33573 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33574 - current->comm, current->pid, start, end - 1);
33575 + current->comm, task_pid_nr(current), start, end - 1);
33576 return -EINVAL;
33577 }
33578
33579 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33580
33581 while (cursor < to) {
33582 if (!devmem_is_allowed(pfn)) {
33583 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33584 - current->comm, from, to - 1);
33585 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33586 + current->comm, from, to - 1, cursor);
33587 return 0;
33588 }
33589 cursor += PAGE_SIZE;
33590 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33591 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33592 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33593 "for [mem %#010Lx-%#010Lx]\n",
33594 - current->comm, current->pid,
33595 + current->comm, task_pid_nr(current),
33596 cattr_name(flags),
33597 base, (unsigned long long)(base + size-1));
33598 return -EINVAL;
33599 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33600 flags = lookup_memtype(paddr);
33601 if (want_flags != flags) {
33602 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33603 - current->comm, current->pid,
33604 + current->comm, task_pid_nr(current),
33605 cattr_name(want_flags),
33606 (unsigned long long)paddr,
33607 (unsigned long long)(paddr + size - 1),
33608 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33609 free_memtype(paddr, paddr + size);
33610 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33611 " for [mem %#010Lx-%#010Lx], got %s\n",
33612 - current->comm, current->pid,
33613 + current->comm, task_pid_nr(current),
33614 cattr_name(want_flags),
33615 (unsigned long long)paddr,
33616 (unsigned long long)(paddr + size - 1),
33617 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33618 index 415f6c4..d319983 100644
33619 --- a/arch/x86/mm/pat_rbtree.c
33620 +++ b/arch/x86/mm/pat_rbtree.c
33621 @@ -160,7 +160,7 @@ success:
33622
33623 failure:
33624 printk(KERN_INFO "%s:%d conflicting memory types "
33625 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33626 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33627 end, cattr_name(found_type), cattr_name(match->type));
33628 return -EBUSY;
33629 }
33630 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33631 index 9f0614d..92ae64a 100644
33632 --- a/arch/x86/mm/pf_in.c
33633 +++ b/arch/x86/mm/pf_in.c
33634 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33635 int i;
33636 enum reason_type rv = OTHERS;
33637
33638 - p = (unsigned char *)ins_addr;
33639 + p = (unsigned char *)ktla_ktva(ins_addr);
33640 p += skip_prefix(p, &prf);
33641 p += get_opcode(p, &opcode);
33642
33643 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33644 struct prefix_bits prf;
33645 int i;
33646
33647 - p = (unsigned char *)ins_addr;
33648 + p = (unsigned char *)ktla_ktva(ins_addr);
33649 p += skip_prefix(p, &prf);
33650 p += get_opcode(p, &opcode);
33651
33652 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33653 struct prefix_bits prf;
33654 int i;
33655
33656 - p = (unsigned char *)ins_addr;
33657 + p = (unsigned char *)ktla_ktva(ins_addr);
33658 p += skip_prefix(p, &prf);
33659 p += get_opcode(p, &opcode);
33660
33661 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33662 struct prefix_bits prf;
33663 int i;
33664
33665 - p = (unsigned char *)ins_addr;
33666 + p = (unsigned char *)ktla_ktva(ins_addr);
33667 p += skip_prefix(p, &prf);
33668 p += get_opcode(p, &opcode);
33669 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33670 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33671 struct prefix_bits prf;
33672 int i;
33673
33674 - p = (unsigned char *)ins_addr;
33675 + p = (unsigned char *)ktla_ktva(ins_addr);
33676 p += skip_prefix(p, &prf);
33677 p += get_opcode(p, &opcode);
33678 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33679 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33680 index 6fb6927..4fc13c0 100644
33681 --- a/arch/x86/mm/pgtable.c
33682 +++ b/arch/x86/mm/pgtable.c
33683 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33684 list_del(&page->lru);
33685 }
33686
33687 -#define UNSHARED_PTRS_PER_PGD \
33688 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33689 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33690 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33691
33692 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33693 +{
33694 + unsigned int count = USER_PGD_PTRS;
33695
33696 + if (!pax_user_shadow_base)
33697 + return;
33698 +
33699 + while (count--)
33700 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33701 +}
33702 +#endif
33703 +
33704 +#ifdef CONFIG_PAX_PER_CPU_PGD
33705 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33706 +{
33707 + unsigned int count = USER_PGD_PTRS;
33708 +
33709 + while (count--) {
33710 + pgd_t pgd;
33711 +
33712 +#ifdef CONFIG_X86_64
33713 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33714 +#else
33715 + pgd = *src++;
33716 +#endif
33717 +
33718 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33719 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33720 +#endif
33721 +
33722 + *dst++ = pgd;
33723 + }
33724 +
33725 +}
33726 +#endif
33727 +
33728 +#ifdef CONFIG_X86_64
33729 +#define pxd_t pud_t
33730 +#define pyd_t pgd_t
33731 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33732 +#define pgtable_pxd_page_ctor(page) true
33733 +#define pgtable_pxd_page_dtor(page)
33734 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33735 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33736 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33737 +#define PYD_SIZE PGDIR_SIZE
33738 +#else
33739 +#define pxd_t pmd_t
33740 +#define pyd_t pud_t
33741 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33742 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33743 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33744 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33745 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33746 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33747 +#define PYD_SIZE PUD_SIZE
33748 +#endif
33749 +
33750 +#ifdef CONFIG_PAX_PER_CPU_PGD
33751 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33752 +static inline void pgd_dtor(pgd_t *pgd) {}
33753 +#else
33754 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33755 {
33756 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33757 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33758 pgd_list_del(pgd);
33759 spin_unlock(&pgd_lock);
33760 }
33761 +#endif
33762
33763 /*
33764 * List of all pgd's needed for non-PAE so it can invalidate entries
33765 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33766 * -- nyc
33767 */
33768
33769 -#ifdef CONFIG_X86_PAE
33770 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33771 /*
33772 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33773 * updating the top-level pagetable entries to guarantee the
33774 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33775 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33776 * and initialize the kernel pmds here.
33777 */
33778 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33779 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33780
33781 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33782 {
33783 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33784 */
33785 flush_tlb_mm(mm);
33786 }
33787 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33788 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33789 #else /* !CONFIG_X86_PAE */
33790
33791 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33792 -#define PREALLOCATED_PMDS 0
33793 +#define PREALLOCATED_PXDS 0
33794
33795 #endif /* CONFIG_X86_PAE */
33796
33797 -static void free_pmds(pmd_t *pmds[])
33798 +static void free_pxds(pxd_t *pxds[])
33799 {
33800 int i;
33801
33802 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33803 - if (pmds[i]) {
33804 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33805 - free_page((unsigned long)pmds[i]);
33806 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33807 + if (pxds[i]) {
33808 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33809 + free_page((unsigned long)pxds[i]);
33810 }
33811 }
33812
33813 -static int preallocate_pmds(pmd_t *pmds[])
33814 +static int preallocate_pxds(pxd_t *pxds[])
33815 {
33816 int i;
33817 bool failed = false;
33818
33819 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33820 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33821 - if (!pmd)
33822 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33823 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33824 + if (!pxd)
33825 failed = true;
33826 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33827 - free_page((unsigned long)pmd);
33828 - pmd = NULL;
33829 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33830 + free_page((unsigned long)pxd);
33831 + pxd = NULL;
33832 failed = true;
33833 }
33834 - pmds[i] = pmd;
33835 + pxds[i] = pxd;
33836 }
33837
33838 if (failed) {
33839 - free_pmds(pmds);
33840 + free_pxds(pxds);
33841 return -ENOMEM;
33842 }
33843
33844 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33845 * preallocate which never got a corresponding vma will need to be
33846 * freed manually.
33847 */
33848 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33849 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33850 {
33851 int i;
33852
33853 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33854 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33855 pgd_t pgd = pgdp[i];
33856
33857 if (pgd_val(pgd) != 0) {
33858 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33859 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33860
33861 - pgdp[i] = native_make_pgd(0);
33862 + set_pgd(pgdp + i, native_make_pgd(0));
33863
33864 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33865 - pmd_free(mm, pmd);
33866 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33867 + pxd_free(mm, pxd);
33868 }
33869 }
33870 }
33871
33872 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33873 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33874 {
33875 - pud_t *pud;
33876 + pyd_t *pyd;
33877 int i;
33878
33879 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33880 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33881 return;
33882
33883 - pud = pud_offset(pgd, 0);
33884 -
33885 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33886 - pmd_t *pmd = pmds[i];
33887 +#ifdef CONFIG_X86_64
33888 + pyd = pyd_offset(mm, 0L);
33889 +#else
33890 + pyd = pyd_offset(pgd, 0L);
33891 +#endif
33892
33893 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33894 + pxd_t *pxd = pxds[i];
33895 if (i >= KERNEL_PGD_BOUNDARY)
33896 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33897 - sizeof(pmd_t) * PTRS_PER_PMD);
33898 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33899 + sizeof(pxd_t) * PTRS_PER_PMD);
33900
33901 - pud_populate(mm, pud, pmd);
33902 + pyd_populate(mm, pyd, pxd);
33903 }
33904 }
33905
33906 pgd_t *pgd_alloc(struct mm_struct *mm)
33907 {
33908 pgd_t *pgd;
33909 - pmd_t *pmds[PREALLOCATED_PMDS];
33910 + pxd_t *pxds[PREALLOCATED_PXDS];
33911
33912 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33913
33914 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33915
33916 mm->pgd = pgd;
33917
33918 - if (preallocate_pmds(pmds) != 0)
33919 + if (preallocate_pxds(pxds) != 0)
33920 goto out_free_pgd;
33921
33922 if (paravirt_pgd_alloc(mm) != 0)
33923 - goto out_free_pmds;
33924 + goto out_free_pxds;
33925
33926 /*
33927 * Make sure that pre-populating the pmds is atomic with
33928 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33929 spin_lock(&pgd_lock);
33930
33931 pgd_ctor(mm, pgd);
33932 - pgd_prepopulate_pmd(mm, pgd, pmds);
33933 + pgd_prepopulate_pxd(mm, pgd, pxds);
33934
33935 spin_unlock(&pgd_lock);
33936
33937 return pgd;
33938
33939 -out_free_pmds:
33940 - free_pmds(pmds);
33941 +out_free_pxds:
33942 + free_pxds(pxds);
33943 out_free_pgd:
33944 free_page((unsigned long)pgd);
33945 out:
33946 @@ -313,7 +380,7 @@ out:
33947
33948 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33949 {
33950 - pgd_mop_up_pmds(mm, pgd);
33951 + pgd_mop_up_pxds(mm, pgd);
33952 pgd_dtor(pgd);
33953 paravirt_pgd_free(mm, pgd);
33954 free_page((unsigned long)pgd);
33955 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33956 index 75cc097..79a097f 100644
33957 --- a/arch/x86/mm/pgtable_32.c
33958 +++ b/arch/x86/mm/pgtable_32.c
33959 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33960 return;
33961 }
33962 pte = pte_offset_kernel(pmd, vaddr);
33963 +
33964 + pax_open_kernel();
33965 if (pte_val(pteval))
33966 set_pte_at(&init_mm, vaddr, pte, pteval);
33967 else
33968 pte_clear(&init_mm, vaddr, pte);
33969 + pax_close_kernel();
33970
33971 /*
33972 * It's enough to flush this one mapping.
33973 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33974 index e666cbb..61788c45 100644
33975 --- a/arch/x86/mm/physaddr.c
33976 +++ b/arch/x86/mm/physaddr.c
33977 @@ -10,7 +10,7 @@
33978 #ifdef CONFIG_X86_64
33979
33980 #ifdef CONFIG_DEBUG_VIRTUAL
33981 -unsigned long __phys_addr(unsigned long x)
33982 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33983 {
33984 unsigned long y = x - __START_KERNEL_map;
33985
33986 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33987 #else
33988
33989 #ifdef CONFIG_DEBUG_VIRTUAL
33990 -unsigned long __phys_addr(unsigned long x)
33991 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33992 {
33993 unsigned long phys_addr = x - PAGE_OFFSET;
33994 /* VMALLOC_* aren't constants */
33995 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33996 index 90555bf..f5f1828 100644
33997 --- a/arch/x86/mm/setup_nx.c
33998 +++ b/arch/x86/mm/setup_nx.c
33999 @@ -5,8 +5,10 @@
34000 #include <asm/pgtable.h>
34001 #include <asm/proto.h>
34002
34003 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34004 static int disable_nx;
34005
34006 +#ifndef CONFIG_PAX_PAGEEXEC
34007 /*
34008 * noexec = on|off
34009 *
34010 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34011 return 0;
34012 }
34013 early_param("noexec", noexec_setup);
34014 +#endif
34015 +
34016 +#endif
34017
34018 void x86_configure_nx(void)
34019 {
34020 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34021 if (cpu_has_nx && !disable_nx)
34022 __supported_pte_mask |= _PAGE_NX;
34023 else
34024 +#endif
34025 __supported_pte_mask &= ~_PAGE_NX;
34026 }
34027
34028 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34029 index ee61c36..e6fedeb 100644
34030 --- a/arch/x86/mm/tlb.c
34031 +++ b/arch/x86/mm/tlb.c
34032 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34033 BUG();
34034 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34035 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34036 +
34037 +#ifndef CONFIG_PAX_PER_CPU_PGD
34038 load_cr3(swapper_pg_dir);
34039 +#endif
34040 +
34041 /*
34042 * This gets called in the idle path where RCU
34043 * functions differently. Tracing normally
34044 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34045 new file mode 100644
34046 index 0000000..dace51c
34047 --- /dev/null
34048 +++ b/arch/x86/mm/uderef_64.c
34049 @@ -0,0 +1,37 @@
34050 +#include <linux/mm.h>
34051 +#include <asm/pgtable.h>
34052 +#include <asm/uaccess.h>
34053 +
34054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34055 +/* PaX: due to the special call convention these functions must
34056 + * - remain leaf functions under all configurations,
34057 + * - never be called directly, only dereferenced from the wrappers.
34058 + */
34059 +void __pax_open_userland(void)
34060 +{
34061 + unsigned int cpu;
34062 +
34063 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34064 + return;
34065 +
34066 + cpu = raw_get_cpu();
34067 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34068 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34069 + raw_put_cpu_no_resched();
34070 +}
34071 +EXPORT_SYMBOL(__pax_open_userland);
34072 +
34073 +void __pax_close_userland(void)
34074 +{
34075 + unsigned int cpu;
34076 +
34077 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34078 + return;
34079 +
34080 + cpu = raw_get_cpu();
34081 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34082 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34083 + raw_put_cpu_no_resched();
34084 +}
34085 +EXPORT_SYMBOL(__pax_close_userland);
34086 +#endif
34087 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34088 index 6440221..f84b5c7 100644
34089 --- a/arch/x86/net/bpf_jit.S
34090 +++ b/arch/x86/net/bpf_jit.S
34091 @@ -9,6 +9,7 @@
34092 */
34093 #include <linux/linkage.h>
34094 #include <asm/dwarf2.h>
34095 +#include <asm/alternative-asm.h>
34096
34097 /*
34098 * Calling convention :
34099 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34100 jle bpf_slow_path_word
34101 mov (SKBDATA,%rsi),%eax
34102 bswap %eax /* ntohl() */
34103 + pax_force_retaddr
34104 ret
34105
34106 sk_load_half:
34107 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34108 jle bpf_slow_path_half
34109 movzwl (SKBDATA,%rsi),%eax
34110 rol $8,%ax # ntohs()
34111 + pax_force_retaddr
34112 ret
34113
34114 sk_load_byte:
34115 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34116 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34117 jle bpf_slow_path_byte
34118 movzbl (SKBDATA,%rsi),%eax
34119 + pax_force_retaddr
34120 ret
34121
34122 /* rsi contains offset and can be scratched */
34123 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34124 js bpf_error
34125 mov - MAX_BPF_STACK + 32(%rbp),%eax
34126 bswap %eax
34127 + pax_force_retaddr
34128 ret
34129
34130 bpf_slow_path_half:
34131 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34132 mov - MAX_BPF_STACK + 32(%rbp),%ax
34133 rol $8,%ax
34134 movzwl %ax,%eax
34135 + pax_force_retaddr
34136 ret
34137
34138 bpf_slow_path_byte:
34139 bpf_slow_path_common(1)
34140 js bpf_error
34141 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34142 + pax_force_retaddr
34143 ret
34144
34145 #define sk_negative_common(SIZE) \
34146 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34147 sk_negative_common(4)
34148 mov (%rax), %eax
34149 bswap %eax
34150 + pax_force_retaddr
34151 ret
34152
34153 bpf_slow_path_half_neg:
34154 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34155 mov (%rax),%ax
34156 rol $8,%ax
34157 movzwl %ax,%eax
34158 + pax_force_retaddr
34159 ret
34160
34161 bpf_slow_path_byte_neg:
34162 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34163 .globl sk_load_byte_negative_offset
34164 sk_negative_common(1)
34165 movzbl (%rax), %eax
34166 + pax_force_retaddr
34167 ret
34168
34169 bpf_error:
34170 @@ -156,4 +166,5 @@ bpf_error:
34171 mov - MAX_BPF_STACK + 16(%rbp),%r14
34172 mov - MAX_BPF_STACK + 24(%rbp),%r15
34173 leaveq
34174 + pax_force_retaddr
34175 ret
34176 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34177 index 3f62734..a57894f 100644
34178 --- a/arch/x86/net/bpf_jit_comp.c
34179 +++ b/arch/x86/net/bpf_jit_comp.c
34180 @@ -13,7 +13,11 @@
34181 #include <linux/if_vlan.h>
34182 #include <asm/cacheflush.h>
34183
34184 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34185 +int bpf_jit_enable __read_only;
34186 +#else
34187 int bpf_jit_enable __read_mostly;
34188 +#endif
34189
34190 /*
34191 * assembly code in arch/x86/net/bpf_jit.S
34192 @@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34193 static void jit_fill_hole(void *area, unsigned int size)
34194 {
34195 /* fill whole space with int3 instructions */
34196 + pax_open_kernel();
34197 memset(area, 0xcc, size);
34198 + pax_close_kernel();
34199 }
34200
34201 struct jit_context {
34202 @@ -894,7 +900,9 @@ common_load:
34203 pr_err("bpf_jit_compile fatal error\n");
34204 return -EFAULT;
34205 }
34206 + pax_open_kernel();
34207 memcpy(image + proglen, temp, ilen);
34208 + pax_close_kernel();
34209 }
34210 proglen += ilen;
34211 addrs[i] = proglen;
34212 @@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34213
34214 if (image) {
34215 bpf_flush_icache(header, image + proglen);
34216 - set_memory_ro((unsigned long)header, header->pages);
34217 prog->bpf_func = (void *)image;
34218 prog->jited = true;
34219 }
34220 @@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34221 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34222 struct bpf_binary_header *header = (void *)addr;
34223
34224 - if (!fp->jited)
34225 - goto free_filter;
34226 + if (fp->jited)
34227 + bpf_jit_binary_free(header);
34228
34229 - set_memory_rw(addr, header->pages);
34230 - bpf_jit_binary_free(header);
34231 -
34232 -free_filter:
34233 bpf_prog_unlock_free(fp);
34234 }
34235 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34236 index 5d04be5..2beeaa2 100644
34237 --- a/arch/x86/oprofile/backtrace.c
34238 +++ b/arch/x86/oprofile/backtrace.c
34239 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34240 struct stack_frame_ia32 *fp;
34241 unsigned long bytes;
34242
34243 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34244 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34245 if (bytes != 0)
34246 return NULL;
34247
34248 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34249 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34250
34251 oprofile_add_trace(bufhead[0].return_address);
34252
34253 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34254 struct stack_frame bufhead[2];
34255 unsigned long bytes;
34256
34257 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34258 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34259 if (bytes != 0)
34260 return NULL;
34261
34262 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34263 {
34264 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34265
34266 - if (!user_mode_vm(regs)) {
34267 + if (!user_mode(regs)) {
34268 unsigned long stack = kernel_stack_pointer(regs);
34269 if (depth)
34270 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34271 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34272 index 1d2e639..f6ef82a 100644
34273 --- a/arch/x86/oprofile/nmi_int.c
34274 +++ b/arch/x86/oprofile/nmi_int.c
34275 @@ -23,6 +23,7 @@
34276 #include <asm/nmi.h>
34277 #include <asm/msr.h>
34278 #include <asm/apic.h>
34279 +#include <asm/pgtable.h>
34280
34281 #include "op_counter.h"
34282 #include "op_x86_model.h"
34283 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34284 if (ret)
34285 return ret;
34286
34287 - if (!model->num_virt_counters)
34288 - model->num_virt_counters = model->num_counters;
34289 + if (!model->num_virt_counters) {
34290 + pax_open_kernel();
34291 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34292 + pax_close_kernel();
34293 + }
34294
34295 mux_init(ops);
34296
34297 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34298 index 50d86c0..7985318 100644
34299 --- a/arch/x86/oprofile/op_model_amd.c
34300 +++ b/arch/x86/oprofile/op_model_amd.c
34301 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34302 num_counters = AMD64_NUM_COUNTERS;
34303 }
34304
34305 - op_amd_spec.num_counters = num_counters;
34306 - op_amd_spec.num_controls = num_counters;
34307 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34308 + pax_open_kernel();
34309 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34310 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34311 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34312 + pax_close_kernel();
34313
34314 return 0;
34315 }
34316 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34317 index d90528e..0127e2b 100644
34318 --- a/arch/x86/oprofile/op_model_ppro.c
34319 +++ b/arch/x86/oprofile/op_model_ppro.c
34320 @@ -19,6 +19,7 @@
34321 #include <asm/msr.h>
34322 #include <asm/apic.h>
34323 #include <asm/nmi.h>
34324 +#include <asm/pgtable.h>
34325
34326 #include "op_x86_model.h"
34327 #include "op_counter.h"
34328 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34329
34330 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34331
34332 - op_arch_perfmon_spec.num_counters = num_counters;
34333 - op_arch_perfmon_spec.num_controls = num_counters;
34334 + pax_open_kernel();
34335 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34336 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34337 + pax_close_kernel();
34338 }
34339
34340 static int arch_perfmon_init(struct oprofile_operations *ignore)
34341 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34342 index 71e8a67..6a313bb 100644
34343 --- a/arch/x86/oprofile/op_x86_model.h
34344 +++ b/arch/x86/oprofile/op_x86_model.h
34345 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34346 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34347 struct op_msrs const * const msrs);
34348 #endif
34349 -};
34350 +} __do_const;
34351
34352 struct op_counter_config;
34353
34354 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34355 index b9958c3..24229ab 100644
34356 --- a/arch/x86/pci/intel_mid_pci.c
34357 +++ b/arch/x86/pci/intel_mid_pci.c
34358 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34359 pci_mmcfg_late_init();
34360 pcibios_enable_irq = intel_mid_pci_irq_enable;
34361 pcibios_disable_irq = intel_mid_pci_irq_disable;
34362 - pci_root_ops = intel_mid_pci_ops;
34363 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34364 pci_soc_mode = 1;
34365 /* Continue with standard init */
34366 return 1;
34367 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34368 index eb500c2..eab9e70 100644
34369 --- a/arch/x86/pci/irq.c
34370 +++ b/arch/x86/pci/irq.c
34371 @@ -51,7 +51,7 @@ struct irq_router {
34372 struct irq_router_handler {
34373 u16 vendor;
34374 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34375 -};
34376 +} __do_const;
34377
34378 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34379 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34380 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34381 return 0;
34382 }
34383
34384 -static __initdata struct irq_router_handler pirq_routers[] = {
34385 +static __initconst const struct irq_router_handler pirq_routers[] = {
34386 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34387 { PCI_VENDOR_ID_AL, ali_router_probe },
34388 { PCI_VENDOR_ID_ITE, ite_router_probe },
34389 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34390 static void __init pirq_find_router(struct irq_router *r)
34391 {
34392 struct irq_routing_table *rt = pirq_table;
34393 - struct irq_router_handler *h;
34394 + const struct irq_router_handler *h;
34395
34396 #ifdef CONFIG_PCI_BIOS
34397 if (!rt->signature) {
34398 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34399 return 0;
34400 }
34401
34402 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34403 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34404 {
34405 .callback = fix_broken_hp_bios_irq9,
34406 .ident = "HP Pavilion N5400 Series Laptop",
34407 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34408 index 9b83b90..4112152 100644
34409 --- a/arch/x86/pci/pcbios.c
34410 +++ b/arch/x86/pci/pcbios.c
34411 @@ -79,7 +79,7 @@ union bios32 {
34412 static struct {
34413 unsigned long address;
34414 unsigned short segment;
34415 -} bios32_indirect __initdata = { 0, __KERNEL_CS };
34416 +} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34417
34418 /*
34419 * Returns the entry point for the given service, NULL on error
34420 @@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34421 unsigned long length; /* %ecx */
34422 unsigned long entry; /* %edx */
34423 unsigned long flags;
34424 + struct desc_struct d, *gdt;
34425
34426 local_irq_save(flags);
34427 - __asm__("lcall *(%%edi); cld"
34428 +
34429 + gdt = get_cpu_gdt_table(smp_processor_id());
34430 +
34431 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34432 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34433 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34434 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34435 +
34436 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34437 : "=a" (return_code),
34438 "=b" (address),
34439 "=c" (length),
34440 "=d" (entry)
34441 : "0" (service),
34442 "1" (0),
34443 - "D" (&bios32_indirect));
34444 + "D" (&bios32_indirect),
34445 + "r"(__PCIBIOS_DS)
34446 + : "memory");
34447 +
34448 + pax_open_kernel();
34449 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34450 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34451 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34452 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34453 + pax_close_kernel();
34454 +
34455 local_irq_restore(flags);
34456
34457 switch (return_code) {
34458 - case 0:
34459 - return address + entry;
34460 - case 0x80: /* Not present */
34461 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34462 - return 0;
34463 - default: /* Shouldn't happen */
34464 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34465 - service, return_code);
34466 + case 0: {
34467 + int cpu;
34468 + unsigned char flags;
34469 +
34470 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34471 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34472 + printk(KERN_WARNING "bios32_service: not valid\n");
34473 return 0;
34474 + }
34475 + address = address + PAGE_OFFSET;
34476 + length += 16UL; /* some BIOSs underreport this... */
34477 + flags = 4;
34478 + if (length >= 64*1024*1024) {
34479 + length >>= PAGE_SHIFT;
34480 + flags |= 8;
34481 + }
34482 +
34483 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34484 + gdt = get_cpu_gdt_table(cpu);
34485 + pack_descriptor(&d, address, length, 0x9b, flags);
34486 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34487 + pack_descriptor(&d, address, length, 0x93, flags);
34488 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34489 + }
34490 + return entry;
34491 + }
34492 + case 0x80: /* Not present */
34493 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34494 + return 0;
34495 + default: /* Shouldn't happen */
34496 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34497 + service, return_code);
34498 + return 0;
34499 }
34500 }
34501
34502 static struct {
34503 unsigned long address;
34504 unsigned short segment;
34505 -} pci_indirect = { 0, __KERNEL_CS };
34506 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34507
34508 -static int pci_bios_present;
34509 +static int pci_bios_present __read_only;
34510
34511 static int __init check_pcibios(void)
34512 {
34513 @@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34514 unsigned long flags, pcibios_entry;
34515
34516 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34517 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34518 + pci_indirect.address = pcibios_entry;
34519
34520 local_irq_save(flags);
34521 - __asm__(
34522 - "lcall *(%%edi); cld\n\t"
34523 + __asm__("movw %w6, %%ds\n\t"
34524 + "lcall *%%ss:(%%edi); cld\n\t"
34525 + "push %%ss\n\t"
34526 + "pop %%ds\n\t"
34527 "jc 1f\n\t"
34528 "xor %%ah, %%ah\n"
34529 "1:"
34530 @@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34531 "=b" (ebx),
34532 "=c" (ecx)
34533 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34534 - "D" (&pci_indirect)
34535 + "D" (&pci_indirect),
34536 + "r" (__PCIBIOS_DS)
34537 : "memory");
34538 local_irq_restore(flags);
34539
34540 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34541
34542 switch (len) {
34543 case 1:
34544 - __asm__("lcall *(%%esi); cld\n\t"
34545 + __asm__("movw %w6, %%ds\n\t"
34546 + "lcall *%%ss:(%%esi); cld\n\t"
34547 + "push %%ss\n\t"
34548 + "pop %%ds\n\t"
34549 "jc 1f\n\t"
34550 "xor %%ah, %%ah\n"
34551 "1:"
34552 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34553 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34554 "b" (bx),
34555 "D" ((long)reg),
34556 - "S" (&pci_indirect));
34557 + "S" (&pci_indirect),
34558 + "r" (__PCIBIOS_DS));
34559 /*
34560 * Zero-extend the result beyond 8 bits, do not trust the
34561 * BIOS having done it:
34562 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34563 *value &= 0xff;
34564 break;
34565 case 2:
34566 - __asm__("lcall *(%%esi); cld\n\t"
34567 + __asm__("movw %w6, %%ds\n\t"
34568 + "lcall *%%ss:(%%esi); cld\n\t"
34569 + "push %%ss\n\t"
34570 + "pop %%ds\n\t"
34571 "jc 1f\n\t"
34572 "xor %%ah, %%ah\n"
34573 "1:"
34574 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34575 : "1" (PCIBIOS_READ_CONFIG_WORD),
34576 "b" (bx),
34577 "D" ((long)reg),
34578 - "S" (&pci_indirect));
34579 + "S" (&pci_indirect),
34580 + "r" (__PCIBIOS_DS));
34581 /*
34582 * Zero-extend the result beyond 16 bits, do not trust the
34583 * BIOS having done it:
34584 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34585 *value &= 0xffff;
34586 break;
34587 case 4:
34588 - __asm__("lcall *(%%esi); cld\n\t"
34589 + __asm__("movw %w6, %%ds\n\t"
34590 + "lcall *%%ss:(%%esi); cld\n\t"
34591 + "push %%ss\n\t"
34592 + "pop %%ds\n\t"
34593 "jc 1f\n\t"
34594 "xor %%ah, %%ah\n"
34595 "1:"
34596 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34597 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34598 "b" (bx),
34599 "D" ((long)reg),
34600 - "S" (&pci_indirect));
34601 + "S" (&pci_indirect),
34602 + "r" (__PCIBIOS_DS));
34603 break;
34604 }
34605
34606 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34607
34608 switch (len) {
34609 case 1:
34610 - __asm__("lcall *(%%esi); cld\n\t"
34611 + __asm__("movw %w6, %%ds\n\t"
34612 + "lcall *%%ss:(%%esi); cld\n\t"
34613 + "push %%ss\n\t"
34614 + "pop %%ds\n\t"
34615 "jc 1f\n\t"
34616 "xor %%ah, %%ah\n"
34617 "1:"
34618 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34619 "c" (value),
34620 "b" (bx),
34621 "D" ((long)reg),
34622 - "S" (&pci_indirect));
34623 + "S" (&pci_indirect),
34624 + "r" (__PCIBIOS_DS));
34625 break;
34626 case 2:
34627 - __asm__("lcall *(%%esi); cld\n\t"
34628 + __asm__("movw %w6, %%ds\n\t"
34629 + "lcall *%%ss:(%%esi); cld\n\t"
34630 + "push %%ss\n\t"
34631 + "pop %%ds\n\t"
34632 "jc 1f\n\t"
34633 "xor %%ah, %%ah\n"
34634 "1:"
34635 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34636 "c" (value),
34637 "b" (bx),
34638 "D" ((long)reg),
34639 - "S" (&pci_indirect));
34640 + "S" (&pci_indirect),
34641 + "r" (__PCIBIOS_DS));
34642 break;
34643 case 4:
34644 - __asm__("lcall *(%%esi); cld\n\t"
34645 + __asm__("movw %w6, %%ds\n\t"
34646 + "lcall *%%ss:(%%esi); cld\n\t"
34647 + "push %%ss\n\t"
34648 + "pop %%ds\n\t"
34649 "jc 1f\n\t"
34650 "xor %%ah, %%ah\n"
34651 "1:"
34652 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34653 "c" (value),
34654 "b" (bx),
34655 "D" ((long)reg),
34656 - "S" (&pci_indirect));
34657 + "S" (&pci_indirect),
34658 + "r" (__PCIBIOS_DS));
34659 break;
34660 }
34661
34662 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34663
34664 DBG("PCI: Fetching IRQ routing table... ");
34665 __asm__("push %%es\n\t"
34666 + "movw %w8, %%ds\n\t"
34667 "push %%ds\n\t"
34668 "pop %%es\n\t"
34669 - "lcall *(%%esi); cld\n\t"
34670 + "lcall *%%ss:(%%esi); cld\n\t"
34671 "pop %%es\n\t"
34672 + "push %%ss\n\t"
34673 + "pop %%ds\n"
34674 "jc 1f\n\t"
34675 "xor %%ah, %%ah\n"
34676 "1:"
34677 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34678 "1" (0),
34679 "D" ((long) &opt),
34680 "S" (&pci_indirect),
34681 - "m" (opt)
34682 + "m" (opt),
34683 + "r" (__PCIBIOS_DS)
34684 : "memory");
34685 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34686 if (ret & 0xff00)
34687 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34688 {
34689 int ret;
34690
34691 - __asm__("lcall *(%%esi); cld\n\t"
34692 + __asm__("movw %w5, %%ds\n\t"
34693 + "lcall *%%ss:(%%esi); cld\n\t"
34694 + "push %%ss\n\t"
34695 + "pop %%ds\n"
34696 "jc 1f\n\t"
34697 "xor %%ah, %%ah\n"
34698 "1:"
34699 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34700 : "0" (PCIBIOS_SET_PCI_HW_INT),
34701 "b" ((dev->bus->number << 8) | dev->devfn),
34702 "c" ((irq << 8) | (pin + 10)),
34703 - "S" (&pci_indirect));
34704 + "S" (&pci_indirect),
34705 + "r" (__PCIBIOS_DS));
34706 return !(ret & 0xff00);
34707 }
34708 EXPORT_SYMBOL(pcibios_set_irq_routing);
34709 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34710 index 40e7cda..c7e6672 100644
34711 --- a/arch/x86/platform/efi/efi_32.c
34712 +++ b/arch/x86/platform/efi/efi_32.c
34713 @@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34714 {
34715 struct desc_ptr gdt_descr;
34716
34717 +#ifdef CONFIG_PAX_KERNEXEC
34718 + struct desc_struct d;
34719 +#endif
34720 +
34721 local_irq_save(efi_rt_eflags);
34722
34723 load_cr3(initial_page_table);
34724 __flush_tlb_all();
34725
34726 +#ifdef CONFIG_PAX_KERNEXEC
34727 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34728 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34729 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34730 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34731 +#endif
34732 +
34733 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34734 gdt_descr.size = GDT_SIZE - 1;
34735 load_gdt(&gdt_descr);
34736 @@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34737 {
34738 struct desc_ptr gdt_descr;
34739
34740 +#ifdef CONFIG_PAX_KERNEXEC
34741 + struct desc_struct d;
34742 +
34743 + memset(&d, 0, sizeof d);
34744 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34745 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34746 +#endif
34747 +
34748 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34749 gdt_descr.size = GDT_SIZE - 1;
34750 load_gdt(&gdt_descr);
34751
34752 +#ifdef CONFIG_PAX_PER_CPU_PGD
34753 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34754 +#else
34755 load_cr3(swapper_pg_dir);
34756 +#endif
34757 +
34758 __flush_tlb_all();
34759
34760 local_irq_restore(efi_rt_eflags);
34761 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34762 index 35aecb6..46177db 100644
34763 --- a/arch/x86/platform/efi/efi_64.c
34764 +++ b/arch/x86/platform/efi/efi_64.c
34765 @@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34766 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34767 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34768 }
34769 +
34770 +#ifdef CONFIG_PAX_PER_CPU_PGD
34771 + load_cr3(swapper_pg_dir);
34772 +#endif
34773 +
34774 __flush_tlb_all();
34775 }
34776
34777 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34778 for (pgd = 0; pgd < n_pgds; pgd++)
34779 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34780 kfree(save_pgd);
34781 +
34782 +#ifdef CONFIG_PAX_PER_CPU_PGD
34783 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34784 +#endif
34785 +
34786 __flush_tlb_all();
34787 local_irq_restore(efi_flags);
34788 early_code_mapping_set_exec(0);
34789 @@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34790 unsigned npages;
34791 pgd_t *pgd;
34792
34793 - if (efi_enabled(EFI_OLD_MEMMAP))
34794 + if (efi_enabled(EFI_OLD_MEMMAP)) {
34795 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34796 + * able to execute the EFI services.
34797 + */
34798 + if (__supported_pte_mask & _PAGE_NX) {
34799 + unsigned long addr = (unsigned long) __va(0);
34800 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34801 +
34802 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34803 +#ifdef CONFIG_PAX_PER_CPU_PGD
34804 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34805 +#endif
34806 + set_pgd(pgd_offset_k(addr), pe);
34807 + }
34808 +
34809 return 0;
34810 + }
34811
34812 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34813 pgd = __va(efi_scratch.efi_pgt);
34814 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34815 index 040192b..7d3300f 100644
34816 --- a/arch/x86/platform/efi/efi_stub_32.S
34817 +++ b/arch/x86/platform/efi/efi_stub_32.S
34818 @@ -6,7 +6,9 @@
34819 */
34820
34821 #include <linux/linkage.h>
34822 +#include <linux/init.h>
34823 #include <asm/page_types.h>
34824 +#include <asm/segment.h>
34825
34826 /*
34827 * efi_call_phys(void *, ...) is a function with variable parameters.
34828 @@ -20,7 +22,7 @@
34829 * service functions will comply with gcc calling convention, too.
34830 */
34831
34832 -.text
34833 +__INIT
34834 ENTRY(efi_call_phys)
34835 /*
34836 * 0. The function can only be called in Linux kernel. So CS has been
34837 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34838 * The mapping of lower virtual memory has been created in prolog and
34839 * epilog.
34840 */
34841 - movl $1f, %edx
34842 - subl $__PAGE_OFFSET, %edx
34843 - jmp *%edx
34844 +#ifdef CONFIG_PAX_KERNEXEC
34845 + movl $(__KERNEXEC_EFI_DS), %edx
34846 + mov %edx, %ds
34847 + mov %edx, %es
34848 + mov %edx, %ss
34849 + addl $2f,(1f)
34850 + ljmp *(1f)
34851 +
34852 +__INITDATA
34853 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34854 +.previous
34855 +
34856 +2:
34857 + subl $2b,(1b)
34858 +#else
34859 + jmp 1f-__PAGE_OFFSET
34860 1:
34861 +#endif
34862
34863 /*
34864 * 2. Now on the top of stack is the return
34865 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34866 * parameter 2, ..., param n. To make things easy, we save the return
34867 * address of efi_call_phys in a global variable.
34868 */
34869 - popl %edx
34870 - movl %edx, saved_return_addr
34871 - /* get the function pointer into ECX*/
34872 - popl %ecx
34873 - movl %ecx, efi_rt_function_ptr
34874 - movl $2f, %edx
34875 - subl $__PAGE_OFFSET, %edx
34876 - pushl %edx
34877 + popl (saved_return_addr)
34878 + popl (efi_rt_function_ptr)
34879
34880 /*
34881 * 3. Clear PG bit in %CR0.
34882 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34883 /*
34884 * 5. Call the physical function.
34885 */
34886 - jmp *%ecx
34887 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34888
34889 -2:
34890 /*
34891 * 6. After EFI runtime service returns, control will return to
34892 * following instruction. We'd better readjust stack pointer first.
34893 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34894 movl %cr0, %edx
34895 orl $0x80000000, %edx
34896 movl %edx, %cr0
34897 - jmp 1f
34898 -1:
34899 +
34900 /*
34901 * 8. Now restore the virtual mode from flat mode by
34902 * adding EIP with PAGE_OFFSET.
34903 */
34904 - movl $1f, %edx
34905 - jmp *%edx
34906 +#ifdef CONFIG_PAX_KERNEXEC
34907 + movl $(__KERNEL_DS), %edx
34908 + mov %edx, %ds
34909 + mov %edx, %es
34910 + mov %edx, %ss
34911 + ljmp $(__KERNEL_CS),$1f
34912 +#else
34913 + jmp 1f+__PAGE_OFFSET
34914 +#endif
34915 1:
34916
34917 /*
34918 * 9. Balance the stack. And because EAX contain the return value,
34919 * we'd better not clobber it.
34920 */
34921 - leal efi_rt_function_ptr, %edx
34922 - movl (%edx), %ecx
34923 - pushl %ecx
34924 + pushl (efi_rt_function_ptr)
34925
34926 /*
34927 - * 10. Push the saved return address onto the stack and return.
34928 + * 10. Return to the saved return address.
34929 */
34930 - leal saved_return_addr, %edx
34931 - movl (%edx), %ecx
34932 - pushl %ecx
34933 - ret
34934 + jmpl *(saved_return_addr)
34935 ENDPROC(efi_call_phys)
34936 .previous
34937
34938 -.data
34939 +__INITDATA
34940 saved_return_addr:
34941 .long 0
34942 efi_rt_function_ptr:
34943 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34944 index 5fcda72..cd4dc41 100644
34945 --- a/arch/x86/platform/efi/efi_stub_64.S
34946 +++ b/arch/x86/platform/efi/efi_stub_64.S
34947 @@ -11,6 +11,7 @@
34948 #include <asm/msr.h>
34949 #include <asm/processor-flags.h>
34950 #include <asm/page_types.h>
34951 +#include <asm/alternative-asm.h>
34952
34953 #define SAVE_XMM \
34954 mov %rsp, %rax; \
34955 @@ -88,6 +89,7 @@ ENTRY(efi_call)
34956 RESTORE_PGT
34957 addq $48, %rsp
34958 RESTORE_XMM
34959 + pax_force_retaddr 0, 1
34960 ret
34961 ENDPROC(efi_call)
34962
34963 @@ -245,8 +247,8 @@ efi_gdt64:
34964 .long 0 /* Filled out by user */
34965 .word 0
34966 .quad 0x0000000000000000 /* NULL descriptor */
34967 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
34968 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
34969 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
34970 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
34971 .quad 0x0080890000000000 /* TS descriptor */
34972 .quad 0x0000000000000000 /* TS continued */
34973 efi_gdt64_end:
34974 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34975 index 1bbedc4..eb795b5 100644
34976 --- a/arch/x86/platform/intel-mid/intel-mid.c
34977 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34978 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34979 {
34980 };
34981
34982 -static void intel_mid_reboot(void)
34983 +static void __noreturn intel_mid_reboot(void)
34984 {
34985 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34986 + BUG();
34987 }
34988
34989 static unsigned long __init intel_mid_calibrate_tsc(void)
34990 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34991 index 3c1c386..59a68ed 100644
34992 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34993 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34994 @@ -13,6 +13,6 @@
34995 /* For every CPU addition a new get_<cpuname>_ops interface needs
34996 * to be added.
34997 */
34998 -extern void *get_penwell_ops(void);
34999 -extern void *get_cloverview_ops(void);
35000 -extern void *get_tangier_ops(void);
35001 +extern const void *get_penwell_ops(void);
35002 +extern const void *get_cloverview_ops(void);
35003 +extern const void *get_tangier_ops(void);
35004 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35005 index 23381d2..8ddc10e 100644
35006 --- a/arch/x86/platform/intel-mid/mfld.c
35007 +++ b/arch/x86/platform/intel-mid/mfld.c
35008 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35009 pm_power_off = mfld_power_off;
35010 }
35011
35012 -void *get_penwell_ops(void)
35013 +const void *get_penwell_ops(void)
35014 {
35015 return &penwell_ops;
35016 }
35017
35018 -void *get_cloverview_ops(void)
35019 +const void *get_cloverview_ops(void)
35020 {
35021 return &penwell_ops;
35022 }
35023 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35024 index aaca917..66eadbc 100644
35025 --- a/arch/x86/platform/intel-mid/mrfl.c
35026 +++ b/arch/x86/platform/intel-mid/mrfl.c
35027 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35028 .arch_setup = tangier_arch_setup,
35029 };
35030
35031 -void *get_tangier_ops(void)
35032 +const void *get_tangier_ops(void)
35033 {
35034 return &tangier_ops;
35035 }
35036 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35037 index d6ee929..3637cb5 100644
35038 --- a/arch/x86/platform/olpc/olpc_dt.c
35039 +++ b/arch/x86/platform/olpc/olpc_dt.c
35040 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35041 return res;
35042 }
35043
35044 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35045 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35046 .nextprop = olpc_dt_nextprop,
35047 .getproplen = olpc_dt_getproplen,
35048 .getproperty = olpc_dt_getproperty,
35049 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35050 index 6ec7910..ecdbb11 100644
35051 --- a/arch/x86/power/cpu.c
35052 +++ b/arch/x86/power/cpu.c
35053 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35054 static void fix_processor_context(void)
35055 {
35056 int cpu = smp_processor_id();
35057 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35058 -#ifdef CONFIG_X86_64
35059 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35060 - tss_desc tss;
35061 -#endif
35062 + struct tss_struct *t = init_tss + cpu;
35063 +
35064 set_tss_desc(cpu, t); /*
35065 * This just modifies memory; should not be
35066 * necessary. But... This is necessary, because
35067 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35068 */
35069
35070 #ifdef CONFIG_X86_64
35071 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35072 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35073 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35074 -
35075 syscall_init(); /* This sets MSR_*STAR and related */
35076 #endif
35077 load_TR_desc(); /* This does ltr */
35078 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35079 index bad628a..a102610 100644
35080 --- a/arch/x86/realmode/init.c
35081 +++ b/arch/x86/realmode/init.c
35082 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35083 __va(real_mode_header->trampoline_header);
35084
35085 #ifdef CONFIG_X86_32
35086 - trampoline_header->start = __pa_symbol(startup_32_smp);
35087 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35088 +
35089 +#ifdef CONFIG_PAX_KERNEXEC
35090 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35091 +#endif
35092 +
35093 + trampoline_header->boot_cs = __BOOT_CS;
35094 trampoline_header->gdt_limit = __BOOT_DS + 7;
35095 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35096 #else
35097 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35098 *trampoline_cr4_features = read_cr4();
35099
35100 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35101 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35102 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35103 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35104 #endif
35105 }
35106 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35107 index 7c0d7be..d24dc88 100644
35108 --- a/arch/x86/realmode/rm/Makefile
35109 +++ b/arch/x86/realmode/rm/Makefile
35110 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35111
35112 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35113 -I$(srctree)/arch/x86/boot
35114 +ifdef CONSTIFY_PLUGIN
35115 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35116 +endif
35117 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35118 GCOV_PROFILE := n
35119 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35120 index a28221d..93c40f1 100644
35121 --- a/arch/x86/realmode/rm/header.S
35122 +++ b/arch/x86/realmode/rm/header.S
35123 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35124 #endif
35125 /* APM/BIOS reboot */
35126 .long pa_machine_real_restart_asm
35127 -#ifdef CONFIG_X86_64
35128 +#ifdef CONFIG_X86_32
35129 + .long __KERNEL_CS
35130 +#else
35131 .long __KERNEL32_CS
35132 #endif
35133 END(real_mode_header)
35134 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35135 index 48ddd76..c26749f 100644
35136 --- a/arch/x86/realmode/rm/trampoline_32.S
35137 +++ b/arch/x86/realmode/rm/trampoline_32.S
35138 @@ -24,6 +24,12 @@
35139 #include <asm/page_types.h>
35140 #include "realmode.h"
35141
35142 +#ifdef CONFIG_PAX_KERNEXEC
35143 +#define ta(X) (X)
35144 +#else
35145 +#define ta(X) (pa_ ## X)
35146 +#endif
35147 +
35148 .text
35149 .code16
35150
35151 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35152
35153 cli # We should be safe anyway
35154
35155 - movl tr_start, %eax # where we need to go
35156 -
35157 movl $0xA5A5A5A5, trampoline_status
35158 # write marker for master knows we're running
35159
35160 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35161 movw $1, %dx # protected mode (PE) bit
35162 lmsw %dx # into protected mode
35163
35164 - ljmpl $__BOOT_CS, $pa_startup_32
35165 + ljmpl *(trampoline_header)
35166
35167 .section ".text32","ax"
35168 .code32
35169 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35170 .balign 8
35171 GLOBAL(trampoline_header)
35172 tr_start: .space 4
35173 - tr_gdt_pad: .space 2
35174 + tr_boot_cs: .space 2
35175 tr_gdt: .space 6
35176 END(trampoline_header)
35177
35178 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35179 index dac7b20..72dbaca 100644
35180 --- a/arch/x86/realmode/rm/trampoline_64.S
35181 +++ b/arch/x86/realmode/rm/trampoline_64.S
35182 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35183 movl %edx, %gs
35184
35185 movl pa_tr_cr4, %eax
35186 + andl $~X86_CR4_PCIDE, %eax
35187 movl %eax, %cr4 # Enable PAE mode
35188
35189 # Setup trampoline 4 level pagetables
35190 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35191 wrmsr
35192
35193 # Enable paging and in turn activate Long Mode
35194 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35195 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35196 movl %eax, %cr0
35197
35198 /*
35199 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35200 index 9e7e147..25a4158 100644
35201 --- a/arch/x86/realmode/rm/wakeup_asm.S
35202 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35203 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35204 lgdtl pmode_gdt
35205
35206 /* This really couldn't... */
35207 - movl pmode_entry, %eax
35208 movl pmode_cr0, %ecx
35209 movl %ecx, %cr0
35210 - ljmpl $__KERNEL_CS, $pa_startup_32
35211 - /* -> jmp *%eax in trampoline_32.S */
35212 +
35213 + ljmpl *pmode_entry
35214 #else
35215 jmp trampoline_start
35216 #endif
35217 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35218 index 604a37e..e49702a 100644
35219 --- a/arch/x86/tools/Makefile
35220 +++ b/arch/x86/tools/Makefile
35221 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35222
35223 $(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
35224
35225 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35226 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35227 hostprogs-y += relocs
35228 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35229 PHONY += relocs
35230 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35231 index a5efb21..97490e9 100644
35232 --- a/arch/x86/tools/relocs.c
35233 +++ b/arch/x86/tools/relocs.c
35234 @@ -1,5 +1,7 @@
35235 /* This is included from relocs_32/64.c */
35236
35237 +#include "../../../include/generated/autoconf.h"
35238 +
35239 #define ElfW(type) _ElfW(ELF_BITS, type)
35240 #define _ElfW(bits, type) __ElfW(bits, type)
35241 #define __ElfW(bits, type) Elf##bits##_##type
35242 @@ -11,6 +13,7 @@
35243 #define Elf_Sym ElfW(Sym)
35244
35245 static Elf_Ehdr ehdr;
35246 +static Elf_Phdr *phdr;
35247
35248 struct relocs {
35249 uint32_t *offset;
35250 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35251 }
35252 }
35253
35254 +static void read_phdrs(FILE *fp)
35255 +{
35256 + unsigned int i;
35257 +
35258 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35259 + if (!phdr) {
35260 + die("Unable to allocate %d program headers\n",
35261 + ehdr.e_phnum);
35262 + }
35263 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35264 + die("Seek to %d failed: %s\n",
35265 + ehdr.e_phoff, strerror(errno));
35266 + }
35267 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35268 + die("Cannot read ELF program headers: %s\n",
35269 + strerror(errno));
35270 + }
35271 + for(i = 0; i < ehdr.e_phnum; i++) {
35272 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35273 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35274 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35275 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35276 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35277 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35278 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35279 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35280 + }
35281 +
35282 +}
35283 +
35284 static void read_shdrs(FILE *fp)
35285 {
35286 - int i;
35287 + unsigned int i;
35288 Elf_Shdr shdr;
35289
35290 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35291 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35292
35293 static void read_strtabs(FILE *fp)
35294 {
35295 - int i;
35296 + unsigned int i;
35297 for (i = 0; i < ehdr.e_shnum; i++) {
35298 struct section *sec = &secs[i];
35299 if (sec->shdr.sh_type != SHT_STRTAB) {
35300 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35301
35302 static void read_symtabs(FILE *fp)
35303 {
35304 - int i,j;
35305 + unsigned int i,j;
35306 for (i = 0; i < ehdr.e_shnum; i++) {
35307 struct section *sec = &secs[i];
35308 if (sec->shdr.sh_type != SHT_SYMTAB) {
35309 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35310 }
35311
35312
35313 -static void read_relocs(FILE *fp)
35314 +static void read_relocs(FILE *fp, int use_real_mode)
35315 {
35316 - int i,j;
35317 + unsigned int i,j;
35318 + uint32_t base;
35319 +
35320 for (i = 0; i < ehdr.e_shnum; i++) {
35321 struct section *sec = &secs[i];
35322 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35323 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35324 die("Cannot read symbol table: %s\n",
35325 strerror(errno));
35326 }
35327 + base = 0;
35328 +
35329 +#ifdef CONFIG_X86_32
35330 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35331 + if (phdr[j].p_type != PT_LOAD )
35332 + continue;
35333 + 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)
35334 + continue;
35335 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35336 + break;
35337 + }
35338 +#endif
35339 +
35340 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35341 Elf_Rel *rel = &sec->reltab[j];
35342 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35343 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35344 rel->r_info = elf_xword_to_cpu(rel->r_info);
35345 #if (SHT_REL_TYPE == SHT_RELA)
35346 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35347 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35348
35349 static void print_absolute_symbols(void)
35350 {
35351 - int i;
35352 + unsigned int i;
35353 const char *format;
35354
35355 if (ELF_BITS == 64)
35356 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35357 for (i = 0; i < ehdr.e_shnum; i++) {
35358 struct section *sec = &secs[i];
35359 char *sym_strtab;
35360 - int j;
35361 + unsigned int j;
35362
35363 if (sec->shdr.sh_type != SHT_SYMTAB) {
35364 continue;
35365 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35366
35367 static void print_absolute_relocs(void)
35368 {
35369 - int i, printed = 0;
35370 + unsigned int i, printed = 0;
35371 const char *format;
35372
35373 if (ELF_BITS == 64)
35374 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35375 struct section *sec_applies, *sec_symtab;
35376 char *sym_strtab;
35377 Elf_Sym *sh_symtab;
35378 - int j;
35379 + unsigned int j;
35380 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35381 continue;
35382 }
35383 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35384 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35385 Elf_Sym *sym, const char *symname))
35386 {
35387 - int i;
35388 + unsigned int i;
35389 /* Walk through the relocations */
35390 for (i = 0; i < ehdr.e_shnum; i++) {
35391 char *sym_strtab;
35392 Elf_Sym *sh_symtab;
35393 struct section *sec_applies, *sec_symtab;
35394 - int j;
35395 + unsigned int j;
35396 struct section *sec = &secs[i];
35397
35398 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35399 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35400 {
35401 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35402 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35403 + char *sym_strtab = sec->link->link->strtab;
35404 +
35405 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35406 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35407 + return 0;
35408 +
35409 +#ifdef CONFIG_PAX_KERNEXEC
35410 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35411 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35412 + return 0;
35413 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35414 + return 0;
35415 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35416 + return 0;
35417 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35418 + return 0;
35419 +#endif
35420
35421 switch (r_type) {
35422 case R_386_NONE:
35423 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35424
35425 static void emit_relocs(int as_text, int use_real_mode)
35426 {
35427 - int i;
35428 + unsigned int i;
35429 int (*write_reloc)(uint32_t, FILE *) = write32;
35430 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35431 const char *symname);
35432 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35433 {
35434 regex_init(use_real_mode);
35435 read_ehdr(fp);
35436 + read_phdrs(fp);
35437 read_shdrs(fp);
35438 read_strtabs(fp);
35439 read_symtabs(fp);
35440 - read_relocs(fp);
35441 + read_relocs(fp, use_real_mode);
35442 if (ELF_BITS == 64)
35443 percpu_init();
35444 if (show_absolute_syms) {
35445 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35446 index f40281e..92728c9 100644
35447 --- a/arch/x86/um/mem_32.c
35448 +++ b/arch/x86/um/mem_32.c
35449 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35450 gate_vma.vm_start = FIXADDR_USER_START;
35451 gate_vma.vm_end = FIXADDR_USER_END;
35452 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35453 - gate_vma.vm_page_prot = __P101;
35454 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35455
35456 return 0;
35457 }
35458 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35459 index 80ffa5b..a33bd15 100644
35460 --- a/arch/x86/um/tls_32.c
35461 +++ b/arch/x86/um/tls_32.c
35462 @@ -260,7 +260,7 @@ out:
35463 if (unlikely(task == current &&
35464 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35465 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35466 - "without flushed TLS.", current->pid);
35467 + "without flushed TLS.", task_pid_nr(current));
35468 }
35469
35470 return 0;
35471 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35472 index 5a4affe..9e2d522 100644
35473 --- a/arch/x86/vdso/Makefile
35474 +++ b/arch/x86/vdso/Makefile
35475 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35476 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35477 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35478
35479 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35480 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35481 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35482 GCOV_PROFILE := n
35483
35484 diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35485 index 0224987..c7d65a5 100644
35486 --- a/arch/x86/vdso/vdso2c.h
35487 +++ b/arch/x86/vdso/vdso2c.h
35488 @@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35489 unsigned long load_size = -1; /* Work around bogus warning */
35490 unsigned long mapping_size;
35491 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35492 - int i;
35493 + unsigned int i;
35494 unsigned long j;
35495 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35496 *alt_sec = NULL;
35497 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35498 index e904c27..b9eaa03 100644
35499 --- a/arch/x86/vdso/vdso32-setup.c
35500 +++ b/arch/x86/vdso/vdso32-setup.c
35501 @@ -14,6 +14,7 @@
35502 #include <asm/cpufeature.h>
35503 #include <asm/processor.h>
35504 #include <asm/vdso.h>
35505 +#include <asm/mman.h>
35506
35507 #ifdef CONFIG_COMPAT_VDSO
35508 #define VDSO_DEFAULT 0
35509 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35510 index 208c220..54f1447 100644
35511 --- a/arch/x86/vdso/vma.c
35512 +++ b/arch/x86/vdso/vma.c
35513 @@ -16,10 +16,9 @@
35514 #include <asm/vdso.h>
35515 #include <asm/page.h>
35516 #include <asm/hpet.h>
35517 +#include <asm/mman.h>
35518
35519 #if defined(CONFIG_X86_64)
35520 -unsigned int __read_mostly vdso64_enabled = 1;
35521 -
35522 extern unsigned short vdso_sync_cpuid;
35523 #endif
35524
35525 @@ -114,6 +113,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35526 .pages = no_pages,
35527 };
35528
35529 +#ifdef CONFIG_PAX_RANDMMAP
35530 + if (mm->pax_flags & MF_PAX_RANDMMAP)
35531 + calculate_addr = false;
35532 +#endif
35533 +
35534 if (calculate_addr) {
35535 addr = vdso_addr(current->mm->start_stack,
35536 image->size - image->sym_vvar_start);
35537 @@ -124,14 +128,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35538 down_write(&mm->mmap_sem);
35539
35540 addr = get_unmapped_area(NULL, addr,
35541 - image->size - image->sym_vvar_start, 0, 0);
35542 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35543 if (IS_ERR_VALUE(addr)) {
35544 ret = addr;
35545 goto up_fail;
35546 }
35547
35548 text_start = addr - image->sym_vvar_start;
35549 - current->mm->context.vdso = (void __user *)text_start;
35550 + mm->context.vdso = text_start;
35551
35552 /*
35553 * MAYWRITE to allow gdb to COW and set breakpoints
35554 @@ -176,15 +180,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35555 hpet_address >> PAGE_SHIFT,
35556 PAGE_SIZE,
35557 pgprot_noncached(PAGE_READONLY));
35558 -
35559 - if (ret)
35560 - goto up_fail;
35561 }
35562 #endif
35563
35564 up_fail:
35565 if (ret)
35566 - current->mm->context.vdso = NULL;
35567 + current->mm->context.vdso = 0;
35568
35569 up_write(&mm->mmap_sem);
35570 return ret;
35571 @@ -204,8 +205,8 @@ static int load_vdso32(void)
35572
35573 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35574 current_thread_info()->sysenter_return =
35575 - current->mm->context.vdso +
35576 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35577 + (void __force_user *)(current->mm->context.vdso +
35578 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35579
35580 return 0;
35581 }
35582 @@ -214,9 +215,6 @@ static int load_vdso32(void)
35583 #ifdef CONFIG_X86_64
35584 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35585 {
35586 - if (!vdso64_enabled)
35587 - return 0;
35588 -
35589 return map_vdso(&vdso_image_64, true);
35590 }
35591
35592 @@ -225,12 +223,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35593 int uses_interp)
35594 {
35595 #ifdef CONFIG_X86_X32_ABI
35596 - if (test_thread_flag(TIF_X32)) {
35597 - if (!vdso64_enabled)
35598 - return 0;
35599 -
35600 + if (test_thread_flag(TIF_X32))
35601 return map_vdso(&vdso_image_x32, true);
35602 - }
35603 #endif
35604
35605 return load_vdso32();
35606 @@ -242,12 +236,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35607 return load_vdso32();
35608 }
35609 #endif
35610 -
35611 -#ifdef CONFIG_X86_64
35612 -static __init int vdso_setup(char *s)
35613 -{
35614 - vdso64_enabled = simple_strtoul(s, NULL, 0);
35615 - return 0;
35616 -}
35617 -__setup("vdso=", vdso_setup);
35618 -#endif
35619 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35620 index e88fda8..76ce7ce 100644
35621 --- a/arch/x86/xen/Kconfig
35622 +++ b/arch/x86/xen/Kconfig
35623 @@ -9,6 +9,7 @@ config XEN
35624 select XEN_HAVE_PVMMU
35625 depends on X86_64 || (X86_32 && X86_PAE)
35626 depends on X86_TSC
35627 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35628 help
35629 This is the Linux Xen port. Enabling this will allow the
35630 kernel to boot in a paravirtualized environment under the
35631 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35632 index fac5e4f..89c3525 100644
35633 --- a/arch/x86/xen/enlighten.c
35634 +++ b/arch/x86/xen/enlighten.c
35635 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35636
35637 struct shared_info xen_dummy_shared_info;
35638
35639 -void *xen_initial_gdt;
35640 -
35641 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35642 __read_mostly int xen_have_vector_callback;
35643 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35644 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35645 {
35646 unsigned long va = dtr->address;
35647 unsigned int size = dtr->size + 1;
35648 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35649 - unsigned long frames[pages];
35650 + unsigned long frames[65536 / PAGE_SIZE];
35651 int f;
35652
35653 /*
35654 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35655 {
35656 unsigned long va = dtr->address;
35657 unsigned int size = dtr->size + 1;
35658 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35659 - unsigned long frames[pages];
35660 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35661 int f;
35662
35663 /*
35664 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35665 * 8-byte entries, or 16 4k pages..
35666 */
35667
35668 - BUG_ON(size > 65536);
35669 + BUG_ON(size > GDT_SIZE);
35670 BUG_ON(va & ~PAGE_MASK);
35671
35672 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35673 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35674 return 0;
35675 }
35676
35677 -static void set_xen_basic_apic_ops(void)
35678 +static void __init set_xen_basic_apic_ops(void)
35679 {
35680 apic->read = xen_apic_read;
35681 apic->write = xen_apic_write;
35682 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35683 #endif
35684 };
35685
35686 -static void xen_reboot(int reason)
35687 +static __noreturn void xen_reboot(int reason)
35688 {
35689 struct sched_shutdown r = { .reason = reason };
35690
35691 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35692 - BUG();
35693 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35694 + BUG();
35695 }
35696
35697 -static void xen_restart(char *msg)
35698 +static __noreturn void xen_restart(char *msg)
35699 {
35700 xen_reboot(SHUTDOWN_reboot);
35701 }
35702
35703 -static void xen_emergency_restart(void)
35704 +static __noreturn void xen_emergency_restart(void)
35705 {
35706 xen_reboot(SHUTDOWN_reboot);
35707 }
35708
35709 -static void xen_machine_halt(void)
35710 +static __noreturn void xen_machine_halt(void)
35711 {
35712 xen_reboot(SHUTDOWN_poweroff);
35713 }
35714
35715 -static void xen_machine_power_off(void)
35716 +static __noreturn void xen_machine_power_off(void)
35717 {
35718 if (pm_power_off)
35719 pm_power_off();
35720 @@ -1456,8 +1452,11 @@ static void __ref xen_setup_gdt(int cpu)
35721 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
35722 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
35723
35724 - setup_stack_canary_segment(0);
35725 - switch_to_new_gdt(0);
35726 + setup_stack_canary_segment(cpu);
35727 +#ifdef CONFIG_X86_64
35728 + load_percpu_segment(cpu);
35729 +#endif
35730 + switch_to_new_gdt(cpu);
35731
35732 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
35733 pv_cpu_ops.load_gdt = xen_load_gdt;
35734 @@ -1573,7 +1572,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35735 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35736
35737 /* Work out if we support NX */
35738 - x86_configure_nx();
35739 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35740 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35741 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35742 + unsigned l, h;
35743 +
35744 + __supported_pte_mask |= _PAGE_NX;
35745 + rdmsr(MSR_EFER, l, h);
35746 + l |= EFER_NX;
35747 + wrmsr(MSR_EFER, l, h);
35748 + }
35749 +#endif
35750
35751 /* Get mfn list */
35752 xen_build_dynamic_phys_to_machine();
35753 @@ -1601,13 +1610,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35754
35755 machine_ops = xen_machine_ops;
35756
35757 - /*
35758 - * The only reliable way to retain the initial address of the
35759 - * percpu gdt_page is to remember it here, so we can go and
35760 - * mark it RW later, when the initial percpu area is freed.
35761 - */
35762 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35763 -
35764 xen_smp_init();
35765
35766 #ifdef CONFIG_ACPI_NUMA
35767 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35768 index a8a1a3d..8216142 100644
35769 --- a/arch/x86/xen/mmu.c
35770 +++ b/arch/x86/xen/mmu.c
35771 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35772 return val;
35773 }
35774
35775 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35776 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35777 {
35778 if (val & _PAGE_PRESENT) {
35779 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35780 @@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35781 * L3_k[511] -> level2_fixmap_pgt */
35782 convert_pfn_mfn(level3_kernel_pgt);
35783
35784 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35785 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35786 + convert_pfn_mfn(level3_vmemmap_pgt);
35787 /* L3_k[511][506] -> level1_fixmap_pgt */
35788 + /* L3_k[511][507] -> level1_vsyscall_pgt */
35789 convert_pfn_mfn(level2_fixmap_pgt);
35790 }
35791 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35792 @@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35793 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35794 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35795 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35796 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35797 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35798 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35799 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35800 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35801 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35802 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35803 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35804 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35805 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35806
35807 /* Pin down new L4 */
35808 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35809 @@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35810 pv_mmu_ops.set_pud = xen_set_pud;
35811 #if PAGETABLE_LEVELS == 4
35812 pv_mmu_ops.set_pgd = xen_set_pgd;
35813 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35814 #endif
35815
35816 /* This will work as long as patching hasn't happened yet
35817 @@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35818 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35819 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35820 .set_pgd = xen_set_pgd_hyper,
35821 + .set_pgd_batched = xen_set_pgd_hyper,
35822
35823 .alloc_pud = xen_alloc_pmd_init,
35824 .release_pud = xen_release_pmd_init,
35825 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35826 index 4c071ae..00e7049 100644
35827 --- a/arch/x86/xen/smp.c
35828 +++ b/arch/x86/xen/smp.c
35829 @@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35830
35831 if (xen_pv_domain()) {
35832 if (!xen_feature(XENFEAT_writable_page_tables))
35833 - /* We've switched to the "real" per-cpu gdt, so make
35834 - * sure the old memory can be recycled. */
35835 - make_lowmem_page_readwrite(xen_initial_gdt);
35836 -
35837 #ifdef CONFIG_X86_32
35838 /*
35839 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35840 * expects __USER_DS
35841 */
35842 - loadsegment(ds, __USER_DS);
35843 - loadsegment(es, __USER_DS);
35844 + loadsegment(ds, __KERNEL_DS);
35845 + loadsegment(es, __KERNEL_DS);
35846 #endif
35847
35848 xen_filter_cpu_maps();
35849 @@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35850 #ifdef CONFIG_X86_32
35851 /* Note: PVH is not yet supported on x86_32. */
35852 ctxt->user_regs.fs = __KERNEL_PERCPU;
35853 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35854 + savesegment(gs, ctxt->user_regs.gs);
35855 #endif
35856 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35857
35858 @@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35859 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35860 ctxt->flags = VGCF_IN_KERNEL;
35861 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35862 - ctxt->user_regs.ds = __USER_DS;
35863 - ctxt->user_regs.es = __USER_DS;
35864 + ctxt->user_regs.ds = __KERNEL_DS;
35865 + ctxt->user_regs.es = __KERNEL_DS;
35866 ctxt->user_regs.ss = __KERNEL_DS;
35867
35868 xen_copy_trap_info(ctxt->trap_ctxt);
35869 @@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35870 int rc;
35871
35872 per_cpu(current_task, cpu) = idle;
35873 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35874 #ifdef CONFIG_X86_32
35875 irq_ctx_init(cpu);
35876 #else
35877 clear_tsk_thread_flag(idle, TIF_FORK);
35878 #endif
35879 - per_cpu(kernel_stack, cpu) =
35880 - (unsigned long)task_stack_page(idle) -
35881 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35882 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35883
35884 xen_setup_runstate_info(cpu);
35885 xen_setup_timer(cpu);
35886 @@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35887
35888 void __init xen_smp_init(void)
35889 {
35890 - smp_ops = xen_smp_ops;
35891 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35892 xen_fill_possible_map();
35893 }
35894
35895 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35896 index fd92a64..1f72641 100644
35897 --- a/arch/x86/xen/xen-asm_32.S
35898 +++ b/arch/x86/xen/xen-asm_32.S
35899 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35900 pushw %fs
35901 movl $(__KERNEL_PERCPU), %eax
35902 movl %eax, %fs
35903 - movl %fs:xen_vcpu, %eax
35904 + mov PER_CPU_VAR(xen_vcpu), %eax
35905 POP_FS
35906 #else
35907 movl %ss:xen_vcpu, %eax
35908 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35909 index 674b2225..f1f5dc1 100644
35910 --- a/arch/x86/xen/xen-head.S
35911 +++ b/arch/x86/xen/xen-head.S
35912 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35913 #ifdef CONFIG_X86_32
35914 mov %esi,xen_start_info
35915 mov $init_thread_union+THREAD_SIZE,%esp
35916 +#ifdef CONFIG_SMP
35917 + movl $cpu_gdt_table,%edi
35918 + movl $__per_cpu_load,%eax
35919 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35920 + rorl $16,%eax
35921 + movb %al,__KERNEL_PERCPU + 4(%edi)
35922 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35923 + movl $__per_cpu_end - 1,%eax
35924 + subl $__per_cpu_start,%eax
35925 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35926 +#endif
35927 #else
35928 mov %rsi,xen_start_info
35929 mov $init_thread_union+THREAD_SIZE,%rsp
35930 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35931 index 28c7e0b..2acfec7 100644
35932 --- a/arch/x86/xen/xen-ops.h
35933 +++ b/arch/x86/xen/xen-ops.h
35934 @@ -10,8 +10,6 @@
35935 extern const char xen_hypervisor_callback[];
35936 extern const char xen_failsafe_callback[];
35937
35938 -extern void *xen_initial_gdt;
35939 -
35940 struct trap_info;
35941 void xen_copy_trap_info(struct trap_info *traps);
35942
35943 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35944 index 525bd3d..ef888b1 100644
35945 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35946 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35947 @@ -119,9 +119,9 @@
35948 ----------------------------------------------------------------------*/
35949
35950 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35951 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35952 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35953 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35954 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35955
35956 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35957 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35958 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35959 index 2f33760..835e50a 100644
35960 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35961 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35962 @@ -11,6 +11,7 @@
35963 #ifndef _XTENSA_CORE_H
35964 #define _XTENSA_CORE_H
35965
35966 +#include <linux/const.h>
35967
35968 /****************************************************************************
35969 Parameters Useful for Any Code, USER or PRIVILEGED
35970 @@ -112,9 +113,9 @@
35971 ----------------------------------------------------------------------*/
35972
35973 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35974 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35975 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35976 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35977 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35978
35979 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35980 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35981 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35982 index af00795..2bb8105 100644
35983 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35984 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35985 @@ -11,6 +11,7 @@
35986 #ifndef _XTENSA_CORE_CONFIGURATION_H
35987 #define _XTENSA_CORE_CONFIGURATION_H
35988
35989 +#include <linux/const.h>
35990
35991 /****************************************************************************
35992 Parameters Useful for Any Code, USER or PRIVILEGED
35993 @@ -118,9 +119,9 @@
35994 ----------------------------------------------------------------------*/
35995
35996 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35997 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35998 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35999 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36000 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36001
36002 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36003 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36004 diff --git a/block/bio.c b/block/bio.c
36005 index 3e6e198..5c65199 100644
36006 --- a/block/bio.c
36007 +++ b/block/bio.c
36008 @@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36009 /*
36010 * Overflow, abort
36011 */
36012 - if (end < start)
36013 + if (end < start || end - start > INT_MAX - nr_pages)
36014 return ERR_PTR(-EINVAL);
36015
36016 nr_pages += end - start;
36017 @@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36018 /*
36019 * Overflow, abort
36020 */
36021 - if (end < start)
36022 + if (end < start || end - start > INT_MAX - nr_pages)
36023 return ERR_PTR(-EINVAL);
36024
36025 nr_pages += end - start;
36026 @@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36027 const int read = bio_data_dir(bio) == READ;
36028 struct bio_map_data *bmd = bio->bi_private;
36029 int i;
36030 - char *p = bmd->sgvecs[0].iov_base;
36031 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36032
36033 bio_for_each_segment_all(bvec, bio, i) {
36034 char *addr = page_address(bvec->bv_page);
36035 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36036 index 0736729..2ec3b48 100644
36037 --- a/block/blk-iopoll.c
36038 +++ b/block/blk-iopoll.c
36039 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36040 }
36041 EXPORT_SYMBOL(blk_iopoll_complete);
36042
36043 -static void blk_iopoll_softirq(struct softirq_action *h)
36044 +static __latent_entropy void blk_iopoll_softirq(void)
36045 {
36046 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36047 int rearm = 0, budget = blk_iopoll_budget;
36048 diff --git a/block/blk-map.c b/block/blk-map.c
36049 index f890d43..97b0482 100644
36050 --- a/block/blk-map.c
36051 +++ b/block/blk-map.c
36052 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36053 if (!len || !kbuf)
36054 return -EINVAL;
36055
36056 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36057 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36058 if (do_copy)
36059 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36060 else
36061 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36062 index 53b1737..08177d2e 100644
36063 --- a/block/blk-softirq.c
36064 +++ b/block/blk-softirq.c
36065 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36066 * Softirq action handler - move entries to local list and loop over them
36067 * while passing them to the queue registered handler.
36068 */
36069 -static void blk_done_softirq(struct softirq_action *h)
36070 +static __latent_entropy void blk_done_softirq(void)
36071 {
36072 struct list_head *cpu_list, local_list;
36073
36074 diff --git a/block/bsg.c b/block/bsg.c
36075 index 276e869..6fe4c61 100644
36076 --- a/block/bsg.c
36077 +++ b/block/bsg.c
36078 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36079 struct sg_io_v4 *hdr, struct bsg_device *bd,
36080 fmode_t has_write_perm)
36081 {
36082 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36083 + unsigned char *cmdptr;
36084 +
36085 if (hdr->request_len > BLK_MAX_CDB) {
36086 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36087 if (!rq->cmd)
36088 return -ENOMEM;
36089 - }
36090 + cmdptr = rq->cmd;
36091 + } else
36092 + cmdptr = tmpcmd;
36093
36094 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36095 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36096 hdr->request_len))
36097 return -EFAULT;
36098
36099 + if (cmdptr != rq->cmd)
36100 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36101 +
36102 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36103 if (blk_verify_command(rq->cmd, has_write_perm))
36104 return -EPERM;
36105 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36106 index f678c73..f35aa18 100644
36107 --- a/block/compat_ioctl.c
36108 +++ b/block/compat_ioctl.c
36109 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36110 cgc = compat_alloc_user_space(sizeof(*cgc));
36111 cgc32 = compat_ptr(arg);
36112
36113 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36114 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36115 get_user(data, &cgc32->buffer) ||
36116 put_user(compat_ptr(data), &cgc->buffer) ||
36117 copy_in_user(&cgc->buflen, &cgc32->buflen,
36118 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36119 err |= __get_user(f->spec1, &uf->spec1);
36120 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36121 err |= __get_user(name, &uf->name);
36122 - f->name = compat_ptr(name);
36123 + f->name = (void __force_kernel *)compat_ptr(name);
36124 if (err) {
36125 err = -EFAULT;
36126 goto out;
36127 diff --git a/block/genhd.c b/block/genhd.c
36128 index 0a536dc..b8f7aca 100644
36129 --- a/block/genhd.c
36130 +++ b/block/genhd.c
36131 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36132
36133 /*
36134 * Register device numbers dev..(dev+range-1)
36135 - * range must be nonzero
36136 + * Noop if @range is zero.
36137 * The hash chain is sorted on range, so that subranges can override.
36138 */
36139 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36140 struct kobject *(*probe)(dev_t, int *, void *),
36141 int (*lock)(dev_t, void *), void *data)
36142 {
36143 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36144 + if (range)
36145 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36146 }
36147
36148 EXPORT_SYMBOL(blk_register_region);
36149
36150 +/* undo blk_register_region(), noop if @range is zero */
36151 void blk_unregister_region(dev_t devt, unsigned long range)
36152 {
36153 - kobj_unmap(bdev_map, devt, range);
36154 + if (range)
36155 + kobj_unmap(bdev_map, devt, range);
36156 }
36157
36158 EXPORT_SYMBOL(blk_unregister_region);
36159 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36160 index 56d08fd..2e07090 100644
36161 --- a/block/partitions/efi.c
36162 +++ b/block/partitions/efi.c
36163 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36164 if (!gpt)
36165 return NULL;
36166
36167 + if (!le32_to_cpu(gpt->num_partition_entries))
36168 + return NULL;
36169 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36170 + if (!pte)
36171 + return NULL;
36172 +
36173 count = le32_to_cpu(gpt->num_partition_entries) *
36174 le32_to_cpu(gpt->sizeof_partition_entry);
36175 - if (!count)
36176 - return NULL;
36177 - pte = kmalloc(count, GFP_KERNEL);
36178 - if (!pte)
36179 - return NULL;
36180 -
36181 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36182 (u8 *) pte, count) < count) {
36183 kfree(pte);
36184 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36185 index b0c2a61..10bb6ec 100644
36186 --- a/block/scsi_ioctl.c
36187 +++ b/block/scsi_ioctl.c
36188 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36189 return put_user(0, p);
36190 }
36191
36192 -static int sg_get_timeout(struct request_queue *q)
36193 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36194 {
36195 return jiffies_to_clock_t(q->sg_timeout);
36196 }
36197 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36198 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36199 struct sg_io_hdr *hdr, fmode_t mode)
36200 {
36201 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36202 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36203 + unsigned char *cmdptr;
36204 +
36205 + if (rq->cmd != rq->__cmd)
36206 + cmdptr = rq->cmd;
36207 + else
36208 + cmdptr = tmpcmd;
36209 +
36210 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36211 return -EFAULT;
36212 +
36213 + if (cmdptr != rq->cmd)
36214 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36215 +
36216 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36217 return -EPERM;
36218
36219 @@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36220 int err;
36221 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36222 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36223 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36224 + unsigned char *cmdptr;
36225
36226 if (!sic)
36227 return -EINVAL;
36228 @@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36229 */
36230 err = -EFAULT;
36231 rq->cmd_len = cmdlen;
36232 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36233 +
36234 + if (rq->cmd != rq->__cmd)
36235 + cmdptr = rq->cmd;
36236 + else
36237 + cmdptr = tmpcmd;
36238 +
36239 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36240 goto error;
36241
36242 + if (rq->cmd != cmdptr)
36243 + memcpy(rq->cmd, cmdptr, cmdlen);
36244 +
36245 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36246 goto error;
36247
36248 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36249 index 650afac1..f3307de 100644
36250 --- a/crypto/cryptd.c
36251 +++ b/crypto/cryptd.c
36252 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36253
36254 struct cryptd_blkcipher_request_ctx {
36255 crypto_completion_t complete;
36256 -};
36257 +} __no_const;
36258
36259 struct cryptd_hash_ctx {
36260 struct crypto_shash *child;
36261 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36262
36263 struct cryptd_aead_request_ctx {
36264 crypto_completion_t complete;
36265 -};
36266 +} __no_const;
36267
36268 static void cryptd_queue_worker(struct work_struct *work);
36269
36270 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36271 index c305d41..a96de79 100644
36272 --- a/crypto/pcrypt.c
36273 +++ b/crypto/pcrypt.c
36274 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36275 int ret;
36276
36277 pinst->kobj.kset = pcrypt_kset;
36278 - ret = kobject_add(&pinst->kobj, NULL, name);
36279 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36280 if (!ret)
36281 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36282
36283 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36284 index 6921c7f..78e1af7 100644
36285 --- a/drivers/acpi/acpica/hwxfsleep.c
36286 +++ b/drivers/acpi/acpica/hwxfsleep.c
36287 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36288 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36289
36290 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36291 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36292 - acpi_hw_extended_sleep},
36293 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36294 - acpi_hw_extended_wake_prep},
36295 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36296 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36297 + .extended_function = acpi_hw_extended_sleep},
36298 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36299 + .extended_function = acpi_hw_extended_wake_prep},
36300 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36301 + .extended_function = acpi_hw_extended_wake}
36302 };
36303
36304 /*
36305 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36306 index 16129c7..8b675cd 100644
36307 --- a/drivers/acpi/apei/apei-internal.h
36308 +++ b/drivers/acpi/apei/apei-internal.h
36309 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36310 struct apei_exec_ins_type {
36311 u32 flags;
36312 apei_exec_ins_func_t run;
36313 -};
36314 +} __do_const;
36315
36316 struct apei_exec_context {
36317 u32 ip;
36318 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36319 index fc5f780..e5ac91a 100644
36320 --- a/drivers/acpi/apei/ghes.c
36321 +++ b/drivers/acpi/apei/ghes.c
36322 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36323 const struct acpi_hest_generic *generic,
36324 const struct acpi_hest_generic_status *estatus)
36325 {
36326 - static atomic_t seqno;
36327 + static atomic_unchecked_t seqno;
36328 unsigned int curr_seqno;
36329 char pfx_seq[64];
36330
36331 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36332 else
36333 pfx = KERN_ERR;
36334 }
36335 - curr_seqno = atomic_inc_return(&seqno);
36336 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36337 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36338 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36339 pfx_seq, generic->header.source_id);
36340 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36341 index a83e3c6..c3d617f 100644
36342 --- a/drivers/acpi/bgrt.c
36343 +++ b/drivers/acpi/bgrt.c
36344 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36345 if (!bgrt_image)
36346 return -ENODEV;
36347
36348 - bin_attr_image.private = bgrt_image;
36349 - bin_attr_image.size = bgrt_image_size;
36350 + pax_open_kernel();
36351 + *(void **)&bin_attr_image.private = bgrt_image;
36352 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36353 + pax_close_kernel();
36354
36355 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36356 if (!bgrt_kobj)
36357 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36358 index 7556e7c..89a96bd 100644
36359 --- a/drivers/acpi/blacklist.c
36360 +++ b/drivers/acpi/blacklist.c
36361 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36362 u32 is_critical_error;
36363 };
36364
36365 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36366 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36367
36368 /*
36369 * POLICY: If *anything* doesn't work, put it on the blacklist.
36370 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36371 return 0;
36372 }
36373
36374 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36375 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36376 {
36377 .callback = dmi_disable_osi_vista,
36378 .ident = "Fujitsu Siemens",
36379 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36380 index c68e724..e863008 100644
36381 --- a/drivers/acpi/custom_method.c
36382 +++ b/drivers/acpi/custom_method.c
36383 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36384 struct acpi_table_header table;
36385 acpi_status status;
36386
36387 +#ifdef CONFIG_GRKERNSEC_KMEM
36388 + return -EPERM;
36389 +#endif
36390 +
36391 if (!(*ppos)) {
36392 /* parse the table header to get the table length */
36393 if (count <= sizeof(struct acpi_table_header))
36394 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36395 index 6341e66..ebcf59c 100644
36396 --- a/drivers/acpi/device_pm.c
36397 +++ b/drivers/acpi/device_pm.c
36398 @@ -1029,6 +1029,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36399
36400 #endif /* CONFIG_PM_SLEEP */
36401
36402 +static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36403 +
36404 static struct dev_pm_domain acpi_general_pm_domain = {
36405 .ops = {
36406 #ifdef CONFIG_PM_RUNTIME
36407 @@ -1047,6 +1049,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36408 .restore_early = acpi_subsys_resume_early,
36409 #endif
36410 },
36411 + .detach = acpi_dev_pm_detach
36412 };
36413
36414 /**
36415 @@ -1116,7 +1119,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36416 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36417 }
36418
36419 - dev->pm_domain->detach = acpi_dev_pm_detach;
36420 return 0;
36421 }
36422 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36423 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36424 index 17f9ec5..d9a455e 100644
36425 --- a/drivers/acpi/processor_idle.c
36426 +++ b/drivers/acpi/processor_idle.c
36427 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36428 {
36429 int i, count = CPUIDLE_DRIVER_STATE_START;
36430 struct acpi_processor_cx *cx;
36431 - struct cpuidle_state *state;
36432 + cpuidle_state_no_const *state;
36433 struct cpuidle_driver *drv = &acpi_idle_driver;
36434
36435 if (!pr->flags.power_setup_done)
36436 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36437 index 13e577c..cef11ee 100644
36438 --- a/drivers/acpi/sysfs.c
36439 +++ b/drivers/acpi/sysfs.c
36440 @@ -423,11 +423,11 @@ static u32 num_counters;
36441 static struct attribute **all_attrs;
36442 static u32 acpi_gpe_count;
36443
36444 -static struct attribute_group interrupt_stats_attr_group = {
36445 +static attribute_group_no_const interrupt_stats_attr_group = {
36446 .name = "interrupts",
36447 };
36448
36449 -static struct kobj_attribute *counter_attrs;
36450 +static kobj_attribute_no_const *counter_attrs;
36451
36452 static void delete_gpe_attr_array(void)
36453 {
36454 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36455 index 97683e4..655f6ba 100644
36456 --- a/drivers/ata/libahci.c
36457 +++ b/drivers/ata/libahci.c
36458 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36459 }
36460 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36461
36462 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36463 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36464 struct ata_taskfile *tf, int is_cmd, u16 flags,
36465 unsigned long timeout_msec)
36466 {
36467 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36468 index 485f7ea..9a8df4a 100644
36469 --- a/drivers/ata/libata-core.c
36470 +++ b/drivers/ata/libata-core.c
36471 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36472 static void ata_dev_xfermask(struct ata_device *dev);
36473 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36474
36475 -atomic_t ata_print_id = ATOMIC_INIT(0);
36476 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36477
36478 struct ata_force_param {
36479 const char *name;
36480 @@ -4800,7 +4800,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36481 struct ata_port *ap;
36482 unsigned int tag;
36483
36484 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36485 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36486 ap = qc->ap;
36487
36488 qc->flags = 0;
36489 @@ -4816,7 +4816,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36490 struct ata_port *ap;
36491 struct ata_link *link;
36492
36493 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36494 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36495 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36496 ap = qc->ap;
36497 link = qc->dev->link;
36498 @@ -5920,6 +5920,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36499 return;
36500
36501 spin_lock(&lock);
36502 + pax_open_kernel();
36503
36504 for (cur = ops->inherits; cur; cur = cur->inherits) {
36505 void **inherit = (void **)cur;
36506 @@ -5933,8 +5934,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36507 if (IS_ERR(*pp))
36508 *pp = NULL;
36509
36510 - ops->inherits = NULL;
36511 + *(struct ata_port_operations **)&ops->inherits = NULL;
36512
36513 + pax_close_kernel();
36514 spin_unlock(&lock);
36515 }
36516
36517 @@ -6130,7 +6132,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36518
36519 /* give ports names and add SCSI hosts */
36520 for (i = 0; i < host->n_ports; i++) {
36521 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36522 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36523 host->ports[i]->local_port_no = i + 1;
36524 }
36525
36526 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36527 index 0586f66..1a8f74a 100644
36528 --- a/drivers/ata/libata-scsi.c
36529 +++ b/drivers/ata/libata-scsi.c
36530 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36531
36532 if (rc)
36533 return rc;
36534 - ap->print_id = atomic_inc_return(&ata_print_id);
36535 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36536 return 0;
36537 }
36538 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36539 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36540 index 5f4e0cc..ff2c347 100644
36541 --- a/drivers/ata/libata.h
36542 +++ b/drivers/ata/libata.h
36543 @@ -53,7 +53,7 @@ enum {
36544 ATA_DNXFER_QUIET = (1 << 31),
36545 };
36546
36547 -extern atomic_t ata_print_id;
36548 +extern atomic_unchecked_t ata_print_id;
36549 extern int atapi_passthru16;
36550 extern int libata_fua;
36551 extern int libata_noacpi;
36552 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36553 index 38216b9..4ec6aeb 100644
36554 --- a/drivers/ata/pata_arasan_cf.c
36555 +++ b/drivers/ata/pata_arasan_cf.c
36556 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36557 /* Handle platform specific quirks */
36558 if (quirk) {
36559 if (quirk & CF_BROKEN_PIO) {
36560 - ap->ops->set_piomode = NULL;
36561 + pax_open_kernel();
36562 + *(void **)&ap->ops->set_piomode = NULL;
36563 + pax_close_kernel();
36564 ap->pio_mask = 0;
36565 }
36566 if (quirk & CF_BROKEN_MWDMA)
36567 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36568 index f9b983a..887b9d8 100644
36569 --- a/drivers/atm/adummy.c
36570 +++ b/drivers/atm/adummy.c
36571 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36572 vcc->pop(vcc, skb);
36573 else
36574 dev_kfree_skb_any(skb);
36575 - atomic_inc(&vcc->stats->tx);
36576 + atomic_inc_unchecked(&vcc->stats->tx);
36577
36578 return 0;
36579 }
36580 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36581 index f1a9198..f466a4a 100644
36582 --- a/drivers/atm/ambassador.c
36583 +++ b/drivers/atm/ambassador.c
36584 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36585 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36586
36587 // VC layer stats
36588 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36589 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36590
36591 // free the descriptor
36592 kfree (tx_descr);
36593 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36594 dump_skb ("<<<", vc, skb);
36595
36596 // VC layer stats
36597 - atomic_inc(&atm_vcc->stats->rx);
36598 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36599 __net_timestamp(skb);
36600 // end of our responsibility
36601 atm_vcc->push (atm_vcc, skb);
36602 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36603 } else {
36604 PRINTK (KERN_INFO, "dropped over-size frame");
36605 // should we count this?
36606 - atomic_inc(&atm_vcc->stats->rx_drop);
36607 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36608 }
36609
36610 } else {
36611 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36612 }
36613
36614 if (check_area (skb->data, skb->len)) {
36615 - atomic_inc(&atm_vcc->stats->tx_err);
36616 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36617 return -ENOMEM; // ?
36618 }
36619
36620 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36621 index 480fa6f..947067c 100644
36622 --- a/drivers/atm/atmtcp.c
36623 +++ b/drivers/atm/atmtcp.c
36624 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36625 if (vcc->pop) vcc->pop(vcc,skb);
36626 else dev_kfree_skb(skb);
36627 if (dev_data) return 0;
36628 - atomic_inc(&vcc->stats->tx_err);
36629 + atomic_inc_unchecked(&vcc->stats->tx_err);
36630 return -ENOLINK;
36631 }
36632 size = skb->len+sizeof(struct atmtcp_hdr);
36633 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36634 if (!new_skb) {
36635 if (vcc->pop) vcc->pop(vcc,skb);
36636 else dev_kfree_skb(skb);
36637 - atomic_inc(&vcc->stats->tx_err);
36638 + atomic_inc_unchecked(&vcc->stats->tx_err);
36639 return -ENOBUFS;
36640 }
36641 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36642 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36643 if (vcc->pop) vcc->pop(vcc,skb);
36644 else dev_kfree_skb(skb);
36645 out_vcc->push(out_vcc,new_skb);
36646 - atomic_inc(&vcc->stats->tx);
36647 - atomic_inc(&out_vcc->stats->rx);
36648 + atomic_inc_unchecked(&vcc->stats->tx);
36649 + atomic_inc_unchecked(&out_vcc->stats->rx);
36650 return 0;
36651 }
36652
36653 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36654 read_unlock(&vcc_sklist_lock);
36655 if (!out_vcc) {
36656 result = -EUNATCH;
36657 - atomic_inc(&vcc->stats->tx_err);
36658 + atomic_inc_unchecked(&vcc->stats->tx_err);
36659 goto done;
36660 }
36661 skb_pull(skb,sizeof(struct atmtcp_hdr));
36662 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36663 __net_timestamp(new_skb);
36664 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36665 out_vcc->push(out_vcc,new_skb);
36666 - atomic_inc(&vcc->stats->tx);
36667 - atomic_inc(&out_vcc->stats->rx);
36668 + atomic_inc_unchecked(&vcc->stats->tx);
36669 + atomic_inc_unchecked(&out_vcc->stats->rx);
36670 done:
36671 if (vcc->pop) vcc->pop(vcc,skb);
36672 else dev_kfree_skb(skb);
36673 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36674 index d65975a..0b87e20 100644
36675 --- a/drivers/atm/eni.c
36676 +++ b/drivers/atm/eni.c
36677 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36678 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36679 vcc->dev->number);
36680 length = 0;
36681 - atomic_inc(&vcc->stats->rx_err);
36682 + atomic_inc_unchecked(&vcc->stats->rx_err);
36683 }
36684 else {
36685 length = ATM_CELL_SIZE-1; /* no HEC */
36686 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36687 size);
36688 }
36689 eff = length = 0;
36690 - atomic_inc(&vcc->stats->rx_err);
36691 + atomic_inc_unchecked(&vcc->stats->rx_err);
36692 }
36693 else {
36694 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36695 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36696 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36697 vcc->dev->number,vcc->vci,length,size << 2,descr);
36698 length = eff = 0;
36699 - atomic_inc(&vcc->stats->rx_err);
36700 + atomic_inc_unchecked(&vcc->stats->rx_err);
36701 }
36702 }
36703 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36704 @@ -767,7 +767,7 @@ rx_dequeued++;
36705 vcc->push(vcc,skb);
36706 pushed++;
36707 }
36708 - atomic_inc(&vcc->stats->rx);
36709 + atomic_inc_unchecked(&vcc->stats->rx);
36710 }
36711 wake_up(&eni_dev->rx_wait);
36712 }
36713 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36714 PCI_DMA_TODEVICE);
36715 if (vcc->pop) vcc->pop(vcc,skb);
36716 else dev_kfree_skb_irq(skb);
36717 - atomic_inc(&vcc->stats->tx);
36718 + atomic_inc_unchecked(&vcc->stats->tx);
36719 wake_up(&eni_dev->tx_wait);
36720 dma_complete++;
36721 }
36722 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36723 index 82f2ae0..f205c02 100644
36724 --- a/drivers/atm/firestream.c
36725 +++ b/drivers/atm/firestream.c
36726 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36727 }
36728 }
36729
36730 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36731 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36732
36733 fs_dprintk (FS_DEBUG_TXMEM, "i");
36734 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36735 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36736 #endif
36737 skb_put (skb, qe->p1 & 0xffff);
36738 ATM_SKB(skb)->vcc = atm_vcc;
36739 - atomic_inc(&atm_vcc->stats->rx);
36740 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36741 __net_timestamp(skb);
36742 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36743 atm_vcc->push (atm_vcc, skb);
36744 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36745 kfree (pe);
36746 }
36747 if (atm_vcc)
36748 - atomic_inc(&atm_vcc->stats->rx_drop);
36749 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36750 break;
36751 case 0x1f: /* Reassembly abort: no buffers. */
36752 /* Silently increment error counter. */
36753 if (atm_vcc)
36754 - atomic_inc(&atm_vcc->stats->rx_drop);
36755 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36756 break;
36757 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36758 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36759 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36760 index d4725fc..2d4ea65 100644
36761 --- a/drivers/atm/fore200e.c
36762 +++ b/drivers/atm/fore200e.c
36763 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36764 #endif
36765 /* check error condition */
36766 if (*entry->status & STATUS_ERROR)
36767 - atomic_inc(&vcc->stats->tx_err);
36768 + atomic_inc_unchecked(&vcc->stats->tx_err);
36769 else
36770 - atomic_inc(&vcc->stats->tx);
36771 + atomic_inc_unchecked(&vcc->stats->tx);
36772 }
36773 }
36774
36775 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36776 if (skb == NULL) {
36777 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36778
36779 - atomic_inc(&vcc->stats->rx_drop);
36780 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36781 return -ENOMEM;
36782 }
36783
36784 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36785
36786 dev_kfree_skb_any(skb);
36787
36788 - atomic_inc(&vcc->stats->rx_drop);
36789 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36790 return -ENOMEM;
36791 }
36792
36793 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36794
36795 vcc->push(vcc, skb);
36796 - atomic_inc(&vcc->stats->rx);
36797 + atomic_inc_unchecked(&vcc->stats->rx);
36798
36799 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36800
36801 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36802 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36803 fore200e->atm_dev->number,
36804 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36805 - atomic_inc(&vcc->stats->rx_err);
36806 + atomic_inc_unchecked(&vcc->stats->rx_err);
36807 }
36808 }
36809
36810 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36811 goto retry_here;
36812 }
36813
36814 - atomic_inc(&vcc->stats->tx_err);
36815 + atomic_inc_unchecked(&vcc->stats->tx_err);
36816
36817 fore200e->tx_sat++;
36818 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36819 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36820 index c39702b..785b73b 100644
36821 --- a/drivers/atm/he.c
36822 +++ b/drivers/atm/he.c
36823 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36824
36825 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36826 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36827 - atomic_inc(&vcc->stats->rx_drop);
36828 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36829 goto return_host_buffers;
36830 }
36831
36832 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36833 RBRQ_LEN_ERR(he_dev->rbrq_head)
36834 ? "LEN_ERR" : "",
36835 vcc->vpi, vcc->vci);
36836 - atomic_inc(&vcc->stats->rx_err);
36837 + atomic_inc_unchecked(&vcc->stats->rx_err);
36838 goto return_host_buffers;
36839 }
36840
36841 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36842 vcc->push(vcc, skb);
36843 spin_lock(&he_dev->global_lock);
36844
36845 - atomic_inc(&vcc->stats->rx);
36846 + atomic_inc_unchecked(&vcc->stats->rx);
36847
36848 return_host_buffers:
36849 ++pdus_assembled;
36850 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36851 tpd->vcc->pop(tpd->vcc, tpd->skb);
36852 else
36853 dev_kfree_skb_any(tpd->skb);
36854 - atomic_inc(&tpd->vcc->stats->tx_err);
36855 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36856 }
36857 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36858 return;
36859 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36860 vcc->pop(vcc, skb);
36861 else
36862 dev_kfree_skb_any(skb);
36863 - atomic_inc(&vcc->stats->tx_err);
36864 + atomic_inc_unchecked(&vcc->stats->tx_err);
36865 return -EINVAL;
36866 }
36867
36868 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36869 vcc->pop(vcc, skb);
36870 else
36871 dev_kfree_skb_any(skb);
36872 - atomic_inc(&vcc->stats->tx_err);
36873 + atomic_inc_unchecked(&vcc->stats->tx_err);
36874 return -EINVAL;
36875 }
36876 #endif
36877 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36878 vcc->pop(vcc, skb);
36879 else
36880 dev_kfree_skb_any(skb);
36881 - atomic_inc(&vcc->stats->tx_err);
36882 + atomic_inc_unchecked(&vcc->stats->tx_err);
36883 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36884 return -ENOMEM;
36885 }
36886 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36887 vcc->pop(vcc, skb);
36888 else
36889 dev_kfree_skb_any(skb);
36890 - atomic_inc(&vcc->stats->tx_err);
36891 + atomic_inc_unchecked(&vcc->stats->tx_err);
36892 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36893 return -ENOMEM;
36894 }
36895 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36896 __enqueue_tpd(he_dev, tpd, cid);
36897 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36898
36899 - atomic_inc(&vcc->stats->tx);
36900 + atomic_inc_unchecked(&vcc->stats->tx);
36901
36902 return 0;
36903 }
36904 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36905 index 1dc0519..1aadaf7 100644
36906 --- a/drivers/atm/horizon.c
36907 +++ b/drivers/atm/horizon.c
36908 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36909 {
36910 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36911 // VC layer stats
36912 - atomic_inc(&vcc->stats->rx);
36913 + atomic_inc_unchecked(&vcc->stats->rx);
36914 __net_timestamp(skb);
36915 // end of our responsibility
36916 vcc->push (vcc, skb);
36917 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36918 dev->tx_iovec = NULL;
36919
36920 // VC layer stats
36921 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36922 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36923
36924 // free the skb
36925 hrz_kfree_skb (skb);
36926 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36927 index 2b24ed0..b3d6acc 100644
36928 --- a/drivers/atm/idt77252.c
36929 +++ b/drivers/atm/idt77252.c
36930 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36931 else
36932 dev_kfree_skb(skb);
36933
36934 - atomic_inc(&vcc->stats->tx);
36935 + atomic_inc_unchecked(&vcc->stats->tx);
36936 }
36937
36938 atomic_dec(&scq->used);
36939 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36940 if ((sb = dev_alloc_skb(64)) == NULL) {
36941 printk("%s: Can't allocate buffers for aal0.\n",
36942 card->name);
36943 - atomic_add(i, &vcc->stats->rx_drop);
36944 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36945 break;
36946 }
36947 if (!atm_charge(vcc, sb->truesize)) {
36948 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36949 card->name);
36950 - atomic_add(i - 1, &vcc->stats->rx_drop);
36951 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36952 dev_kfree_skb(sb);
36953 break;
36954 }
36955 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36956 ATM_SKB(sb)->vcc = vcc;
36957 __net_timestamp(sb);
36958 vcc->push(vcc, sb);
36959 - atomic_inc(&vcc->stats->rx);
36960 + atomic_inc_unchecked(&vcc->stats->rx);
36961
36962 cell += ATM_CELL_PAYLOAD;
36963 }
36964 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36965 "(CDC: %08x)\n",
36966 card->name, len, rpp->len, readl(SAR_REG_CDC));
36967 recycle_rx_pool_skb(card, rpp);
36968 - atomic_inc(&vcc->stats->rx_err);
36969 + atomic_inc_unchecked(&vcc->stats->rx_err);
36970 return;
36971 }
36972 if (stat & SAR_RSQE_CRC) {
36973 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36974 recycle_rx_pool_skb(card, rpp);
36975 - atomic_inc(&vcc->stats->rx_err);
36976 + atomic_inc_unchecked(&vcc->stats->rx_err);
36977 return;
36978 }
36979 if (skb_queue_len(&rpp->queue) > 1) {
36980 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36981 RXPRINTK("%s: Can't alloc RX skb.\n",
36982 card->name);
36983 recycle_rx_pool_skb(card, rpp);
36984 - atomic_inc(&vcc->stats->rx_err);
36985 + atomic_inc_unchecked(&vcc->stats->rx_err);
36986 return;
36987 }
36988 if (!atm_charge(vcc, skb->truesize)) {
36989 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36990 __net_timestamp(skb);
36991
36992 vcc->push(vcc, skb);
36993 - atomic_inc(&vcc->stats->rx);
36994 + atomic_inc_unchecked(&vcc->stats->rx);
36995
36996 return;
36997 }
36998 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36999 __net_timestamp(skb);
37000
37001 vcc->push(vcc, skb);
37002 - atomic_inc(&vcc->stats->rx);
37003 + atomic_inc_unchecked(&vcc->stats->rx);
37004
37005 if (skb->truesize > SAR_FB_SIZE_3)
37006 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37007 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37008 if (vcc->qos.aal != ATM_AAL0) {
37009 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37010 card->name, vpi, vci);
37011 - atomic_inc(&vcc->stats->rx_drop);
37012 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37013 goto drop;
37014 }
37015
37016 if ((sb = dev_alloc_skb(64)) == NULL) {
37017 printk("%s: Can't allocate buffers for AAL0.\n",
37018 card->name);
37019 - atomic_inc(&vcc->stats->rx_err);
37020 + atomic_inc_unchecked(&vcc->stats->rx_err);
37021 goto drop;
37022 }
37023
37024 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37025 ATM_SKB(sb)->vcc = vcc;
37026 __net_timestamp(sb);
37027 vcc->push(vcc, sb);
37028 - atomic_inc(&vcc->stats->rx);
37029 + atomic_inc_unchecked(&vcc->stats->rx);
37030
37031 drop:
37032 skb_pull(queue, 64);
37033 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37034
37035 if (vc == NULL) {
37036 printk("%s: NULL connection in send().\n", card->name);
37037 - atomic_inc(&vcc->stats->tx_err);
37038 + atomic_inc_unchecked(&vcc->stats->tx_err);
37039 dev_kfree_skb(skb);
37040 return -EINVAL;
37041 }
37042 if (!test_bit(VCF_TX, &vc->flags)) {
37043 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37044 - atomic_inc(&vcc->stats->tx_err);
37045 + atomic_inc_unchecked(&vcc->stats->tx_err);
37046 dev_kfree_skb(skb);
37047 return -EINVAL;
37048 }
37049 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37050 break;
37051 default:
37052 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37053 - atomic_inc(&vcc->stats->tx_err);
37054 + atomic_inc_unchecked(&vcc->stats->tx_err);
37055 dev_kfree_skb(skb);
37056 return -EINVAL;
37057 }
37058
37059 if (skb_shinfo(skb)->nr_frags != 0) {
37060 printk("%s: No scatter-gather yet.\n", card->name);
37061 - atomic_inc(&vcc->stats->tx_err);
37062 + atomic_inc_unchecked(&vcc->stats->tx_err);
37063 dev_kfree_skb(skb);
37064 return -EINVAL;
37065 }
37066 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37067
37068 err = queue_skb(card, vc, skb, oam);
37069 if (err) {
37070 - atomic_inc(&vcc->stats->tx_err);
37071 + atomic_inc_unchecked(&vcc->stats->tx_err);
37072 dev_kfree_skb(skb);
37073 return err;
37074 }
37075 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37076 skb = dev_alloc_skb(64);
37077 if (!skb) {
37078 printk("%s: Out of memory in send_oam().\n", card->name);
37079 - atomic_inc(&vcc->stats->tx_err);
37080 + atomic_inc_unchecked(&vcc->stats->tx_err);
37081 return -ENOMEM;
37082 }
37083 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37084 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37085 index 4217f29..88f547a 100644
37086 --- a/drivers/atm/iphase.c
37087 +++ b/drivers/atm/iphase.c
37088 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37089 status = (u_short) (buf_desc_ptr->desc_mode);
37090 if (status & (RX_CER | RX_PTE | RX_OFL))
37091 {
37092 - atomic_inc(&vcc->stats->rx_err);
37093 + atomic_inc_unchecked(&vcc->stats->rx_err);
37094 IF_ERR(printk("IA: bad packet, dropping it");)
37095 if (status & RX_CER) {
37096 IF_ERR(printk(" cause: packet CRC error\n");)
37097 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37098 len = dma_addr - buf_addr;
37099 if (len > iadev->rx_buf_sz) {
37100 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37101 - atomic_inc(&vcc->stats->rx_err);
37102 + atomic_inc_unchecked(&vcc->stats->rx_err);
37103 goto out_free_desc;
37104 }
37105
37106 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37107 ia_vcc = INPH_IA_VCC(vcc);
37108 if (ia_vcc == NULL)
37109 {
37110 - atomic_inc(&vcc->stats->rx_err);
37111 + atomic_inc_unchecked(&vcc->stats->rx_err);
37112 atm_return(vcc, skb->truesize);
37113 dev_kfree_skb_any(skb);
37114 goto INCR_DLE;
37115 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37116 if ((length > iadev->rx_buf_sz) || (length >
37117 (skb->len - sizeof(struct cpcs_trailer))))
37118 {
37119 - atomic_inc(&vcc->stats->rx_err);
37120 + atomic_inc_unchecked(&vcc->stats->rx_err);
37121 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37122 length, skb->len);)
37123 atm_return(vcc, skb->truesize);
37124 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37125
37126 IF_RX(printk("rx_dle_intr: skb push");)
37127 vcc->push(vcc,skb);
37128 - atomic_inc(&vcc->stats->rx);
37129 + atomic_inc_unchecked(&vcc->stats->rx);
37130 iadev->rx_pkt_cnt++;
37131 }
37132 INCR_DLE:
37133 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37134 {
37135 struct k_sonet_stats *stats;
37136 stats = &PRIV(_ia_dev[board])->sonet_stats;
37137 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37138 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37139 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37140 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37141 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37142 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37143 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37144 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37145 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37146 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37147 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37148 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37149 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37150 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37151 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37152 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37153 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37154 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37155 }
37156 ia_cmds.status = 0;
37157 break;
37158 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37159 if ((desc == 0) || (desc > iadev->num_tx_desc))
37160 {
37161 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37162 - atomic_inc(&vcc->stats->tx);
37163 + atomic_inc_unchecked(&vcc->stats->tx);
37164 if (vcc->pop)
37165 vcc->pop(vcc, skb);
37166 else
37167 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37168 ATM_DESC(skb) = vcc->vci;
37169 skb_queue_tail(&iadev->tx_dma_q, skb);
37170
37171 - atomic_inc(&vcc->stats->tx);
37172 + atomic_inc_unchecked(&vcc->stats->tx);
37173 iadev->tx_pkt_cnt++;
37174 /* Increment transaction counter */
37175 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37176
37177 #if 0
37178 /* add flow control logic */
37179 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37180 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37181 if (iavcc->vc_desc_cnt > 10) {
37182 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37183 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37184 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37185 index 93eaf8d..b4ca7da 100644
37186 --- a/drivers/atm/lanai.c
37187 +++ b/drivers/atm/lanai.c
37188 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37189 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37190 lanai_endtx(lanai, lvcc);
37191 lanai_free_skb(lvcc->tx.atmvcc, skb);
37192 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37193 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37194 }
37195
37196 /* Try to fill the buffer - don't call unless there is backlog */
37197 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37198 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37199 __net_timestamp(skb);
37200 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37201 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37202 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37203 out:
37204 lvcc->rx.buf.ptr = end;
37205 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37206 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37207 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37208 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37209 lanai->stats.service_rxnotaal5++;
37210 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37211 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37212 return 0;
37213 }
37214 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37215 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37216 int bytes;
37217 read_unlock(&vcc_sklist_lock);
37218 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37219 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37220 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37221 lvcc->stats.x.aal5.service_trash++;
37222 bytes = (SERVICE_GET_END(s) * 16) -
37223 (((unsigned long) lvcc->rx.buf.ptr) -
37224 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37225 }
37226 if (s & SERVICE_STREAM) {
37227 read_unlock(&vcc_sklist_lock);
37228 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37229 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37230 lvcc->stats.x.aal5.service_stream++;
37231 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37232 "PDU on VCI %d!\n", lanai->number, vci);
37233 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37234 return 0;
37235 }
37236 DPRINTK("got rx crc error on vci %d\n", vci);
37237 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37238 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37239 lvcc->stats.x.aal5.service_rxcrc++;
37240 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37241 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37242 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37243 index 9988ac9..7c52585 100644
37244 --- a/drivers/atm/nicstar.c
37245 +++ b/drivers/atm/nicstar.c
37246 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37247 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37248 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37249 card->index);
37250 - atomic_inc(&vcc->stats->tx_err);
37251 + atomic_inc_unchecked(&vcc->stats->tx_err);
37252 dev_kfree_skb_any(skb);
37253 return -EINVAL;
37254 }
37255 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37256 if (!vc->tx) {
37257 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37258 card->index);
37259 - atomic_inc(&vcc->stats->tx_err);
37260 + atomic_inc_unchecked(&vcc->stats->tx_err);
37261 dev_kfree_skb_any(skb);
37262 return -EINVAL;
37263 }
37264 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37265 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37266 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37267 card->index);
37268 - atomic_inc(&vcc->stats->tx_err);
37269 + atomic_inc_unchecked(&vcc->stats->tx_err);
37270 dev_kfree_skb_any(skb);
37271 return -EINVAL;
37272 }
37273
37274 if (skb_shinfo(skb)->nr_frags != 0) {
37275 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37276 - atomic_inc(&vcc->stats->tx_err);
37277 + atomic_inc_unchecked(&vcc->stats->tx_err);
37278 dev_kfree_skb_any(skb);
37279 return -EINVAL;
37280 }
37281 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37282 }
37283
37284 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37285 - atomic_inc(&vcc->stats->tx_err);
37286 + atomic_inc_unchecked(&vcc->stats->tx_err);
37287 dev_kfree_skb_any(skb);
37288 return -EIO;
37289 }
37290 - atomic_inc(&vcc->stats->tx);
37291 + atomic_inc_unchecked(&vcc->stats->tx);
37292
37293 return 0;
37294 }
37295 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37296 printk
37297 ("nicstar%d: Can't allocate buffers for aal0.\n",
37298 card->index);
37299 - atomic_add(i, &vcc->stats->rx_drop);
37300 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37301 break;
37302 }
37303 if (!atm_charge(vcc, sb->truesize)) {
37304 RXPRINTK
37305 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37306 card->index);
37307 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37308 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37309 dev_kfree_skb_any(sb);
37310 break;
37311 }
37312 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37313 ATM_SKB(sb)->vcc = vcc;
37314 __net_timestamp(sb);
37315 vcc->push(vcc, sb);
37316 - atomic_inc(&vcc->stats->rx);
37317 + atomic_inc_unchecked(&vcc->stats->rx);
37318 cell += ATM_CELL_PAYLOAD;
37319 }
37320
37321 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37322 if (iovb == NULL) {
37323 printk("nicstar%d: Out of iovec buffers.\n",
37324 card->index);
37325 - atomic_inc(&vcc->stats->rx_drop);
37326 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37327 recycle_rx_buf(card, skb);
37328 return;
37329 }
37330 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37331 small or large buffer itself. */
37332 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37333 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37334 - atomic_inc(&vcc->stats->rx_err);
37335 + atomic_inc_unchecked(&vcc->stats->rx_err);
37336 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37337 NS_MAX_IOVECS);
37338 NS_PRV_IOVCNT(iovb) = 0;
37339 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37340 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37341 card->index);
37342 which_list(card, skb);
37343 - atomic_inc(&vcc->stats->rx_err);
37344 + atomic_inc_unchecked(&vcc->stats->rx_err);
37345 recycle_rx_buf(card, skb);
37346 vc->rx_iov = NULL;
37347 recycle_iov_buf(card, iovb);
37348 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37349 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37350 card->index);
37351 which_list(card, skb);
37352 - atomic_inc(&vcc->stats->rx_err);
37353 + atomic_inc_unchecked(&vcc->stats->rx_err);
37354 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37355 NS_PRV_IOVCNT(iovb));
37356 vc->rx_iov = NULL;
37357 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37358 printk(" - PDU size mismatch.\n");
37359 else
37360 printk(".\n");
37361 - atomic_inc(&vcc->stats->rx_err);
37362 + atomic_inc_unchecked(&vcc->stats->rx_err);
37363 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37364 NS_PRV_IOVCNT(iovb));
37365 vc->rx_iov = NULL;
37366 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37367 /* skb points to a small buffer */
37368 if (!atm_charge(vcc, skb->truesize)) {
37369 push_rxbufs(card, skb);
37370 - atomic_inc(&vcc->stats->rx_drop);
37371 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37372 } else {
37373 skb_put(skb, len);
37374 dequeue_sm_buf(card, skb);
37375 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37376 ATM_SKB(skb)->vcc = vcc;
37377 __net_timestamp(skb);
37378 vcc->push(vcc, skb);
37379 - atomic_inc(&vcc->stats->rx);
37380 + atomic_inc_unchecked(&vcc->stats->rx);
37381 }
37382 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37383 struct sk_buff *sb;
37384 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37385 if (len <= NS_SMBUFSIZE) {
37386 if (!atm_charge(vcc, sb->truesize)) {
37387 push_rxbufs(card, sb);
37388 - atomic_inc(&vcc->stats->rx_drop);
37389 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37390 } else {
37391 skb_put(sb, len);
37392 dequeue_sm_buf(card, sb);
37393 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37394 ATM_SKB(sb)->vcc = vcc;
37395 __net_timestamp(sb);
37396 vcc->push(vcc, sb);
37397 - atomic_inc(&vcc->stats->rx);
37398 + atomic_inc_unchecked(&vcc->stats->rx);
37399 }
37400
37401 push_rxbufs(card, skb);
37402 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37403
37404 if (!atm_charge(vcc, skb->truesize)) {
37405 push_rxbufs(card, skb);
37406 - atomic_inc(&vcc->stats->rx_drop);
37407 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37408 } else {
37409 dequeue_lg_buf(card, skb);
37410 #ifdef NS_USE_DESTRUCTORS
37411 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37412 ATM_SKB(skb)->vcc = vcc;
37413 __net_timestamp(skb);
37414 vcc->push(vcc, skb);
37415 - atomic_inc(&vcc->stats->rx);
37416 + atomic_inc_unchecked(&vcc->stats->rx);
37417 }
37418
37419 push_rxbufs(card, sb);
37420 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37421 printk
37422 ("nicstar%d: Out of huge buffers.\n",
37423 card->index);
37424 - atomic_inc(&vcc->stats->rx_drop);
37425 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37426 recycle_iovec_rx_bufs(card,
37427 (struct iovec *)
37428 iovb->data,
37429 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37430 card->hbpool.count++;
37431 } else
37432 dev_kfree_skb_any(hb);
37433 - atomic_inc(&vcc->stats->rx_drop);
37434 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37435 } else {
37436 /* Copy the small buffer to the huge buffer */
37437 sb = (struct sk_buff *)iov->iov_base;
37438 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37439 #endif /* NS_USE_DESTRUCTORS */
37440 __net_timestamp(hb);
37441 vcc->push(vcc, hb);
37442 - atomic_inc(&vcc->stats->rx);
37443 + atomic_inc_unchecked(&vcc->stats->rx);
37444 }
37445 }
37446
37447 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37448 index 21b0bc6..b5f40ba 100644
37449 --- a/drivers/atm/solos-pci.c
37450 +++ b/drivers/atm/solos-pci.c
37451 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37452 }
37453 atm_charge(vcc, skb->truesize);
37454 vcc->push(vcc, skb);
37455 - atomic_inc(&vcc->stats->rx);
37456 + atomic_inc_unchecked(&vcc->stats->rx);
37457 break;
37458
37459 case PKT_STATUS:
37460 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37461 vcc = SKB_CB(oldskb)->vcc;
37462
37463 if (vcc) {
37464 - atomic_inc(&vcc->stats->tx);
37465 + atomic_inc_unchecked(&vcc->stats->tx);
37466 solos_pop(vcc, oldskb);
37467 } else {
37468 dev_kfree_skb_irq(oldskb);
37469 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37470 index 0215934..ce9f5b1 100644
37471 --- a/drivers/atm/suni.c
37472 +++ b/drivers/atm/suni.c
37473 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37474
37475
37476 #define ADD_LIMITED(s,v) \
37477 - atomic_add((v),&stats->s); \
37478 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37479 + atomic_add_unchecked((v),&stats->s); \
37480 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37481
37482
37483 static void suni_hz(unsigned long from_timer)
37484 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37485 index 5120a96..e2572bd 100644
37486 --- a/drivers/atm/uPD98402.c
37487 +++ b/drivers/atm/uPD98402.c
37488 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37489 struct sonet_stats tmp;
37490 int error = 0;
37491
37492 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37493 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37494 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37495 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37496 if (zero && !error) {
37497 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37498
37499
37500 #define ADD_LIMITED(s,v) \
37501 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37502 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37503 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37504 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37505 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37506 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37507
37508
37509 static void stat_event(struct atm_dev *dev)
37510 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37511 if (reason & uPD98402_INT_PFM) stat_event(dev);
37512 if (reason & uPD98402_INT_PCO) {
37513 (void) GET(PCOCR); /* clear interrupt cause */
37514 - atomic_add(GET(HECCT),
37515 + atomic_add_unchecked(GET(HECCT),
37516 &PRIV(dev)->sonet_stats.uncorr_hcs);
37517 }
37518 if ((reason & uPD98402_INT_RFO) &&
37519 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37520 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37521 uPD98402_INT_LOS),PIMR); /* enable them */
37522 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37523 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37524 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37525 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37526 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37527 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37528 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37529 return 0;
37530 }
37531
37532 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37533 index 969c3c2..9b72956 100644
37534 --- a/drivers/atm/zatm.c
37535 +++ b/drivers/atm/zatm.c
37536 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37537 }
37538 if (!size) {
37539 dev_kfree_skb_irq(skb);
37540 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37541 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37542 continue;
37543 }
37544 if (!atm_charge(vcc,skb->truesize)) {
37545 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37546 skb->len = size;
37547 ATM_SKB(skb)->vcc = vcc;
37548 vcc->push(vcc,skb);
37549 - atomic_inc(&vcc->stats->rx);
37550 + atomic_inc_unchecked(&vcc->stats->rx);
37551 }
37552 zout(pos & 0xffff,MTA(mbx));
37553 #if 0 /* probably a stupid idea */
37554 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37555 skb_queue_head(&zatm_vcc->backlog,skb);
37556 break;
37557 }
37558 - atomic_inc(&vcc->stats->tx);
37559 + atomic_inc_unchecked(&vcc->stats->tx);
37560 wake_up(&zatm_vcc->tx_wait);
37561 }
37562
37563 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37564 index 876bae5..8978785 100644
37565 --- a/drivers/base/bus.c
37566 +++ b/drivers/base/bus.c
37567 @@ -1126,7 +1126,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37568 return -EINVAL;
37569
37570 mutex_lock(&subsys->p->mutex);
37571 - list_add_tail(&sif->node, &subsys->p->interfaces);
37572 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37573 if (sif->add_dev) {
37574 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37575 while ((dev = subsys_dev_iter_next(&iter)))
37576 @@ -1151,7 +1151,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37577 subsys = sif->subsys;
37578
37579 mutex_lock(&subsys->p->mutex);
37580 - list_del_init(&sif->node);
37581 + pax_list_del_init((struct list_head *)&sif->node);
37582 if (sif->remove_dev) {
37583 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37584 while ((dev = subsys_dev_iter_next(&iter)))
37585 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37586 index 25798db..15f130e 100644
37587 --- a/drivers/base/devtmpfs.c
37588 +++ b/drivers/base/devtmpfs.c
37589 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37590 if (!thread)
37591 return 0;
37592
37593 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37594 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37595 if (err)
37596 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37597 else
37598 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37599 *err = sys_unshare(CLONE_NEWNS);
37600 if (*err)
37601 goto out;
37602 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37603 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37604 if (*err)
37605 goto out;
37606 - sys_chdir("/.."); /* will traverse into overmounted root */
37607 - sys_chroot(".");
37608 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37609 + sys_chroot((char __force_user *)".");
37610 complete(&setup_done);
37611 while (1) {
37612 spin_lock(&req_lock);
37613 diff --git a/drivers/base/node.c b/drivers/base/node.c
37614 index 472168c..4af587e 100644
37615 --- a/drivers/base/node.c
37616 +++ b/drivers/base/node.c
37617 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37618 struct node_attr {
37619 struct device_attribute attr;
37620 enum node_states state;
37621 -};
37622 +} __do_const;
37623
37624 static ssize_t show_node_state(struct device *dev,
37625 struct device_attribute *attr, char *buf)
37626 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37627 index fb83d4a..e1797b3 100644
37628 --- a/drivers/base/power/domain.c
37629 +++ b/drivers/base/power/domain.c
37630 @@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37631 {
37632 struct cpuidle_driver *cpuidle_drv;
37633 struct gpd_cpuidle_data *cpuidle_data;
37634 - struct cpuidle_state *idle_state;
37635 + cpuidle_state_no_const *idle_state;
37636 int ret = 0;
37637
37638 if (IS_ERR_OR_NULL(genpd) || state < 0)
37639 @@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37640 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37641 {
37642 struct gpd_cpuidle_data *cpuidle_data;
37643 - struct cpuidle_state *idle_state;
37644 + cpuidle_state_no_const *idle_state;
37645 int ret = 0;
37646
37647 if (IS_ERR_OR_NULL(genpd))
37648 @@ -2215,7 +2215,9 @@ int genpd_dev_pm_attach(struct device *dev)
37649 return ret;
37650 }
37651
37652 - dev->pm_domain->detach = genpd_dev_pm_detach;
37653 + pax_open_kernel();
37654 + *(void **)&dev->pm_domain->detach = genpd_dev_pm_detach;
37655 + pax_close_kernel();
37656
37657 return 0;
37658 }
37659 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37660 index a9d26ed..74b8405 100644
37661 --- a/drivers/base/power/sysfs.c
37662 +++ b/drivers/base/power/sysfs.c
37663 @@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37664 return -EIO;
37665 }
37666 }
37667 - return sprintf(buf, p);
37668 + return sprintf(buf, "%s", p);
37669 }
37670
37671 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37672 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37673 index c2744b3..08fac19 100644
37674 --- a/drivers/base/power/wakeup.c
37675 +++ b/drivers/base/power/wakeup.c
37676 @@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37677 * They need to be modified together atomically, so it's better to use one
37678 * atomic variable to hold them both.
37679 */
37680 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37681 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37682
37683 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37684 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37685
37686 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37687 {
37688 - unsigned int comb = atomic_read(&combined_event_count);
37689 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37690
37691 *cnt = (comb >> IN_PROGRESS_BITS);
37692 *inpr = comb & MAX_IN_PROGRESS;
37693 @@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37694 ws->start_prevent_time = ws->last_time;
37695
37696 /* Increment the counter of events in progress. */
37697 - cec = atomic_inc_return(&combined_event_count);
37698 + cec = atomic_inc_return_unchecked(&combined_event_count);
37699
37700 trace_wakeup_source_activate(ws->name, cec);
37701 }
37702 @@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37703 * Increment the counter of registered wakeup events and decrement the
37704 * couter of wakeup events in progress simultaneously.
37705 */
37706 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37707 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37708 trace_wakeup_source_deactivate(ws->name, cec);
37709
37710 split_counters(&cnt, &inpr);
37711 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37712 index 8d98a32..61d3165 100644
37713 --- a/drivers/base/syscore.c
37714 +++ b/drivers/base/syscore.c
37715 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37716 void register_syscore_ops(struct syscore_ops *ops)
37717 {
37718 mutex_lock(&syscore_ops_lock);
37719 - list_add_tail(&ops->node, &syscore_ops_list);
37720 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37721 mutex_unlock(&syscore_ops_lock);
37722 }
37723 EXPORT_SYMBOL_GPL(register_syscore_ops);
37724 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37725 void unregister_syscore_ops(struct syscore_ops *ops)
37726 {
37727 mutex_lock(&syscore_ops_lock);
37728 - list_del(&ops->node);
37729 + pax_list_del((struct list_head *)&ops->node);
37730 mutex_unlock(&syscore_ops_lock);
37731 }
37732 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37733 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37734 index ff20f19..018f1da 100644
37735 --- a/drivers/block/cciss.c
37736 +++ b/drivers/block/cciss.c
37737 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37738 while (!list_empty(&h->reqQ)) {
37739 c = list_entry(h->reqQ.next, CommandList_struct, list);
37740 /* can't do anything if fifo is full */
37741 - if ((h->access.fifo_full(h))) {
37742 + if ((h->access->fifo_full(h))) {
37743 dev_warn(&h->pdev->dev, "fifo full\n");
37744 break;
37745 }
37746 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37747 h->Qdepth--;
37748
37749 /* Tell the controller execute command */
37750 - h->access.submit_command(h, c);
37751 + h->access->submit_command(h, c);
37752
37753 /* Put job onto the completed Q */
37754 addQ(&h->cmpQ, c);
37755 @@ -3444,17 +3444,17 @@ startio:
37756
37757 static inline unsigned long get_next_completion(ctlr_info_t *h)
37758 {
37759 - return h->access.command_completed(h);
37760 + return h->access->command_completed(h);
37761 }
37762
37763 static inline int interrupt_pending(ctlr_info_t *h)
37764 {
37765 - return h->access.intr_pending(h);
37766 + return h->access->intr_pending(h);
37767 }
37768
37769 static inline long interrupt_not_for_us(ctlr_info_t *h)
37770 {
37771 - return ((h->access.intr_pending(h) == 0) ||
37772 + return ((h->access->intr_pending(h) == 0) ||
37773 (h->interrupts_enabled == 0));
37774 }
37775
37776 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37777 u32 a;
37778
37779 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37780 - return h->access.command_completed(h);
37781 + return h->access->command_completed(h);
37782
37783 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37784 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37785 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37786 trans_support & CFGTBL_Trans_use_short_tags);
37787
37788 /* Change the access methods to the performant access methods */
37789 - h->access = SA5_performant_access;
37790 + h->access = &SA5_performant_access;
37791 h->transMethod = CFGTBL_Trans_Performant;
37792
37793 return;
37794 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37795 if (prod_index < 0)
37796 return -ENODEV;
37797 h->product_name = products[prod_index].product_name;
37798 - h->access = *(products[prod_index].access);
37799 + h->access = products[prod_index].access;
37800
37801 if (cciss_board_disabled(h)) {
37802 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37803 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37804 }
37805
37806 /* make sure the board interrupts are off */
37807 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37808 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37809 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37810 if (rc)
37811 goto clean2;
37812 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37813 * fake ones to scoop up any residual completions.
37814 */
37815 spin_lock_irqsave(&h->lock, flags);
37816 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37817 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37818 spin_unlock_irqrestore(&h->lock, flags);
37819 free_irq(h->intr[h->intr_mode], h);
37820 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37821 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37822 dev_info(&h->pdev->dev, "Board READY.\n");
37823 dev_info(&h->pdev->dev,
37824 "Waiting for stale completions to drain.\n");
37825 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37826 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37827 msleep(10000);
37828 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37829 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37830
37831 rc = controller_reset_failed(h->cfgtable);
37832 if (rc)
37833 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37834 cciss_scsi_setup(h);
37835
37836 /* Turn the interrupts on so we can service requests */
37837 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37838 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37839
37840 /* Get the firmware version */
37841 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37842 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37843 kfree(flush_buf);
37844 if (return_code != IO_OK)
37845 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37846 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37847 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37848 free_irq(h->intr[h->intr_mode], h);
37849 }
37850
37851 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37852 index 7fda30e..2f27946 100644
37853 --- a/drivers/block/cciss.h
37854 +++ b/drivers/block/cciss.h
37855 @@ -101,7 +101,7 @@ struct ctlr_info
37856 /* information about each logical volume */
37857 drive_info_struct *drv[CISS_MAX_LUN];
37858
37859 - struct access_method access;
37860 + struct access_method *access;
37861
37862 /* queue and queue Info */
37863 struct list_head reqQ;
37864 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37865 }
37866
37867 static struct access_method SA5_access = {
37868 - SA5_submit_command,
37869 - SA5_intr_mask,
37870 - SA5_fifo_full,
37871 - SA5_intr_pending,
37872 - SA5_completed,
37873 + .submit_command = SA5_submit_command,
37874 + .set_intr_mask = SA5_intr_mask,
37875 + .fifo_full = SA5_fifo_full,
37876 + .intr_pending = SA5_intr_pending,
37877 + .command_completed = SA5_completed,
37878 };
37879
37880 static struct access_method SA5B_access = {
37881 - SA5_submit_command,
37882 - SA5B_intr_mask,
37883 - SA5_fifo_full,
37884 - SA5B_intr_pending,
37885 - SA5_completed,
37886 + .submit_command = SA5_submit_command,
37887 + .set_intr_mask = SA5B_intr_mask,
37888 + .fifo_full = SA5_fifo_full,
37889 + .intr_pending = SA5B_intr_pending,
37890 + .command_completed = SA5_completed,
37891 };
37892
37893 static struct access_method SA5_performant_access = {
37894 - SA5_submit_command,
37895 - SA5_performant_intr_mask,
37896 - SA5_fifo_full,
37897 - SA5_performant_intr_pending,
37898 - SA5_performant_completed,
37899 + .submit_command = SA5_submit_command,
37900 + .set_intr_mask = SA5_performant_intr_mask,
37901 + .fifo_full = SA5_fifo_full,
37902 + .intr_pending = SA5_performant_intr_pending,
37903 + .command_completed = SA5_performant_completed,
37904 };
37905
37906 struct board_type {
37907 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37908 index 2b94403..fd6ad1f 100644
37909 --- a/drivers/block/cpqarray.c
37910 +++ b/drivers/block/cpqarray.c
37911 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37912 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37913 goto Enomem4;
37914 }
37915 - hba[i]->access.set_intr_mask(hba[i], 0);
37916 + hba[i]->access->set_intr_mask(hba[i], 0);
37917 if (request_irq(hba[i]->intr, do_ida_intr,
37918 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37919 {
37920 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37921 add_timer(&hba[i]->timer);
37922
37923 /* Enable IRQ now that spinlock and rate limit timer are set up */
37924 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37925 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37926
37927 for(j=0; j<NWD; j++) {
37928 struct gendisk *disk = ida_gendisk[i][j];
37929 @@ -694,7 +694,7 @@ DBGINFO(
37930 for(i=0; i<NR_PRODUCTS; i++) {
37931 if (board_id == products[i].board_id) {
37932 c->product_name = products[i].product_name;
37933 - c->access = *(products[i].access);
37934 + c->access = products[i].access;
37935 break;
37936 }
37937 }
37938 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37939 hba[ctlr]->intr = intr;
37940 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37941 hba[ctlr]->product_name = products[j].product_name;
37942 - hba[ctlr]->access = *(products[j].access);
37943 + hba[ctlr]->access = products[j].access;
37944 hba[ctlr]->ctlr = ctlr;
37945 hba[ctlr]->board_id = board_id;
37946 hba[ctlr]->pci_dev = NULL; /* not PCI */
37947 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37948
37949 while((c = h->reqQ) != NULL) {
37950 /* Can't do anything if we're busy */
37951 - if (h->access.fifo_full(h) == 0)
37952 + if (h->access->fifo_full(h) == 0)
37953 return;
37954
37955 /* Get the first entry from the request Q */
37956 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37957 h->Qdepth--;
37958
37959 /* Tell the controller to do our bidding */
37960 - h->access.submit_command(h, c);
37961 + h->access->submit_command(h, c);
37962
37963 /* Get onto the completion Q */
37964 addQ(&h->cmpQ, c);
37965 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37966 unsigned long flags;
37967 __u32 a,a1;
37968
37969 - istat = h->access.intr_pending(h);
37970 + istat = h->access->intr_pending(h);
37971 /* Is this interrupt for us? */
37972 if (istat == 0)
37973 return IRQ_NONE;
37974 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37975 */
37976 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37977 if (istat & FIFO_NOT_EMPTY) {
37978 - while((a = h->access.command_completed(h))) {
37979 + while((a = h->access->command_completed(h))) {
37980 a1 = a; a &= ~3;
37981 if ((c = h->cmpQ) == NULL)
37982 {
37983 @@ -1448,11 +1448,11 @@ static int sendcmd(
37984 /*
37985 * Disable interrupt
37986 */
37987 - info_p->access.set_intr_mask(info_p, 0);
37988 + info_p->access->set_intr_mask(info_p, 0);
37989 /* Make sure there is room in the command FIFO */
37990 /* Actually it should be completely empty at this time. */
37991 for (i = 200000; i > 0; i--) {
37992 - temp = info_p->access.fifo_full(info_p);
37993 + temp = info_p->access->fifo_full(info_p);
37994 if (temp != 0) {
37995 break;
37996 }
37997 @@ -1465,7 +1465,7 @@ DBG(
37998 /*
37999 * Send the cmd
38000 */
38001 - info_p->access.submit_command(info_p, c);
38002 + info_p->access->submit_command(info_p, c);
38003 complete = pollcomplete(ctlr);
38004
38005 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38006 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38007 * we check the new geometry. Then turn interrupts back on when
38008 * we're done.
38009 */
38010 - host->access.set_intr_mask(host, 0);
38011 + host->access->set_intr_mask(host, 0);
38012 getgeometry(ctlr);
38013 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38014 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38015
38016 for(i=0; i<NWD; i++) {
38017 struct gendisk *disk = ida_gendisk[ctlr][i];
38018 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38019 /* Wait (up to 2 seconds) for a command to complete */
38020
38021 for (i = 200000; i > 0; i--) {
38022 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38023 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38024 if (done == 0) {
38025 udelay(10); /* a short fixed delay */
38026 } else
38027 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38028 index be73e9d..7fbf140 100644
38029 --- a/drivers/block/cpqarray.h
38030 +++ b/drivers/block/cpqarray.h
38031 @@ -99,7 +99,7 @@ struct ctlr_info {
38032 drv_info_t drv[NWD];
38033 struct proc_dir_entry *proc;
38034
38035 - struct access_method access;
38036 + struct access_method *access;
38037
38038 cmdlist_t *reqQ;
38039 cmdlist_t *cmpQ;
38040 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38041 index 434c77d..6d3219a 100644
38042 --- a/drivers/block/drbd/drbd_bitmap.c
38043 +++ b/drivers/block/drbd/drbd_bitmap.c
38044 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38045 submit_bio(rw, bio);
38046 /* this should not count as user activity and cause the
38047 * resync to throttle -- see drbd_rs_should_slow_down(). */
38048 - atomic_add(len >> 9, &device->rs_sect_ev);
38049 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38050 }
38051 }
38052
38053 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38054 index 9b22f8f..f2932af 100644
38055 --- a/drivers/block/drbd/drbd_int.h
38056 +++ b/drivers/block/drbd/drbd_int.h
38057 @@ -385,7 +385,7 @@ struct drbd_epoch {
38058 struct drbd_connection *connection;
38059 struct list_head list;
38060 unsigned int barrier_nr;
38061 - atomic_t epoch_size; /* increased on every request added. */
38062 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38063 atomic_t active; /* increased on every req. added, and dec on every finished. */
38064 unsigned long flags;
38065 };
38066 @@ -946,7 +946,7 @@ struct drbd_device {
38067 unsigned int al_tr_number;
38068 int al_tr_cycle;
38069 wait_queue_head_t seq_wait;
38070 - atomic_t packet_seq;
38071 + atomic_unchecked_t packet_seq;
38072 unsigned int peer_seq;
38073 spinlock_t peer_seq_lock;
38074 unsigned long comm_bm_set; /* communicated number of set bits. */
38075 @@ -955,8 +955,8 @@ struct drbd_device {
38076 struct mutex own_state_mutex;
38077 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38078 char congestion_reason; /* Why we where congested... */
38079 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38080 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38081 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38082 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38083 int rs_last_sect_ev; /* counter to compare with */
38084 int rs_last_events; /* counter of read or write "events" (unit sectors)
38085 * on the lower level device when we last looked. */
38086 @@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38087 char __user *uoptval;
38088 int err;
38089
38090 - uoptval = (char __user __force *)optval;
38091 + uoptval = (char __force_user *)optval;
38092
38093 set_fs(KERNEL_DS);
38094 if (level == SOL_SOCKET)
38095 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38096 index 973c185..05d8b1a 100644
38097 --- a/drivers/block/drbd/drbd_main.c
38098 +++ b/drivers/block/drbd/drbd_main.c
38099 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38100 p->sector = sector;
38101 p->block_id = block_id;
38102 p->blksize = blksize;
38103 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38104 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38105 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38106 }
38107
38108 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38109 return -EIO;
38110 p->sector = cpu_to_be64(req->i.sector);
38111 p->block_id = (unsigned long)req;
38112 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38113 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38114 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38115 if (device->state.conn >= C_SYNC_SOURCE &&
38116 device->state.conn <= C_PAUSED_SYNC_T)
38117 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38118 atomic_set(&device->unacked_cnt, 0);
38119 atomic_set(&device->local_cnt, 0);
38120 atomic_set(&device->pp_in_use_by_net, 0);
38121 - atomic_set(&device->rs_sect_in, 0);
38122 - atomic_set(&device->rs_sect_ev, 0);
38123 + atomic_set_unchecked(&device->rs_sect_in, 0);
38124 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38125 atomic_set(&device->ap_in_flight, 0);
38126 atomic_set(&device->md_io.in_use, 0);
38127
38128 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38129 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38130 struct drbd_resource *resource = connection->resource;
38131
38132 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38133 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38134 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38135 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38136 kfree(connection->current_epoch);
38137
38138 idr_destroy(&connection->peer_devices);
38139 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38140 index 1cd47df..57c53c0 100644
38141 --- a/drivers/block/drbd/drbd_nl.c
38142 +++ b/drivers/block/drbd/drbd_nl.c
38143 @@ -3645,13 +3645,13 @@ finish:
38144
38145 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38146 {
38147 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38148 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38149 struct sk_buff *msg;
38150 struct drbd_genlmsghdr *d_out;
38151 unsigned seq;
38152 int err = -ENOMEM;
38153
38154 - seq = atomic_inc_return(&drbd_genl_seq);
38155 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38156 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38157 if (!msg)
38158 goto failed;
38159 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38160 index 6960fb0..215d76b 100644
38161 --- a/drivers/block/drbd/drbd_receiver.c
38162 +++ b/drivers/block/drbd/drbd_receiver.c
38163 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38164 struct drbd_device *device = peer_device->device;
38165 int err;
38166
38167 - atomic_set(&device->packet_seq, 0);
38168 + atomic_set_unchecked(&device->packet_seq, 0);
38169 device->peer_seq = 0;
38170
38171 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38172 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38173 do {
38174 next_epoch = NULL;
38175
38176 - epoch_size = atomic_read(&epoch->epoch_size);
38177 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38178
38179 switch (ev & ~EV_CLEANUP) {
38180 case EV_PUT:
38181 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38182 rv = FE_DESTROYED;
38183 } else {
38184 epoch->flags = 0;
38185 - atomic_set(&epoch->epoch_size, 0);
38186 + atomic_set_unchecked(&epoch->epoch_size, 0);
38187 /* atomic_set(&epoch->active, 0); is already zero */
38188 if (rv == FE_STILL_LIVE)
38189 rv = FE_RECYCLED;
38190 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38191 conn_wait_active_ee_empty(connection);
38192 drbd_flush(connection);
38193
38194 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38195 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38196 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38197 if (epoch)
38198 break;
38199 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38200 }
38201
38202 epoch->flags = 0;
38203 - atomic_set(&epoch->epoch_size, 0);
38204 + atomic_set_unchecked(&epoch->epoch_size, 0);
38205 atomic_set(&epoch->active, 0);
38206
38207 spin_lock(&connection->epoch_lock);
38208 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38209 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38210 list_add(&epoch->list, &connection->current_epoch->list);
38211 connection->current_epoch = epoch;
38212 connection->epochs++;
38213 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38214 list_add_tail(&peer_req->w.list, &device->sync_ee);
38215 spin_unlock_irq(&device->resource->req_lock);
38216
38217 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
38218 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38219 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38220 return 0;
38221
38222 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38223 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38224 }
38225
38226 - atomic_add(pi->size >> 9, &device->rs_sect_in);
38227 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38228
38229 return err;
38230 }
38231 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38232
38233 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38234 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38235 - atomic_inc(&connection->current_epoch->epoch_size);
38236 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38237 err2 = drbd_drain_block(peer_device, pi->size);
38238 if (!err)
38239 err = err2;
38240 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38241
38242 spin_lock(&connection->epoch_lock);
38243 peer_req->epoch = connection->current_epoch;
38244 - atomic_inc(&peer_req->epoch->epoch_size);
38245 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38246 atomic_inc(&peer_req->epoch->active);
38247 spin_unlock(&connection->epoch_lock);
38248
38249 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38250
38251 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38252 (int)part_stat_read(&disk->part0, sectors[1]) -
38253 - atomic_read(&device->rs_sect_ev);
38254 + atomic_read_unchecked(&device->rs_sect_ev);
38255
38256 if (atomic_read(&device->ap_actlog_cnt)
38257 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38258 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38259 device->use_csums = true;
38260 } else if (pi->cmd == P_OV_REPLY) {
38261 /* track progress, we may need to throttle */
38262 - atomic_add(size >> 9, &device->rs_sect_in);
38263 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38264 peer_req->w.cb = w_e_end_ov_reply;
38265 dec_rs_pending(device);
38266 /* drbd_rs_begin_io done when we sent this request,
38267 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38268 goto out_free_e;
38269
38270 submit_for_resync:
38271 - atomic_add(size >> 9, &device->rs_sect_ev);
38272 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38273
38274 submit:
38275 update_receiver_timing_details(connection, drbd_submit_peer_request);
38276 @@ -4564,7 +4564,7 @@ struct data_cmd {
38277 int expect_payload;
38278 size_t pkt_size;
38279 int (*fn)(struct drbd_connection *, struct packet_info *);
38280 -};
38281 +} __do_const;
38282
38283 static struct data_cmd drbd_cmd_handler[] = {
38284 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38285 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38286 if (!list_empty(&connection->current_epoch->list))
38287 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38288 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38289 - atomic_set(&connection->current_epoch->epoch_size, 0);
38290 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38291 connection->send.seen_any_write_yet = false;
38292
38293 drbd_info(connection, "Connection closed\n");
38294 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38295 put_ldev(device);
38296 }
38297 dec_rs_pending(device);
38298 - atomic_add(blksize >> 9, &device->rs_sect_in);
38299 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38300
38301 return 0;
38302 }
38303 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38304 struct asender_cmd {
38305 size_t pkt_size;
38306 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38307 -};
38308 +} __do_const;
38309
38310 static struct asender_cmd asender_tbl[] = {
38311 [P_PING] = { 0, got_Ping },
38312 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38313 index d2d1f97..6a1188f 100644
38314 --- a/drivers/block/drbd/drbd_worker.c
38315 +++ b/drivers/block/drbd/drbd_worker.c
38316 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38317 list_add_tail(&peer_req->w.list, &device->read_ee);
38318 spin_unlock_irq(&device->resource->req_lock);
38319
38320 - atomic_add(size >> 9, &device->rs_sect_ev);
38321 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38322 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38323 return 0;
38324
38325 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38326 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38327 int number, mxb;
38328
38329 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
38330 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38331 device->rs_in_flight -= sect_in;
38332
38333 rcu_read_lock();
38334 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38335 {
38336 struct fifo_buffer *plan;
38337
38338 - atomic_set(&device->rs_sect_in, 0);
38339 - atomic_set(&device->rs_sect_ev, 0);
38340 + atomic_set_unchecked(&device->rs_sect_in, 0);
38341 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38342 device->rs_in_flight = 0;
38343
38344 /* Updating the RCU protected object in place is necessary since
38345 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38346 index 6cb1beb..bf490f7 100644
38347 --- a/drivers/block/loop.c
38348 +++ b/drivers/block/loop.c
38349 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38350
38351 file_start_write(file);
38352 set_fs(get_ds());
38353 - bw = file->f_op->write(file, buf, len, &pos);
38354 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38355 set_fs(old_fs);
38356 file_end_write(file);
38357 if (likely(bw == len))
38358 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38359 index e2bb8af..44b8aef 100644
38360 --- a/drivers/block/nvme-core.c
38361 +++ b/drivers/block/nvme-core.c
38362 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38363 static struct task_struct *nvme_thread;
38364 static struct workqueue_struct *nvme_workq;
38365 static wait_queue_head_t nvme_kthread_wait;
38366 -static struct notifier_block nvme_nb;
38367
38368 static void nvme_reset_failed_dev(struct work_struct *ws);
38369
38370 @@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38371 .err_handler = &nvme_err_handler,
38372 };
38373
38374 +static struct notifier_block nvme_nb = {
38375 + .notifier_call = &nvme_cpu_notify,
38376 +};
38377 +
38378 static int __init nvme_init(void)
38379 {
38380 int result;
38381 @@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38382 else if (result > 0)
38383 nvme_major = result;
38384
38385 - nvme_nb.notifier_call = &nvme_cpu_notify;
38386 result = register_hotcpu_notifier(&nvme_nb);
38387 if (result)
38388 goto unregister_blkdev;
38389 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38390 index 09e628da..7607aaa 100644
38391 --- a/drivers/block/pktcdvd.c
38392 +++ b/drivers/block/pktcdvd.c
38393 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38394
38395 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38396 {
38397 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38398 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38399 }
38400
38401 /*
38402 @@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38403 return -EROFS;
38404 }
38405 pd->settings.fp = ti.fp;
38406 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38407 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38408
38409 if (ti.nwa_v) {
38410 pd->nwa = be32_to_cpu(ti.next_writable);
38411 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38412 index e5565fb..71be10b4 100644
38413 --- a/drivers/block/smart1,2.h
38414 +++ b/drivers/block/smart1,2.h
38415 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38416 }
38417
38418 static struct access_method smart4_access = {
38419 - smart4_submit_command,
38420 - smart4_intr_mask,
38421 - smart4_fifo_full,
38422 - smart4_intr_pending,
38423 - smart4_completed,
38424 + .submit_command = smart4_submit_command,
38425 + .set_intr_mask = smart4_intr_mask,
38426 + .fifo_full = smart4_fifo_full,
38427 + .intr_pending = smart4_intr_pending,
38428 + .command_completed = smart4_completed,
38429 };
38430
38431 /*
38432 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38433 }
38434
38435 static struct access_method smart2_access = {
38436 - smart2_submit_command,
38437 - smart2_intr_mask,
38438 - smart2_fifo_full,
38439 - smart2_intr_pending,
38440 - smart2_completed,
38441 + .submit_command = smart2_submit_command,
38442 + .set_intr_mask = smart2_intr_mask,
38443 + .fifo_full = smart2_fifo_full,
38444 + .intr_pending = smart2_intr_pending,
38445 + .command_completed = smart2_completed,
38446 };
38447
38448 /*
38449 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38450 }
38451
38452 static struct access_method smart2e_access = {
38453 - smart2e_submit_command,
38454 - smart2e_intr_mask,
38455 - smart2e_fifo_full,
38456 - smart2e_intr_pending,
38457 - smart2e_completed,
38458 + .submit_command = smart2e_submit_command,
38459 + .set_intr_mask = smart2e_intr_mask,
38460 + .fifo_full = smart2e_fifo_full,
38461 + .intr_pending = smart2e_intr_pending,
38462 + .command_completed = smart2e_completed,
38463 };
38464
38465 /*
38466 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38467 }
38468
38469 static struct access_method smart1_access = {
38470 - smart1_submit_command,
38471 - smart1_intr_mask,
38472 - smart1_fifo_full,
38473 - smart1_intr_pending,
38474 - smart1_completed,
38475 + .submit_command = smart1_submit_command,
38476 + .set_intr_mask = smart1_intr_mask,
38477 + .fifo_full = smart1_fifo_full,
38478 + .intr_pending = smart1_intr_pending,
38479 + .command_completed = smart1_completed,
38480 };
38481 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38482 index f038dba..bb74c08 100644
38483 --- a/drivers/bluetooth/btwilink.c
38484 +++ b/drivers/bluetooth/btwilink.c
38485 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38486
38487 static int bt_ti_probe(struct platform_device *pdev)
38488 {
38489 - static struct ti_st *hst;
38490 + struct ti_st *hst;
38491 struct hci_dev *hdev;
38492 int err;
38493
38494 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38495 index 5d28a45..a538f90 100644
38496 --- a/drivers/cdrom/cdrom.c
38497 +++ b/drivers/cdrom/cdrom.c
38498 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38499 ENSURE(reset, CDC_RESET);
38500 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38501 cdi->mc_flags = 0;
38502 - cdo->n_minors = 0;
38503 cdi->options = CDO_USE_FFLAGS;
38504
38505 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38506 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38507 else
38508 cdi->cdda_method = CDDA_OLD;
38509
38510 - if (!cdo->generic_packet)
38511 - cdo->generic_packet = cdrom_dummy_generic_packet;
38512 + if (!cdo->generic_packet) {
38513 + pax_open_kernel();
38514 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38515 + pax_close_kernel();
38516 + }
38517
38518 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38519 mutex_lock(&cdrom_mutex);
38520 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38521 if (cdi->exit)
38522 cdi->exit(cdi);
38523
38524 - cdi->ops->n_minors--;
38525 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38526 }
38527
38528 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38529 */
38530 nr = nframes;
38531 do {
38532 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38533 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38534 if (cgc.buffer)
38535 break;
38536
38537 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38538 struct cdrom_device_info *cdi;
38539 int ret;
38540
38541 - ret = scnprintf(info + *pos, max_size - *pos, header);
38542 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38543 if (!ret)
38544 return 1;
38545
38546 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38547 index 584bc31..e64a12c 100644
38548 --- a/drivers/cdrom/gdrom.c
38549 +++ b/drivers/cdrom/gdrom.c
38550 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38551 .audio_ioctl = gdrom_audio_ioctl,
38552 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38553 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38554 - .n_minors = 1,
38555 };
38556
38557 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38558 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38559 index efefd12..4f1d494 100644
38560 --- a/drivers/char/Kconfig
38561 +++ b/drivers/char/Kconfig
38562 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38563
38564 config DEVKMEM
38565 bool "/dev/kmem virtual device support"
38566 - default y
38567 + default n
38568 + depends on !GRKERNSEC_KMEM
38569 help
38570 Say Y here if you want to support the /dev/kmem device. The
38571 /dev/kmem device is rarely used, but can be used for certain
38572 @@ -577,6 +578,7 @@ config DEVPORT
38573 bool
38574 depends on !M68K
38575 depends on ISA || PCI
38576 + depends on !GRKERNSEC_KMEM
38577 default y
38578
38579 source "drivers/s390/char/Kconfig"
38580 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38581 index a48e05b..6bac831 100644
38582 --- a/drivers/char/agp/compat_ioctl.c
38583 +++ b/drivers/char/agp/compat_ioctl.c
38584 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38585 return -ENOMEM;
38586 }
38587
38588 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38589 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38590 sizeof(*usegment) * ureserve.seg_count)) {
38591 kfree(usegment);
38592 kfree(ksegment);
38593 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38594 index 09f17eb..8531d2f 100644
38595 --- a/drivers/char/agp/frontend.c
38596 +++ b/drivers/char/agp/frontend.c
38597 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38598 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38599 return -EFAULT;
38600
38601 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38602 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38603 return -EFAULT;
38604
38605 client = agp_find_client_by_pid(reserve.pid);
38606 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38607 if (segment == NULL)
38608 return -ENOMEM;
38609
38610 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38611 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38612 sizeof(struct agp_segment) * reserve.seg_count)) {
38613 kfree(segment);
38614 return -EFAULT;
38615 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38616 index 4f94375..413694e 100644
38617 --- a/drivers/char/genrtc.c
38618 +++ b/drivers/char/genrtc.c
38619 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38620 switch (cmd) {
38621
38622 case RTC_PLL_GET:
38623 + memset(&pll, 0, sizeof(pll));
38624 if (get_rtc_pll(&pll))
38625 return -EINVAL;
38626 else
38627 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38628 index d5d4cd8..22d561d 100644
38629 --- a/drivers/char/hpet.c
38630 +++ b/drivers/char/hpet.c
38631 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38632 }
38633
38634 static int
38635 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38636 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38637 struct hpet_info *info)
38638 {
38639 struct hpet_timer __iomem *timer;
38640 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38641 index f816211..89eadea 100644
38642 --- a/drivers/char/ipmi/ipmi_msghandler.c
38643 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38644 @@ -438,7 +438,7 @@ struct ipmi_smi {
38645 struct proc_dir_entry *proc_dir;
38646 char proc_dir_name[10];
38647
38648 - atomic_t stats[IPMI_NUM_STATS];
38649 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38650
38651 /*
38652 * run_to_completion duplicate of smb_info, smi_info
38653 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38654 static DEFINE_MUTEX(smi_watchers_mutex);
38655
38656 #define ipmi_inc_stat(intf, stat) \
38657 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38658 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38659 #define ipmi_get_stat(intf, stat) \
38660 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38661 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38662
38663 static int is_lan_addr(struct ipmi_addr *addr)
38664 {
38665 @@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38666 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38667 init_waitqueue_head(&intf->waitq);
38668 for (i = 0; i < IPMI_NUM_STATS; i++)
38669 - atomic_set(&intf->stats[i], 0);
38670 + atomic_set_unchecked(&intf->stats[i], 0);
38671
38672 intf->proc_dir = NULL;
38673
38674 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38675 index 5c4e1f6..0ea58f9 100644
38676 --- a/drivers/char/ipmi/ipmi_si_intf.c
38677 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38678 @@ -285,7 +285,7 @@ struct smi_info {
38679 unsigned char slave_addr;
38680
38681 /* Counters and things for the proc filesystem. */
38682 - atomic_t stats[SI_NUM_STATS];
38683 + atomic_unchecked_t stats[SI_NUM_STATS];
38684
38685 struct task_struct *thread;
38686
38687 @@ -294,9 +294,9 @@ struct smi_info {
38688 };
38689
38690 #define smi_inc_stat(smi, stat) \
38691 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38692 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38693 #define smi_get_stat(smi, stat) \
38694 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38695 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38696
38697 #define SI_MAX_PARMS 4
38698
38699 @@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38700 atomic_set(&new_smi->req_events, 0);
38701 new_smi->run_to_completion = false;
38702 for (i = 0; i < SI_NUM_STATS; i++)
38703 - atomic_set(&new_smi->stats[i], 0);
38704 + atomic_set_unchecked(&new_smi->stats[i], 0);
38705
38706 new_smi->interrupt_disabled = true;
38707 atomic_set(&new_smi->stop_operation, 0);
38708 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38709 index 524b707..29d07c1 100644
38710 --- a/drivers/char/mem.c
38711 +++ b/drivers/char/mem.c
38712 @@ -18,6 +18,7 @@
38713 #include <linux/raw.h>
38714 #include <linux/tty.h>
38715 #include <linux/capability.h>
38716 +#include <linux/security.h>
38717 #include <linux/ptrace.h>
38718 #include <linux/device.h>
38719 #include <linux/highmem.h>
38720 @@ -36,6 +37,10 @@
38721
38722 #define DEVPORT_MINOR 4
38723
38724 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38725 +extern const struct file_operations grsec_fops;
38726 +#endif
38727 +
38728 static inline unsigned long size_inside_page(unsigned long start,
38729 unsigned long size)
38730 {
38731 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38732
38733 while (cursor < to) {
38734 if (!devmem_is_allowed(pfn)) {
38735 +#ifdef CONFIG_GRKERNSEC_KMEM
38736 + gr_handle_mem_readwrite(from, to);
38737 +#else
38738 printk(KERN_INFO
38739 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38740 current->comm, from, to);
38741 +#endif
38742 return 0;
38743 }
38744 cursor += PAGE_SIZE;
38745 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38746 }
38747 return 1;
38748 }
38749 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38750 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38751 +{
38752 + return 0;
38753 +}
38754 #else
38755 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38756 {
38757 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38758
38759 while (count > 0) {
38760 unsigned long remaining;
38761 + char *temp;
38762
38763 sz = size_inside_page(p, count);
38764
38765 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38766 if (!ptr)
38767 return -EFAULT;
38768
38769 - remaining = copy_to_user(buf, ptr, sz);
38770 +#ifdef CONFIG_PAX_USERCOPY
38771 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38772 + if (!temp) {
38773 + unxlate_dev_mem_ptr(p, ptr);
38774 + return -ENOMEM;
38775 + }
38776 + memcpy(temp, ptr, sz);
38777 +#else
38778 + temp = ptr;
38779 +#endif
38780 +
38781 + remaining = copy_to_user(buf, temp, sz);
38782 +
38783 +#ifdef CONFIG_PAX_USERCOPY
38784 + kfree(temp);
38785 +#endif
38786 +
38787 unxlate_dev_mem_ptr(p, ptr);
38788 if (remaining)
38789 return -EFAULT;
38790 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38791 size_t count, loff_t *ppos)
38792 {
38793 unsigned long p = *ppos;
38794 - ssize_t low_count, read, sz;
38795 + ssize_t low_count, read, sz, err = 0;
38796 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38797 - int err = 0;
38798
38799 read = 0;
38800 if (p < (unsigned long) high_memory) {
38801 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38802 }
38803 #endif
38804 while (low_count > 0) {
38805 + char *temp;
38806 +
38807 sz = size_inside_page(p, low_count);
38808
38809 /*
38810 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38811 */
38812 kbuf = xlate_dev_kmem_ptr((char *)p);
38813
38814 - if (copy_to_user(buf, kbuf, sz))
38815 +#ifdef CONFIG_PAX_USERCOPY
38816 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38817 + if (!temp)
38818 + return -ENOMEM;
38819 + memcpy(temp, kbuf, sz);
38820 +#else
38821 + temp = kbuf;
38822 +#endif
38823 +
38824 + err = copy_to_user(buf, temp, sz);
38825 +
38826 +#ifdef CONFIG_PAX_USERCOPY
38827 + kfree(temp);
38828 +#endif
38829 +
38830 + if (err)
38831 return -EFAULT;
38832 buf += sz;
38833 p += sz;
38834 @@ -797,6 +844,9 @@ static const struct memdev {
38835 #ifdef CONFIG_PRINTK
38836 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38837 #endif
38838 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38839 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38840 +#endif
38841 };
38842
38843 static int memory_open(struct inode *inode, struct file *filp)
38844 @@ -868,7 +918,7 @@ static int __init chr_dev_init(void)
38845 continue;
38846
38847 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38848 - NULL, devlist[minor].name);
38849 + NULL, "%s", devlist[minor].name);
38850 }
38851
38852 return tty_init();
38853 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38854 index 9df78e2..01ba9ae 100644
38855 --- a/drivers/char/nvram.c
38856 +++ b/drivers/char/nvram.c
38857 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38858
38859 spin_unlock_irq(&rtc_lock);
38860
38861 - if (copy_to_user(buf, contents, tmp - contents))
38862 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38863 return -EFAULT;
38864
38865 *ppos = i;
38866 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38867 index 0ea9986..e7b07e4 100644
38868 --- a/drivers/char/pcmcia/synclink_cs.c
38869 +++ b/drivers/char/pcmcia/synclink_cs.c
38870 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38871
38872 if (debug_level >= DEBUG_LEVEL_INFO)
38873 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38874 - __FILE__, __LINE__, info->device_name, port->count);
38875 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38876
38877 if (tty_port_close_start(port, tty, filp) == 0)
38878 goto cleanup;
38879 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38880 cleanup:
38881 if (debug_level >= DEBUG_LEVEL_INFO)
38882 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38883 - tty->driver->name, port->count);
38884 + tty->driver->name, atomic_read(&port->count));
38885 }
38886
38887 /* Wait until the transmitter is empty.
38888 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38889
38890 if (debug_level >= DEBUG_LEVEL_INFO)
38891 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38892 - __FILE__, __LINE__, tty->driver->name, port->count);
38893 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38894
38895 /* If port is closing, signal caller to try again */
38896 if (port->flags & ASYNC_CLOSING){
38897 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38898 goto cleanup;
38899 }
38900 spin_lock(&port->lock);
38901 - port->count++;
38902 + atomic_inc(&port->count);
38903 spin_unlock(&port->lock);
38904 spin_unlock_irqrestore(&info->netlock, flags);
38905
38906 - if (port->count == 1) {
38907 + if (atomic_read(&port->count) == 1) {
38908 /* 1st open on this device, init hardware */
38909 retval = startup(info, tty);
38910 if (retval < 0)
38911 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38912 unsigned short new_crctype;
38913
38914 /* return error if TTY interface open */
38915 - if (info->port.count)
38916 + if (atomic_read(&info->port.count))
38917 return -EBUSY;
38918
38919 switch (encoding)
38920 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38921
38922 /* arbitrate between network and tty opens */
38923 spin_lock_irqsave(&info->netlock, flags);
38924 - if (info->port.count != 0 || info->netcount != 0) {
38925 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38926 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38927 spin_unlock_irqrestore(&info->netlock, flags);
38928 return -EBUSY;
38929 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38930 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38931
38932 /* return error if TTY interface open */
38933 - if (info->port.count)
38934 + if (atomic_read(&info->port.count))
38935 return -EBUSY;
38936
38937 if (cmd != SIOCWANDEV)
38938 diff --git a/drivers/char/random.c b/drivers/char/random.c
38939 index 04645c0..560e350 100644
38940 --- a/drivers/char/random.c
38941 +++ b/drivers/char/random.c
38942 @@ -289,9 +289,6 @@
38943 /*
38944 * To allow fractional bits to be tracked, the entropy_count field is
38945 * denominated in units of 1/8th bits.
38946 - *
38947 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38948 - * credit_entropy_bits() needs to be 64 bits wide.
38949 */
38950 #define ENTROPY_SHIFT 3
38951 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38952 @@ -439,9 +436,9 @@ struct entropy_store {
38953 };
38954
38955 static void push_to_pool(struct work_struct *work);
38956 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38957 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38958 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38959 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38960 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38961 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38962
38963 static struct entropy_store input_pool = {
38964 .poolinfo = &poolinfo_table[0],
38965 @@ -635,7 +632,7 @@ retry:
38966 /* The +2 corresponds to the /4 in the denominator */
38967
38968 do {
38969 - unsigned int anfrac = min(pnfrac, pool_size/2);
38970 + u64 anfrac = min(pnfrac, pool_size/2);
38971 unsigned int add =
38972 ((pool_size - entropy_count)*anfrac*3) >> s;
38973
38974 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38975
38976 extract_buf(r, tmp);
38977 i = min_t(int, nbytes, EXTRACT_SIZE);
38978 - if (copy_to_user(buf, tmp, i)) {
38979 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38980 ret = -EFAULT;
38981 break;
38982 }
38983 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
38984 static int proc_do_uuid(struct ctl_table *table, int write,
38985 void __user *buffer, size_t *lenp, loff_t *ppos)
38986 {
38987 - struct ctl_table fake_table;
38988 + ctl_table_no_const fake_table;
38989 unsigned char buf[64], tmp_uuid[16], *uuid;
38990
38991 uuid = table->data;
38992 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38993 static int proc_do_entropy(struct ctl_table *table, int write,
38994 void __user *buffer, size_t *lenp, loff_t *ppos)
38995 {
38996 - struct ctl_table fake_table;
38997 + ctl_table_no_const fake_table;
38998 int entropy_count;
38999
39000 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39001 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39002 index 7cc1fe22..b602d6b 100644
39003 --- a/drivers/char/sonypi.c
39004 +++ b/drivers/char/sonypi.c
39005 @@ -54,6 +54,7 @@
39006
39007 #include <asm/uaccess.h>
39008 #include <asm/io.h>
39009 +#include <asm/local.h>
39010
39011 #include <linux/sonypi.h>
39012
39013 @@ -490,7 +491,7 @@ static struct sonypi_device {
39014 spinlock_t fifo_lock;
39015 wait_queue_head_t fifo_proc_list;
39016 struct fasync_struct *fifo_async;
39017 - int open_count;
39018 + local_t open_count;
39019 int model;
39020 struct input_dev *input_jog_dev;
39021 struct input_dev *input_key_dev;
39022 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39023 static int sonypi_misc_release(struct inode *inode, struct file *file)
39024 {
39025 mutex_lock(&sonypi_device.lock);
39026 - sonypi_device.open_count--;
39027 + local_dec(&sonypi_device.open_count);
39028 mutex_unlock(&sonypi_device.lock);
39029 return 0;
39030 }
39031 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39032 {
39033 mutex_lock(&sonypi_device.lock);
39034 /* Flush input queue on first open */
39035 - if (!sonypi_device.open_count)
39036 + if (!local_read(&sonypi_device.open_count))
39037 kfifo_reset(&sonypi_device.fifo);
39038 - sonypi_device.open_count++;
39039 + local_inc(&sonypi_device.open_count);
39040 mutex_unlock(&sonypi_device.lock);
39041
39042 return 0;
39043 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39044 index 565a947..dcdc06e 100644
39045 --- a/drivers/char/tpm/tpm_acpi.c
39046 +++ b/drivers/char/tpm/tpm_acpi.c
39047 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39048 virt = acpi_os_map_iomem(start, len);
39049 if (!virt) {
39050 kfree(log->bios_event_log);
39051 + log->bios_event_log = NULL;
39052 printk("%s: ERROR - Unable to map memory\n", __func__);
39053 return -EIO;
39054 }
39055
39056 - memcpy_fromio(log->bios_event_log, virt, len);
39057 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39058
39059 acpi_os_unmap_iomem(virt, len);
39060 return 0;
39061 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39062 index 3a56a13..f8cbd25 100644
39063 --- a/drivers/char/tpm/tpm_eventlog.c
39064 +++ b/drivers/char/tpm/tpm_eventlog.c
39065 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39066 event = addr;
39067
39068 if ((event->event_type == 0 && event->event_size == 0) ||
39069 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39070 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39071 return NULL;
39072
39073 return addr;
39074 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39075 return NULL;
39076
39077 if ((event->event_type == 0 && event->event_size == 0) ||
39078 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39079 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39080 return NULL;
39081
39082 (*pos)++;
39083 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39084 int i;
39085
39086 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39087 - seq_putc(m, data[i]);
39088 + if (!seq_putc(m, data[i]))
39089 + return -EFAULT;
39090
39091 return 0;
39092 }
39093 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39094 index cf7a561..c319ce0 100644
39095 --- a/drivers/char/virtio_console.c
39096 +++ b/drivers/char/virtio_console.c
39097 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39098 if (to_user) {
39099 ssize_t ret;
39100
39101 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39102 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39103 if (ret)
39104 return -EFAULT;
39105 } else {
39106 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39107 if (!port_has_data(port) && !port->host_connected)
39108 return 0;
39109
39110 - return fill_readbuf(port, ubuf, count, true);
39111 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39112 }
39113
39114 static int wait_port_writable(struct port *port, bool nonblock)
39115 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39116 index b9355da..9611f4e 100644
39117 --- a/drivers/clk/clk-composite.c
39118 +++ b/drivers/clk/clk-composite.c
39119 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39120 struct clk *clk;
39121 struct clk_init_data init;
39122 struct clk_composite *composite;
39123 - struct clk_ops *clk_composite_ops;
39124 + clk_ops_no_const *clk_composite_ops;
39125
39126 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39127 if (!composite) {
39128 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39129 index dd3a78c..386d49c 100644
39130 --- a/drivers/clk/socfpga/clk-gate.c
39131 +++ b/drivers/clk/socfpga/clk-gate.c
39132 @@ -22,6 +22,7 @@
39133 #include <linux/mfd/syscon.h>
39134 #include <linux/of.h>
39135 #include <linux/regmap.h>
39136 +#include <asm/pgtable.h>
39137
39138 #include "clk.h"
39139
39140 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39141 return 0;
39142 }
39143
39144 -static struct clk_ops gateclk_ops = {
39145 +static clk_ops_no_const gateclk_ops __read_only = {
39146 .prepare = socfpga_clk_prepare,
39147 .recalc_rate = socfpga_clk_recalc_rate,
39148 .get_parent = socfpga_clk_get_parent,
39149 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39150 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39151 socfpga_clk->hw.bit_idx = clk_gate[1];
39152
39153 - gateclk_ops.enable = clk_gate_ops.enable;
39154 - gateclk_ops.disable = clk_gate_ops.disable;
39155 + pax_open_kernel();
39156 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39157 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39158 + pax_close_kernel();
39159 }
39160
39161 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39162 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39163 index de6da95..c98278b 100644
39164 --- a/drivers/clk/socfpga/clk-pll.c
39165 +++ b/drivers/clk/socfpga/clk-pll.c
39166 @@ -21,6 +21,7 @@
39167 #include <linux/io.h>
39168 #include <linux/of.h>
39169 #include <linux/of_address.h>
39170 +#include <asm/pgtable.h>
39171
39172 #include "clk.h"
39173
39174 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39175 CLK_MGR_PLL_CLK_SRC_MASK;
39176 }
39177
39178 -static struct clk_ops clk_pll_ops = {
39179 +static clk_ops_no_const clk_pll_ops __read_only = {
39180 .recalc_rate = clk_pll_recalc_rate,
39181 .get_parent = clk_pll_get_parent,
39182 };
39183 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39184 pll_clk->hw.hw.init = &init;
39185
39186 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39187 - clk_pll_ops.enable = clk_gate_ops.enable;
39188 - clk_pll_ops.disable = clk_gate_ops.disable;
39189 + pax_open_kernel();
39190 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39191 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39192 + pax_close_kernel();
39193
39194 clk = clk_register(NULL, &pll_clk->hw.hw);
39195 if (WARN_ON(IS_ERR(clk))) {
39196 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39197 index b0c18ed..1713a80 100644
39198 --- a/drivers/cpufreq/acpi-cpufreq.c
39199 +++ b/drivers/cpufreq/acpi-cpufreq.c
39200 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39201 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39202 per_cpu(acfreq_data, cpu) = data;
39203
39204 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39205 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39206 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39207 + pax_open_kernel();
39208 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39209 + pax_close_kernel();
39210 + }
39211
39212 result = acpi_processor_register_performance(data->acpi_data, cpu);
39213 if (result)
39214 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39215 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39216 break;
39217 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39218 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39219 + pax_open_kernel();
39220 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39221 + pax_close_kernel();
39222 break;
39223 default:
39224 break;
39225 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39226 if (!msrs)
39227 return;
39228
39229 - acpi_cpufreq_driver.boost_supported = true;
39230 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39231 + pax_open_kernel();
39232 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39233 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39234 + pax_close_kernel();
39235
39236 cpu_notifier_register_begin();
39237
39238 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39239 index f657c57..31d97ae 100644
39240 --- a/drivers/cpufreq/cpufreq-dt.c
39241 +++ b/drivers/cpufreq/cpufreq-dt.c
39242 @@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39243 if (!IS_ERR(cpu_reg))
39244 regulator_put(cpu_reg);
39245
39246 - dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39247 + pax_open_kernel();
39248 + *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39249 + pax_close_kernel();
39250
39251 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39252 if (ret)
39253 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39254 index 4473eba..a4c9dc2 100644
39255 --- a/drivers/cpufreq/cpufreq.c
39256 +++ b/drivers/cpufreq/cpufreq.c
39257 @@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39258 }
39259
39260 mutex_lock(&cpufreq_governor_mutex);
39261 - list_del(&governor->governor_list);
39262 + pax_list_del(&governor->governor_list);
39263 mutex_unlock(&cpufreq_governor_mutex);
39264 return;
39265 }
39266 @@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39267 return NOTIFY_OK;
39268 }
39269
39270 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39271 +static struct notifier_block cpufreq_cpu_notifier = {
39272 .notifier_call = cpufreq_cpu_callback,
39273 };
39274
39275 @@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39276 return 0;
39277
39278 write_lock_irqsave(&cpufreq_driver_lock, flags);
39279 - cpufreq_driver->boost_enabled = state;
39280 + pax_open_kernel();
39281 + *(bool *)&cpufreq_driver->boost_enabled = state;
39282 + pax_close_kernel();
39283 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39284
39285 ret = cpufreq_driver->set_boost(state);
39286 if (ret) {
39287 write_lock_irqsave(&cpufreq_driver_lock, flags);
39288 - cpufreq_driver->boost_enabled = !state;
39289 + pax_open_kernel();
39290 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39291 + pax_close_kernel();
39292 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39293
39294 pr_err("%s: Cannot %s BOOST\n",
39295 @@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39296
39297 pr_debug("trying to register driver %s\n", driver_data->name);
39298
39299 - if (driver_data->setpolicy)
39300 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39301 + if (driver_data->setpolicy) {
39302 + pax_open_kernel();
39303 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39304 + pax_close_kernel();
39305 + }
39306
39307 write_lock_irqsave(&cpufreq_driver_lock, flags);
39308 if (cpufreq_driver) {
39309 @@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39310 * Check if driver provides function to enable boost -
39311 * if not, use cpufreq_boost_set_sw as default
39312 */
39313 - if (!cpufreq_driver->set_boost)
39314 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39315 + if (!cpufreq_driver->set_boost) {
39316 + pax_open_kernel();
39317 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39318 + pax_close_kernel();
39319 + }
39320
39321 ret = cpufreq_sysfs_create_file(&boost.attr);
39322 if (ret) {
39323 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39324 index 1b44496..b80ff5e 100644
39325 --- a/drivers/cpufreq/cpufreq_governor.c
39326 +++ b/drivers/cpufreq/cpufreq_governor.c
39327 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39328 struct dbs_data *dbs_data;
39329 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39330 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39331 - struct od_ops *od_ops = NULL;
39332 + const struct od_ops *od_ops = NULL;
39333 struct od_dbs_tuners *od_tuners = NULL;
39334 struct cs_dbs_tuners *cs_tuners = NULL;
39335 struct cpu_dbs_common_info *cpu_cdbs;
39336 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39337
39338 if ((cdata->governor == GOV_CONSERVATIVE) &&
39339 (!policy->governor->initialized)) {
39340 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39341 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39342
39343 cpufreq_register_notifier(cs_ops->notifier_block,
39344 CPUFREQ_TRANSITION_NOTIFIER);
39345 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39346
39347 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39348 (policy->governor->initialized == 1)) {
39349 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39350 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39351
39352 cpufreq_unregister_notifier(cs_ops->notifier_block,
39353 CPUFREQ_TRANSITION_NOTIFIER);
39354 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39355 index cc401d1..8197340 100644
39356 --- a/drivers/cpufreq/cpufreq_governor.h
39357 +++ b/drivers/cpufreq/cpufreq_governor.h
39358 @@ -212,7 +212,7 @@ struct common_dbs_data {
39359 void (*exit)(struct dbs_data *dbs_data);
39360
39361 /* Governor specific ops, see below */
39362 - void *gov_ops;
39363 + const void *gov_ops;
39364 };
39365
39366 /* Governor Per policy data */
39367 @@ -232,7 +232,7 @@ struct od_ops {
39368 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39369 unsigned int freq_next, unsigned int relation);
39370 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39371 -};
39372 +} __no_const;
39373
39374 struct cs_ops {
39375 struct notifier_block *notifier_block;
39376 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39377 index ad3f38f..8f086cd 100644
39378 --- a/drivers/cpufreq/cpufreq_ondemand.c
39379 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39380 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39381
39382 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39383
39384 -static struct od_ops od_ops = {
39385 +static struct od_ops od_ops __read_only = {
39386 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39387 .powersave_bias_target = generic_powersave_bias_target,
39388 .freq_increase = dbs_freq_increase,
39389 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39390 (struct cpufreq_policy *, unsigned int, unsigned int),
39391 unsigned int powersave_bias)
39392 {
39393 - od_ops.powersave_bias_target = f;
39394 + pax_open_kernel();
39395 + *(void **)&od_ops.powersave_bias_target = f;
39396 + pax_close_kernel();
39397 od_set_powersave_bias(powersave_bias);
39398 }
39399 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39400
39401 void od_unregister_powersave_bias_handler(void)
39402 {
39403 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39404 + pax_open_kernel();
39405 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39406 + pax_close_kernel();
39407 od_set_powersave_bias(0);
39408 }
39409 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39410 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39411 index 27bb6d3..4cf595c 100644
39412 --- a/drivers/cpufreq/intel_pstate.c
39413 +++ b/drivers/cpufreq/intel_pstate.c
39414 @@ -133,10 +133,10 @@ struct pstate_funcs {
39415 struct cpu_defaults {
39416 struct pstate_adjust_policy pid_policy;
39417 struct pstate_funcs funcs;
39418 -};
39419 +} __do_const;
39420
39421 static struct pstate_adjust_policy pid_params;
39422 -static struct pstate_funcs pstate_funcs;
39423 +static struct pstate_funcs *pstate_funcs;
39424
39425 struct perf_limits {
39426 int no_turbo;
39427 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39428
39429 cpu->pstate.current_pstate = pstate;
39430
39431 - pstate_funcs.set(cpu, pstate);
39432 + pstate_funcs->set(cpu, pstate);
39433 }
39434
39435 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39436 {
39437 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39438 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39439 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39440 - cpu->pstate.scaling = pstate_funcs.get_scaling();
39441 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39442 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39443 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39444 + cpu->pstate.scaling = pstate_funcs->get_scaling();
39445
39446 - if (pstate_funcs.get_vid)
39447 - pstate_funcs.get_vid(cpu);
39448 + if (pstate_funcs->get_vid)
39449 + pstate_funcs->get_vid(cpu);
39450 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39451 }
39452
39453 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39454 rdmsrl(MSR_IA32_APERF, aperf);
39455 rdmsrl(MSR_IA32_MPERF, mperf);
39456
39457 - if (!pstate_funcs.get_max() ||
39458 - !pstate_funcs.get_min() ||
39459 - !pstate_funcs.get_turbo())
39460 + if (!pstate_funcs->get_max() ||
39461 + !pstate_funcs->get_min() ||
39462 + !pstate_funcs->get_turbo())
39463 return -ENODEV;
39464
39465 rdmsrl(MSR_IA32_APERF, tmp);
39466 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39467 return 0;
39468 }
39469
39470 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39471 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39472 {
39473 pid_params.sample_rate_ms = policy->sample_rate_ms;
39474 pid_params.p_gain_pct = policy->p_gain_pct;
39475 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39476
39477 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39478 {
39479 - pstate_funcs.get_max = funcs->get_max;
39480 - pstate_funcs.get_min = funcs->get_min;
39481 - pstate_funcs.get_turbo = funcs->get_turbo;
39482 - pstate_funcs.get_scaling = funcs->get_scaling;
39483 - pstate_funcs.set = funcs->set;
39484 - pstate_funcs.get_vid = funcs->get_vid;
39485 + pstate_funcs = funcs;
39486 }
39487
39488 #if IS_ENABLED(CONFIG_ACPI)
39489 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39490 index 529cfd9..0e28fff 100644
39491 --- a/drivers/cpufreq/p4-clockmod.c
39492 +++ b/drivers/cpufreq/p4-clockmod.c
39493 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39494 case 0x0F: /* Core Duo */
39495 case 0x16: /* Celeron Core */
39496 case 0x1C: /* Atom */
39497 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39498 + pax_open_kernel();
39499 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39500 + pax_close_kernel();
39501 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39502 case 0x0D: /* Pentium M (Dothan) */
39503 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39504 + pax_open_kernel();
39505 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39506 + pax_close_kernel();
39507 /* fall through */
39508 case 0x09: /* Pentium M (Banias) */
39509 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39510 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39511
39512 /* on P-4s, the TSC runs with constant frequency independent whether
39513 * throttling is active or not. */
39514 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39515 + pax_open_kernel();
39516 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39517 + pax_close_kernel();
39518
39519 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39520 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39521 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39522 index 9bb42ba..b01b4a2 100644
39523 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39524 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39525 @@ -18,14 +18,12 @@
39526 #include <asm/head.h>
39527 #include <asm/timer.h>
39528
39529 -static struct cpufreq_driver *cpufreq_us3_driver;
39530 -
39531 struct us3_freq_percpu_info {
39532 struct cpufreq_frequency_table table[4];
39533 };
39534
39535 /* Indexed by cpu number. */
39536 -static struct us3_freq_percpu_info *us3_freq_table;
39537 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39538
39539 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39540 * in the Safari config register.
39541 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39542
39543 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39544 {
39545 - if (cpufreq_us3_driver)
39546 - us3_freq_target(policy, 0);
39547 + us3_freq_target(policy, 0);
39548
39549 return 0;
39550 }
39551
39552 +static int __init us3_freq_init(void);
39553 +static void __exit us3_freq_exit(void);
39554 +
39555 +static struct cpufreq_driver cpufreq_us3_driver = {
39556 + .init = us3_freq_cpu_init,
39557 + .verify = cpufreq_generic_frequency_table_verify,
39558 + .target_index = us3_freq_target,
39559 + .get = us3_freq_get,
39560 + .exit = us3_freq_cpu_exit,
39561 + .name = "UltraSPARC-III",
39562 +
39563 +};
39564 +
39565 static int __init us3_freq_init(void)
39566 {
39567 unsigned long manuf, impl, ver;
39568 - int ret;
39569
39570 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39571 return -ENODEV;
39572 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39573 (impl == CHEETAH_IMPL ||
39574 impl == CHEETAH_PLUS_IMPL ||
39575 impl == JAGUAR_IMPL ||
39576 - impl == PANTHER_IMPL)) {
39577 - struct cpufreq_driver *driver;
39578 -
39579 - ret = -ENOMEM;
39580 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39581 - if (!driver)
39582 - goto err_out;
39583 -
39584 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39585 - GFP_KERNEL);
39586 - if (!us3_freq_table)
39587 - goto err_out;
39588 -
39589 - driver->init = us3_freq_cpu_init;
39590 - driver->verify = cpufreq_generic_frequency_table_verify;
39591 - driver->target_index = us3_freq_target;
39592 - driver->get = us3_freq_get;
39593 - driver->exit = us3_freq_cpu_exit;
39594 - strcpy(driver->name, "UltraSPARC-III");
39595 -
39596 - cpufreq_us3_driver = driver;
39597 - ret = cpufreq_register_driver(driver);
39598 - if (ret)
39599 - goto err_out;
39600 -
39601 - return 0;
39602 -
39603 -err_out:
39604 - if (driver) {
39605 - kfree(driver);
39606 - cpufreq_us3_driver = NULL;
39607 - }
39608 - kfree(us3_freq_table);
39609 - us3_freq_table = NULL;
39610 - return ret;
39611 - }
39612 + impl == PANTHER_IMPL))
39613 + return cpufreq_register_driver(&cpufreq_us3_driver);
39614
39615 return -ENODEV;
39616 }
39617
39618 static void __exit us3_freq_exit(void)
39619 {
39620 - if (cpufreq_us3_driver) {
39621 - cpufreq_unregister_driver(cpufreq_us3_driver);
39622 - kfree(cpufreq_us3_driver);
39623 - cpufreq_us3_driver = NULL;
39624 - kfree(us3_freq_table);
39625 - us3_freq_table = NULL;
39626 - }
39627 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39628 }
39629
39630 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39631 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39632 index 7d4a315..21bb886 100644
39633 --- a/drivers/cpufreq/speedstep-centrino.c
39634 +++ b/drivers/cpufreq/speedstep-centrino.c
39635 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39636 !cpu_has(cpu, X86_FEATURE_EST))
39637 return -ENODEV;
39638
39639 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39640 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39641 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39642 + pax_open_kernel();
39643 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39644 + pax_close_kernel();
39645 + }
39646
39647 if (policy->cpu != 0)
39648 return -ENODEV;
39649 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39650 index e431d11..d0b997e 100644
39651 --- a/drivers/cpuidle/driver.c
39652 +++ b/drivers/cpuidle/driver.c
39653 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39654
39655 static void poll_idle_init(struct cpuidle_driver *drv)
39656 {
39657 - struct cpuidle_state *state = &drv->states[0];
39658 + cpuidle_state_no_const *state = &drv->states[0];
39659
39660 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39661 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39662 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39663 index fb9f511..213e6cc 100644
39664 --- a/drivers/cpuidle/governor.c
39665 +++ b/drivers/cpuidle/governor.c
39666 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39667 mutex_lock(&cpuidle_lock);
39668 if (__cpuidle_find_governor(gov->name) == NULL) {
39669 ret = 0;
39670 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39671 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39672 if (!cpuidle_curr_governor ||
39673 cpuidle_curr_governor->rating < gov->rating)
39674 cpuidle_switch_governor(gov);
39675 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39676 index 97c5903..023ad23 100644
39677 --- a/drivers/cpuidle/sysfs.c
39678 +++ b/drivers/cpuidle/sysfs.c
39679 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39680 NULL
39681 };
39682
39683 -static struct attribute_group cpuidle_attr_group = {
39684 +static attribute_group_no_const cpuidle_attr_group = {
39685 .attrs = cpuidle_default_attrs,
39686 .name = "cpuidle",
39687 };
39688 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39689 index 8d2a772..33826c9 100644
39690 --- a/drivers/crypto/hifn_795x.c
39691 +++ b/drivers/crypto/hifn_795x.c
39692 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39693 MODULE_PARM_DESC(hifn_pll_ref,
39694 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39695
39696 -static atomic_t hifn_dev_number;
39697 +static atomic_unchecked_t hifn_dev_number;
39698
39699 #define ACRYPTO_OP_DECRYPT 0
39700 #define ACRYPTO_OP_ENCRYPT 1
39701 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39702 goto err_out_disable_pci_device;
39703
39704 snprintf(name, sizeof(name), "hifn%d",
39705 - atomic_inc_return(&hifn_dev_number)-1);
39706 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39707
39708 err = pci_request_regions(pdev, name);
39709 if (err)
39710 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39711 index 30b538d8..1610d75 100644
39712 --- a/drivers/devfreq/devfreq.c
39713 +++ b/drivers/devfreq/devfreq.c
39714 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39715 goto err_out;
39716 }
39717
39718 - list_add(&governor->node, &devfreq_governor_list);
39719 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39720
39721 list_for_each_entry(devfreq, &devfreq_list, node) {
39722 int ret = 0;
39723 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39724 }
39725 }
39726
39727 - list_del(&governor->node);
39728 + pax_list_del((struct list_head *)&governor->node);
39729 err_out:
39730 mutex_unlock(&devfreq_list_lock);
39731
39732 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39733 index 42d4974..2714f36 100644
39734 --- a/drivers/dma/sh/shdma-base.c
39735 +++ b/drivers/dma/sh/shdma-base.c
39736 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39737 schan->slave_id = -EINVAL;
39738 }
39739
39740 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39741 - sdev->desc_size, GFP_KERNEL);
39742 + schan->desc = kcalloc(sdev->desc_size,
39743 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39744 if (!schan->desc) {
39745 ret = -ENOMEM;
39746 goto edescalloc;
39747 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39748 index 58eb857..d7e42c8 100644
39749 --- a/drivers/dma/sh/shdmac.c
39750 +++ b/drivers/dma/sh/shdmac.c
39751 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39752 return ret;
39753 }
39754
39755 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39756 +static struct notifier_block sh_dmae_nmi_notifier = {
39757 .notifier_call = sh_dmae_nmi_handler,
39758
39759 /* Run before NMI debug handler and KGDB */
39760 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39761 index 592af5f..bb1d583 100644
39762 --- a/drivers/edac/edac_device.c
39763 +++ b/drivers/edac/edac_device.c
39764 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39765 */
39766 int edac_device_alloc_index(void)
39767 {
39768 - static atomic_t device_indexes = ATOMIC_INIT(0);
39769 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39770
39771 - return atomic_inc_return(&device_indexes) - 1;
39772 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39773 }
39774 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39775
39776 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39777 index a6cd361..7bdbf53 100644
39778 --- a/drivers/edac/edac_mc_sysfs.c
39779 +++ b/drivers/edac/edac_mc_sysfs.c
39780 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39781 struct dev_ch_attribute {
39782 struct device_attribute attr;
39783 int channel;
39784 -};
39785 +} __do_const;
39786
39787 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39788 struct dev_ch_attribute dev_attr_legacy_##_name = \
39789 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39790 }
39791
39792 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39793 + pax_open_kernel();
39794 if (mci->get_sdram_scrub_rate) {
39795 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39796 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39797 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39798 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39799 }
39800 if (mci->set_sdram_scrub_rate) {
39801 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39802 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39803 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39804 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39805 }
39806 + pax_close_kernel();
39807 err = device_create_file(&mci->dev,
39808 &dev_attr_sdram_scrub_rate);
39809 if (err) {
39810 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39811 index 2cf44b4d..6dd2dc7 100644
39812 --- a/drivers/edac/edac_pci.c
39813 +++ b/drivers/edac/edac_pci.c
39814 @@ -29,7 +29,7 @@
39815
39816 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39817 static LIST_HEAD(edac_pci_list);
39818 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39819 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39820
39821 /*
39822 * edac_pci_alloc_ctl_info
39823 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39824 */
39825 int edac_pci_alloc_index(void)
39826 {
39827 - return atomic_inc_return(&pci_indexes) - 1;
39828 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39829 }
39830 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39831
39832 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39833 index e8658e4..22746d6 100644
39834 --- a/drivers/edac/edac_pci_sysfs.c
39835 +++ b/drivers/edac/edac_pci_sysfs.c
39836 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39837 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39838 static int edac_pci_poll_msec = 1000; /* one second workq period */
39839
39840 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39841 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39842 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39843 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39844
39845 static struct kobject *edac_pci_top_main_kobj;
39846 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39847 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39848 void *value;
39849 ssize_t(*show) (void *, char *);
39850 ssize_t(*store) (void *, const char *, size_t);
39851 -};
39852 +} __do_const;
39853
39854 /* Set of show/store abstract level functions for PCI Parity object */
39855 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39856 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39857 edac_printk(KERN_CRIT, EDAC_PCI,
39858 "Signaled System Error on %s\n",
39859 pci_name(dev));
39860 - atomic_inc(&pci_nonparity_count);
39861 + atomic_inc_unchecked(&pci_nonparity_count);
39862 }
39863
39864 if (status & (PCI_STATUS_PARITY)) {
39865 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39866 "Master Data Parity Error on %s\n",
39867 pci_name(dev));
39868
39869 - atomic_inc(&pci_parity_count);
39870 + atomic_inc_unchecked(&pci_parity_count);
39871 }
39872
39873 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39874 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39875 "Detected Parity Error on %s\n",
39876 pci_name(dev));
39877
39878 - atomic_inc(&pci_parity_count);
39879 + atomic_inc_unchecked(&pci_parity_count);
39880 }
39881 }
39882
39883 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39884 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39885 "Signaled System Error on %s\n",
39886 pci_name(dev));
39887 - atomic_inc(&pci_nonparity_count);
39888 + atomic_inc_unchecked(&pci_nonparity_count);
39889 }
39890
39891 if (status & (PCI_STATUS_PARITY)) {
39892 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39893 "Master Data Parity Error on "
39894 "%s\n", pci_name(dev));
39895
39896 - atomic_inc(&pci_parity_count);
39897 + atomic_inc_unchecked(&pci_parity_count);
39898 }
39899
39900 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39901 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39902 "Detected Parity Error on %s\n",
39903 pci_name(dev));
39904
39905 - atomic_inc(&pci_parity_count);
39906 + atomic_inc_unchecked(&pci_parity_count);
39907 }
39908 }
39909 }
39910 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39911 if (!check_pci_errors)
39912 return;
39913
39914 - before_count = atomic_read(&pci_parity_count);
39915 + before_count = atomic_read_unchecked(&pci_parity_count);
39916
39917 /* scan all PCI devices looking for a Parity Error on devices and
39918 * bridges.
39919 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39920 /* Only if operator has selected panic on PCI Error */
39921 if (edac_pci_get_panic_on_pe()) {
39922 /* If the count is different 'after' from 'before' */
39923 - if (before_count != atomic_read(&pci_parity_count))
39924 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39925 panic("EDAC: PCI Parity Error");
39926 }
39927 }
39928 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39929 index 51b7e3a..aa8a3e8 100644
39930 --- a/drivers/edac/mce_amd.h
39931 +++ b/drivers/edac/mce_amd.h
39932 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39933 bool (*mc0_mce)(u16, u8);
39934 bool (*mc1_mce)(u16, u8);
39935 bool (*mc2_mce)(u16, u8);
39936 -};
39937 +} __no_const;
39938
39939 void amd_report_gart_errors(bool);
39940 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39941 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39942 index 57ea7f4..af06b76 100644
39943 --- a/drivers/firewire/core-card.c
39944 +++ b/drivers/firewire/core-card.c
39945 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39946 const struct fw_card_driver *driver,
39947 struct device *device)
39948 {
39949 - static atomic_t index = ATOMIC_INIT(-1);
39950 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39951
39952 - card->index = atomic_inc_return(&index);
39953 + card->index = atomic_inc_return_unchecked(&index);
39954 card->driver = driver;
39955 card->device = device;
39956 card->current_tlabel = 0;
39957 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39958
39959 void fw_core_remove_card(struct fw_card *card)
39960 {
39961 - struct fw_card_driver dummy_driver = dummy_driver_template;
39962 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39963
39964 card->driver->update_phy_reg(card, 4,
39965 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39966 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39967 index 2c6d5e1..a2cca6b 100644
39968 --- a/drivers/firewire/core-device.c
39969 +++ b/drivers/firewire/core-device.c
39970 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39971 struct config_rom_attribute {
39972 struct device_attribute attr;
39973 u32 key;
39974 -};
39975 +} __do_const;
39976
39977 static ssize_t show_immediate(struct device *dev,
39978 struct device_attribute *dattr, char *buf)
39979 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39980 index eb6935c..3cc2bfa 100644
39981 --- a/drivers/firewire/core-transaction.c
39982 +++ b/drivers/firewire/core-transaction.c
39983 @@ -38,6 +38,7 @@
39984 #include <linux/timer.h>
39985 #include <linux/types.h>
39986 #include <linux/workqueue.h>
39987 +#include <linux/sched.h>
39988
39989 #include <asm/byteorder.h>
39990
39991 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39992 index e1480ff6..1a429bd 100644
39993 --- a/drivers/firewire/core.h
39994 +++ b/drivers/firewire/core.h
39995 @@ -111,6 +111,7 @@ struct fw_card_driver {
39996
39997 int (*stop_iso)(struct fw_iso_context *ctx);
39998 };
39999 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40000
40001 void fw_card_initialize(struct fw_card *card,
40002 const struct fw_card_driver *driver, struct device *device);
40003 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40004 index a66a321..f6caf20 100644
40005 --- a/drivers/firewire/ohci.c
40006 +++ b/drivers/firewire/ohci.c
40007 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40008 be32_to_cpu(ohci->next_header));
40009 }
40010
40011 +#ifndef CONFIG_GRKERNSEC
40012 if (param_remote_dma) {
40013 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40014 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40015 }
40016 +#endif
40017
40018 spin_unlock_irq(&ohci->lock);
40019
40020 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40021 unsigned long flags;
40022 int n, ret = 0;
40023
40024 +#ifndef CONFIG_GRKERNSEC
40025 if (param_remote_dma)
40026 return 0;
40027 +#endif
40028
40029 /*
40030 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40031 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40032 index 94a58a0..f5eba42 100644
40033 --- a/drivers/firmware/dmi-id.c
40034 +++ b/drivers/firmware/dmi-id.c
40035 @@ -16,7 +16,7 @@
40036 struct dmi_device_attribute{
40037 struct device_attribute dev_attr;
40038 int field;
40039 -};
40040 +} __do_const;
40041 #define to_dmi_dev_attr(_dev_attr) \
40042 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40043
40044 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40045 index 17afc51..0ef90cd 100644
40046 --- a/drivers/firmware/dmi_scan.c
40047 +++ b/drivers/firmware/dmi_scan.c
40048 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40049 if (buf == NULL)
40050 return -1;
40051
40052 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40053 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40054
40055 dmi_unmap(buf);
40056 return 0;
40057 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40058 index 5b53d61..72cee96 100644
40059 --- a/drivers/firmware/efi/cper.c
40060 +++ b/drivers/firmware/efi/cper.c
40061 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40062 */
40063 u64 cper_next_record_id(void)
40064 {
40065 - static atomic64_t seq;
40066 + static atomic64_unchecked_t seq;
40067
40068 - if (!atomic64_read(&seq))
40069 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40070 + if (!atomic64_read_unchecked(&seq))
40071 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40072
40073 - return atomic64_inc_return(&seq);
40074 + return atomic64_inc_return_unchecked(&seq);
40075 }
40076 EXPORT_SYMBOL_GPL(cper_next_record_id);
40077
40078 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40079 index 8590099..d83627a 100644
40080 --- a/drivers/firmware/efi/efi.c
40081 +++ b/drivers/firmware/efi/efi.c
40082 @@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40083 };
40084
40085 static struct efivars generic_efivars;
40086 -static struct efivar_operations generic_ops;
40087 +static efivar_operations_no_const generic_ops __read_only;
40088
40089 static int generic_ops_register(void)
40090 {
40091 - generic_ops.get_variable = efi.get_variable;
40092 - generic_ops.set_variable = efi.set_variable;
40093 - generic_ops.get_next_variable = efi.get_next_variable;
40094 - generic_ops.query_variable_store = efi_query_variable_store;
40095 + pax_open_kernel();
40096 + *(void **)&generic_ops.get_variable = efi.get_variable;
40097 + *(void **)&generic_ops.set_variable = efi.set_variable;
40098 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40099 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40100 + pax_close_kernel();
40101
40102 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40103 }
40104 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40105 index f256ecd..387dcb1 100644
40106 --- a/drivers/firmware/efi/efivars.c
40107 +++ b/drivers/firmware/efi/efivars.c
40108 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40109 static int
40110 create_efivars_bin_attributes(void)
40111 {
40112 - struct bin_attribute *attr;
40113 + bin_attribute_no_const *attr;
40114 int error;
40115
40116 /* new_var */
40117 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40118 index 2f569aa..c95f4fb 100644
40119 --- a/drivers/firmware/google/memconsole.c
40120 +++ b/drivers/firmware/google/memconsole.c
40121 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40122 if (!found_memconsole())
40123 return -ENODEV;
40124
40125 - memconsole_bin_attr.size = memconsole_length;
40126 + pax_open_kernel();
40127 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40128 + pax_close_kernel();
40129 +
40130 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40131 }
40132
40133 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40134 index fe49ec3..1ade794 100644
40135 --- a/drivers/gpio/gpio-em.c
40136 +++ b/drivers/gpio/gpio-em.c
40137 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40138 struct em_gio_priv *p;
40139 struct resource *io[2], *irq[2];
40140 struct gpio_chip *gpio_chip;
40141 - struct irq_chip *irq_chip;
40142 + irq_chip_no_const *irq_chip;
40143 const char *name = dev_name(&pdev->dev);
40144 int ret;
40145
40146 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40147 index 3784e81..73637b5 100644
40148 --- a/drivers/gpio/gpio-ich.c
40149 +++ b/drivers/gpio/gpio-ich.c
40150 @@ -94,7 +94,7 @@ struct ichx_desc {
40151 * this option allows driver caching written output values
40152 */
40153 bool use_outlvl_cache;
40154 -};
40155 +} __do_const;
40156
40157 static struct {
40158 spinlock_t lock;
40159 diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
40160 index 415682f..08438b8 100644
40161 --- a/drivers/gpio/gpio-omap.c
40162 +++ b/drivers/gpio/gpio-omap.c
40163 @@ -1162,7 +1162,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
40164 const struct omap_gpio_platform_data *pdata;
40165 struct resource *res;
40166 struct gpio_bank *bank;
40167 - struct irq_chip *irqc;
40168 + irq_chip_no_const *irqc;
40169 int ret;
40170
40171 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
40172 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40173 index bf6c094..6573caf 100644
40174 --- a/drivers/gpio/gpio-rcar.c
40175 +++ b/drivers/gpio/gpio-rcar.c
40176 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40177 struct gpio_rcar_priv *p;
40178 struct resource *io, *irq;
40179 struct gpio_chip *gpio_chip;
40180 - struct irq_chip *irq_chip;
40181 + irq_chip_no_const *irq_chip;
40182 struct device *dev = &pdev->dev;
40183 const char *name = dev_name(dev);
40184 int ret;
40185 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40186 index dbf28fa..04dad4e 100644
40187 --- a/drivers/gpio/gpio-vr41xx.c
40188 +++ b/drivers/gpio/gpio-vr41xx.c
40189 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40190 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40191 maskl, pendl, maskh, pendh);
40192
40193 - atomic_inc(&irq_err_count);
40194 + atomic_inc_unchecked(&irq_err_count);
40195
40196 return -EINVAL;
40197 }
40198 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40199 index c81bda0..a8ccd9f 100644
40200 --- a/drivers/gpio/gpiolib.c
40201 +++ b/drivers/gpio/gpiolib.c
40202 @@ -539,8 +539,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40203 }
40204
40205 if (gpiochip->irqchip) {
40206 - gpiochip->irqchip->irq_request_resources = NULL;
40207 - gpiochip->irqchip->irq_release_resources = NULL;
40208 + pax_open_kernel();
40209 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40210 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40211 + pax_close_kernel();
40212 gpiochip->irqchip = NULL;
40213 }
40214 }
40215 @@ -606,8 +608,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40216 gpiochip->irqchip = NULL;
40217 return -EINVAL;
40218 }
40219 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40220 - irqchip->irq_release_resources = gpiochip_irq_relres;
40221 +
40222 + pax_open_kernel();
40223 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40224 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40225 + pax_close_kernel();
40226
40227 /*
40228 * Prepare the mapping since the irqchip shall be orthogonal to
40229 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40230 index e79c8d3..a9370bc 100644
40231 --- a/drivers/gpu/drm/drm_crtc.c
40232 +++ b/drivers/gpu/drm/drm_crtc.c
40233 @@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40234 goto done;
40235 }
40236
40237 - if (copy_to_user(&enum_ptr[copied].name,
40238 + if (copy_to_user(enum_ptr[copied].name,
40239 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40240 ret = -EFAULT;
40241 goto done;
40242 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40243 index bc3da32..7289357 100644
40244 --- a/drivers/gpu/drm/drm_drv.c
40245 +++ b/drivers/gpu/drm/drm_drv.c
40246 @@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40247
40248 drm_device_set_unplugged(dev);
40249
40250 - if (dev->open_count == 0) {
40251 + if (local_read(&dev->open_count) == 0) {
40252 drm_put_dev(dev);
40253 }
40254 mutex_unlock(&drm_global_mutex);
40255 diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
40256 index ef757f7..98f720c 100644
40257 --- a/drivers/gpu/drm/drm_fb_helper.c
40258 +++ b/drivers/gpu/drm/drm_fb_helper.c
40259 @@ -741,7 +741,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
40260 int i, j, rc = 0;
40261 int start;
40262
40263 - drm_modeset_lock_all(dev);
40264 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40265 + return -EBUSY;
40266 + }
40267 if (!drm_fb_helper_is_bound(fb_helper)) {
40268 drm_modeset_unlock_all(dev);
40269 return -EBUSY;
40270 @@ -915,7 +917,9 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
40271 int ret = 0;
40272 int i;
40273
40274 - drm_modeset_lock_all(dev);
40275 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40276 + return -EBUSY;
40277 + }
40278 if (!drm_fb_helper_is_bound(fb_helper)) {
40279 drm_modeset_unlock_all(dev);
40280 return -EBUSY;
40281 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40282 index ed7bc68..0d536af 100644
40283 --- a/drivers/gpu/drm/drm_fops.c
40284 +++ b/drivers/gpu/drm/drm_fops.c
40285 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40286 return PTR_ERR(minor);
40287
40288 dev = minor->dev;
40289 - if (!dev->open_count++)
40290 + if (local_inc_return(&dev->open_count) == 1)
40291 need_setup = 1;
40292
40293 /* share address_space across all char-devs of a single device */
40294 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40295 return 0;
40296
40297 err_undo:
40298 - dev->open_count--;
40299 + local_dec(&dev->open_count);
40300 drm_minor_release(minor);
40301 return retcode;
40302 }
40303 @@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40304
40305 mutex_lock(&drm_global_mutex);
40306
40307 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40308 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40309
40310 mutex_lock(&dev->struct_mutex);
40311 list_del(&file_priv->lhead);
40312 @@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40313 * Begin inline drm_release
40314 */
40315
40316 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40317 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40318 task_pid_nr(current),
40319 (long)old_encode_dev(file_priv->minor->kdev->devt),
40320 - dev->open_count);
40321 + local_read(&dev->open_count));
40322
40323 /* Release any auth tokens that might point to this file_priv,
40324 (do that under the drm_global_mutex) */
40325 @@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40326 * End inline drm_release
40327 */
40328
40329 - if (!--dev->open_count) {
40330 + if (local_dec_and_test(&dev->open_count)) {
40331 retcode = drm_lastclose(dev);
40332 if (drm_device_is_unplugged(dev))
40333 drm_put_dev(dev);
40334 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40335 index 3d2e91c..d31c4c9 100644
40336 --- a/drivers/gpu/drm/drm_global.c
40337 +++ b/drivers/gpu/drm/drm_global.c
40338 @@ -36,7 +36,7 @@
40339 struct drm_global_item {
40340 struct mutex mutex;
40341 void *object;
40342 - int refcount;
40343 + atomic_t refcount;
40344 };
40345
40346 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40347 @@ -49,7 +49,7 @@ void drm_global_init(void)
40348 struct drm_global_item *item = &glob[i];
40349 mutex_init(&item->mutex);
40350 item->object = NULL;
40351 - item->refcount = 0;
40352 + atomic_set(&item->refcount, 0);
40353 }
40354 }
40355
40356 @@ -59,7 +59,7 @@ void drm_global_release(void)
40357 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40358 struct drm_global_item *item = &glob[i];
40359 BUG_ON(item->object != NULL);
40360 - BUG_ON(item->refcount != 0);
40361 + BUG_ON(atomic_read(&item->refcount) != 0);
40362 }
40363 }
40364
40365 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40366 struct drm_global_item *item = &glob[ref->global_type];
40367
40368 mutex_lock(&item->mutex);
40369 - if (item->refcount == 0) {
40370 + if (atomic_read(&item->refcount) == 0) {
40371 item->object = kzalloc(ref->size, GFP_KERNEL);
40372 if (unlikely(item->object == NULL)) {
40373 ret = -ENOMEM;
40374 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40375 goto out_err;
40376
40377 }
40378 - ++item->refcount;
40379 + atomic_inc(&item->refcount);
40380 ref->object = item->object;
40381 mutex_unlock(&item->mutex);
40382 return 0;
40383 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40384 struct drm_global_item *item = &glob[ref->global_type];
40385
40386 mutex_lock(&item->mutex);
40387 - BUG_ON(item->refcount == 0);
40388 + BUG_ON(atomic_read(&item->refcount) == 0);
40389 BUG_ON(ref->object != item->object);
40390 - if (--item->refcount == 0) {
40391 + if (atomic_dec_and_test(&item->refcount)) {
40392 ref->release(ref);
40393 item->object = NULL;
40394 }
40395 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40396 index 51efebd..2b70935 100644
40397 --- a/drivers/gpu/drm/drm_info.c
40398 +++ b/drivers/gpu/drm/drm_info.c
40399 @@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40400 struct drm_local_map *map;
40401 struct drm_map_list *r_list;
40402
40403 - /* Hardcoded from _DRM_FRAME_BUFFER,
40404 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40405 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40406 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40407 + static const char * const types[] = {
40408 + [_DRM_FRAME_BUFFER] = "FB",
40409 + [_DRM_REGISTERS] = "REG",
40410 + [_DRM_SHM] = "SHM",
40411 + [_DRM_AGP] = "AGP",
40412 + [_DRM_SCATTER_GATHER] = "SG",
40413 + [_DRM_CONSISTENT] = "PCI"};
40414 const char *type;
40415 int i;
40416
40417 @@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40418 map = r_list->map;
40419 if (!map)
40420 continue;
40421 - if (map->type < 0 || map->type > 5)
40422 + if (map->type >= ARRAY_SIZE(types))
40423 type = "??";
40424 else
40425 type = types[map->type];
40426 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40427 index 2f4c4343..dd12cd2 100644
40428 --- a/drivers/gpu/drm/drm_ioc32.c
40429 +++ b/drivers/gpu/drm/drm_ioc32.c
40430 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40431 request = compat_alloc_user_space(nbytes);
40432 if (!access_ok(VERIFY_WRITE, request, nbytes))
40433 return -EFAULT;
40434 - list = (struct drm_buf_desc *) (request + 1);
40435 + list = (struct drm_buf_desc __user *) (request + 1);
40436
40437 if (__put_user(count, &request->count)
40438 || __put_user(list, &request->list))
40439 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40440 request = compat_alloc_user_space(nbytes);
40441 if (!access_ok(VERIFY_WRITE, request, nbytes))
40442 return -EFAULT;
40443 - list = (struct drm_buf_pub *) (request + 1);
40444 + list = (struct drm_buf_pub __user *) (request + 1);
40445
40446 if (__put_user(count, &request->count)
40447 || __put_user(list, &request->list))
40448 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40449 return 0;
40450 }
40451
40452 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40453 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40454 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40455 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40456 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40457 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40458 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40459 {
40460 unsigned int nr = DRM_IOCTL_NR(cmd);
40461 - drm_ioctl_compat_t *fn;
40462 int ret;
40463
40464 /* Assume that ioctls without an explicit compat routine will just
40465 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40466 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40467 return drm_ioctl(filp, cmd, arg);
40468
40469 - fn = drm_compat_ioctls[nr];
40470 -
40471 - if (fn != NULL)
40472 - ret = (*fn) (filp, cmd, arg);
40473 + if (drm_compat_ioctls[nr] != NULL)
40474 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40475 else
40476 ret = drm_ioctl(filp, cmd, arg);
40477
40478 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40479 index 00587a1..57a65ca 100644
40480 --- a/drivers/gpu/drm/drm_ioctl.c
40481 +++ b/drivers/gpu/drm/drm_ioctl.c
40482 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40483 struct drm_file *file_priv = filp->private_data;
40484 struct drm_device *dev;
40485 const struct drm_ioctl_desc *ioctl = NULL;
40486 - drm_ioctl_t *func;
40487 + drm_ioctl_no_const_t func;
40488 unsigned int nr = DRM_IOCTL_NR(cmd);
40489 int retcode = -EINVAL;
40490 char stack_kdata[128];
40491 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40492 index 93ec5dc..82acbaf 100644
40493 --- a/drivers/gpu/drm/i810/i810_drv.h
40494 +++ b/drivers/gpu/drm/i810/i810_drv.h
40495 @@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40496 int page_flipping;
40497
40498 wait_queue_head_t irq_queue;
40499 - atomic_t irq_received;
40500 - atomic_t irq_emitted;
40501 + atomic_unchecked_t irq_received;
40502 + atomic_unchecked_t irq_emitted;
40503
40504 int front_offset;
40505 } drm_i810_private_t;
40506 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40507 index 318ade9..1f5de55 100644
40508 --- a/drivers/gpu/drm/i915/i915_dma.c
40509 +++ b/drivers/gpu/drm/i915/i915_dma.c
40510 @@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40511 * locking inversion with the driver load path. And the access here is
40512 * completely racy anyway. So don't bother with locking for now.
40513 */
40514 - return dev->open_count == 0;
40515 + return local_read(&dev->open_count) == 0;
40516 }
40517
40518 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40519 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40520 index 1a0611b..dd1fbfc 100644
40521 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40522 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40523 @@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40524 static int
40525 validate_exec_list(struct drm_device *dev,
40526 struct drm_i915_gem_exec_object2 *exec,
40527 - int count)
40528 + unsigned int count)
40529 {
40530 unsigned relocs_total = 0;
40531 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40532 unsigned invalid_flags;
40533 - int i;
40534 + unsigned int i;
40535
40536 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40537 if (USES_FULL_PPGTT(dev))
40538 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40539 index 2e0613e..a8b94d9 100644
40540 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40541 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40542 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40543 (unsigned long)request);
40544 }
40545
40546 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40547 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40548 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40549 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40550 [DRM_I915_GETPARAM] = compat_i915_getparam,
40551 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40552 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40553 {
40554 unsigned int nr = DRM_IOCTL_NR(cmd);
40555 - drm_ioctl_compat_t *fn = NULL;
40556 int ret;
40557
40558 if (nr < DRM_COMMAND_BASE)
40559 return drm_compat_ioctl(filp, cmd, arg);
40560
40561 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40562 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40563 -
40564 - if (fn != NULL)
40565 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40566 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40567 ret = (*fn) (filp, cmd, arg);
40568 - else
40569 + } else
40570 ret = drm_ioctl(filp, cmd, arg);
40571
40572 return ret;
40573 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40574 index 31b9664..5d478d3 100644
40575 --- a/drivers/gpu/drm/i915/intel_display.c
40576 +++ b/drivers/gpu/drm/i915/intel_display.c
40577 @@ -12811,13 +12811,13 @@ struct intel_quirk {
40578 int subsystem_vendor;
40579 int subsystem_device;
40580 void (*hook)(struct drm_device *dev);
40581 -};
40582 +} __do_const;
40583
40584 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40585 struct intel_dmi_quirk {
40586 void (*hook)(struct drm_device *dev);
40587 const struct dmi_system_id (*dmi_id_list)[];
40588 -};
40589 +} __do_const;
40590
40591 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40592 {
40593 @@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40594 return 1;
40595 }
40596
40597 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40598 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40599 {
40600 - .dmi_id_list = &(const struct dmi_system_id[]) {
40601 - {
40602 - .callback = intel_dmi_reverse_brightness,
40603 - .ident = "NCR Corporation",
40604 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40605 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40606 - },
40607 - },
40608 - { } /* terminating entry */
40609 + .callback = intel_dmi_reverse_brightness,
40610 + .ident = "NCR Corporation",
40611 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40612 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40613 },
40614 + },
40615 + { } /* terminating entry */
40616 +};
40617 +
40618 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40619 + {
40620 + .dmi_id_list = &intel_dmi_quirks_table,
40621 .hook = quirk_invert_brightness,
40622 },
40623 };
40624 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40625 index b4a2014..219ab78 100644
40626 --- a/drivers/gpu/drm/mga/mga_drv.h
40627 +++ b/drivers/gpu/drm/mga/mga_drv.h
40628 @@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40629 u32 clear_cmd;
40630 u32 maccess;
40631
40632 - atomic_t vbl_received; /**< Number of vblanks received. */
40633 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40634 wait_queue_head_t fence_queue;
40635 - atomic_t last_fence_retired;
40636 + atomic_unchecked_t last_fence_retired;
40637 u32 next_fence_to_post;
40638
40639 unsigned int fb_cpp;
40640 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40641 index 729bfd5..ead8823 100644
40642 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40643 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40644 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40645 return 0;
40646 }
40647
40648 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40649 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40650 [DRM_MGA_INIT] = compat_mga_init,
40651 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40652 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40653 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40654 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40655 {
40656 unsigned int nr = DRM_IOCTL_NR(cmd);
40657 - drm_ioctl_compat_t *fn = NULL;
40658 int ret;
40659
40660 if (nr < DRM_COMMAND_BASE)
40661 return drm_compat_ioctl(filp, cmd, arg);
40662
40663 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40664 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40665 -
40666 - if (fn != NULL)
40667 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40668 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40669 ret = (*fn) (filp, cmd, arg);
40670 - else
40671 + } else
40672 ret = drm_ioctl(filp, cmd, arg);
40673
40674 return ret;
40675 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40676 index 1b071b8..de8601a 100644
40677 --- a/drivers/gpu/drm/mga/mga_irq.c
40678 +++ b/drivers/gpu/drm/mga/mga_irq.c
40679 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40680 if (crtc != 0)
40681 return 0;
40682
40683 - return atomic_read(&dev_priv->vbl_received);
40684 + return atomic_read_unchecked(&dev_priv->vbl_received);
40685 }
40686
40687
40688 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40689 /* VBLANK interrupt */
40690 if (status & MGA_VLINEPEN) {
40691 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40692 - atomic_inc(&dev_priv->vbl_received);
40693 + atomic_inc_unchecked(&dev_priv->vbl_received);
40694 drm_handle_vblank(dev, 0);
40695 handled = 1;
40696 }
40697 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40698 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40699 MGA_WRITE(MGA_PRIMEND, prim_end);
40700
40701 - atomic_inc(&dev_priv->last_fence_retired);
40702 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40703 wake_up(&dev_priv->fence_queue);
40704 handled = 1;
40705 }
40706 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40707 * using fences.
40708 */
40709 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40710 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40711 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40712 - *sequence) <= (1 << 23)));
40713
40714 *sequence = cur_fence;
40715 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40716 index dae2c96..324dbe4 100644
40717 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40718 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40719 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40720 struct bit_table {
40721 const char id;
40722 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40723 -};
40724 +} __no_const;
40725
40726 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40727
40728 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40729 index 8ae36f2..1147a30 100644
40730 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40731 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40732 @@ -121,7 +121,6 @@ struct nouveau_drm {
40733 struct drm_global_reference mem_global_ref;
40734 struct ttm_bo_global_ref bo_global_ref;
40735 struct ttm_bo_device bdev;
40736 - atomic_t validate_sequence;
40737 int (*move)(struct nouveau_channel *,
40738 struct ttm_buffer_object *,
40739 struct ttm_mem_reg *, struct ttm_mem_reg *);
40740 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40741 index 462679a..88e32a7 100644
40742 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40743 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40744 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40745 unsigned long arg)
40746 {
40747 unsigned int nr = DRM_IOCTL_NR(cmd);
40748 - drm_ioctl_compat_t *fn = NULL;
40749 + drm_ioctl_compat_t fn = NULL;
40750 int ret;
40751
40752 if (nr < DRM_COMMAND_BASE)
40753 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40754 index 3d1cfcb..0542700 100644
40755 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40756 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40757 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40758 }
40759
40760 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40761 - nouveau_vram_manager_init,
40762 - nouveau_vram_manager_fini,
40763 - nouveau_vram_manager_new,
40764 - nouveau_vram_manager_del,
40765 - nouveau_vram_manager_debug
40766 + .init = nouveau_vram_manager_init,
40767 + .takedown = nouveau_vram_manager_fini,
40768 + .get_node = nouveau_vram_manager_new,
40769 + .put_node = nouveau_vram_manager_del,
40770 + .debug = nouveau_vram_manager_debug
40771 };
40772
40773 static int
40774 @@ -195,11 +195,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40775 }
40776
40777 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40778 - nouveau_gart_manager_init,
40779 - nouveau_gart_manager_fini,
40780 - nouveau_gart_manager_new,
40781 - nouveau_gart_manager_del,
40782 - nouveau_gart_manager_debug
40783 + .init = nouveau_gart_manager_init,
40784 + .takedown = nouveau_gart_manager_fini,
40785 + .get_node = nouveau_gart_manager_new,
40786 + .put_node = nouveau_gart_manager_del,
40787 + .debug = nouveau_gart_manager_debug
40788 };
40789
40790 /*XXX*/
40791 @@ -268,11 +268,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40792 }
40793
40794 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40795 - nv04_gart_manager_init,
40796 - nv04_gart_manager_fini,
40797 - nv04_gart_manager_new,
40798 - nv04_gart_manager_del,
40799 - nv04_gart_manager_debug
40800 + .init = nv04_gart_manager_init,
40801 + .takedown = nv04_gart_manager_fini,
40802 + .get_node = nv04_gart_manager_new,
40803 + .put_node = nv04_gart_manager_del,
40804 + .debug = nv04_gart_manager_debug
40805 };
40806
40807 int
40808 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40809 index c7592ec..dd45ebc 100644
40810 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40811 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40812 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40813 * locking inversion with the driver load path. And the access here is
40814 * completely racy anyway. So don't bother with locking for now.
40815 */
40816 - return dev->open_count == 0;
40817 + return local_read(&dev->open_count) == 0;
40818 }
40819
40820 static const struct vga_switcheroo_client_ops
40821 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40822 index 9782364..89bd954 100644
40823 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40824 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40825 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40826 int ret;
40827
40828 mutex_lock(&qdev->async_io_mutex);
40829 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40830 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40831 if (qdev->last_sent_io_cmd > irq_num) {
40832 if (intr)
40833 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40834 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40835 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40836 else
40837 ret = wait_event_timeout(qdev->io_cmd_event,
40838 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40839 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40840 /* 0 is timeout, just bail the "hw" has gone away */
40841 if (ret <= 0)
40842 goto out;
40843 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40844 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40845 }
40846 outb(val, addr);
40847 qdev->last_sent_io_cmd = irq_num + 1;
40848 if (intr)
40849 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40850 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40851 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40852 else
40853 ret = wait_event_timeout(qdev->io_cmd_event,
40854 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40855 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40856 out:
40857 if (ret > 0)
40858 ret = 0;
40859 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40860 index 6911b8c..89d6867 100644
40861 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40862 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40863 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40864 struct drm_info_node *node = (struct drm_info_node *) m->private;
40865 struct qxl_device *qdev = node->minor->dev->dev_private;
40866
40867 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40868 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40869 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40870 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40871 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40872 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40873 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40874 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40875 seq_printf(m, "%d\n", qdev->irq_received_error);
40876 return 0;
40877 }
40878 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40879 index 7c6cafe..460f542 100644
40880 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40881 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40882 @@ -290,10 +290,10 @@ struct qxl_device {
40883 unsigned int last_sent_io_cmd;
40884
40885 /* interrupt handling */
40886 - atomic_t irq_received;
40887 - atomic_t irq_received_display;
40888 - atomic_t irq_received_cursor;
40889 - atomic_t irq_received_io_cmd;
40890 + atomic_unchecked_t irq_received;
40891 + atomic_unchecked_t irq_received_display;
40892 + atomic_unchecked_t irq_received_cursor;
40893 + atomic_unchecked_t irq_received_io_cmd;
40894 unsigned irq_received_error;
40895 wait_queue_head_t display_event;
40896 wait_queue_head_t cursor_event;
40897 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40898 index b110883..dd06418 100644
40899 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40900 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40901 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40902
40903 /* TODO copy slow path code from i915 */
40904 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40905 - 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);
40906 + 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);
40907
40908 {
40909 struct qxl_drawable *draw = fb_cmd;
40910 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40911 struct drm_qxl_reloc reloc;
40912
40913 if (copy_from_user(&reloc,
40914 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40915 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40916 sizeof(reloc))) {
40917 ret = -EFAULT;
40918 goto out_free_bos;
40919 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40920
40921 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40922
40923 - struct drm_qxl_command *commands =
40924 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40925 + struct drm_qxl_command __user *commands =
40926 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40927
40928 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40929 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40930 sizeof(user_cmd)))
40931 return -EFAULT;
40932
40933 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40934 index 0bf1e20..42a7310 100644
40935 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40936 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40937 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40938 if (!pending)
40939 return IRQ_NONE;
40940
40941 - atomic_inc(&qdev->irq_received);
40942 + atomic_inc_unchecked(&qdev->irq_received);
40943
40944 if (pending & QXL_INTERRUPT_DISPLAY) {
40945 - atomic_inc(&qdev->irq_received_display);
40946 + atomic_inc_unchecked(&qdev->irq_received_display);
40947 wake_up_all(&qdev->display_event);
40948 qxl_queue_garbage_collect(qdev, false);
40949 }
40950 if (pending & QXL_INTERRUPT_CURSOR) {
40951 - atomic_inc(&qdev->irq_received_cursor);
40952 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40953 wake_up_all(&qdev->cursor_event);
40954 }
40955 if (pending & QXL_INTERRUPT_IO_CMD) {
40956 - atomic_inc(&qdev->irq_received_io_cmd);
40957 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40958 wake_up_all(&qdev->io_cmd_event);
40959 }
40960 if (pending & QXL_INTERRUPT_ERROR) {
40961 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40962 init_waitqueue_head(&qdev->io_cmd_event);
40963 INIT_WORK(&qdev->client_monitors_config_work,
40964 qxl_client_monitors_config_work_func);
40965 - atomic_set(&qdev->irq_received, 0);
40966 - atomic_set(&qdev->irq_received_display, 0);
40967 - atomic_set(&qdev->irq_received_cursor, 0);
40968 - atomic_set(&qdev->irq_received_io_cmd, 0);
40969 + atomic_set_unchecked(&qdev->irq_received, 0);
40970 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40971 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40972 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40973 qdev->irq_received_error = 0;
40974 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
40975 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40976 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40977 index 0cbc4c9..0e46686 100644
40978 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40979 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40980 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40981 }
40982 }
40983
40984 -static struct vm_operations_struct qxl_ttm_vm_ops;
40985 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40986 static const struct vm_operations_struct *ttm_vm_ops;
40987
40988 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40989 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40990 return r;
40991 if (unlikely(ttm_vm_ops == NULL)) {
40992 ttm_vm_ops = vma->vm_ops;
40993 + pax_open_kernel();
40994 qxl_ttm_vm_ops = *ttm_vm_ops;
40995 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40996 + pax_close_kernel();
40997 }
40998 vma->vm_ops = &qxl_ttm_vm_ops;
40999 return 0;
41000 @@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41001 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41002 {
41003 #if defined(CONFIG_DEBUG_FS)
41004 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41005 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41006 - unsigned i;
41007 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41008 + {
41009 + .name = "qxl_mem_mm",
41010 + .show = &qxl_mm_dump_table,
41011 + },
41012 + {
41013 + .name = "qxl_surf_mm",
41014 + .show = &qxl_mm_dump_table,
41015 + }
41016 + };
41017
41018 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41019 - if (i == 0)
41020 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41021 - else
41022 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41023 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41024 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41025 - qxl_mem_types_list[i].driver_features = 0;
41026 - if (i == 0)
41027 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41028 - else
41029 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41030 + pax_open_kernel();
41031 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41032 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41033 + pax_close_kernel();
41034
41035 - }
41036 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41037 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41038 #else
41039 return 0;
41040 #endif
41041 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41042 index 2c45ac9..5d740f8 100644
41043 --- a/drivers/gpu/drm/r128/r128_cce.c
41044 +++ b/drivers/gpu/drm/r128/r128_cce.c
41045 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41046
41047 /* GH: Simple idle check.
41048 */
41049 - atomic_set(&dev_priv->idle_count, 0);
41050 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41051
41052 /* We don't support anything other than bus-mastering ring mode,
41053 * but the ring can be in either AGP or PCI space for the ring
41054 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41055 index 723e5d6..102dbaf 100644
41056 --- a/drivers/gpu/drm/r128/r128_drv.h
41057 +++ b/drivers/gpu/drm/r128/r128_drv.h
41058 @@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41059 int is_pci;
41060 unsigned long cce_buffers_offset;
41061
41062 - atomic_t idle_count;
41063 + atomic_unchecked_t idle_count;
41064
41065 int page_flipping;
41066 int current_page;
41067 u32 crtc_offset;
41068 u32 crtc_offset_cntl;
41069
41070 - atomic_t vbl_received;
41071 + atomic_unchecked_t vbl_received;
41072
41073 u32 color_fmt;
41074 unsigned int front_offset;
41075 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41076 index 663f38c..c689495 100644
41077 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41078 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41079 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41080 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41081 }
41082
41083 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41084 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41085 [DRM_R128_INIT] = compat_r128_init,
41086 [DRM_R128_DEPTH] = compat_r128_depth,
41087 [DRM_R128_STIPPLE] = compat_r128_stipple,
41088 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41089 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41090 {
41091 unsigned int nr = DRM_IOCTL_NR(cmd);
41092 - drm_ioctl_compat_t *fn = NULL;
41093 int ret;
41094
41095 if (nr < DRM_COMMAND_BASE)
41096 return drm_compat_ioctl(filp, cmd, arg);
41097
41098 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41099 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41100 -
41101 - if (fn != NULL)
41102 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41103 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41104 ret = (*fn) (filp, cmd, arg);
41105 - else
41106 + } else
41107 ret = drm_ioctl(filp, cmd, arg);
41108
41109 return ret;
41110 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41111 index c2ae496..30b5993 100644
41112 --- a/drivers/gpu/drm/r128/r128_irq.c
41113 +++ b/drivers/gpu/drm/r128/r128_irq.c
41114 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41115 if (crtc != 0)
41116 return 0;
41117
41118 - return atomic_read(&dev_priv->vbl_received);
41119 + return atomic_read_unchecked(&dev_priv->vbl_received);
41120 }
41121
41122 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41123 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41124 /* VBLANK interrupt */
41125 if (status & R128_CRTC_VBLANK_INT) {
41126 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41127 - atomic_inc(&dev_priv->vbl_received);
41128 + atomic_inc_unchecked(&dev_priv->vbl_received);
41129 drm_handle_vblank(dev, 0);
41130 return IRQ_HANDLED;
41131 }
41132 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41133 index 575e986..66e62ca 100644
41134 --- a/drivers/gpu/drm/r128/r128_state.c
41135 +++ b/drivers/gpu/drm/r128/r128_state.c
41136 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41137
41138 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41139 {
41140 - if (atomic_read(&dev_priv->idle_count) == 0)
41141 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41142 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41143 else
41144 - atomic_set(&dev_priv->idle_count, 0);
41145 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41146 }
41147
41148 #endif
41149 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41150 index 4a85bb6..aaea819 100644
41151 --- a/drivers/gpu/drm/radeon/mkregtable.c
41152 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41153 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41154 regex_t mask_rex;
41155 regmatch_t match[4];
41156 char buf[1024];
41157 - size_t end;
41158 + long end;
41159 int len;
41160 int done = 0;
41161 int r;
41162 unsigned o;
41163 struct offset *offset;
41164 char last_reg_s[10];
41165 - int last_reg;
41166 + unsigned long last_reg;
41167
41168 if (regcomp
41169 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41170 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41171 index 995a8b1..b7cb898 100644
41172 --- a/drivers/gpu/drm/radeon/radeon_device.c
41173 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41174 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41175 * locking inversion with the driver load path. And the access here is
41176 * completely racy anyway. So don't bother with locking for now.
41177 */
41178 - return dev->open_count == 0;
41179 + return local_read(&dev->open_count) == 0;
41180 }
41181
41182 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41183 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41184 index 46bd393..6ae4719 100644
41185 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41186 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41187 @@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41188
41189 /* SW interrupt */
41190 wait_queue_head_t swi_queue;
41191 - atomic_t swi_emitted;
41192 + atomic_unchecked_t swi_emitted;
41193 int vblank_crtc;
41194 uint32_t irq_enable_reg;
41195 uint32_t r500_disp_irq_reg;
41196 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41197 index 0b98ea1..0881827 100644
41198 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41199 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41200 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41201 request = compat_alloc_user_space(sizeof(*request));
41202 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41203 || __put_user(req32.param, &request->param)
41204 - || __put_user((void __user *)(unsigned long)req32.value,
41205 + || __put_user((unsigned long)req32.value,
41206 &request->value))
41207 return -EFAULT;
41208
41209 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41210 #define compat_radeon_cp_setparam NULL
41211 #endif /* X86_64 || IA64 */
41212
41213 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41214 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41215 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41216 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41217 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41218 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41219 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41220 {
41221 unsigned int nr = DRM_IOCTL_NR(cmd);
41222 - drm_ioctl_compat_t *fn = NULL;
41223 int ret;
41224
41225 if (nr < DRM_COMMAND_BASE)
41226 return drm_compat_ioctl(filp, cmd, arg);
41227
41228 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41229 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41230 -
41231 - if (fn != NULL)
41232 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41233 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41234 ret = (*fn) (filp, cmd, arg);
41235 - else
41236 + } else
41237 ret = drm_ioctl(filp, cmd, arg);
41238
41239 return ret;
41240 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41241 index 244b19b..c19226d 100644
41242 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41243 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41244 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41245 unsigned int ret;
41246 RING_LOCALS;
41247
41248 - atomic_inc(&dev_priv->swi_emitted);
41249 - ret = atomic_read(&dev_priv->swi_emitted);
41250 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41251 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41252
41253 BEGIN_RING(4);
41254 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41255 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41256 drm_radeon_private_t *dev_priv =
41257 (drm_radeon_private_t *) dev->dev_private;
41258
41259 - atomic_set(&dev_priv->swi_emitted, 0);
41260 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41261 init_waitqueue_head(&dev_priv->swi_queue);
41262
41263 dev->max_vblank_count = 0x001fffff;
41264 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41265 index 535403e..5dd655b 100644
41266 --- a/drivers/gpu/drm/radeon/radeon_state.c
41267 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41268 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41269 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41270 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41271
41272 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41273 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41274 sarea_priv->nbox * sizeof(depth_boxes[0])))
41275 return -EFAULT;
41276
41277 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41278 {
41279 drm_radeon_private_t *dev_priv = dev->dev_private;
41280 drm_radeon_getparam_t *param = data;
41281 - int value;
41282 + int value = 0;
41283
41284 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41285
41286 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41287 index d2510cf..63bd4ed 100644
41288 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41289 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41290 @@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41291 man->size = size >> PAGE_SHIFT;
41292 }
41293
41294 -static struct vm_operations_struct radeon_ttm_vm_ops;
41295 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41296 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41297
41298 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41299 @@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41300 }
41301 if (unlikely(ttm_vm_ops == NULL)) {
41302 ttm_vm_ops = vma->vm_ops;
41303 + pax_open_kernel();
41304 radeon_ttm_vm_ops = *ttm_vm_ops;
41305 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41306 + pax_close_kernel();
41307 }
41308 vma->vm_ops = &radeon_ttm_vm_ops;
41309 return 0;
41310 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41311 index 054a79f..30d9ac4 100644
41312 --- a/drivers/gpu/drm/tegra/dc.c
41313 +++ b/drivers/gpu/drm/tegra/dc.c
41314 @@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41315 }
41316
41317 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41318 - dc->debugfs_files[i].data = dc;
41319 + *(void **)&dc->debugfs_files[i].data = dc;
41320
41321 err = drm_debugfs_create_files(dc->debugfs_files,
41322 ARRAY_SIZE(debugfs_files),
41323 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41324 index f787445..2df2c65 100644
41325 --- a/drivers/gpu/drm/tegra/dsi.c
41326 +++ b/drivers/gpu/drm/tegra/dsi.c
41327 @@ -41,7 +41,7 @@ struct tegra_dsi {
41328 struct clk *clk_lp;
41329 struct clk *clk;
41330
41331 - struct drm_info_list *debugfs_files;
41332 + drm_info_list_no_const *debugfs_files;
41333 struct drm_minor *minor;
41334 struct dentry *debugfs;
41335
41336 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41337 index ffe2654..03c7b1c 100644
41338 --- a/drivers/gpu/drm/tegra/hdmi.c
41339 +++ b/drivers/gpu/drm/tegra/hdmi.c
41340 @@ -60,7 +60,7 @@ struct tegra_hdmi {
41341 bool stereo;
41342 bool dvi;
41343
41344 - struct drm_info_list *debugfs_files;
41345 + drm_info_list_no_const *debugfs_files;
41346 struct drm_minor *minor;
41347 struct dentry *debugfs;
41348 };
41349 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41350 index 964387f..4eafc00 100644
41351 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41352 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41353 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41354 }
41355
41356 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41357 - ttm_bo_man_init,
41358 - ttm_bo_man_takedown,
41359 - ttm_bo_man_get_node,
41360 - ttm_bo_man_put_node,
41361 - ttm_bo_man_debug
41362 + .init = ttm_bo_man_init,
41363 + .takedown = ttm_bo_man_takedown,
41364 + .get_node = ttm_bo_man_get_node,
41365 + .put_node = ttm_bo_man_put_node,
41366 + .debug = ttm_bo_man_debug
41367 };
41368 EXPORT_SYMBOL(ttm_bo_manager_func);
41369 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41370 index a1803fb..c53f6b0 100644
41371 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41372 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41373 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41374 zone->glob = glob;
41375 glob->zone_kernel = zone;
41376 ret = kobject_init_and_add(
41377 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41378 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41379 if (unlikely(ret != 0)) {
41380 kobject_put(&zone->kobj);
41381 return ret;
41382 @@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41383 zone->glob = glob;
41384 glob->zone_dma32 = zone;
41385 ret = kobject_init_and_add(
41386 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41387 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41388 if (unlikely(ret != 0)) {
41389 kobject_put(&zone->kobj);
41390 return ret;
41391 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41392 index 025c429..314062f 100644
41393 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41394 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41395 @@ -54,7 +54,7 @@
41396
41397 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41398 #define SMALL_ALLOCATION 16
41399 -#define FREE_ALL_PAGES (~0U)
41400 +#define FREE_ALL_PAGES (~0UL)
41401 /* times are in msecs */
41402 #define PAGE_FREE_INTERVAL 1000
41403
41404 @@ -299,15 +299,14 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41405 * @free_all: If set to true will free all pages in pool
41406 * @use_static: Safe to use static buffer
41407 **/
41408 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41409 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41410 bool use_static)
41411 {
41412 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41413 unsigned long irq_flags;
41414 struct page *p;
41415 struct page **pages_to_free;
41416 - unsigned freed_pages = 0,
41417 - npages_to_free = nr_free;
41418 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41419
41420 if (NUM_PAGES_TO_ALLOC < nr_free)
41421 npages_to_free = NUM_PAGES_TO_ALLOC;
41422 @@ -371,7 +370,8 @@ restart:
41423 __list_del(&p->lru, &pool->list);
41424
41425 ttm_pool_update_free_locked(pool, freed_pages);
41426 - nr_free -= freed_pages;
41427 + if (likely(nr_free != FREE_ALL_PAGES))
41428 + nr_free -= freed_pages;
41429 }
41430
41431 spin_unlock_irqrestore(&pool->lock, irq_flags);
41432 @@ -399,7 +399,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41433 unsigned i;
41434 unsigned pool_offset;
41435 struct ttm_page_pool *pool;
41436 - int shrink_pages = sc->nr_to_scan;
41437 + unsigned long shrink_pages = sc->nr_to_scan;
41438 unsigned long freed = 0;
41439
41440 if (!mutex_trylock(&lock))
41441 @@ -407,7 +407,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41442 pool_offset = ++start_pool % NUM_POOLS;
41443 /* select start pool in round robin fashion */
41444 for (i = 0; i < NUM_POOLS; ++i) {
41445 - unsigned nr_free = shrink_pages;
41446 + unsigned long nr_free = shrink_pages;
41447 if (shrink_pages == 0)
41448 break;
41449 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41450 @@ -673,7 +673,7 @@ out:
41451 }
41452
41453 /* Put all pages in pages list to correct pool to wait for reuse */
41454 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41455 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41456 enum ttm_caching_state cstate)
41457 {
41458 unsigned long irq_flags;
41459 @@ -728,7 +728,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41460 struct list_head plist;
41461 struct page *p = NULL;
41462 gfp_t gfp_flags = GFP_USER;
41463 - unsigned count;
41464 + unsigned long count;
41465 int r;
41466
41467 /* set zero flag for page allocation if required */
41468 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41469 index 01e1d27..aaa018a 100644
41470 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41471 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41472 @@ -56,7 +56,7 @@
41473
41474 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41475 #define SMALL_ALLOCATION 4
41476 -#define FREE_ALL_PAGES (~0U)
41477 +#define FREE_ALL_PAGES (~0UL)
41478 /* times are in msecs */
41479 #define IS_UNDEFINED (0)
41480 #define IS_WC (1<<1)
41481 @@ -413,7 +413,7 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41482 * @nr_free: If set to true will free all pages in pool
41483 * @use_static: Safe to use static buffer
41484 **/
41485 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41486 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41487 bool use_static)
41488 {
41489 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41490 @@ -421,8 +421,7 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41491 struct dma_page *dma_p, *tmp;
41492 struct page **pages_to_free;
41493 struct list_head d_pages;
41494 - unsigned freed_pages = 0,
41495 - npages_to_free = nr_free;
41496 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41497
41498 if (NUM_PAGES_TO_ALLOC < nr_free)
41499 npages_to_free = NUM_PAGES_TO_ALLOC;
41500 @@ -499,7 +498,8 @@ restart:
41501 /* remove range of pages from the pool */
41502 if (freed_pages) {
41503 ttm_pool_update_free_locked(pool, freed_pages);
41504 - nr_free -= freed_pages;
41505 + if (likely(nr_free != FREE_ALL_PAGES))
41506 + nr_free -= freed_pages;
41507 }
41508
41509 spin_unlock_irqrestore(&pool->lock, irq_flags);
41510 @@ -936,7 +936,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41511 struct dma_page *d_page, *next;
41512 enum pool_type type;
41513 bool is_cached = false;
41514 - unsigned count = 0, i, npages = 0;
41515 + unsigned long count = 0, i, npages = 0;
41516 unsigned long irq_flags;
41517
41518 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41519 @@ -1012,7 +1012,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41520 static unsigned start_pool;
41521 unsigned idx = 0;
41522 unsigned pool_offset;
41523 - unsigned shrink_pages = sc->nr_to_scan;
41524 + unsigned long shrink_pages = sc->nr_to_scan;
41525 struct device_pools *p;
41526 unsigned long freed = 0;
41527
41528 @@ -1025,7 +1025,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41529 goto out;
41530 pool_offset = ++start_pool % _manager->npools;
41531 list_for_each_entry(p, &_manager->pools, pools) {
41532 - unsigned nr_free;
41533 + unsigned long nr_free;
41534
41535 if (!p->dev)
41536 continue;
41537 @@ -1039,7 +1039,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41538 shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
41539 freed += nr_free - shrink_pages;
41540
41541 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41542 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41543 p->pool->dev_name, p->pool->name, current->pid,
41544 nr_free, shrink_pages);
41545 }
41546 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41547 index 8cbcb45..a4d9cf7 100644
41548 --- a/drivers/gpu/drm/udl/udl_fb.c
41549 +++ b/drivers/gpu/drm/udl/udl_fb.c
41550 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41551 fb_deferred_io_cleanup(info);
41552 kfree(info->fbdefio);
41553 info->fbdefio = NULL;
41554 - info->fbops->fb_mmap = udl_fb_mmap;
41555 }
41556
41557 pr_warn("released /dev/fb%d user=%d count=%d\n",
41558 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41559 index ef8c500..01030c8 100644
41560 --- a/drivers/gpu/drm/via/via_drv.h
41561 +++ b/drivers/gpu/drm/via/via_drv.h
41562 @@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41563 typedef uint32_t maskarray_t[5];
41564
41565 typedef struct drm_via_irq {
41566 - atomic_t irq_received;
41567 + atomic_unchecked_t irq_received;
41568 uint32_t pending_mask;
41569 uint32_t enable_mask;
41570 wait_queue_head_t irq_queue;
41571 @@ -77,7 +77,7 @@ typedef struct drm_via_private {
41572 struct timeval last_vblank;
41573 int last_vblank_valid;
41574 unsigned usec_per_vblank;
41575 - atomic_t vbl_received;
41576 + atomic_unchecked_t vbl_received;
41577 drm_via_state_t hc_state;
41578 char pci_buf[VIA_PCI_BUF_SIZE];
41579 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41580 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41581 index 1319433..a993b0c 100644
41582 --- a/drivers/gpu/drm/via/via_irq.c
41583 +++ b/drivers/gpu/drm/via/via_irq.c
41584 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41585 if (crtc != 0)
41586 return 0;
41587
41588 - return atomic_read(&dev_priv->vbl_received);
41589 + return atomic_read_unchecked(&dev_priv->vbl_received);
41590 }
41591
41592 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41593 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41594
41595 status = VIA_READ(VIA_REG_INTERRUPT);
41596 if (status & VIA_IRQ_VBLANK_PENDING) {
41597 - atomic_inc(&dev_priv->vbl_received);
41598 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41599 + atomic_inc_unchecked(&dev_priv->vbl_received);
41600 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41601 do_gettimeofday(&cur_vblank);
41602 if (dev_priv->last_vblank_valid) {
41603 dev_priv->usec_per_vblank =
41604 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41605 dev_priv->last_vblank = cur_vblank;
41606 dev_priv->last_vblank_valid = 1;
41607 }
41608 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41609 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41610 DRM_DEBUG("US per vblank is: %u\n",
41611 dev_priv->usec_per_vblank);
41612 }
41613 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41614
41615 for (i = 0; i < dev_priv->num_irqs; ++i) {
41616 if (status & cur_irq->pending_mask) {
41617 - atomic_inc(&cur_irq->irq_received);
41618 + atomic_inc_unchecked(&cur_irq->irq_received);
41619 wake_up(&cur_irq->irq_queue);
41620 handled = 1;
41621 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41622 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41623 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41624 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41625 masks[irq][4]));
41626 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41627 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41628 } else {
41629 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41630 (((cur_irq_sequence =
41631 - atomic_read(&cur_irq->irq_received)) -
41632 + atomic_read_unchecked(&cur_irq->irq_received)) -
41633 *sequence) <= (1 << 23)));
41634 }
41635 *sequence = cur_irq_sequence;
41636 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41637 }
41638
41639 for (i = 0; i < dev_priv->num_irqs; ++i) {
41640 - atomic_set(&cur_irq->irq_received, 0);
41641 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41642 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41643 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41644 init_waitqueue_head(&cur_irq->irq_queue);
41645 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41646 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41647 case VIA_IRQ_RELATIVE:
41648 irqwait->request.sequence +=
41649 - atomic_read(&cur_irq->irq_received);
41650 + atomic_read_unchecked(&cur_irq->irq_received);
41651 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41652 case VIA_IRQ_ABSOLUTE:
41653 break;
41654 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41655 index 4ee799b..69fc0d1 100644
41656 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41657 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41658 @@ -446,7 +446,7 @@ struct vmw_private {
41659 * Fencing and IRQs.
41660 */
41661
41662 - atomic_t marker_seq;
41663 + atomic_unchecked_t marker_seq;
41664 wait_queue_head_t fence_queue;
41665 wait_queue_head_t fifo_queue;
41666 int fence_queue_waiters; /* Protected by hw_mutex */
41667 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41668 index 09e10ae..cb76c60 100644
41669 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41670 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41671 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41672 (unsigned int) min,
41673 (unsigned int) fifo->capabilities);
41674
41675 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41676 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41677 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41678 vmw_marker_queue_init(&fifo->marker_queue);
41679 return vmw_fifo_send_fence(dev_priv, &dummy);
41680 @@ -378,7 +378,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41681 if (reserveable)
41682 iowrite32(bytes, fifo_mem +
41683 SVGA_FIFO_RESERVED);
41684 - return fifo_mem + (next_cmd >> 2);
41685 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41686 } else {
41687 need_bounce = true;
41688 }
41689 @@ -498,7 +498,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41690
41691 fm = vmw_fifo_reserve(dev_priv, bytes);
41692 if (unlikely(fm == NULL)) {
41693 - *seqno = atomic_read(&dev_priv->marker_seq);
41694 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41695 ret = -ENOMEM;
41696 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41697 false, 3*HZ);
41698 @@ -506,7 +506,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41699 }
41700
41701 do {
41702 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41703 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41704 } while (*seqno == 0);
41705
41706 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41707 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41708 index 170b61b..fec7348 100644
41709 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41710 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41711 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41712 }
41713
41714 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41715 - vmw_gmrid_man_init,
41716 - vmw_gmrid_man_takedown,
41717 - vmw_gmrid_man_get_node,
41718 - vmw_gmrid_man_put_node,
41719 - vmw_gmrid_man_debug
41720 + .init = vmw_gmrid_man_init,
41721 + .takedown = vmw_gmrid_man_takedown,
41722 + .get_node = vmw_gmrid_man_get_node,
41723 + .put_node = vmw_gmrid_man_put_node,
41724 + .debug = vmw_gmrid_man_debug
41725 };
41726 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41727 index 37881ec..319065d 100644
41728 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41729 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41730 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41731 int ret;
41732
41733 num_clips = arg->num_clips;
41734 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41735 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41736
41737 if (unlikely(num_clips == 0))
41738 return 0;
41739 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41740 int ret;
41741
41742 num_clips = arg->num_clips;
41743 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41744 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41745
41746 if (unlikely(num_clips == 0))
41747 return 0;
41748 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41749 index 0c42376..6febe77 100644
41750 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41751 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41752 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41753 * emitted. Then the fence is stale and signaled.
41754 */
41755
41756 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41757 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41758 > VMW_FENCE_WRAP);
41759
41760 return ret;
41761 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41762
41763 if (fifo_idle)
41764 down_read(&fifo_state->rwsem);
41765 - signal_seq = atomic_read(&dev_priv->marker_seq);
41766 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41767 ret = 0;
41768
41769 for (;;) {
41770 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41771 index efd1ffd..0ae13ca 100644
41772 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41773 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41774 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41775 while (!vmw_lag_lt(queue, us)) {
41776 spin_lock(&queue->lock);
41777 if (list_empty(&queue->head))
41778 - seqno = atomic_read(&dev_priv->marker_seq);
41779 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41780 else {
41781 marker = list_first_entry(&queue->head,
41782 struct vmw_marker, head);
41783 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41784 index 37ac7b5..d52a5c9 100644
41785 --- a/drivers/gpu/vga/vga_switcheroo.c
41786 +++ b/drivers/gpu/vga/vga_switcheroo.c
41787 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41788
41789 /* this version is for the case where the power switch is separate
41790 to the device being powered down. */
41791 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41792 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41793 {
41794 /* copy over all the bus versions */
41795 if (dev->bus && dev->bus->pm) {
41796 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41797 return ret;
41798 }
41799
41800 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41801 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41802 {
41803 /* copy over all the bus versions */
41804 if (dev->bus && dev->bus->pm) {
41805 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41806 index dfaccfc..bfea740 100644
41807 --- a/drivers/hid/hid-core.c
41808 +++ b/drivers/hid/hid-core.c
41809 @@ -2507,7 +2507,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41810
41811 int hid_add_device(struct hid_device *hdev)
41812 {
41813 - static atomic_t id = ATOMIC_INIT(0);
41814 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41815 int ret;
41816
41817 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41818 @@ -2549,7 +2549,7 @@ int hid_add_device(struct hid_device *hdev)
41819 /* XXX hack, any other cleaner solution after the driver core
41820 * is converted to allow more than 20 bytes as the device name? */
41821 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41822 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41823 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41824
41825 hid_debug_register(hdev, dev_name(&hdev->dev));
41826 ret = device_add(&hdev->dev);
41827 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41828 index 71f5692..147d3da 100644
41829 --- a/drivers/hid/hid-logitech-dj.c
41830 +++ b/drivers/hid/hid-logitech-dj.c
41831 @@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41832 * device (via hid_input_report() ) and return 1 so hid-core does not do
41833 * anything else with it.
41834 */
41835 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41836 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41837 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41838 + __func__, dj_report->device_index);
41839 + return false;
41840 + }
41841
41842 /* case 1) */
41843 if (data[0] != REPORT_ID_DJ_SHORT)
41844 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41845 index bc4269e..b6e6102 100644
41846 --- a/drivers/hid/hid-sony.c
41847 +++ b/drivers/hid/hid-sony.c
41848 @@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41849 __u8 buf[36];
41850 };
41851
41852 +#define DS4_REPORT_0x02_SIZE 37
41853 +#define DS4_REPORT_0x05_SIZE 32
41854 +#define DS4_REPORT_0x11_SIZE 78
41855 +#define DS4_REPORT_0x81_SIZE 7
41856 +#define SIXAXIS_REPORT_0xF2_SIZE 18
41857 +
41858 static spinlock_t sony_dev_list_lock;
41859 static LIST_HEAD(sony_device_list);
41860 static DEFINE_IDA(sony_device_id_allocator);
41861 @@ -811,6 +817,7 @@ struct sony_sc {
41862 struct work_struct state_worker;
41863 struct power_supply battery;
41864 int device_id;
41865 + __u8 *output_report_dmabuf;
41866
41867 #ifdef CONFIG_SONY_FF
41868 __u8 left;
41869 @@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41870
41871 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41872 {
41873 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41874 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41875 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41876 + __u8 *buf;
41877 + int ret;
41878 +
41879 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41880 + if (!buf)
41881 + return -ENOMEM;
41882 +
41883 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41884 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41885 +
41886 + kfree(buf);
41887 +
41888 + return ret;
41889 }
41890
41891 /*
41892 @@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41893 */
41894 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41895 {
41896 - __u8 buf[37] = { 0 };
41897 + __u8 *buf;
41898 + int ret;
41899
41900 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41901 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41902 + if (!buf)
41903 + return -ENOMEM;
41904 +
41905 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41906 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41907 +
41908 + kfree(buf);
41909 +
41910 + return ret;
41911 }
41912
41913 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41914 @@ -1471,9 +1498,7 @@ error_leds:
41915
41916 static void sixaxis_state_worker(struct work_struct *work)
41917 {
41918 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41919 - int n;
41920 - union sixaxis_output_report_01 report = {
41921 + static const union sixaxis_output_report_01 default_report = {
41922 .buf = {
41923 0x01,
41924 0x00, 0xff, 0x00, 0xff, 0x00,
41925 @@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41926 0x00, 0x00, 0x00, 0x00, 0x00
41927 }
41928 };
41929 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41930 + struct sixaxis_output_report *report =
41931 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
41932 + int n;
41933 +
41934 + /* Initialize the report with default values */
41935 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41936
41937 #ifdef CONFIG_SONY_FF
41938 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41939 - report.data.rumble.left_motor_force = sc->left;
41940 + report->rumble.right_motor_on = sc->right ? 1 : 0;
41941 + report->rumble.left_motor_force = sc->left;
41942 #endif
41943
41944 - report.data.leds_bitmap |= sc->led_state[0] << 1;
41945 - report.data.leds_bitmap |= sc->led_state[1] << 2;
41946 - report.data.leds_bitmap |= sc->led_state[2] << 3;
41947 - report.data.leds_bitmap |= sc->led_state[3] << 4;
41948 + report->leds_bitmap |= sc->led_state[0] << 1;
41949 + report->leds_bitmap |= sc->led_state[1] << 2;
41950 + report->leds_bitmap |= sc->led_state[2] << 3;
41951 + report->leds_bitmap |= sc->led_state[3] << 4;
41952
41953 /* Set flag for all leds off, required for 3rd party INTEC controller */
41954 - if ((report.data.leds_bitmap & 0x1E) == 0)
41955 - report.data.leds_bitmap |= 0x20;
41956 + if ((report->leds_bitmap & 0x1E) == 0)
41957 + report->leds_bitmap |= 0x20;
41958
41959 /*
41960 * The LEDs in the report are indexed in reverse order to their
41961 @@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41962 */
41963 for (n = 0; n < 4; n++) {
41964 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
41965 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
41966 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
41967 + report->led[3 - n].duty_off = sc->led_delay_off[n];
41968 + report->led[3 - n].duty_on = sc->led_delay_on[n];
41969 }
41970 }
41971
41972 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
41973 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41974 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
41975 + sizeof(struct sixaxis_output_report),
41976 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41977 }
41978
41979 static void dualshock4_state_worker(struct work_struct *work)
41980 {
41981 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41982 struct hid_device *hdev = sc->hdev;
41983 + __u8 *buf = sc->output_report_dmabuf;
41984 int offset;
41985
41986 - __u8 buf[78] = { 0 };
41987 -
41988 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41989 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
41990 buf[0] = 0x05;
41991 buf[1] = 0xFF;
41992 offset = 4;
41993 } else {
41994 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
41995 buf[0] = 0x11;
41996 buf[1] = 0xB0;
41997 buf[3] = 0x0F;
41998 @@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
41999 buf[offset++] = sc->led_delay_off[3];
42000
42001 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42002 - hid_hw_output_report(hdev, buf, 32);
42003 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
42004 else
42005 - hid_hw_raw_request(hdev, 0x11, buf, 78,
42006 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
42007 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42008 }
42009
42010 +static int sony_allocate_output_report(struct sony_sc *sc)
42011 +{
42012 + if (sc->quirks & SIXAXIS_CONTROLLER)
42013 + sc->output_report_dmabuf =
42014 + kmalloc(sizeof(union sixaxis_output_report_01),
42015 + GFP_KERNEL);
42016 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
42017 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
42018 + GFP_KERNEL);
42019 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42020 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
42021 + GFP_KERNEL);
42022 + else
42023 + return 0;
42024 +
42025 + if (!sc->output_report_dmabuf)
42026 + return -ENOMEM;
42027 +
42028 + return 0;
42029 +}
42030 +
42031 #ifdef CONFIG_SONY_FF
42032 static int sony_play_effect(struct input_dev *dev, void *data,
42033 struct ff_effect *effect)
42034 @@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
42035
42036 static int sony_check_add(struct sony_sc *sc)
42037 {
42038 + __u8 *buf = NULL;
42039 int n, ret;
42040
42041 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42042 @@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42043 return 0;
42044 }
42045 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42046 - __u8 buf[7];
42047 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42048 + if (!buf)
42049 + return -ENOMEM;
42050
42051 /*
42052 * The MAC address of a DS4 controller connected via USB can be
42053 * retrieved with feature report 0x81. The address begins at
42054 * offset 1.
42055 */
42056 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42057 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42058 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42059 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42060 + HID_REQ_GET_REPORT);
42061
42062 - if (ret != 7) {
42063 + if (ret != DS4_REPORT_0x81_SIZE) {
42064 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42065 - return ret < 0 ? ret : -EINVAL;
42066 + ret = ret < 0 ? ret : -EINVAL;
42067 + goto out_free;
42068 }
42069
42070 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42071 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42072 - __u8 buf[18];
42073 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42074 + if (!buf)
42075 + return -ENOMEM;
42076
42077 /*
42078 * The MAC address of a Sixaxis controller connected via USB can
42079 * be retrieved with feature report 0xf2. The address begins at
42080 * offset 4.
42081 */
42082 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42083 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42084 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42085 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42086 + HID_REQ_GET_REPORT);
42087
42088 - if (ret != 18) {
42089 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42090 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42091 - return ret < 0 ? ret : -EINVAL;
42092 + ret = ret < 0 ? ret : -EINVAL;
42093 + goto out_free;
42094 }
42095
42096 /*
42097 @@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42098 return 0;
42099 }
42100
42101 - return sony_check_add_dev_list(sc);
42102 + ret = sony_check_add_dev_list(sc);
42103 +
42104 +out_free:
42105 +
42106 + kfree(buf);
42107 +
42108 + return ret;
42109 }
42110
42111 static int sony_set_device_id(struct sony_sc *sc)
42112 @@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42113 return ret;
42114 }
42115
42116 + ret = sony_allocate_output_report(sc);
42117 + if (ret < 0) {
42118 + hid_err(hdev, "failed to allocate the output report buffer\n");
42119 + goto err_stop;
42120 + }
42121 +
42122 ret = sony_set_device_id(sc);
42123 if (ret < 0) {
42124 hid_err(hdev, "failed to allocate the device id\n");
42125 @@ -1984,6 +2060,7 @@ err_stop:
42126 if (sc->quirks & SONY_BATTERY_SUPPORT)
42127 sony_battery_remove(sc);
42128 sony_cancel_work_sync(sc);
42129 + kfree(sc->output_report_dmabuf);
42130 sony_remove_dev_list(sc);
42131 sony_release_device_id(sc);
42132 hid_hw_stop(hdev);
42133 @@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42134
42135 sony_cancel_work_sync(sc);
42136
42137 + kfree(sc->output_report_dmabuf);
42138 +
42139 sony_remove_dev_list(sc);
42140
42141 sony_release_device_id(sc);
42142 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42143 index c13fb5b..55a3802 100644
42144 --- a/drivers/hid/hid-wiimote-debug.c
42145 +++ b/drivers/hid/hid-wiimote-debug.c
42146 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42147 else if (size == 0)
42148 return -EIO;
42149
42150 - if (copy_to_user(u, buf, size))
42151 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42152 return -EFAULT;
42153
42154 *off += size;
42155 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42156 index 433f72a..2926005 100644
42157 --- a/drivers/hv/channel.c
42158 +++ b/drivers/hv/channel.c
42159 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42160 unsigned long flags;
42161 int ret = 0;
42162
42163 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42164 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42165 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42166 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42167
42168 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42169 if (ret)
42170 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42171 index 3e4235c..877d0e5 100644
42172 --- a/drivers/hv/hv.c
42173 +++ b/drivers/hv/hv.c
42174 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42175 u64 output_address = (output) ? virt_to_phys(output) : 0;
42176 u32 output_address_hi = output_address >> 32;
42177 u32 output_address_lo = output_address & 0xFFFFFFFF;
42178 - void *hypercall_page = hv_context.hypercall_page;
42179 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42180
42181 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42182 "=a"(hv_status_lo) : "d" (control_hi),
42183 @@ -156,7 +156,7 @@ int hv_init(void)
42184 /* See if the hypercall page is already set */
42185 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42186
42187 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42188 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42189
42190 if (!virtaddr)
42191 goto cleanup;
42192 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42193 index 5e90c5d..d8fcefb 100644
42194 --- a/drivers/hv/hv_balloon.c
42195 +++ b/drivers/hv/hv_balloon.c
42196 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42197
42198 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42199 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42200 -static atomic_t trans_id = ATOMIC_INIT(0);
42201 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42202
42203 static int dm_ring_size = (5 * PAGE_SIZE);
42204
42205 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42206 pr_info("Memory hot add failed\n");
42207
42208 dm->state = DM_INITIALIZED;
42209 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42210 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42211 vmbus_sendpacket(dm->dev->channel, &resp,
42212 sizeof(struct dm_hot_add_response),
42213 (unsigned long)NULL,
42214 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42215 memset(&status, 0, sizeof(struct dm_status));
42216 status.hdr.type = DM_STATUS_REPORT;
42217 status.hdr.size = sizeof(struct dm_status);
42218 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42219 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42220
42221 /*
42222 * The host expects the guest to report free memory.
42223 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42224 * send the status. This can happen if we were interrupted
42225 * after we picked our transaction ID.
42226 */
42227 - if (status.hdr.trans_id != atomic_read(&trans_id))
42228 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42229 return;
42230
42231 /*
42232 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42233 */
42234
42235 do {
42236 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42237 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42238 ret = vmbus_sendpacket(dm_device.dev->channel,
42239 bl_resp,
42240 bl_resp->hdr.size,
42241 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42242
42243 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42244 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42245 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42246 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42247 resp.hdr.size = sizeof(struct dm_unballoon_response);
42248
42249 vmbus_sendpacket(dm_device.dev->channel, &resp,
42250 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42251 memset(&version_req, 0, sizeof(struct dm_version_request));
42252 version_req.hdr.type = DM_VERSION_REQUEST;
42253 version_req.hdr.size = sizeof(struct dm_version_request);
42254 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42255 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42256 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42257 version_req.is_last_attempt = 1;
42258
42259 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42260 memset(&version_req, 0, sizeof(struct dm_version_request));
42261 version_req.hdr.type = DM_VERSION_REQUEST;
42262 version_req.hdr.size = sizeof(struct dm_version_request);
42263 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42264 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42265 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42266 version_req.is_last_attempt = 0;
42267
42268 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42269 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42270 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42271 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42272 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42273 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42274
42275 cap_msg.caps.cap_bits.balloon = 1;
42276 cap_msg.caps.cap_bits.hot_add = 1;
42277 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42278 index c386d8d..d6004c4 100644
42279 --- a/drivers/hv/hyperv_vmbus.h
42280 +++ b/drivers/hv/hyperv_vmbus.h
42281 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42282 struct vmbus_connection {
42283 enum vmbus_connect_state conn_state;
42284
42285 - atomic_t next_gpadl_handle;
42286 + atomic_unchecked_t next_gpadl_handle;
42287
42288 /*
42289 * Represents channel interrupts. Each bit position represents a
42290 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42291 index 4d6b269..2e23b86 100644
42292 --- a/drivers/hv/vmbus_drv.c
42293 +++ b/drivers/hv/vmbus_drv.c
42294 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42295 {
42296 int ret = 0;
42297
42298 - static atomic_t device_num = ATOMIC_INIT(0);
42299 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42300
42301 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42302 - atomic_inc_return(&device_num));
42303 + atomic_inc_return_unchecked(&device_num));
42304
42305 child_device_obj->device.bus = &hv_bus;
42306 child_device_obj->device.parent = &hv_acpi_dev->dev;
42307 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42308 index 579bdf9..75118b5 100644
42309 --- a/drivers/hwmon/acpi_power_meter.c
42310 +++ b/drivers/hwmon/acpi_power_meter.c
42311 @@ -116,7 +116,7 @@ struct sensor_template {
42312 struct device_attribute *devattr,
42313 const char *buf, size_t count);
42314 int index;
42315 -};
42316 +} __do_const;
42317
42318 /* Averaging interval */
42319 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42320 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42321 struct sensor_template *attrs)
42322 {
42323 struct device *dev = &resource->acpi_dev->dev;
42324 - struct sensor_device_attribute *sensors =
42325 + sensor_device_attribute_no_const *sensors =
42326 &resource->sensors[resource->num_sensors];
42327 int res = 0;
42328
42329 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42330 index 3288f13..71cfb4e 100644
42331 --- a/drivers/hwmon/applesmc.c
42332 +++ b/drivers/hwmon/applesmc.c
42333 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42334 {
42335 struct applesmc_node_group *grp;
42336 struct applesmc_dev_attr *node;
42337 - struct attribute *attr;
42338 + attribute_no_const *attr;
42339 int ret, i;
42340
42341 for (grp = groups; grp->format; grp++) {
42342 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42343 index cccef87..06ce8ec 100644
42344 --- a/drivers/hwmon/asus_atk0110.c
42345 +++ b/drivers/hwmon/asus_atk0110.c
42346 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42347 struct atk_sensor_data {
42348 struct list_head list;
42349 struct atk_data *data;
42350 - struct device_attribute label_attr;
42351 - struct device_attribute input_attr;
42352 - struct device_attribute limit1_attr;
42353 - struct device_attribute limit2_attr;
42354 + device_attribute_no_const label_attr;
42355 + device_attribute_no_const input_attr;
42356 + device_attribute_no_const limit1_attr;
42357 + device_attribute_no_const limit2_attr;
42358 char label_attr_name[ATTR_NAME_SIZE];
42359 char input_attr_name[ATTR_NAME_SIZE];
42360 char limit1_attr_name[ATTR_NAME_SIZE];
42361 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42362 static struct device_attribute atk_name_attr =
42363 __ATTR(name, 0444, atk_name_show, NULL);
42364
42365 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42366 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42367 sysfs_show_func show)
42368 {
42369 sysfs_attr_init(&attr->attr);
42370 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42371 index d76f0b7..55ae976 100644
42372 --- a/drivers/hwmon/coretemp.c
42373 +++ b/drivers/hwmon/coretemp.c
42374 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42375 return NOTIFY_OK;
42376 }
42377
42378 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42379 +static struct notifier_block coretemp_cpu_notifier = {
42380 .notifier_call = coretemp_cpu_callback,
42381 };
42382
42383 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42384 index 7a8a6fb..015c1fd 100644
42385 --- a/drivers/hwmon/ibmaem.c
42386 +++ b/drivers/hwmon/ibmaem.c
42387 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42388 struct aem_rw_sensor_template *rw)
42389 {
42390 struct device *dev = &data->pdev->dev;
42391 - struct sensor_device_attribute *sensors = data->sensors;
42392 + sensor_device_attribute_no_const *sensors = data->sensors;
42393 int err;
42394
42395 /* Set up read-only sensors */
42396 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42397 index 14c82da..09b25d7 100644
42398 --- a/drivers/hwmon/iio_hwmon.c
42399 +++ b/drivers/hwmon/iio_hwmon.c
42400 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42401 {
42402 struct device *dev = &pdev->dev;
42403 struct iio_hwmon_state *st;
42404 - struct sensor_device_attribute *a;
42405 + sensor_device_attribute_no_const *a;
42406 int ret, i;
42407 int in_i = 1, temp_i = 1, curr_i = 1;
42408 enum iio_chan_type type;
42409 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42410 index 7710f46..427a28d 100644
42411 --- a/drivers/hwmon/nct6683.c
42412 +++ b/drivers/hwmon/nct6683.c
42413 @@ -397,11 +397,11 @@ static struct attribute_group *
42414 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42415 int repeat)
42416 {
42417 - struct sensor_device_attribute_2 *a2;
42418 - struct sensor_device_attribute *a;
42419 + sensor_device_attribute_2_no_const *a2;
42420 + sensor_device_attribute_no_const *a;
42421 struct sensor_device_template **t;
42422 struct sensor_device_attr_u *su;
42423 - struct attribute_group *group;
42424 + attribute_group_no_const *group;
42425 struct attribute **attrs;
42426 int i, j, count;
42427
42428 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42429 index 504cbdd..35d6f25 100644
42430 --- a/drivers/hwmon/nct6775.c
42431 +++ b/drivers/hwmon/nct6775.c
42432 @@ -943,10 +943,10 @@ static struct attribute_group *
42433 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42434 int repeat)
42435 {
42436 - struct attribute_group *group;
42437 + attribute_group_no_const *group;
42438 struct sensor_device_attr_u *su;
42439 - struct sensor_device_attribute *a;
42440 - struct sensor_device_attribute_2 *a2;
42441 + sensor_device_attribute_no_const *a;
42442 + sensor_device_attribute_2_no_const *a2;
42443 struct attribute **attrs;
42444 struct sensor_device_template **t;
42445 int i, count;
42446 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42447 index 291d11f..3f0dbbd 100644
42448 --- a/drivers/hwmon/pmbus/pmbus_core.c
42449 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42450 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42451 return 0;
42452 }
42453
42454 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42455 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42456 const char *name,
42457 umode_t mode,
42458 ssize_t (*show)(struct device *dev,
42459 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42460 dev_attr->store = store;
42461 }
42462
42463 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42464 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42465 const char *name,
42466 umode_t mode,
42467 ssize_t (*show)(struct device *dev,
42468 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42469 u16 reg, u8 mask)
42470 {
42471 struct pmbus_boolean *boolean;
42472 - struct sensor_device_attribute *a;
42473 + sensor_device_attribute_no_const *a;
42474
42475 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42476 if (!boolean)
42477 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42478 bool update, bool readonly)
42479 {
42480 struct pmbus_sensor *sensor;
42481 - struct device_attribute *a;
42482 + device_attribute_no_const *a;
42483
42484 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42485 if (!sensor)
42486 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42487 const char *lstring, int index)
42488 {
42489 struct pmbus_label *label;
42490 - struct device_attribute *a;
42491 + device_attribute_no_const *a;
42492
42493 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42494 if (!label)
42495 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42496 index 97cd45a..ac54d8b 100644
42497 --- a/drivers/hwmon/sht15.c
42498 +++ b/drivers/hwmon/sht15.c
42499 @@ -169,7 +169,7 @@ struct sht15_data {
42500 int supply_uv;
42501 bool supply_uv_valid;
42502 struct work_struct update_supply_work;
42503 - atomic_t interrupt_handled;
42504 + atomic_unchecked_t interrupt_handled;
42505 };
42506
42507 /**
42508 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42509 ret = gpio_direction_input(data->pdata->gpio_data);
42510 if (ret)
42511 return ret;
42512 - atomic_set(&data->interrupt_handled, 0);
42513 + atomic_set_unchecked(&data->interrupt_handled, 0);
42514
42515 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42516 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42517 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42518 /* Only relevant if the interrupt hasn't occurred. */
42519 - if (!atomic_read(&data->interrupt_handled))
42520 + if (!atomic_read_unchecked(&data->interrupt_handled))
42521 schedule_work(&data->read_work);
42522 }
42523 ret = wait_event_timeout(data->wait_queue,
42524 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42525
42526 /* First disable the interrupt */
42527 disable_irq_nosync(irq);
42528 - atomic_inc(&data->interrupt_handled);
42529 + atomic_inc_unchecked(&data->interrupt_handled);
42530 /* Then schedule a reading work struct */
42531 if (data->state != SHT15_READING_NOTHING)
42532 schedule_work(&data->read_work);
42533 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42534 * If not, then start the interrupt again - care here as could
42535 * have gone low in meantime so verify it hasn't!
42536 */
42537 - atomic_set(&data->interrupt_handled, 0);
42538 + atomic_set_unchecked(&data->interrupt_handled, 0);
42539 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42540 /* If still not occurred or another handler was scheduled */
42541 if (gpio_get_value(data->pdata->gpio_data)
42542 - || atomic_read(&data->interrupt_handled))
42543 + || atomic_read_unchecked(&data->interrupt_handled))
42544 return;
42545 }
42546
42547 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42548 index 8df43c5..b07b91d 100644
42549 --- a/drivers/hwmon/via-cputemp.c
42550 +++ b/drivers/hwmon/via-cputemp.c
42551 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42552 return NOTIFY_OK;
42553 }
42554
42555 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42556 +static struct notifier_block via_cputemp_cpu_notifier = {
42557 .notifier_call = via_cputemp_cpu_callback,
42558 };
42559
42560 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42561 index 65e3240..e6c511d 100644
42562 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42563 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42564 @@ -39,7 +39,7 @@
42565 extern struct i2c_adapter amd756_smbus;
42566
42567 static struct i2c_adapter *s4882_adapter;
42568 -static struct i2c_algorithm *s4882_algo;
42569 +static i2c_algorithm_no_const *s4882_algo;
42570
42571 /* Wrapper access functions for multiplexed SMBus */
42572 static DEFINE_MUTEX(amd756_lock);
42573 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42574 index b19a310..d6eece0 100644
42575 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42576 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42577 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42578 /* usb layer */
42579
42580 /* Send command to device, and get response. */
42581 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42582 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42583 {
42584 int ret = 0;
42585 int actual;
42586 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42587 index 88eda09..cf40434 100644
42588 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42589 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42590 @@ -37,7 +37,7 @@
42591 extern struct i2c_adapter *nforce2_smbus;
42592
42593 static struct i2c_adapter *s4985_adapter;
42594 -static struct i2c_algorithm *s4985_algo;
42595 +static i2c_algorithm_no_const *s4985_algo;
42596
42597 /* Wrapper access functions for multiplexed SMBus */
42598 static DEFINE_MUTEX(nforce2_lock);
42599 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42600 index 71c7a39..71dd3e0 100644
42601 --- a/drivers/i2c/i2c-dev.c
42602 +++ b/drivers/i2c/i2c-dev.c
42603 @@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42604 break;
42605 }
42606
42607 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42608 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42609 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42610 if (IS_ERR(rdwr_pa[i].buf)) {
42611 res = PTR_ERR(rdwr_pa[i].buf);
42612 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42613 index 0b510ba..4fbb5085 100644
42614 --- a/drivers/ide/ide-cd.c
42615 +++ b/drivers/ide/ide-cd.c
42616 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42617 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42618 if ((unsigned long)buf & alignment
42619 || blk_rq_bytes(rq) & q->dma_pad_mask
42620 - || object_is_on_stack(buf))
42621 + || object_starts_on_stack(buf))
42622 drive->dma = 0;
42623 }
42624 }
42625 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42626 index af3e76d..96dfe5e 100644
42627 --- a/drivers/iio/industrialio-core.c
42628 +++ b/drivers/iio/industrialio-core.c
42629 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42630 }
42631
42632 static
42633 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42634 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42635 const char *postfix,
42636 struct iio_chan_spec const *chan,
42637 ssize_t (*readfunc)(struct device *dev,
42638 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42639 index e28a494..f7c2671 100644
42640 --- a/drivers/infiniband/core/cm.c
42641 +++ b/drivers/infiniband/core/cm.c
42642 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42643
42644 struct cm_counter_group {
42645 struct kobject obj;
42646 - atomic_long_t counter[CM_ATTR_COUNT];
42647 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42648 };
42649
42650 struct cm_counter_attribute {
42651 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42652 struct ib_mad_send_buf *msg = NULL;
42653 int ret;
42654
42655 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42656 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42657 counter[CM_REQ_COUNTER]);
42658
42659 /* Quick state check to discard duplicate REQs. */
42660 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42661 if (!cm_id_priv)
42662 return;
42663
42664 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42665 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42666 counter[CM_REP_COUNTER]);
42667 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42668 if (ret)
42669 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42670 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42671 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42672 spin_unlock_irq(&cm_id_priv->lock);
42673 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42674 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42675 counter[CM_RTU_COUNTER]);
42676 goto out;
42677 }
42678 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42679 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42680 dreq_msg->local_comm_id);
42681 if (!cm_id_priv) {
42682 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42683 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42684 counter[CM_DREQ_COUNTER]);
42685 cm_issue_drep(work->port, work->mad_recv_wc);
42686 return -EINVAL;
42687 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42688 case IB_CM_MRA_REP_RCVD:
42689 break;
42690 case IB_CM_TIMEWAIT:
42691 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42692 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42693 counter[CM_DREQ_COUNTER]);
42694 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42695 goto unlock;
42696 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42697 cm_free_msg(msg);
42698 goto deref;
42699 case IB_CM_DREQ_RCVD:
42700 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42701 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42702 counter[CM_DREQ_COUNTER]);
42703 goto unlock;
42704 default:
42705 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42706 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42707 cm_id_priv->msg, timeout)) {
42708 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42709 - atomic_long_inc(&work->port->
42710 + atomic_long_inc_unchecked(&work->port->
42711 counter_group[CM_RECV_DUPLICATES].
42712 counter[CM_MRA_COUNTER]);
42713 goto out;
42714 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42715 break;
42716 case IB_CM_MRA_REQ_RCVD:
42717 case IB_CM_MRA_REP_RCVD:
42718 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42719 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42720 counter[CM_MRA_COUNTER]);
42721 /* fall through */
42722 default:
42723 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42724 case IB_CM_LAP_IDLE:
42725 break;
42726 case IB_CM_MRA_LAP_SENT:
42727 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42728 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42729 counter[CM_LAP_COUNTER]);
42730 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42731 goto unlock;
42732 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42733 cm_free_msg(msg);
42734 goto deref;
42735 case IB_CM_LAP_RCVD:
42736 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42737 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42738 counter[CM_LAP_COUNTER]);
42739 goto unlock;
42740 default:
42741 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42742 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42743 if (cur_cm_id_priv) {
42744 spin_unlock_irq(&cm.lock);
42745 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42746 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42747 counter[CM_SIDR_REQ_COUNTER]);
42748 goto out; /* Duplicate message. */
42749 }
42750 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42751 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42752 msg->retries = 1;
42753
42754 - atomic_long_add(1 + msg->retries,
42755 + atomic_long_add_unchecked(1 + msg->retries,
42756 &port->counter_group[CM_XMIT].counter[attr_index]);
42757 if (msg->retries)
42758 - atomic_long_add(msg->retries,
42759 + atomic_long_add_unchecked(msg->retries,
42760 &port->counter_group[CM_XMIT_RETRIES].
42761 counter[attr_index]);
42762
42763 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42764 }
42765
42766 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42767 - atomic_long_inc(&port->counter_group[CM_RECV].
42768 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42769 counter[attr_id - CM_ATTR_ID_OFFSET]);
42770
42771 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42772 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42773 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42774
42775 return sprintf(buf, "%ld\n",
42776 - atomic_long_read(&group->counter[cm_attr->index]));
42777 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42778 }
42779
42780 static const struct sysfs_ops cm_counter_ops = {
42781 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42782 index 9f5ad7c..588cd84 100644
42783 --- a/drivers/infiniband/core/fmr_pool.c
42784 +++ b/drivers/infiniband/core/fmr_pool.c
42785 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42786
42787 struct task_struct *thread;
42788
42789 - atomic_t req_ser;
42790 - atomic_t flush_ser;
42791 + atomic_unchecked_t req_ser;
42792 + atomic_unchecked_t flush_ser;
42793
42794 wait_queue_head_t force_wait;
42795 };
42796 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42797 struct ib_fmr_pool *pool = pool_ptr;
42798
42799 do {
42800 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42801 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42802 ib_fmr_batch_release(pool);
42803
42804 - atomic_inc(&pool->flush_ser);
42805 + atomic_inc_unchecked(&pool->flush_ser);
42806 wake_up_interruptible(&pool->force_wait);
42807
42808 if (pool->flush_function)
42809 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42810 }
42811
42812 set_current_state(TASK_INTERRUPTIBLE);
42813 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42814 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42815 !kthread_should_stop())
42816 schedule();
42817 __set_current_state(TASK_RUNNING);
42818 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42819 pool->dirty_watermark = params->dirty_watermark;
42820 pool->dirty_len = 0;
42821 spin_lock_init(&pool->pool_lock);
42822 - atomic_set(&pool->req_ser, 0);
42823 - atomic_set(&pool->flush_ser, 0);
42824 + atomic_set_unchecked(&pool->req_ser, 0);
42825 + atomic_set_unchecked(&pool->flush_ser, 0);
42826 init_waitqueue_head(&pool->force_wait);
42827
42828 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42829 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42830 }
42831 spin_unlock_irq(&pool->pool_lock);
42832
42833 - serial = atomic_inc_return(&pool->req_ser);
42834 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42835 wake_up_process(pool->thread);
42836
42837 if (wait_event_interruptible(pool->force_wait,
42838 - atomic_read(&pool->flush_ser) - serial >= 0))
42839 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42840 return -EINTR;
42841
42842 return 0;
42843 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42844 } else {
42845 list_add_tail(&fmr->list, &pool->dirty_list);
42846 if (++pool->dirty_len >= pool->dirty_watermark) {
42847 - atomic_inc(&pool->req_ser);
42848 + atomic_inc_unchecked(&pool->req_ser);
42849 wake_up_process(pool->thread);
42850 }
42851 }
42852 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42853 index ec7a298..8742e59 100644
42854 --- a/drivers/infiniband/hw/cxgb4/mem.c
42855 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42856 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42857 int err;
42858 struct fw_ri_tpte tpt;
42859 u32 stag_idx;
42860 - static atomic_t key;
42861 + static atomic_unchecked_t key;
42862
42863 if (c4iw_fatal_error(rdev))
42864 return -EIO;
42865 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42866 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42867 rdev->stats.stag.max = rdev->stats.stag.cur;
42868 mutex_unlock(&rdev->stats.lock);
42869 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42870 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42871 }
42872 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42873 __func__, stag_state, type, pdid, stag_idx);
42874 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42875 index 79b3dbc..96e5fcc 100644
42876 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42877 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42878 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42879 struct ib_atomic_eth *ateth;
42880 struct ipath_ack_entry *e;
42881 u64 vaddr;
42882 - atomic64_t *maddr;
42883 + atomic64_unchecked_t *maddr;
42884 u64 sdata;
42885 u32 rkey;
42886 u8 next;
42887 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42888 IB_ACCESS_REMOTE_ATOMIC)))
42889 goto nack_acc_unlck;
42890 /* Perform atomic OP and save result. */
42891 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42892 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42893 sdata = be64_to_cpu(ateth->swap_data);
42894 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42895 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42896 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42897 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42898 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42899 be64_to_cpu(ateth->compare_data),
42900 sdata);
42901 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42902 index 1f95bba..9530f87 100644
42903 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42904 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42905 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42906 unsigned long flags;
42907 struct ib_wc wc;
42908 u64 sdata;
42909 - atomic64_t *maddr;
42910 + atomic64_unchecked_t *maddr;
42911 enum ib_wc_status send_status;
42912
42913 /*
42914 @@ -382,11 +382,11 @@ again:
42915 IB_ACCESS_REMOTE_ATOMIC)))
42916 goto acc_err;
42917 /* Perform atomic OP and save result. */
42918 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42919 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42920 sdata = wqe->wr.wr.atomic.compare_add;
42921 *(u64 *) sqp->s_sge.sge.vaddr =
42922 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42923 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42924 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42925 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42926 sdata, wqe->wr.wr.atomic.swap);
42927 goto send_comp;
42928 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42929 index 82a7dd8..8fb6ba6 100644
42930 --- a/drivers/infiniband/hw/mlx4/mad.c
42931 +++ b/drivers/infiniband/hw/mlx4/mad.c
42932 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42933
42934 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42935 {
42936 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42937 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42938 cpu_to_be64(0xff00000000000000LL);
42939 }
42940
42941 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42942 index ed327e6..ca1739e0 100644
42943 --- a/drivers/infiniband/hw/mlx4/mcg.c
42944 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42945 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42946 {
42947 char name[20];
42948
42949 - atomic_set(&ctx->tid, 0);
42950 + atomic_set_unchecked(&ctx->tid, 0);
42951 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42952 ctx->mcg_wq = create_singlethread_workqueue(name);
42953 if (!ctx->mcg_wq)
42954 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42955 index 6eb743f..a7b0f6d 100644
42956 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42957 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42958 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42959 struct list_head mcg_mgid0_list;
42960 struct workqueue_struct *mcg_wq;
42961 struct mlx4_ib_demux_pv_ctx **tun;
42962 - atomic_t tid;
42963 + atomic_unchecked_t tid;
42964 int flushing; /* flushing the work queue */
42965 };
42966
42967 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42968 index 9d3e5c1..6f166df 100644
42969 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42970 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42971 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42972 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42973 }
42974
42975 -int mthca_QUERY_FW(struct mthca_dev *dev)
42976 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42977 {
42978 struct mthca_mailbox *mailbox;
42979 u32 *outbox;
42980 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42981 CMD_TIME_CLASS_B);
42982 }
42983
42984 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42985 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42986 int num_mtt)
42987 {
42988 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42989 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42990 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42991 }
42992
42993 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42994 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42995 int eq_num)
42996 {
42997 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42998 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42999 CMD_TIME_CLASS_B);
43000 }
43001
43002 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43003 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43004 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43005 void *in_mad, void *response_mad)
43006 {
43007 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43008 index ded76c1..0cf0a08 100644
43009 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43010 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43011 @@ -692,7 +692,7 @@ err_close:
43012 return err;
43013 }
43014
43015 -static int mthca_setup_hca(struct mthca_dev *dev)
43016 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43017 {
43018 int err;
43019
43020 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43021 index ed9a989..6aa5dc2 100644
43022 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43023 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43024 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43025 * through the bitmaps)
43026 */
43027
43028 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43029 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43030 {
43031 int o;
43032 int m;
43033 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43034 return key;
43035 }
43036
43037 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43038 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43039 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43040 {
43041 struct mthca_mailbox *mailbox;
43042 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43043 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43044 }
43045
43046 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43047 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43048 u64 *buffer_list, int buffer_size_shift,
43049 int list_len, u64 iova, u64 total_size,
43050 u32 access, struct mthca_mr *mr)
43051 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43052 index 415f8e1..e34214e 100644
43053 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43054 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43055 @@ -764,7 +764,7 @@ unlock:
43056 return 0;
43057 }
43058
43059 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43060 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43061 {
43062 struct mthca_dev *dev = to_mdev(ibcq->device);
43063 struct mthca_cq *cq = to_mcq(ibcq);
43064 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43065 index 3b2a6dc..bce26ff 100644
43066 --- a/drivers/infiniband/hw/nes/nes.c
43067 +++ b/drivers/infiniband/hw/nes/nes.c
43068 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43069 LIST_HEAD(nes_adapter_list);
43070 static LIST_HEAD(nes_dev_list);
43071
43072 -atomic_t qps_destroyed;
43073 +atomic_unchecked_t qps_destroyed;
43074
43075 static unsigned int ee_flsh_adapter;
43076 static unsigned int sysfs_nonidx_addr;
43077 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43078 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43079 struct nes_adapter *nesadapter = nesdev->nesadapter;
43080
43081 - atomic_inc(&qps_destroyed);
43082 + atomic_inc_unchecked(&qps_destroyed);
43083
43084 /* Free the control structures */
43085
43086 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43087 index bd9d132..70d84f4 100644
43088 --- a/drivers/infiniband/hw/nes/nes.h
43089 +++ b/drivers/infiniband/hw/nes/nes.h
43090 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43091 extern unsigned int wqm_quanta;
43092 extern struct list_head nes_adapter_list;
43093
43094 -extern atomic_t cm_connects;
43095 -extern atomic_t cm_accepts;
43096 -extern atomic_t cm_disconnects;
43097 -extern atomic_t cm_closes;
43098 -extern atomic_t cm_connecteds;
43099 -extern atomic_t cm_connect_reqs;
43100 -extern atomic_t cm_rejects;
43101 -extern atomic_t mod_qp_timouts;
43102 -extern atomic_t qps_created;
43103 -extern atomic_t qps_destroyed;
43104 -extern atomic_t sw_qps_destroyed;
43105 +extern atomic_unchecked_t cm_connects;
43106 +extern atomic_unchecked_t cm_accepts;
43107 +extern atomic_unchecked_t cm_disconnects;
43108 +extern atomic_unchecked_t cm_closes;
43109 +extern atomic_unchecked_t cm_connecteds;
43110 +extern atomic_unchecked_t cm_connect_reqs;
43111 +extern atomic_unchecked_t cm_rejects;
43112 +extern atomic_unchecked_t mod_qp_timouts;
43113 +extern atomic_unchecked_t qps_created;
43114 +extern atomic_unchecked_t qps_destroyed;
43115 +extern atomic_unchecked_t sw_qps_destroyed;
43116 extern u32 mh_detected;
43117 extern u32 mh_pauses_sent;
43118 extern u32 cm_packets_sent;
43119 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43120 extern u32 cm_packets_received;
43121 extern u32 cm_packets_dropped;
43122 extern u32 cm_packets_retrans;
43123 -extern atomic_t cm_listens_created;
43124 -extern atomic_t cm_listens_destroyed;
43125 +extern atomic_unchecked_t cm_listens_created;
43126 +extern atomic_unchecked_t cm_listens_destroyed;
43127 extern u32 cm_backlog_drops;
43128 -extern atomic_t cm_loopbacks;
43129 -extern atomic_t cm_nodes_created;
43130 -extern atomic_t cm_nodes_destroyed;
43131 -extern atomic_t cm_accel_dropped_pkts;
43132 -extern atomic_t cm_resets_recvd;
43133 -extern atomic_t pau_qps_created;
43134 -extern atomic_t pau_qps_destroyed;
43135 +extern atomic_unchecked_t cm_loopbacks;
43136 +extern atomic_unchecked_t cm_nodes_created;
43137 +extern atomic_unchecked_t cm_nodes_destroyed;
43138 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43139 +extern atomic_unchecked_t cm_resets_recvd;
43140 +extern atomic_unchecked_t pau_qps_created;
43141 +extern atomic_unchecked_t pau_qps_destroyed;
43142
43143 extern u32 int_mod_timer_init;
43144 extern u32 int_mod_cq_depth_256;
43145 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43146 index 6f09a72..cf4399d 100644
43147 --- a/drivers/infiniband/hw/nes/nes_cm.c
43148 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43149 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43150 u32 cm_packets_retrans;
43151 u32 cm_packets_created;
43152 u32 cm_packets_received;
43153 -atomic_t cm_listens_created;
43154 -atomic_t cm_listens_destroyed;
43155 +atomic_unchecked_t cm_listens_created;
43156 +atomic_unchecked_t cm_listens_destroyed;
43157 u32 cm_backlog_drops;
43158 -atomic_t cm_loopbacks;
43159 -atomic_t cm_nodes_created;
43160 -atomic_t cm_nodes_destroyed;
43161 -atomic_t cm_accel_dropped_pkts;
43162 -atomic_t cm_resets_recvd;
43163 +atomic_unchecked_t cm_loopbacks;
43164 +atomic_unchecked_t cm_nodes_created;
43165 +atomic_unchecked_t cm_nodes_destroyed;
43166 +atomic_unchecked_t cm_accel_dropped_pkts;
43167 +atomic_unchecked_t cm_resets_recvd;
43168
43169 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43170 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43171 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43172 /* instance of function pointers for client API */
43173 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43174 static struct nes_cm_ops nes_cm_api = {
43175 - mini_cm_accelerated,
43176 - mini_cm_listen,
43177 - mini_cm_del_listen,
43178 - mini_cm_connect,
43179 - mini_cm_close,
43180 - mini_cm_accept,
43181 - mini_cm_reject,
43182 - mini_cm_recv_pkt,
43183 - mini_cm_dealloc_core,
43184 - mini_cm_get,
43185 - mini_cm_set
43186 + .accelerated = mini_cm_accelerated,
43187 + .listen = mini_cm_listen,
43188 + .stop_listener = mini_cm_del_listen,
43189 + .connect = mini_cm_connect,
43190 + .close = mini_cm_close,
43191 + .accept = mini_cm_accept,
43192 + .reject = mini_cm_reject,
43193 + .recv_pkt = mini_cm_recv_pkt,
43194 + .destroy_cm_core = mini_cm_dealloc_core,
43195 + .get = mini_cm_get,
43196 + .set = mini_cm_set
43197 };
43198
43199 static struct nes_cm_core *g_cm_core;
43200
43201 -atomic_t cm_connects;
43202 -atomic_t cm_accepts;
43203 -atomic_t cm_disconnects;
43204 -atomic_t cm_closes;
43205 -atomic_t cm_connecteds;
43206 -atomic_t cm_connect_reqs;
43207 -atomic_t cm_rejects;
43208 +atomic_unchecked_t cm_connects;
43209 +atomic_unchecked_t cm_accepts;
43210 +atomic_unchecked_t cm_disconnects;
43211 +atomic_unchecked_t cm_closes;
43212 +atomic_unchecked_t cm_connecteds;
43213 +atomic_unchecked_t cm_connect_reqs;
43214 +atomic_unchecked_t cm_rejects;
43215
43216 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43217 {
43218 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43219 kfree(listener);
43220 listener = NULL;
43221 ret = 0;
43222 - atomic_inc(&cm_listens_destroyed);
43223 + atomic_inc_unchecked(&cm_listens_destroyed);
43224 } else {
43225 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43226 }
43227 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43228 cm_node->rem_mac);
43229
43230 add_hte_node(cm_core, cm_node);
43231 - atomic_inc(&cm_nodes_created);
43232 + atomic_inc_unchecked(&cm_nodes_created);
43233
43234 return cm_node;
43235 }
43236 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43237 }
43238
43239 atomic_dec(&cm_core->node_cnt);
43240 - atomic_inc(&cm_nodes_destroyed);
43241 + atomic_inc_unchecked(&cm_nodes_destroyed);
43242 nesqp = cm_node->nesqp;
43243 if (nesqp) {
43244 nesqp->cm_node = NULL;
43245 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43246
43247 static void drop_packet(struct sk_buff *skb)
43248 {
43249 - atomic_inc(&cm_accel_dropped_pkts);
43250 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43251 dev_kfree_skb_any(skb);
43252 }
43253
43254 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43255 {
43256
43257 int reset = 0; /* whether to send reset in case of err.. */
43258 - atomic_inc(&cm_resets_recvd);
43259 + atomic_inc_unchecked(&cm_resets_recvd);
43260 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43261 " refcnt=%d\n", cm_node, cm_node->state,
43262 atomic_read(&cm_node->ref_count));
43263 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43264 rem_ref_cm_node(cm_node->cm_core, cm_node);
43265 return NULL;
43266 }
43267 - atomic_inc(&cm_loopbacks);
43268 + atomic_inc_unchecked(&cm_loopbacks);
43269 loopbackremotenode->loopbackpartner = cm_node;
43270 loopbackremotenode->tcp_cntxt.rcv_wscale =
43271 NES_CM_DEFAULT_RCV_WND_SCALE;
43272 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43273 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43274 else {
43275 rem_ref_cm_node(cm_core, cm_node);
43276 - atomic_inc(&cm_accel_dropped_pkts);
43277 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43278 dev_kfree_skb_any(skb);
43279 }
43280 break;
43281 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43282
43283 if ((cm_id) && (cm_id->event_handler)) {
43284 if (issue_disconn) {
43285 - atomic_inc(&cm_disconnects);
43286 + atomic_inc_unchecked(&cm_disconnects);
43287 cm_event.event = IW_CM_EVENT_DISCONNECT;
43288 cm_event.status = disconn_status;
43289 cm_event.local_addr = cm_id->local_addr;
43290 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43291 }
43292
43293 if (issue_close) {
43294 - atomic_inc(&cm_closes);
43295 + atomic_inc_unchecked(&cm_closes);
43296 nes_disconnect(nesqp, 1);
43297
43298 cm_id->provider_data = nesqp;
43299 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43300
43301 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43302 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43303 - atomic_inc(&cm_accepts);
43304 + atomic_inc_unchecked(&cm_accepts);
43305
43306 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43307 netdev_refcnt_read(nesvnic->netdev));
43308 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43309 struct nes_cm_core *cm_core;
43310 u8 *start_buff;
43311
43312 - atomic_inc(&cm_rejects);
43313 + atomic_inc_unchecked(&cm_rejects);
43314 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43315 loopback = cm_node->loopbackpartner;
43316 cm_core = cm_node->cm_core;
43317 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43318 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43319 ntohs(laddr->sin_port));
43320
43321 - atomic_inc(&cm_connects);
43322 + atomic_inc_unchecked(&cm_connects);
43323 nesqp->active_conn = 1;
43324
43325 /* cache the cm_id in the qp */
43326 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43327 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43328 return err;
43329 }
43330 - atomic_inc(&cm_listens_created);
43331 + atomic_inc_unchecked(&cm_listens_created);
43332 }
43333
43334 cm_id->add_ref(cm_id);
43335 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43336
43337 if (nesqp->destroyed)
43338 return;
43339 - atomic_inc(&cm_connecteds);
43340 + atomic_inc_unchecked(&cm_connecteds);
43341 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43342 " local port 0x%04X. jiffies = %lu.\n",
43343 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43344 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43345
43346 cm_id->add_ref(cm_id);
43347 ret = cm_id->event_handler(cm_id, &cm_event);
43348 - atomic_inc(&cm_closes);
43349 + atomic_inc_unchecked(&cm_closes);
43350 cm_event.event = IW_CM_EVENT_CLOSE;
43351 cm_event.status = 0;
43352 cm_event.provider_data = cm_id->provider_data;
43353 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43354 return;
43355 cm_id = cm_node->cm_id;
43356
43357 - atomic_inc(&cm_connect_reqs);
43358 + atomic_inc_unchecked(&cm_connect_reqs);
43359 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43360 cm_node, cm_id, jiffies);
43361
43362 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43363 return;
43364 cm_id = cm_node->cm_id;
43365
43366 - atomic_inc(&cm_connect_reqs);
43367 + atomic_inc_unchecked(&cm_connect_reqs);
43368 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43369 cm_node, cm_id, jiffies);
43370
43371 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43372 index 4166452..fc952c3 100644
43373 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43374 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43375 @@ -40,8 +40,8 @@
43376 #include "nes.h"
43377 #include "nes_mgt.h"
43378
43379 -atomic_t pau_qps_created;
43380 -atomic_t pau_qps_destroyed;
43381 +atomic_unchecked_t pau_qps_created;
43382 +atomic_unchecked_t pau_qps_destroyed;
43383
43384 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43385 {
43386 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43387 {
43388 struct sk_buff *skb;
43389 unsigned long flags;
43390 - atomic_inc(&pau_qps_destroyed);
43391 + atomic_inc_unchecked(&pau_qps_destroyed);
43392
43393 /* Free packets that have not yet been forwarded */
43394 /* Lock is acquired by skb_dequeue when removing the skb */
43395 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43396 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43397 skb_queue_head_init(&nesqp->pau_list);
43398 spin_lock_init(&nesqp->pau_lock);
43399 - atomic_inc(&pau_qps_created);
43400 + atomic_inc_unchecked(&pau_qps_created);
43401 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43402 }
43403
43404 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43405 index 49eb511..a774366 100644
43406 --- a/drivers/infiniband/hw/nes/nes_nic.c
43407 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43408 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43409 target_stat_values[++index] = mh_detected;
43410 target_stat_values[++index] = mh_pauses_sent;
43411 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43412 - target_stat_values[++index] = atomic_read(&cm_connects);
43413 - target_stat_values[++index] = atomic_read(&cm_accepts);
43414 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43415 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43416 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43417 - target_stat_values[++index] = atomic_read(&cm_rejects);
43418 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43419 - target_stat_values[++index] = atomic_read(&qps_created);
43420 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43421 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43422 - target_stat_values[++index] = atomic_read(&cm_closes);
43423 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43424 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43425 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43426 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43427 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43428 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43429 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43430 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43431 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43432 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43433 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43434 target_stat_values[++index] = cm_packets_sent;
43435 target_stat_values[++index] = cm_packets_bounced;
43436 target_stat_values[++index] = cm_packets_created;
43437 target_stat_values[++index] = cm_packets_received;
43438 target_stat_values[++index] = cm_packets_dropped;
43439 target_stat_values[++index] = cm_packets_retrans;
43440 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43441 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43442 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43443 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43444 target_stat_values[++index] = cm_backlog_drops;
43445 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43446 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43447 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43448 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43449 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43450 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43451 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43452 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43453 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43454 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43455 target_stat_values[++index] = nesadapter->free_4kpbl;
43456 target_stat_values[++index] = nesadapter->free_256pbl;
43457 target_stat_values[++index] = int_mod_timer_init;
43458 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43459 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43460 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43461 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43462 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43463 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43464 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43465 }
43466
43467 /**
43468 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43469 index fef067c..6a25ccd 100644
43470 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43471 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43472 @@ -46,9 +46,9 @@
43473
43474 #include <rdma/ib_umem.h>
43475
43476 -atomic_t mod_qp_timouts;
43477 -atomic_t qps_created;
43478 -atomic_t sw_qps_destroyed;
43479 +atomic_unchecked_t mod_qp_timouts;
43480 +atomic_unchecked_t qps_created;
43481 +atomic_unchecked_t sw_qps_destroyed;
43482
43483 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43484
43485 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43486 if (init_attr->create_flags)
43487 return ERR_PTR(-EINVAL);
43488
43489 - atomic_inc(&qps_created);
43490 + atomic_inc_unchecked(&qps_created);
43491 switch (init_attr->qp_type) {
43492 case IB_QPT_RC:
43493 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43494 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43495 struct iw_cm_event cm_event;
43496 int ret = 0;
43497
43498 - atomic_inc(&sw_qps_destroyed);
43499 + atomic_inc_unchecked(&sw_qps_destroyed);
43500 nesqp->destroyed = 1;
43501
43502 /* Blow away the connection if it exists. */
43503 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43504 index c00ae09..04e91be 100644
43505 --- a/drivers/infiniband/hw/qib/qib.h
43506 +++ b/drivers/infiniband/hw/qib/qib.h
43507 @@ -52,6 +52,7 @@
43508 #include <linux/kref.h>
43509 #include <linux/sched.h>
43510 #include <linux/kthread.h>
43511 +#include <linux/slab.h>
43512
43513 #include "qib_common.h"
43514 #include "qib_verbs.h"
43515 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43516 index cdc7df4..a2fdfdb 100644
43517 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43518 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43519 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43520 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43521 }
43522
43523 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43524 +static struct rtnl_link_ops ipoib_link_ops = {
43525 .kind = "ipoib",
43526 .maxtype = IFLA_IPOIB_MAX,
43527 .policy = ipoib_policy,
43528 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43529 index e29c04e..adbf68c 100644
43530 --- a/drivers/input/gameport/gameport.c
43531 +++ b/drivers/input/gameport/gameport.c
43532 @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43533 */
43534 static void gameport_init_port(struct gameport *gameport)
43535 {
43536 - static atomic_t gameport_no = ATOMIC_INIT(0);
43537 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43538
43539 __module_get(THIS_MODULE);
43540
43541 mutex_init(&gameport->drv_mutex);
43542 device_initialize(&gameport->dev);
43543 dev_set_name(&gameport->dev, "gameport%lu",
43544 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43545 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43546 gameport->dev.bus = &gameport_bus;
43547 gameport->dev.release = gameport_release_port;
43548 if (gameport->parent)
43549 diff --git a/drivers/input/input.c b/drivers/input/input.c
43550 index 0f175f5..4c481c0 100644
43551 --- a/drivers/input/input.c
43552 +++ b/drivers/input/input.c
43553 @@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43554 */
43555 struct input_dev *input_allocate_device(void)
43556 {
43557 - static atomic_t input_no = ATOMIC_INIT(0);
43558 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43559 struct input_dev *dev;
43560
43561 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43562 @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43563 INIT_LIST_HEAD(&dev->node);
43564
43565 dev_set_name(&dev->dev, "input%lu",
43566 - (unsigned long) atomic_inc_return(&input_no) - 1);
43567 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43568
43569 __module_get(THIS_MODULE);
43570 }
43571 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43572 index 4a95b22..874c182 100644
43573 --- a/drivers/input/joystick/sidewinder.c
43574 +++ b/drivers/input/joystick/sidewinder.c
43575 @@ -30,6 +30,7 @@
43576 #include <linux/kernel.h>
43577 #include <linux/module.h>
43578 #include <linux/slab.h>
43579 +#include <linux/sched.h>
43580 #include <linux/input.h>
43581 #include <linux/gameport.h>
43582 #include <linux/jiffies.h>
43583 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43584 index fc55f0d..11e2aa6 100644
43585 --- a/drivers/input/joystick/xpad.c
43586 +++ b/drivers/input/joystick/xpad.c
43587 @@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43588
43589 static int xpad_led_probe(struct usb_xpad *xpad)
43590 {
43591 - static atomic_t led_seq = ATOMIC_INIT(0);
43592 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43593 long led_no;
43594 struct xpad_led *led;
43595 struct led_classdev *led_cdev;
43596 @@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43597 if (!led)
43598 return -ENOMEM;
43599
43600 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43601 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43602
43603 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43604 led->xpad = xpad;
43605 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43606 index afed8e2..3aa8a18 100644
43607 --- a/drivers/input/misc/ims-pcu.c
43608 +++ b/drivers/input/misc/ims-pcu.c
43609 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43610
43611 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43612 {
43613 - static atomic_t device_no = ATOMIC_INIT(0);
43614 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43615
43616 const struct ims_pcu_device_info *info;
43617 int error;
43618 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43619 }
43620
43621 /* Device appears to be operable, complete initialization */
43622 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43623 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43624
43625 /*
43626 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43627 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43628 index f4cf664..3204fda 100644
43629 --- a/drivers/input/mouse/psmouse.h
43630 +++ b/drivers/input/mouse/psmouse.h
43631 @@ -117,7 +117,7 @@ struct psmouse_attribute {
43632 ssize_t (*set)(struct psmouse *psmouse, void *data,
43633 const char *buf, size_t count);
43634 bool protect;
43635 -};
43636 +} __do_const;
43637 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43638
43639 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43640 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43641 index b604564..3f14ae4 100644
43642 --- a/drivers/input/mousedev.c
43643 +++ b/drivers/input/mousedev.c
43644 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43645
43646 spin_unlock_irq(&client->packet_lock);
43647
43648 - if (copy_to_user(buffer, data, count))
43649 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43650 return -EFAULT;
43651
43652 return count;
43653 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43654 index d399b8b..4913ede 100644
43655 --- a/drivers/input/serio/serio.c
43656 +++ b/drivers/input/serio/serio.c
43657 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43658 */
43659 static void serio_init_port(struct serio *serio)
43660 {
43661 - static atomic_t serio_no = ATOMIC_INIT(0);
43662 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43663
43664 __module_get(THIS_MODULE);
43665
43666 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43667 mutex_init(&serio->drv_mutex);
43668 device_initialize(&serio->dev);
43669 dev_set_name(&serio->dev, "serio%lu",
43670 - (unsigned long)atomic_inc_return(&serio_no) - 1);
43671 + (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43672 serio->dev.bus = &serio_bus;
43673 serio->dev.release = serio_release_port;
43674 serio->dev.groups = serio_device_attr_groups;
43675 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43676 index c9a02fe..0debc75 100644
43677 --- a/drivers/input/serio/serio_raw.c
43678 +++ b/drivers/input/serio/serio_raw.c
43679 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43680
43681 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43682 {
43683 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43684 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43685 struct serio_raw *serio_raw;
43686 int err;
43687
43688 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43689 }
43690
43691 snprintf(serio_raw->name, sizeof(serio_raw->name),
43692 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43693 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43694 kref_init(&serio_raw->kref);
43695 INIT_LIST_HEAD(&serio_raw->client_list);
43696 init_waitqueue_head(&serio_raw->wait);
43697 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43698 index 505a9ad..356734c 100644
43699 --- a/drivers/iommu/amd_iommu.c
43700 +++ b/drivers/iommu/amd_iommu.c
43701 @@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43702
43703 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43704 {
43705 + phys_addr_t physaddr;
43706 WARN_ON(address & 0x7ULL);
43707
43708 memset(cmd, 0, sizeof(*cmd));
43709 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43710 - cmd->data[1] = upper_32_bits(__pa(address));
43711 +
43712 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43713 + if (object_starts_on_stack((void *)address)) {
43714 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43715 + physaddr = __pa((u64)adjbuf);
43716 + } else
43717 +#endif
43718 + physaddr = __pa(address);
43719 +
43720 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43721 + cmd->data[1] = upper_32_bits(physaddr);
43722 cmd->data[2] = 1;
43723 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43724 }
43725 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43726 index 60558f7..5a02369 100644
43727 --- a/drivers/iommu/arm-smmu.c
43728 +++ b/drivers/iommu/arm-smmu.c
43729 @@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43730 cfg->irptndx = cfg->cbndx;
43731 }
43732
43733 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
43734 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43735 arm_smmu_init_context_bank(smmu_domain);
43736 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43737
43738 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43739 index ed8b048..7fbcc01 100644
43740 --- a/drivers/iommu/iommu.c
43741 +++ b/drivers/iommu/iommu.c
43742 @@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43743 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43744 {
43745 int err;
43746 - struct notifier_block *nb;
43747 + notifier_block_no_const *nb;
43748 struct iommu_callback_data cb = {
43749 .ops = ops,
43750 };
43751 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43752 index 74a1767..5a359e8 100644
43753 --- a/drivers/iommu/irq_remapping.c
43754 +++ b/drivers/iommu/irq_remapping.c
43755 @@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43756 void panic_if_irq_remap(const char *msg)
43757 {
43758 if (irq_remapping_enabled)
43759 - panic(msg);
43760 + panic("%s", msg);
43761 }
43762
43763 static void ir_ack_apic_edge(struct irq_data *data)
43764 @@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43765
43766 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43767 {
43768 - chip->irq_print_chip = ir_print_prefix;
43769 - chip->irq_ack = ir_ack_apic_edge;
43770 - chip->irq_eoi = ir_ack_apic_level;
43771 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43772 + pax_open_kernel();
43773 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43774 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43775 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43776 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43777 + pax_close_kernel();
43778 }
43779
43780 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43781 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43782 index 38493ff..001538b 100644
43783 --- a/drivers/irqchip/irq-gic.c
43784 +++ b/drivers/irqchip/irq-gic.c
43785 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43786 * Supported arch specific GIC irq extension.
43787 * Default make them NULL.
43788 */
43789 -struct irq_chip gic_arch_extn = {
43790 +irq_chip_no_const gic_arch_extn = {
43791 .irq_eoi = NULL,
43792 .irq_mask = NULL,
43793 .irq_unmask = NULL,
43794 @@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43795 chained_irq_exit(chip, desc);
43796 }
43797
43798 -static struct irq_chip gic_chip = {
43799 +static irq_chip_no_const gic_chip __read_only = {
43800 .name = "GIC",
43801 .irq_mask = gic_mask_irq,
43802 .irq_unmask = gic_unmask_irq,
43803 diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
43804 index 542e850..1bb094c 100644
43805 --- a/drivers/irqchip/irq-renesas-intc-irqpin.c
43806 +++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
43807 @@ -353,7 +353,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
43808 struct intc_irqpin_iomem *i;
43809 struct resource *io[INTC_IRQPIN_REG_NR];
43810 struct resource *irq;
43811 - struct irq_chip *irq_chip;
43812 + irq_chip_no_const *irq_chip;
43813 void (*enable_fn)(struct irq_data *d);
43814 void (*disable_fn)(struct irq_data *d);
43815 const char *name = dev_name(dev);
43816 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43817 index 8777065..a4a9967 100644
43818 --- a/drivers/irqchip/irq-renesas-irqc.c
43819 +++ b/drivers/irqchip/irq-renesas-irqc.c
43820 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43821 struct irqc_priv *p;
43822 struct resource *io;
43823 struct resource *irq;
43824 - struct irq_chip *irq_chip;
43825 + irq_chip_no_const *irq_chip;
43826 const char *name = dev_name(&pdev->dev);
43827 int ret;
43828 int k;
43829 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43830 index 6a2df32..dc962f1 100644
43831 --- a/drivers/isdn/capi/capi.c
43832 +++ b/drivers/isdn/capi/capi.c
43833 @@ -81,8 +81,8 @@ struct capiminor {
43834
43835 struct capi20_appl *ap;
43836 u32 ncci;
43837 - atomic_t datahandle;
43838 - atomic_t msgid;
43839 + atomic_unchecked_t datahandle;
43840 + atomic_unchecked_t msgid;
43841
43842 struct tty_port port;
43843 int ttyinstop;
43844 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43845 capimsg_setu16(s, 2, mp->ap->applid);
43846 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43847 capimsg_setu8 (s, 5, CAPI_RESP);
43848 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43849 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43850 capimsg_setu32(s, 8, mp->ncci);
43851 capimsg_setu16(s, 12, datahandle);
43852 }
43853 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43854 mp->outbytes -= len;
43855 spin_unlock_bh(&mp->outlock);
43856
43857 - datahandle = atomic_inc_return(&mp->datahandle);
43858 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43859 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43860 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43861 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43862 capimsg_setu16(skb->data, 2, mp->ap->applid);
43863 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43864 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43865 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43866 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43867 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43868 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43869 capimsg_setu16(skb->data, 16, len); /* Data length */
43870 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43871 index aecec6d..11e13c5 100644
43872 --- a/drivers/isdn/gigaset/bas-gigaset.c
43873 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43874 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43875
43876
43877 static const struct gigaset_ops gigops = {
43878 - gigaset_write_cmd,
43879 - gigaset_write_room,
43880 - gigaset_chars_in_buffer,
43881 - gigaset_brkchars,
43882 - gigaset_init_bchannel,
43883 - gigaset_close_bchannel,
43884 - gigaset_initbcshw,
43885 - gigaset_freebcshw,
43886 - gigaset_reinitbcshw,
43887 - gigaset_initcshw,
43888 - gigaset_freecshw,
43889 - gigaset_set_modem_ctrl,
43890 - gigaset_baud_rate,
43891 - gigaset_set_line_ctrl,
43892 - gigaset_isoc_send_skb,
43893 - gigaset_isoc_input,
43894 + .write_cmd = gigaset_write_cmd,
43895 + .write_room = gigaset_write_room,
43896 + .chars_in_buffer = gigaset_chars_in_buffer,
43897 + .brkchars = gigaset_brkchars,
43898 + .init_bchannel = gigaset_init_bchannel,
43899 + .close_bchannel = gigaset_close_bchannel,
43900 + .initbcshw = gigaset_initbcshw,
43901 + .freebcshw = gigaset_freebcshw,
43902 + .reinitbcshw = gigaset_reinitbcshw,
43903 + .initcshw = gigaset_initcshw,
43904 + .freecshw = gigaset_freecshw,
43905 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43906 + .baud_rate = gigaset_baud_rate,
43907 + .set_line_ctrl = gigaset_set_line_ctrl,
43908 + .send_skb = gigaset_isoc_send_skb,
43909 + .handle_input = gigaset_isoc_input,
43910 };
43911
43912 /* bas_gigaset_init
43913 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43914 index 600c79b..3752bab 100644
43915 --- a/drivers/isdn/gigaset/interface.c
43916 +++ b/drivers/isdn/gigaset/interface.c
43917 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43918 }
43919 tty->driver_data = cs;
43920
43921 - ++cs->port.count;
43922 + atomic_inc(&cs->port.count);
43923
43924 - if (cs->port.count == 1) {
43925 + if (atomic_read(&cs->port.count) == 1) {
43926 tty_port_tty_set(&cs->port, tty);
43927 cs->port.low_latency = 1;
43928 }
43929 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43930
43931 if (!cs->connected)
43932 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43933 - else if (!cs->port.count)
43934 + else if (!atomic_read(&cs->port.count))
43935 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43936 - else if (!--cs->port.count)
43937 + else if (!atomic_dec_return(&cs->port.count))
43938 tty_port_tty_set(&cs->port, NULL);
43939
43940 mutex_unlock(&cs->mutex);
43941 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43942 index 8c91fd5..14f13ce 100644
43943 --- a/drivers/isdn/gigaset/ser-gigaset.c
43944 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43945 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43946 }
43947
43948 static const struct gigaset_ops ops = {
43949 - gigaset_write_cmd,
43950 - gigaset_write_room,
43951 - gigaset_chars_in_buffer,
43952 - gigaset_brkchars,
43953 - gigaset_init_bchannel,
43954 - gigaset_close_bchannel,
43955 - gigaset_initbcshw,
43956 - gigaset_freebcshw,
43957 - gigaset_reinitbcshw,
43958 - gigaset_initcshw,
43959 - gigaset_freecshw,
43960 - gigaset_set_modem_ctrl,
43961 - gigaset_baud_rate,
43962 - gigaset_set_line_ctrl,
43963 - gigaset_m10x_send_skb, /* asyncdata.c */
43964 - gigaset_m10x_input, /* asyncdata.c */
43965 + .write_cmd = gigaset_write_cmd,
43966 + .write_room = gigaset_write_room,
43967 + .chars_in_buffer = gigaset_chars_in_buffer,
43968 + .brkchars = gigaset_brkchars,
43969 + .init_bchannel = gigaset_init_bchannel,
43970 + .close_bchannel = gigaset_close_bchannel,
43971 + .initbcshw = gigaset_initbcshw,
43972 + .freebcshw = gigaset_freebcshw,
43973 + .reinitbcshw = gigaset_reinitbcshw,
43974 + .initcshw = gigaset_initcshw,
43975 + .freecshw = gigaset_freecshw,
43976 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43977 + .baud_rate = gigaset_baud_rate,
43978 + .set_line_ctrl = gigaset_set_line_ctrl,
43979 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43980 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43981 };
43982
43983
43984 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43985 index a8e652d..edadaa4 100644
43986 --- a/drivers/isdn/gigaset/usb-gigaset.c
43987 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43988 @@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43989 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43990 memcpy(cs->hw.usb->bchars, buf, 6);
43991 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43992 - 0, 0, &buf, 6, 2000);
43993 + 0, 0, buf, 6, 2000);
43994 }
43995
43996 static void gigaset_freebcshw(struct bc_state *bcs)
43997 @@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43998 }
43999
44000 static const struct gigaset_ops ops = {
44001 - gigaset_write_cmd,
44002 - gigaset_write_room,
44003 - gigaset_chars_in_buffer,
44004 - gigaset_brkchars,
44005 - gigaset_init_bchannel,
44006 - gigaset_close_bchannel,
44007 - gigaset_initbcshw,
44008 - gigaset_freebcshw,
44009 - gigaset_reinitbcshw,
44010 - gigaset_initcshw,
44011 - gigaset_freecshw,
44012 - gigaset_set_modem_ctrl,
44013 - gigaset_baud_rate,
44014 - gigaset_set_line_ctrl,
44015 - gigaset_m10x_send_skb,
44016 - gigaset_m10x_input,
44017 + .write_cmd = gigaset_write_cmd,
44018 + .write_room = gigaset_write_room,
44019 + .chars_in_buffer = gigaset_chars_in_buffer,
44020 + .brkchars = gigaset_brkchars,
44021 + .init_bchannel = gigaset_init_bchannel,
44022 + .close_bchannel = gigaset_close_bchannel,
44023 + .initbcshw = gigaset_initbcshw,
44024 + .freebcshw = gigaset_freebcshw,
44025 + .reinitbcshw = gigaset_reinitbcshw,
44026 + .initcshw = gigaset_initcshw,
44027 + .freecshw = gigaset_freecshw,
44028 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44029 + .baud_rate = gigaset_baud_rate,
44030 + .set_line_ctrl = gigaset_set_line_ctrl,
44031 + .send_skb = gigaset_m10x_send_skb,
44032 + .handle_input = gigaset_m10x_input,
44033 };
44034
44035 /*
44036 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44037 index 4d9b195..455075c 100644
44038 --- a/drivers/isdn/hardware/avm/b1.c
44039 +++ b/drivers/isdn/hardware/avm/b1.c
44040 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44041 }
44042 if (left) {
44043 if (t4file->user) {
44044 - if (copy_from_user(buf, dp, left))
44045 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44046 return -EFAULT;
44047 } else {
44048 memcpy(buf, dp, left);
44049 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44050 }
44051 if (left) {
44052 if (config->user) {
44053 - if (copy_from_user(buf, dp, left))
44054 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44055 return -EFAULT;
44056 } else {
44057 memcpy(buf, dp, left);
44058 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
44059 index a82e542..f766a79 100644
44060 --- a/drivers/isdn/hardware/eicon/message.c
44061 +++ b/drivers/isdn/hardware/eicon/message.c
44062 @@ -1474,7 +1474,7 @@ static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
44063 add_ai(plci, &parms[5]);
44064 sig_req(plci, REJECT, 0);
44065 }
44066 - else if (Reject == 1 || Reject > 9)
44067 + else if (Reject == 1 || Reject >= 9)
44068 {
44069 add_ai(plci, &parms[5]);
44070 sig_req(plci, HANGUP, 0);
44071 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44072 index 9b856e1..fa03c92 100644
44073 --- a/drivers/isdn/i4l/isdn_common.c
44074 +++ b/drivers/isdn/i4l/isdn_common.c
44075 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44076 } else
44077 return -EINVAL;
44078 case IIOCDBGVAR:
44079 + if (!capable(CAP_SYS_RAWIO))
44080 + return -EPERM;
44081 if (arg) {
44082 if (copy_to_user(argp, &dev, sizeof(ulong)))
44083 return -EFAULT;
44084 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44085 index 91d5730..336523e 100644
44086 --- a/drivers/isdn/i4l/isdn_concap.c
44087 +++ b/drivers/isdn/i4l/isdn_concap.c
44088 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44089 }
44090
44091 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44092 - &isdn_concap_dl_data_req,
44093 - &isdn_concap_dl_connect_req,
44094 - &isdn_concap_dl_disconn_req
44095 + .data_req = &isdn_concap_dl_data_req,
44096 + .connect_req = &isdn_concap_dl_connect_req,
44097 + .disconn_req = &isdn_concap_dl_disconn_req
44098 };
44099
44100 /* The following should better go into a dedicated source file such that
44101 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44102 index bc91261..2ef7e36 100644
44103 --- a/drivers/isdn/i4l/isdn_tty.c
44104 +++ b/drivers/isdn/i4l/isdn_tty.c
44105 @@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44106
44107 #ifdef ISDN_DEBUG_MODEM_OPEN
44108 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44109 - port->count);
44110 + atomic_read(&port->count));
44111 #endif
44112 - port->count++;
44113 + atomic_inc(&port->count);
44114 port->tty = tty;
44115 /*
44116 * Start up serial port
44117 @@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44118 #endif
44119 return;
44120 }
44121 - if ((tty->count == 1) && (port->count != 1)) {
44122 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44123 /*
44124 * Uh, oh. tty->count is 1, which means that the tty
44125 * structure will be freed. Info->count should always
44126 @@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44127 * serial port won't be shutdown.
44128 */
44129 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44130 - "info->count is %d\n", port->count);
44131 - port->count = 1;
44132 + "info->count is %d\n", atomic_read(&port->count));
44133 + atomic_set(&port->count, 1);
44134 }
44135 - if (--port->count < 0) {
44136 + if (atomic_dec_return(&port->count) < 0) {
44137 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44138 - info->line, port->count);
44139 - port->count = 0;
44140 + info->line, atomic_read(&port->count));
44141 + atomic_set(&port->count, 0);
44142 }
44143 - if (port->count) {
44144 + if (atomic_read(&port->count)) {
44145 #ifdef ISDN_DEBUG_MODEM_OPEN
44146 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44147 #endif
44148 @@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44149 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44150 return;
44151 isdn_tty_shutdown(info);
44152 - port->count = 0;
44153 + atomic_set(&port->count, 0);
44154 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44155 port->tty = NULL;
44156 wake_up_interruptible(&port->open_wait);
44157 @@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44158 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44159 modem_info *info = &dev->mdm.info[i];
44160
44161 - if (info->port.count == 0)
44162 + if (atomic_read(&info->port.count) == 0)
44163 continue;
44164 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44165 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44166 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44167 index e2d4e58..40cd045 100644
44168 --- a/drivers/isdn/i4l/isdn_x25iface.c
44169 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44170 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44171
44172
44173 static struct concap_proto_ops ix25_pops = {
44174 - &isdn_x25iface_proto_new,
44175 - &isdn_x25iface_proto_del,
44176 - &isdn_x25iface_proto_restart,
44177 - &isdn_x25iface_proto_close,
44178 - &isdn_x25iface_xmit,
44179 - &isdn_x25iface_receive,
44180 - &isdn_x25iface_connect_ind,
44181 - &isdn_x25iface_disconn_ind
44182 + .proto_new = &isdn_x25iface_proto_new,
44183 + .proto_del = &isdn_x25iface_proto_del,
44184 + .restart = &isdn_x25iface_proto_restart,
44185 + .close = &isdn_x25iface_proto_close,
44186 + .encap_and_xmit = &isdn_x25iface_xmit,
44187 + .data_ind = &isdn_x25iface_receive,
44188 + .connect_ind = &isdn_x25iface_connect_ind,
44189 + .disconn_ind = &isdn_x25iface_disconn_ind
44190 };
44191
44192 /* error message helper function */
44193 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44194 index 6a7447c..cae33fe 100644
44195 --- a/drivers/isdn/icn/icn.c
44196 +++ b/drivers/isdn/icn/icn.c
44197 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44198 if (count > len)
44199 count = len;
44200 if (user) {
44201 - if (copy_from_user(msg, buf, count))
44202 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44203 return -EFAULT;
44204 } else
44205 memcpy(msg, buf, count);
44206 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44207 index 87f7dff..7300125 100644
44208 --- a/drivers/isdn/mISDN/dsp_cmx.c
44209 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44210 @@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44211 static u16 dsp_count; /* last sample count */
44212 static int dsp_count_valid; /* if we have last sample count */
44213
44214 -void
44215 +void __intentional_overflow(-1)
44216 dsp_cmx_send(void *arg)
44217 {
44218 struct dsp_conf *conf;
44219 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44220 index f58a354..fbae176 100644
44221 --- a/drivers/leds/leds-clevo-mail.c
44222 +++ b/drivers/leds/leds-clevo-mail.c
44223 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44224 * detected as working, but in reality it is not) as low as
44225 * possible.
44226 */
44227 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44228 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44229 {
44230 .callback = clevo_mail_led_dmi_callback,
44231 .ident = "Clevo D410J",
44232 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44233 index 046cb70..6b20d39 100644
44234 --- a/drivers/leds/leds-ss4200.c
44235 +++ b/drivers/leds/leds-ss4200.c
44236 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44237 * detected as working, but in reality it is not) as low as
44238 * possible.
44239 */
44240 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44241 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44242 {
44243 .callback = ss4200_led_dmi_callback,
44244 .ident = "Intel SS4200-E",
44245 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44246 index 6590558..a74c5dd 100644
44247 --- a/drivers/lguest/core.c
44248 +++ b/drivers/lguest/core.c
44249 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44250 * The end address needs +1 because __get_vm_area allocates an
44251 * extra guard page, so we need space for that.
44252 */
44253 +
44254 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44255 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44256 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44257 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44258 +#else
44259 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44260 VM_ALLOC, switcher_addr, switcher_addr
44261 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44262 +#endif
44263 +
44264 if (!switcher_vma) {
44265 err = -ENOMEM;
44266 printk("lguest: could not map switcher pages high\n");
44267 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44268 * Now the Switcher is mapped at the right address, we can't fail!
44269 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44270 */
44271 - memcpy(switcher_vma->addr, start_switcher_text,
44272 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44273 end_switcher_text - start_switcher_text);
44274
44275 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44276 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44277 index e8b55c3..3514c37 100644
44278 --- a/drivers/lguest/page_tables.c
44279 +++ b/drivers/lguest/page_tables.c
44280 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44281 /*:*/
44282
44283 #ifdef CONFIG_X86_PAE
44284 -static void release_pmd(pmd_t *spmd)
44285 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44286 {
44287 /* If the entry's not present, there's nothing to release. */
44288 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44289 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44290 index 922a1ac..9dd0c2a 100644
44291 --- a/drivers/lguest/x86/core.c
44292 +++ b/drivers/lguest/x86/core.c
44293 @@ -59,7 +59,7 @@ static struct {
44294 /* Offset from where switcher.S was compiled to where we've copied it */
44295 static unsigned long switcher_offset(void)
44296 {
44297 - return switcher_addr - (unsigned long)start_switcher_text;
44298 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44299 }
44300
44301 /* This cpu's struct lguest_pages (after the Switcher text page) */
44302 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44303 * These copies are pretty cheap, so we do them unconditionally: */
44304 /* Save the current Host top-level page directory.
44305 */
44306 +
44307 +#ifdef CONFIG_PAX_PER_CPU_PGD
44308 + pages->state.host_cr3 = read_cr3();
44309 +#else
44310 pages->state.host_cr3 = __pa(current->mm->pgd);
44311 +#endif
44312 +
44313 /*
44314 * Set up the Guest's page tables to see this CPU's pages (and no
44315 * other CPU's pages).
44316 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44317 * compiled-in switcher code and the high-mapped copy we just made.
44318 */
44319 for (i = 0; i < IDT_ENTRIES; i++)
44320 - default_idt_entries[i] += switcher_offset();
44321 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44322
44323 /*
44324 * Set up the Switcher's per-cpu areas.
44325 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44326 * it will be undisturbed when we switch. To change %cs and jump we
44327 * need this structure to feed to Intel's "lcall" instruction.
44328 */
44329 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44330 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44331 lguest_entry.segment = LGUEST_CS;
44332
44333 /*
44334 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44335 index 40634b0..4f5855e 100644
44336 --- a/drivers/lguest/x86/switcher_32.S
44337 +++ b/drivers/lguest/x86/switcher_32.S
44338 @@ -87,6 +87,7 @@
44339 #include <asm/page.h>
44340 #include <asm/segment.h>
44341 #include <asm/lguest.h>
44342 +#include <asm/processor-flags.h>
44343
44344 // We mark the start of the code to copy
44345 // It's placed in .text tho it's never run here
44346 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44347 // Changes type when we load it: damn Intel!
44348 // For after we switch over our page tables
44349 // That entry will be read-only: we'd crash.
44350 +
44351 +#ifdef CONFIG_PAX_KERNEXEC
44352 + mov %cr0, %edx
44353 + xor $X86_CR0_WP, %edx
44354 + mov %edx, %cr0
44355 +#endif
44356 +
44357 movl $(GDT_ENTRY_TSS*8), %edx
44358 ltr %dx
44359
44360 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44361 // Let's clear it again for our return.
44362 // The GDT descriptor of the Host
44363 // Points to the table after two "size" bytes
44364 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44365 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44366 // Clear "used" from type field (byte 5, bit 2)
44367 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44368 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44369 +
44370 +#ifdef CONFIG_PAX_KERNEXEC
44371 + mov %cr0, %eax
44372 + xor $X86_CR0_WP, %eax
44373 + mov %eax, %cr0
44374 +#endif
44375
44376 // Once our page table's switched, the Guest is live!
44377 // The Host fades as we run this final step.
44378 @@ -295,13 +309,12 @@ deliver_to_host:
44379 // I consulted gcc, and it gave
44380 // These instructions, which I gladly credit:
44381 leal (%edx,%ebx,8), %eax
44382 - movzwl (%eax),%edx
44383 - movl 4(%eax), %eax
44384 - xorw %ax, %ax
44385 - orl %eax, %edx
44386 + movl 4(%eax), %edx
44387 + movw (%eax), %dx
44388 // Now the address of the handler's in %edx
44389 // We call it now: its "iret" drops us home.
44390 - jmp *%edx
44391 + ljmp $__KERNEL_CS, $1f
44392 +1: jmp *%edx
44393
44394 // Every interrupt can come to us here
44395 // But we must truly tell each apart.
44396 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44397 index a08e3ee..df8ade2 100644
44398 --- a/drivers/md/bcache/closure.h
44399 +++ b/drivers/md/bcache/closure.h
44400 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44401 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44402 struct workqueue_struct *wq)
44403 {
44404 - BUG_ON(object_is_on_stack(cl));
44405 + BUG_ON(object_starts_on_stack(cl));
44406 closure_set_ip(cl);
44407 cl->fn = fn;
44408 cl->wq = wq;
44409 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44410 index da3604e..7789cb4c 100644
44411 --- a/drivers/md/bitmap.c
44412 +++ b/drivers/md/bitmap.c
44413 @@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44414 chunk_kb ? "KB" : "B");
44415 if (bitmap->storage.file) {
44416 seq_printf(seq, ", file: ");
44417 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44418 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44419 }
44420
44421 seq_printf(seq, "\n");
44422 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44423 index 0be9381..114262b 100644
44424 --- a/drivers/md/dm-ioctl.c
44425 +++ b/drivers/md/dm-ioctl.c
44426 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44427 cmd == DM_LIST_VERSIONS_CMD)
44428 return 0;
44429
44430 - if ((cmd == DM_DEV_CREATE_CMD)) {
44431 + if (cmd == DM_DEV_CREATE_CMD) {
44432 if (!*param->name) {
44433 DMWARN("name not supplied when creating device");
44434 return -EINVAL;
44435 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44436 index 7dfdb5c..4caada6 100644
44437 --- a/drivers/md/dm-raid1.c
44438 +++ b/drivers/md/dm-raid1.c
44439 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44440
44441 struct mirror {
44442 struct mirror_set *ms;
44443 - atomic_t error_count;
44444 + atomic_unchecked_t error_count;
44445 unsigned long error_type;
44446 struct dm_dev *dev;
44447 sector_t offset;
44448 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44449 struct mirror *m;
44450
44451 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44452 - if (!atomic_read(&m->error_count))
44453 + if (!atomic_read_unchecked(&m->error_count))
44454 return m;
44455
44456 return NULL;
44457 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44458 * simple way to tell if a device has encountered
44459 * errors.
44460 */
44461 - atomic_inc(&m->error_count);
44462 + atomic_inc_unchecked(&m->error_count);
44463
44464 if (test_and_set_bit(error_type, &m->error_type))
44465 return;
44466 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44467 struct mirror *m = get_default_mirror(ms);
44468
44469 do {
44470 - if (likely(!atomic_read(&m->error_count)))
44471 + if (likely(!atomic_read_unchecked(&m->error_count)))
44472 return m;
44473
44474 if (m-- == ms->mirror)
44475 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44476 {
44477 struct mirror *default_mirror = get_default_mirror(m->ms);
44478
44479 - return !atomic_read(&default_mirror->error_count);
44480 + return !atomic_read_unchecked(&default_mirror->error_count);
44481 }
44482
44483 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44484 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44485 */
44486 if (likely(region_in_sync(ms, region, 1)))
44487 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44488 - else if (m && atomic_read(&m->error_count))
44489 + else if (m && atomic_read_unchecked(&m->error_count))
44490 m = NULL;
44491
44492 if (likely(m))
44493 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44494 }
44495
44496 ms->mirror[mirror].ms = ms;
44497 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44498 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44499 ms->mirror[mirror].error_type = 0;
44500 ms->mirror[mirror].offset = offset;
44501
44502 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44503 */
44504 static char device_status_char(struct mirror *m)
44505 {
44506 - if (!atomic_read(&(m->error_count)))
44507 + if (!atomic_read_unchecked(&(m->error_count)))
44508 return 'A';
44509
44510 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44511 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44512 index 87f86c7..a1a4100 100644
44513 --- a/drivers/md/dm-stats.c
44514 +++ b/drivers/md/dm-stats.c
44515 @@ -382,7 +382,7 @@ do_sync_free:
44516 synchronize_rcu_expedited();
44517 dm_stat_free(&s->rcu_head);
44518 } else {
44519 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44520 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44521 call_rcu(&s->rcu_head, dm_stat_free);
44522 }
44523 return 0;
44524 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44525 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44526 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44527 ));
44528 - ACCESS_ONCE(last->last_sector) = end_sector;
44529 - ACCESS_ONCE(last->last_rw) = bi_rw;
44530 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44531 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44532 }
44533
44534 rcu_read_lock();
44535 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44536 index f8b37d4..5c5cafd 100644
44537 --- a/drivers/md/dm-stripe.c
44538 +++ b/drivers/md/dm-stripe.c
44539 @@ -21,7 +21,7 @@ struct stripe {
44540 struct dm_dev *dev;
44541 sector_t physical_start;
44542
44543 - atomic_t error_count;
44544 + atomic_unchecked_t error_count;
44545 };
44546
44547 struct stripe_c {
44548 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44549 kfree(sc);
44550 return r;
44551 }
44552 - atomic_set(&(sc->stripe[i].error_count), 0);
44553 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44554 }
44555
44556 ti->private = sc;
44557 @@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44558 DMEMIT("%d ", sc->stripes);
44559 for (i = 0; i < sc->stripes; i++) {
44560 DMEMIT("%s ", sc->stripe[i].dev->name);
44561 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44562 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44563 'D' : 'A';
44564 }
44565 buffer[i] = '\0';
44566 @@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44567 */
44568 for (i = 0; i < sc->stripes; i++)
44569 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44570 - atomic_inc(&(sc->stripe[i].error_count));
44571 - if (atomic_read(&(sc->stripe[i].error_count)) <
44572 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44573 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44574 DM_IO_ERROR_THRESHOLD)
44575 schedule_work(&sc->trigger_event);
44576 }
44577 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44578 index b2bd1eb..38f7a44 100644
44579 --- a/drivers/md/dm-table.c
44580 +++ b/drivers/md/dm-table.c
44581 @@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44582 if (!dev_size)
44583 return 0;
44584
44585 - if ((start >= dev_size) || (start + len > dev_size)) {
44586 + if ((start >= dev_size) || (len > dev_size - start)) {
44587 DMWARN("%s: %s too small for target: "
44588 "start=%llu, len=%llu, dev_size=%llu",
44589 dm_device_name(ti->table->md), bdevname(bdev, b),
44590 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44591 index e9d33ad..dae9880d 100644
44592 --- a/drivers/md/dm-thin-metadata.c
44593 +++ b/drivers/md/dm-thin-metadata.c
44594 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44595 {
44596 pmd->info.tm = pmd->tm;
44597 pmd->info.levels = 2;
44598 - pmd->info.value_type.context = pmd->data_sm;
44599 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44600 pmd->info.value_type.size = sizeof(__le64);
44601 pmd->info.value_type.inc = data_block_inc;
44602 pmd->info.value_type.dec = data_block_dec;
44603 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44604
44605 pmd->bl_info.tm = pmd->tm;
44606 pmd->bl_info.levels = 1;
44607 - pmd->bl_info.value_type.context = pmd->data_sm;
44608 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44609 pmd->bl_info.value_type.size = sizeof(__le64);
44610 pmd->bl_info.value_type.inc = data_block_inc;
44611 pmd->bl_info.value_type.dec = data_block_dec;
44612 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44613 index 62c5136..aede7f1 100644
44614 --- a/drivers/md/dm.c
44615 +++ b/drivers/md/dm.c
44616 @@ -183,9 +183,9 @@ struct mapped_device {
44617 /*
44618 * Event handling.
44619 */
44620 - atomic_t event_nr;
44621 + atomic_unchecked_t event_nr;
44622 wait_queue_head_t eventq;
44623 - atomic_t uevent_seq;
44624 + atomic_unchecked_t uevent_seq;
44625 struct list_head uevent_list;
44626 spinlock_t uevent_lock; /* Protect access to uevent_list */
44627
44628 @@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44629 spin_lock_init(&md->deferred_lock);
44630 atomic_set(&md->holders, 1);
44631 atomic_set(&md->open_count, 0);
44632 - atomic_set(&md->event_nr, 0);
44633 - atomic_set(&md->uevent_seq, 0);
44634 + atomic_set_unchecked(&md->event_nr, 0);
44635 + atomic_set_unchecked(&md->uevent_seq, 0);
44636 INIT_LIST_HEAD(&md->uevent_list);
44637 INIT_LIST_HEAD(&md->table_devices);
44638 spin_lock_init(&md->uevent_lock);
44639 @@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44640
44641 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44642
44643 - atomic_inc(&md->event_nr);
44644 + atomic_inc_unchecked(&md->event_nr);
44645 wake_up(&md->eventq);
44646 }
44647
44648 @@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44649
44650 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44651 {
44652 - return atomic_add_return(1, &md->uevent_seq);
44653 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44654 }
44655
44656 uint32_t dm_get_event_nr(struct mapped_device *md)
44657 {
44658 - return atomic_read(&md->event_nr);
44659 + return atomic_read_unchecked(&md->event_nr);
44660 }
44661
44662 int dm_wait_event(struct mapped_device *md, int event_nr)
44663 {
44664 return wait_event_interruptible(md->eventq,
44665 - (event_nr != atomic_read(&md->event_nr)));
44666 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44667 }
44668
44669 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44670 diff --git a/drivers/md/md.c b/drivers/md/md.c
44671 index 9233c71..ed5243a 100644
44672 --- a/drivers/md/md.c
44673 +++ b/drivers/md/md.c
44674 @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44675 * start build, activate spare
44676 */
44677 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44678 -static atomic_t md_event_count;
44679 +static atomic_unchecked_t md_event_count;
44680 void md_new_event(struct mddev *mddev)
44681 {
44682 - atomic_inc(&md_event_count);
44683 + atomic_inc_unchecked(&md_event_count);
44684 wake_up(&md_event_waiters);
44685 }
44686 EXPORT_SYMBOL_GPL(md_new_event);
44687 @@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44688 */
44689 static void md_new_event_inintr(struct mddev *mddev)
44690 {
44691 - atomic_inc(&md_event_count);
44692 + atomic_inc_unchecked(&md_event_count);
44693 wake_up(&md_event_waiters);
44694 }
44695
44696 @@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44697 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44698 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44699 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44700 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44701 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44702
44703 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44704 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44705 @@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44706 else
44707 sb->resync_offset = cpu_to_le64(0);
44708
44709 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44710 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44711
44712 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44713 sb->size = cpu_to_le64(mddev->dev_sectors);
44714 @@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44715 static ssize_t
44716 errors_show(struct md_rdev *rdev, char *page)
44717 {
44718 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44719 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44720 }
44721
44722 static ssize_t
44723 @@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44724 char *e;
44725 unsigned long n = simple_strtoul(buf, &e, 10);
44726 if (*buf && (*e == 0 || *e == '\n')) {
44727 - atomic_set(&rdev->corrected_errors, n);
44728 + atomic_set_unchecked(&rdev->corrected_errors, n);
44729 return len;
44730 }
44731 return -EINVAL;
44732 @@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44733 rdev->sb_loaded = 0;
44734 rdev->bb_page = NULL;
44735 atomic_set(&rdev->nr_pending, 0);
44736 - atomic_set(&rdev->read_errors, 0);
44737 - atomic_set(&rdev->corrected_errors, 0);
44738 + atomic_set_unchecked(&rdev->read_errors, 0);
44739 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44740
44741 INIT_LIST_HEAD(&rdev->same_set);
44742 init_waitqueue_head(&rdev->blocked_wait);
44743 @@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44744
44745 spin_unlock(&pers_lock);
44746 seq_printf(seq, "\n");
44747 - seq->poll_event = atomic_read(&md_event_count);
44748 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44749 return 0;
44750 }
44751 if (v == (void*)2) {
44752 @@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44753 return error;
44754
44755 seq = file->private_data;
44756 - seq->poll_event = atomic_read(&md_event_count);
44757 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44758 return error;
44759 }
44760
44761 @@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44762 /* always allow read */
44763 mask = POLLIN | POLLRDNORM;
44764
44765 - if (seq->poll_event != atomic_read(&md_event_count))
44766 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44767 mask |= POLLERR | POLLPRI;
44768 return mask;
44769 }
44770 @@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44771 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44772 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44773 (int)part_stat_read(&disk->part0, sectors[1]) -
44774 - atomic_read(&disk->sync_io);
44775 + atomic_read_unchecked(&disk->sync_io);
44776 /* sync IO will cause sync_io to increase before the disk_stats
44777 * as sync_io is counted when a request starts, and
44778 * disk_stats is counted when it completes.
44779 diff --git a/drivers/md/md.h b/drivers/md/md.h
44780 index 03cec5b..0a658c1 100644
44781 --- a/drivers/md/md.h
44782 +++ b/drivers/md/md.h
44783 @@ -94,13 +94,13 @@ struct md_rdev {
44784 * only maintained for arrays that
44785 * support hot removal
44786 */
44787 - atomic_t read_errors; /* number of consecutive read errors that
44788 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44789 * we have tried to ignore.
44790 */
44791 struct timespec last_read_error; /* monotonic time since our
44792 * last read error
44793 */
44794 - atomic_t corrected_errors; /* number of corrected read errors,
44795 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44796 * for reporting to userspace and storing
44797 * in superblock.
44798 */
44799 @@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44800
44801 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44802 {
44803 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44804 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44805 }
44806
44807 struct md_personality
44808 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44809 index f4e22bc..8f83114 100644
44810 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44811 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44812 @@ -681,7 +681,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44813 * Flick into a mode where all blocks get allocated in the new area.
44814 */
44815 smm->begin = old_len;
44816 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44817 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44818
44819 /*
44820 * Extend.
44821 @@ -712,7 +712,7 @@ out:
44822 /*
44823 * Switch back to normal behaviour.
44824 */
44825 - memcpy(sm, &ops, sizeof(*sm));
44826 + memcpy((void *)sm, &ops, sizeof(*sm));
44827 return r;
44828 }
44829
44830 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44831 index 3e6d115..ffecdeb 100644
44832 --- a/drivers/md/persistent-data/dm-space-map.h
44833 +++ b/drivers/md/persistent-data/dm-space-map.h
44834 @@ -71,6 +71,7 @@ struct dm_space_map {
44835 dm_sm_threshold_fn fn,
44836 void *context);
44837 };
44838 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44839
44840 /*----------------------------------------------------------------*/
44841
44842 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44843 index 40b35be..a327e11 100644
44844 --- a/drivers/md/raid1.c
44845 +++ b/drivers/md/raid1.c
44846 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44847 if (r1_sync_page_io(rdev, sect, s,
44848 bio->bi_io_vec[idx].bv_page,
44849 READ) != 0)
44850 - atomic_add(s, &rdev->corrected_errors);
44851 + atomic_add_unchecked(s, &rdev->corrected_errors);
44852 }
44853 sectors -= s;
44854 sect += s;
44855 @@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44856 !test_bit(Faulty, &rdev->flags)) {
44857 if (r1_sync_page_io(rdev, sect, s,
44858 conf->tmppage, READ)) {
44859 - atomic_add(s, &rdev->corrected_errors);
44860 + atomic_add_unchecked(s, &rdev->corrected_errors);
44861 printk(KERN_INFO
44862 "md/raid1:%s: read error corrected "
44863 "(%d sectors at %llu on %s)\n",
44864 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44865 index 32e282f..5cec803 100644
44866 --- a/drivers/md/raid10.c
44867 +++ b/drivers/md/raid10.c
44868 @@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44869 /* The write handler will notice the lack of
44870 * R10BIO_Uptodate and record any errors etc
44871 */
44872 - atomic_add(r10_bio->sectors,
44873 + atomic_add_unchecked(r10_bio->sectors,
44874 &conf->mirrors[d].rdev->corrected_errors);
44875
44876 /* for reconstruct, we always reschedule after a read.
44877 @@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44878 {
44879 struct timespec cur_time_mon;
44880 unsigned long hours_since_last;
44881 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44882 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44883
44884 ktime_get_ts(&cur_time_mon);
44885
44886 @@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44887 * overflowing the shift of read_errors by hours_since_last.
44888 */
44889 if (hours_since_last >= 8 * sizeof(read_errors))
44890 - atomic_set(&rdev->read_errors, 0);
44891 + atomic_set_unchecked(&rdev->read_errors, 0);
44892 else
44893 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44894 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44895 }
44896
44897 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44898 @@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44899 return;
44900
44901 check_decay_read_errors(mddev, rdev);
44902 - atomic_inc(&rdev->read_errors);
44903 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44904 + atomic_inc_unchecked(&rdev->read_errors);
44905 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44906 char b[BDEVNAME_SIZE];
44907 bdevname(rdev->bdev, b);
44908
44909 @@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44910 "md/raid10:%s: %s: Raid device exceeded "
44911 "read_error threshold [cur %d:max %d]\n",
44912 mdname(mddev), b,
44913 - atomic_read(&rdev->read_errors), max_read_errors);
44914 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44915 printk(KERN_NOTICE
44916 "md/raid10:%s: %s: Failing raid device\n",
44917 mdname(mddev), b);
44918 @@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44919 sect +
44920 choose_data_offset(r10_bio, rdev)),
44921 bdevname(rdev->bdev, b));
44922 - atomic_add(s, &rdev->corrected_errors);
44923 + atomic_add_unchecked(s, &rdev->corrected_errors);
44924 }
44925
44926 rdev_dec_pending(rdev, mddev);
44927 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44928 index c1b0d52..07a0a5d 100644
44929 --- a/drivers/md/raid5.c
44930 +++ b/drivers/md/raid5.c
44931 @@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44932 return 1;
44933 }
44934
44935 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44936 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44937 +#endif
44938 +
44939 static int grow_stripes(struct r5conf *conf, int num)
44940 {
44941 struct kmem_cache *sc;
44942 @@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44943 "raid%d-%s", conf->level, mdname(conf->mddev));
44944 else
44945 sprintf(conf->cache_name[0],
44946 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44947 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44948 +#else
44949 "raid%d-%p", conf->level, conf->mddev);
44950 +#endif
44951 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44952
44953 conf->active_name = 0;
44954 @@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44955 mdname(conf->mddev), STRIPE_SECTORS,
44956 (unsigned long long)s,
44957 bdevname(rdev->bdev, b));
44958 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44959 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44960 clear_bit(R5_ReadError, &sh->dev[i].flags);
44961 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44962 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44963 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44964
44965 - if (atomic_read(&rdev->read_errors))
44966 - atomic_set(&rdev->read_errors, 0);
44967 + if (atomic_read_unchecked(&rdev->read_errors))
44968 + atomic_set_unchecked(&rdev->read_errors, 0);
44969 } else {
44970 const char *bdn = bdevname(rdev->bdev, b);
44971 int retry = 0;
44972 int set_bad = 0;
44973
44974 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44975 - atomic_inc(&rdev->read_errors);
44976 + atomic_inc_unchecked(&rdev->read_errors);
44977 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44978 printk_ratelimited(
44979 KERN_WARNING
44980 @@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44981 mdname(conf->mddev),
44982 (unsigned long long)s,
44983 bdn);
44984 - } else if (atomic_read(&rdev->read_errors)
44985 + } else if (atomic_read_unchecked(&rdev->read_errors)
44986 > conf->max_nr_stripes)
44987 printk(KERN_WARNING
44988 "md/raid:%s: Too many read errors, failing device %s.\n",
44989 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44990 index 983db75..ef9248c 100644
44991 --- a/drivers/media/dvb-core/dvbdev.c
44992 +++ b/drivers/media/dvb-core/dvbdev.c
44993 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44994 const struct dvb_device *template, void *priv, int type)
44995 {
44996 struct dvb_device *dvbdev;
44997 - struct file_operations *dvbdevfops;
44998 + file_operations_no_const *dvbdevfops;
44999 struct device *clsdev;
45000 int minor;
45001 int id;
45002 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45003 index 6ad22b6..6e90e2a 100644
45004 --- a/drivers/media/dvb-frontends/af9033.h
45005 +++ b/drivers/media/dvb-frontends/af9033.h
45006 @@ -96,6 +96,6 @@ struct af9033_ops {
45007 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45008 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45009 int onoff);
45010 -};
45011 +} __no_const;
45012
45013 #endif /* AF9033_H */
45014 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45015 index 9b6c3bb..baeb5c7 100644
45016 --- a/drivers/media/dvb-frontends/dib3000.h
45017 +++ b/drivers/media/dvb-frontends/dib3000.h
45018 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45019 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45020 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45021 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45022 -};
45023 +} __no_const;
45024
45025 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45026 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45027 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45028 index 1fea0e9..321ce8f 100644
45029 --- a/drivers/media/dvb-frontends/dib7000p.h
45030 +++ b/drivers/media/dvb-frontends/dib7000p.h
45031 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45032 int (*get_adc_power)(struct dvb_frontend *fe);
45033 int (*slave_reset)(struct dvb_frontend *fe);
45034 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45035 -};
45036 +} __no_const;
45037
45038 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45039 void *dib7000p_attach(struct dib7000p_ops *ops);
45040 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45041 index 84cc103..5780c54 100644
45042 --- a/drivers/media/dvb-frontends/dib8000.h
45043 +++ b/drivers/media/dvb-frontends/dib8000.h
45044 @@ -61,7 +61,7 @@ struct dib8000_ops {
45045 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45046 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45047 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45048 -};
45049 +} __no_const;
45050
45051 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45052 void *dib8000_attach(struct dib8000_ops *ops);
45053 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45054 index ce27e6d..b70435a 100644
45055 --- a/drivers/media/pci/cx88/cx88-video.c
45056 +++ b/drivers/media/pci/cx88/cx88-video.c
45057 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45058
45059 /* ------------------------------------------------------------------ */
45060
45061 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45062 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45063 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45064 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45065 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45066 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45067
45068 module_param_array(video_nr, int, NULL, 0444);
45069 module_param_array(vbi_nr, int, NULL, 0444);
45070 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45071 index 802642d..5534900 100644
45072 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45073 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45074 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45075 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45076
45077 /* ivtv instance counter */
45078 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45079 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45080
45081 /* Parameter declarations */
45082 static int cardtype[IVTV_MAX_CARDS];
45083 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45084 index 8cbe6b4..ea3601c 100644
45085 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45086 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45087 @@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45088
45089 static int solo_sysfs_init(struct solo_dev *solo_dev)
45090 {
45091 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45092 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45093 struct device *dev = &solo_dev->dev;
45094 const char *driver;
45095 int i;
45096 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45097 index c7141f2..5301fec 100644
45098 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45099 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45100 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45101
45102 int solo_g723_init(struct solo_dev *solo_dev)
45103 {
45104 - static struct snd_device_ops ops = { NULL };
45105 + static struct snd_device_ops ops = { };
45106 struct snd_card *card;
45107 struct snd_kcontrol_new kctl;
45108 char name[32];
45109 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45110 index 8c84846..27b4f83 100644
45111 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45112 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45113 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45114
45115 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45116 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45117 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45118 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45119 if (p2m_id < 0)
45120 p2m_id = -p2m_id;
45121 }
45122 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45123 index 72017b7..dd37ae6 100644
45124 --- a/drivers/media/pci/solo6x10/solo6x10.h
45125 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45126 @@ -219,7 +219,7 @@ struct solo_dev {
45127
45128 /* P2M DMA Engine */
45129 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45130 - atomic_t p2m_count;
45131 + atomic_unchecked_t p2m_count;
45132 int p2m_jiffies;
45133 unsigned int p2m_timeouts;
45134
45135 diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45136 index 63f0b64..a017c1c 100644
45137 --- a/drivers/media/pci/tw68/tw68-core.c
45138 +++ b/drivers/media/pci/tw68/tw68-core.c
45139 @@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45140 module_param_array(card, int, NULL, 0444);
45141 MODULE_PARM_DESC(card, "card type");
45142
45143 -static atomic_t tw68_instance = ATOMIC_INIT(0);
45144 +static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45145
45146 /* ------------------------------------------------------------------ */
45147
45148 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45149 index 64ab6fb..ef4a8b9 100644
45150 --- a/drivers/media/platform/omap/omap_vout.c
45151 +++ b/drivers/media/platform/omap/omap_vout.c
45152 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45153 OMAP_VIDEO2,
45154 };
45155
45156 -static struct videobuf_queue_ops video_vbq_ops;
45157 /* Variables configurable through module params*/
45158 static u32 video1_numbuffers = 3;
45159 static u32 video2_numbuffers = 3;
45160 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45161 {
45162 struct videobuf_queue *q;
45163 struct omap_vout_device *vout = NULL;
45164 + static struct videobuf_queue_ops video_vbq_ops = {
45165 + .buf_setup = omap_vout_buffer_setup,
45166 + .buf_prepare = omap_vout_buffer_prepare,
45167 + .buf_release = omap_vout_buffer_release,
45168 + .buf_queue = omap_vout_buffer_queue,
45169 + };
45170
45171 vout = video_drvdata(file);
45172 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45173 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45174 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45175
45176 q = &vout->vbq;
45177 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45178 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45179 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45180 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45181 spin_lock_init(&vout->vbq_lock);
45182
45183 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45184 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45185 index fb2acc5..a2fcbdc4 100644
45186 --- a/drivers/media/platform/s5p-tv/mixer.h
45187 +++ b/drivers/media/platform/s5p-tv/mixer.h
45188 @@ -156,7 +156,7 @@ struct mxr_layer {
45189 /** layer index (unique identifier) */
45190 int idx;
45191 /** callbacks for layer methods */
45192 - struct mxr_layer_ops ops;
45193 + struct mxr_layer_ops *ops;
45194 /** format array */
45195 const struct mxr_format **fmt_array;
45196 /** size of format array */
45197 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45198 index 74344c7..a39e70e 100644
45199 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45200 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45201 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45202 {
45203 struct mxr_layer *layer;
45204 int ret;
45205 - struct mxr_layer_ops ops = {
45206 + static struct mxr_layer_ops ops = {
45207 .release = mxr_graph_layer_release,
45208 .buffer_set = mxr_graph_buffer_set,
45209 .stream_set = mxr_graph_stream_set,
45210 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45211 index b713403..53cb5ad 100644
45212 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45213 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45214 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45215 layer->update_buf = next;
45216 }
45217
45218 - layer->ops.buffer_set(layer, layer->update_buf);
45219 + layer->ops->buffer_set(layer, layer->update_buf);
45220
45221 if (done && done != layer->shadow_buf)
45222 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45223 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45224 index b4d2696..91df48e 100644
45225 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45226 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45227 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45228 layer->geo.src.height = layer->geo.src.full_height;
45229
45230 mxr_geometry_dump(mdev, &layer->geo);
45231 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45232 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45233 mxr_geometry_dump(mdev, &layer->geo);
45234 }
45235
45236 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45237 layer->geo.dst.full_width = mbus_fmt.width;
45238 layer->geo.dst.full_height = mbus_fmt.height;
45239 layer->geo.dst.field = mbus_fmt.field;
45240 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45241 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45242
45243 mxr_geometry_dump(mdev, &layer->geo);
45244 }
45245 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45246 /* set source size to highest accepted value */
45247 geo->src.full_width = max(geo->dst.full_width, pix->width);
45248 geo->src.full_height = max(geo->dst.full_height, pix->height);
45249 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45250 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45251 mxr_geometry_dump(mdev, &layer->geo);
45252 /* set cropping to total visible screen */
45253 geo->src.width = pix->width;
45254 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45255 geo->src.x_offset = 0;
45256 geo->src.y_offset = 0;
45257 /* assure consistency of geometry */
45258 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45259 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45260 mxr_geometry_dump(mdev, &layer->geo);
45261 /* set full size to lowest possible value */
45262 geo->src.full_width = 0;
45263 geo->src.full_height = 0;
45264 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45265 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45266 mxr_geometry_dump(mdev, &layer->geo);
45267
45268 /* returning results */
45269 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45270 target->width = s->r.width;
45271 target->height = s->r.height;
45272
45273 - layer->ops.fix_geometry(layer, stage, s->flags);
45274 + layer->ops->fix_geometry(layer, stage, s->flags);
45275
45276 /* retrieve update selection rectangle */
45277 res.left = target->x_offset;
45278 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45279 mxr_output_get(mdev);
45280
45281 mxr_layer_update_output(layer);
45282 - layer->ops.format_set(layer);
45283 + layer->ops->format_set(layer);
45284 /* enabling layer in hardware */
45285 spin_lock_irqsave(&layer->enq_slock, flags);
45286 layer->state = MXR_LAYER_STREAMING;
45287 spin_unlock_irqrestore(&layer->enq_slock, flags);
45288
45289 - layer->ops.stream_set(layer, MXR_ENABLE);
45290 + layer->ops->stream_set(layer, MXR_ENABLE);
45291 mxr_streamer_get(mdev);
45292
45293 return 0;
45294 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45295 spin_unlock_irqrestore(&layer->enq_slock, flags);
45296
45297 /* disabling layer in hardware */
45298 - layer->ops.stream_set(layer, MXR_DISABLE);
45299 + layer->ops->stream_set(layer, MXR_DISABLE);
45300 /* remove one streamer */
45301 mxr_streamer_put(mdev);
45302 /* allow changes in output configuration */
45303 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45304
45305 void mxr_layer_release(struct mxr_layer *layer)
45306 {
45307 - if (layer->ops.release)
45308 - layer->ops.release(layer);
45309 + if (layer->ops->release)
45310 + layer->ops->release(layer);
45311 }
45312
45313 void mxr_base_layer_release(struct mxr_layer *layer)
45314 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45315
45316 layer->mdev = mdev;
45317 layer->idx = idx;
45318 - layer->ops = *ops;
45319 + layer->ops = ops;
45320
45321 spin_lock_init(&layer->enq_slock);
45322 INIT_LIST_HEAD(&layer->enq_list);
45323 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45324 index c9388c4..ce71ece 100644
45325 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45326 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45327 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45328 {
45329 struct mxr_layer *layer;
45330 int ret;
45331 - struct mxr_layer_ops ops = {
45332 + static struct mxr_layer_ops ops = {
45333 .release = mxr_vp_layer_release,
45334 .buffer_set = mxr_vp_buffer_set,
45335 .stream_set = mxr_vp_stream_set,
45336 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45337 index 82affae..42833ec 100644
45338 --- a/drivers/media/radio/radio-cadet.c
45339 +++ b/drivers/media/radio/radio-cadet.c
45340 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45341 unsigned char readbuf[RDS_BUFFER];
45342 int i = 0;
45343
45344 + if (count > RDS_BUFFER)
45345 + return -EFAULT;
45346 mutex_lock(&dev->lock);
45347 if (dev->rdsstat == 0)
45348 cadet_start_rds(dev);
45349 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45350 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45351 mutex_unlock(&dev->lock);
45352
45353 - if (i && copy_to_user(data, readbuf, i))
45354 - return -EFAULT;
45355 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45356 + i = -EFAULT;
45357 +
45358 return i;
45359 }
45360
45361 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45362 index 5236035..c622c74 100644
45363 --- a/drivers/media/radio/radio-maxiradio.c
45364 +++ b/drivers/media/radio/radio-maxiradio.c
45365 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45366 /* TEA5757 pin mappings */
45367 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45368
45369 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45370 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45371
45372 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45373 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45374 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45375 index 050b3bb..79f62b9 100644
45376 --- a/drivers/media/radio/radio-shark.c
45377 +++ b/drivers/media/radio/radio-shark.c
45378 @@ -79,7 +79,7 @@ struct shark_device {
45379 u32 last_val;
45380 };
45381
45382 -static atomic_t shark_instance = ATOMIC_INIT(0);
45383 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45384
45385 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45386 {
45387 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45388 index 8654e0d..0608a64 100644
45389 --- a/drivers/media/radio/radio-shark2.c
45390 +++ b/drivers/media/radio/radio-shark2.c
45391 @@ -74,7 +74,7 @@ struct shark_device {
45392 u8 *transfer_buffer;
45393 };
45394
45395 -static atomic_t shark_instance = ATOMIC_INIT(0);
45396 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45397
45398 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45399 {
45400 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45401 index 633022b..7f10754 100644
45402 --- a/drivers/media/radio/radio-si476x.c
45403 +++ b/drivers/media/radio/radio-si476x.c
45404 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45405 struct si476x_radio *radio;
45406 struct v4l2_ctrl *ctrl;
45407
45408 - static atomic_t instance = ATOMIC_INIT(0);
45409 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45410
45411 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45412 if (!radio)
45413 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45414 index 9fd1527..8927230 100644
45415 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45416 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45417 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45418
45419 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45420 {
45421 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45422 - char result[64];
45423 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45424 - sizeof(result), 0);
45425 + char *buf;
45426 + char *result;
45427 + int retval;
45428 +
45429 + buf = kmalloc(2, GFP_KERNEL);
45430 + if (buf == NULL)
45431 + return -ENOMEM;
45432 + result = kmalloc(64, GFP_KERNEL);
45433 + if (result == NULL) {
45434 + kfree(buf);
45435 + return -ENOMEM;
45436 + }
45437 +
45438 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45439 + buf[1] = enable ? 1 : 0;
45440 +
45441 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45442 +
45443 + kfree(buf);
45444 + kfree(result);
45445 + return retval;
45446 }
45447
45448 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45449 {
45450 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45451 - char state[3];
45452 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45453 + char *buf;
45454 + char *state;
45455 + int retval;
45456 +
45457 + buf = kmalloc(2, GFP_KERNEL);
45458 + if (buf == NULL)
45459 + return -ENOMEM;
45460 + state = kmalloc(3, GFP_KERNEL);
45461 + if (state == NULL) {
45462 + kfree(buf);
45463 + return -ENOMEM;
45464 + }
45465 +
45466 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45467 + buf[1] = enable ? 1 : 0;
45468 +
45469 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45470 +
45471 + kfree(buf);
45472 + kfree(state);
45473 + return retval;
45474 }
45475
45476 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45477 {
45478 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45479 - char state[3];
45480 + char *query;
45481 + char *state;
45482 int ret;
45483 + query = kmalloc(1, GFP_KERNEL);
45484 + if (query == NULL)
45485 + return -ENOMEM;
45486 + state = kmalloc(3, GFP_KERNEL);
45487 + if (state == NULL) {
45488 + kfree(query);
45489 + return -ENOMEM;
45490 + }
45491 +
45492 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45493
45494 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45495
45496 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45497 - sizeof(state), 0);
45498 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45499 if (ret < 0) {
45500 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45501 "state info\n");
45502 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45503
45504 /* Copy this pointer as we are gonna need it in the release phase */
45505 cinergyt2_usb_device = adap->dev;
45506 -
45507 + kfree(query);
45508 + kfree(state);
45509 return 0;
45510 }
45511
45512 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45513 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45514 {
45515 struct cinergyt2_state *st = d->priv;
45516 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45517 + u8 *key, *cmd;
45518 int i;
45519
45520 + cmd = kmalloc(1, GFP_KERNEL);
45521 + if (cmd == NULL)
45522 + return -EINVAL;
45523 + key = kzalloc(5, GFP_KERNEL);
45524 + if (key == NULL) {
45525 + kfree(cmd);
45526 + return -EINVAL;
45527 + }
45528 +
45529 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45530 +
45531 *state = REMOTE_NO_KEY_PRESSED;
45532
45533 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45534 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45535 if (key[4] == 0xff) {
45536 /* key repeat */
45537 st->rc_counter++;
45538 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45539 *event = d->last_event;
45540 deb_rc("repeat key, event %x\n",
45541 *event);
45542 - return 0;
45543 + goto out;
45544 }
45545 }
45546 deb_rc("repeated key (non repeatable)\n");
45547 }
45548 - return 0;
45549 + goto out;
45550 }
45551
45552 /* hack to pass checksum on the custom field */
45553 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45554
45555 deb_rc("key: %*ph\n", 5, key);
45556 }
45557 +out:
45558 + kfree(cmd);
45559 + kfree(key);
45560 return 0;
45561 }
45562
45563 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45564 index c890fe4..f9b2ae6 100644
45565 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45566 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45567 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45568 fe_status_t *status)
45569 {
45570 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45571 - struct dvbt_get_status_msg result;
45572 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45573 + struct dvbt_get_status_msg *result;
45574 + u8 *cmd;
45575 int ret;
45576
45577 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45578 - sizeof(result), 0);
45579 + cmd = kmalloc(1, GFP_KERNEL);
45580 + if (cmd == NULL)
45581 + return -ENOMEM;
45582 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45583 + if (result == NULL) {
45584 + kfree(cmd);
45585 + return -ENOMEM;
45586 + }
45587 +
45588 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45589 +
45590 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45591 + sizeof(*result), 0);
45592 if (ret < 0)
45593 - return ret;
45594 + goto out;
45595
45596 *status = 0;
45597
45598 - if (0xffff - le16_to_cpu(result.gain) > 30)
45599 + if (0xffff - le16_to_cpu(result->gain) > 30)
45600 *status |= FE_HAS_SIGNAL;
45601 - if (result.lock_bits & (1 << 6))
45602 + if (result->lock_bits & (1 << 6))
45603 *status |= FE_HAS_LOCK;
45604 - if (result.lock_bits & (1 << 5))
45605 + if (result->lock_bits & (1 << 5))
45606 *status |= FE_HAS_SYNC;
45607 - if (result.lock_bits & (1 << 4))
45608 + if (result->lock_bits & (1 << 4))
45609 *status |= FE_HAS_CARRIER;
45610 - if (result.lock_bits & (1 << 1))
45611 + if (result->lock_bits & (1 << 1))
45612 *status |= FE_HAS_VITERBI;
45613
45614 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45615 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45616 *status &= ~FE_HAS_LOCK;
45617
45618 - return 0;
45619 +out:
45620 + kfree(cmd);
45621 + kfree(result);
45622 + return ret;
45623 }
45624
45625 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45626 {
45627 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45628 - struct dvbt_get_status_msg status;
45629 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45630 + struct dvbt_get_status_msg *status;
45631 + char *cmd;
45632 int ret;
45633
45634 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45635 - sizeof(status), 0);
45636 + cmd = kmalloc(1, GFP_KERNEL);
45637 + if (cmd == NULL)
45638 + return -ENOMEM;
45639 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45640 + if (status == NULL) {
45641 + kfree(cmd);
45642 + return -ENOMEM;
45643 + }
45644 +
45645 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45646 +
45647 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45648 + sizeof(*status), 0);
45649 if (ret < 0)
45650 - return ret;
45651 + goto out;
45652
45653 - *ber = le32_to_cpu(status.viterbi_error_rate);
45654 + *ber = le32_to_cpu(status->viterbi_error_rate);
45655 +out:
45656 + kfree(cmd);
45657 + kfree(status);
45658 return 0;
45659 }
45660
45661 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45662 {
45663 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45664 - struct dvbt_get_status_msg status;
45665 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45666 + struct dvbt_get_status_msg *status;
45667 + u8 *cmd;
45668 int ret;
45669
45670 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45671 - sizeof(status), 0);
45672 + cmd = kmalloc(1, GFP_KERNEL);
45673 + if (cmd == NULL)
45674 + return -ENOMEM;
45675 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45676 + if (status == NULL) {
45677 + kfree(cmd);
45678 + return -ENOMEM;
45679 + }
45680 +
45681 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45682 +
45683 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45684 + sizeof(*status), 0);
45685 if (ret < 0) {
45686 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45687 ret);
45688 - return ret;
45689 + goto out;
45690 }
45691 - *unc = le32_to_cpu(status.uncorrected_block_count);
45692 - return 0;
45693 + *unc = le32_to_cpu(status->uncorrected_block_count);
45694 +
45695 +out:
45696 + kfree(cmd);
45697 + kfree(status);
45698 + return ret;
45699 }
45700
45701 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45702 u16 *strength)
45703 {
45704 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45705 - struct dvbt_get_status_msg status;
45706 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45707 + struct dvbt_get_status_msg *status;
45708 + char *cmd;
45709 int ret;
45710
45711 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45712 - sizeof(status), 0);
45713 + cmd = kmalloc(1, GFP_KERNEL);
45714 + if (cmd == NULL)
45715 + return -ENOMEM;
45716 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45717 + if (status == NULL) {
45718 + kfree(cmd);
45719 + return -ENOMEM;
45720 + }
45721 +
45722 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45723 +
45724 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45725 + sizeof(*status), 0);
45726 if (ret < 0) {
45727 err("cinergyt2_fe_read_signal_strength() Failed!"
45728 " (Error=%d)\n", ret);
45729 - return ret;
45730 + goto out;
45731 }
45732 - *strength = (0xffff - le16_to_cpu(status.gain));
45733 + *strength = (0xffff - le16_to_cpu(status->gain));
45734 +
45735 +out:
45736 + kfree(cmd);
45737 + kfree(status);
45738 return 0;
45739 }
45740
45741 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45742 {
45743 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45744 - struct dvbt_get_status_msg status;
45745 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45746 + struct dvbt_get_status_msg *status;
45747 + char *cmd;
45748 int ret;
45749
45750 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45751 - sizeof(status), 0);
45752 + cmd = kmalloc(1, GFP_KERNEL);
45753 + if (cmd == NULL)
45754 + return -ENOMEM;
45755 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45756 + if (status == NULL) {
45757 + kfree(cmd);
45758 + return -ENOMEM;
45759 + }
45760 +
45761 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45762 +
45763 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45764 + sizeof(*status), 0);
45765 if (ret < 0) {
45766 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45767 - return ret;
45768 + goto out;
45769 }
45770 - *snr = (status.snr << 8) | status.snr;
45771 - return 0;
45772 + *snr = (status->snr << 8) | status->snr;
45773 +
45774 +out:
45775 + kfree(cmd);
45776 + kfree(status);
45777 + return ret;
45778 }
45779
45780 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45781 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45782 {
45783 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45784 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45785 - struct dvbt_set_parameters_msg param;
45786 - char result[2];
45787 + struct dvbt_set_parameters_msg *param;
45788 + char *result;
45789 int err;
45790
45791 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45792 - param.tps = cpu_to_le16(compute_tps(fep));
45793 - param.freq = cpu_to_le32(fep->frequency / 1000);
45794 - param.flags = 0;
45795 + result = kmalloc(2, GFP_KERNEL);
45796 + if (result == NULL)
45797 + return -ENOMEM;
45798 + param = kmalloc(sizeof(*param), GFP_KERNEL);
45799 + if (param == NULL) {
45800 + kfree(result);
45801 + return -ENOMEM;
45802 + }
45803 +
45804 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45805 + param->tps = cpu_to_le16(compute_tps(fep));
45806 + param->freq = cpu_to_le32(fep->frequency / 1000);
45807 + param->flags = 0;
45808
45809 switch (fep->bandwidth_hz) {
45810 default:
45811 case 8000000:
45812 - param.bandwidth = 8;
45813 + param->bandwidth = 8;
45814 break;
45815 case 7000000:
45816 - param.bandwidth = 7;
45817 + param->bandwidth = 7;
45818 break;
45819 case 6000000:
45820 - param.bandwidth = 6;
45821 + param->bandwidth = 6;
45822 break;
45823 }
45824
45825 err = dvb_usb_generic_rw(state->d,
45826 - (char *)&param, sizeof(param),
45827 - result, sizeof(result), 0);
45828 + (char *)param, sizeof(*param),
45829 + result, 2, 0);
45830 if (err < 0)
45831 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45832
45833 - return (err < 0) ? err : 0;
45834 + kfree(result);
45835 + kfree(param);
45836 + return err;
45837 }
45838
45839 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45840 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45841 index 733a7ff..f8b52e3 100644
45842 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45843 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45844 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45845
45846 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45847 {
45848 - struct hexline hx;
45849 - u8 reset;
45850 + struct hexline *hx;
45851 + u8 *reset;
45852 int ret,pos=0;
45853
45854 + reset = kmalloc(1, GFP_KERNEL);
45855 + if (reset == NULL)
45856 + return -ENOMEM;
45857 +
45858 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45859 + if (hx == NULL) {
45860 + kfree(reset);
45861 + return -ENOMEM;
45862 + }
45863 +
45864 /* stop the CPU */
45865 - reset = 1;
45866 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45867 + reset[0] = 1;
45868 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45869 err("could not stop the USB controller CPU.");
45870
45871 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45872 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45873 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45874 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45875 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45876 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45877
45878 - if (ret != hx.len) {
45879 + if (ret != hx->len) {
45880 err("error while transferring firmware "
45881 "(transferred size: %d, block size: %d)",
45882 - ret,hx.len);
45883 + ret,hx->len);
45884 ret = -EINVAL;
45885 break;
45886 }
45887 }
45888 if (ret < 0) {
45889 err("firmware download failed at %d with %d",pos,ret);
45890 + kfree(reset);
45891 + kfree(hx);
45892 return ret;
45893 }
45894
45895 if (ret == 0) {
45896 /* restart the CPU */
45897 - reset = 0;
45898 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45899 + reset[0] = 0;
45900 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45901 err("could not restart the USB controller CPU.");
45902 ret = -EINVAL;
45903 }
45904 } else
45905 ret = -EIO;
45906
45907 + kfree(reset);
45908 + kfree(hx);
45909 +
45910 return ret;
45911 }
45912 EXPORT_SYMBOL(usb_cypress_load_firmware);
45913 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45914 index 1a3df10..57997a5 100644
45915 --- a/drivers/media/usb/dvb-usb/dw2102.c
45916 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45917 @@ -118,7 +118,7 @@ struct su3000_state {
45918
45919 struct s6x0_state {
45920 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45921 -};
45922 +} __no_const;
45923
45924 /* debug */
45925 static int dvb_usb_dw2102_debug;
45926 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45927 index 6b0b8b6b..4038398 100644
45928 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45929 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45930 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
45931 static int technisat_usb2_i2c_access(struct usb_device *udev,
45932 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45933 {
45934 - u8 b[64];
45935 - int ret, actual_length;
45936 + u8 *b = kmalloc(64, GFP_KERNEL);
45937 + int ret, actual_length, error = 0;
45938 +
45939 + if (b == NULL)
45940 + return -ENOMEM;
45941
45942 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45943 debug_dump(tx, txlen, deb_i2c);
45944 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45945
45946 if (ret < 0) {
45947 err("i2c-error: out failed %02x = %d", device_addr, ret);
45948 - return -ENODEV;
45949 + error = -ENODEV;
45950 + goto out;
45951 }
45952
45953 ret = usb_bulk_msg(udev,
45954 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45955 b, 64, &actual_length, 1000);
45956 if (ret < 0) {
45957 err("i2c-error: in failed %02x = %d", device_addr, ret);
45958 - return -ENODEV;
45959 + error = -ENODEV;
45960 + goto out;
45961 }
45962
45963 if (b[0] != I2C_STATUS_OK) {
45964 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45965 /* handle tuner-i2c-nak */
45966 if (!(b[0] == I2C_STATUS_NAK &&
45967 device_addr == 0x60
45968 - /* && device_is_technisat_usb2 */))
45969 - return -ENODEV;
45970 + /* && device_is_technisat_usb2 */)) {
45971 + error = -ENODEV;
45972 + goto out;
45973 + }
45974 }
45975
45976 deb_i2c("status: %d, ", b[0]);
45977 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45978
45979 deb_i2c("\n");
45980
45981 - return 0;
45982 +out:
45983 + kfree(b);
45984 + return error;
45985 }
45986
45987 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
45988 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45989 {
45990 int ret;
45991
45992 - u8 led[8] = {
45993 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45994 - 0
45995 - };
45996 + u8 *led = kzalloc(8, GFP_KERNEL);
45997 +
45998 + if (led == NULL)
45999 + return -ENOMEM;
46000
46001 if (disable_led_control && state != TECH_LED_OFF)
46002 return 0;
46003
46004 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46005 +
46006 switch (state) {
46007 case TECH_LED_ON:
46008 led[1] = 0x82;
46009 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46010 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46011 USB_TYPE_VENDOR | USB_DIR_OUT,
46012 0, 0,
46013 - led, sizeof(led), 500);
46014 + led, 8, 500);
46015
46016 mutex_unlock(&d->i2c_mutex);
46017 +
46018 + kfree(led);
46019 +
46020 return ret;
46021 }
46022
46023 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46024 {
46025 int ret;
46026 - u8 b = 0;
46027 + u8 *b = kzalloc(1, GFP_KERNEL);
46028 +
46029 + if (b == NULL)
46030 + return -ENOMEM;
46031
46032 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46033 return -EAGAIN;
46034 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46035 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46036 USB_TYPE_VENDOR | USB_DIR_OUT,
46037 (red << 8) | green, 0,
46038 - &b, 1, 500);
46039 + b, 1, 500);
46040
46041 mutex_unlock(&d->i2c_mutex);
46042
46043 + kfree(b);
46044 +
46045 return ret;
46046 }
46047
46048 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46049 struct dvb_usb_device_description **desc, int *cold)
46050 {
46051 int ret;
46052 - u8 version[3];
46053 + u8 *version = kmalloc(3, GFP_KERNEL);
46054
46055 /* first select the interface */
46056 if (usb_set_interface(udev, 0, 1) != 0)
46057 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46058
46059 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46060
46061 + if (version == NULL)
46062 + return 0;
46063 +
46064 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46065 GET_VERSION_INFO_VENDOR_REQUEST,
46066 USB_TYPE_VENDOR | USB_DIR_IN,
46067 0, 0,
46068 - version, sizeof(version), 500);
46069 + version, 3, 500);
46070
46071 if (ret < 0)
46072 *cold = 1;
46073 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46074 *cold = 0;
46075 }
46076
46077 + kfree(version);
46078 +
46079 return 0;
46080 }
46081
46082 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46083
46084 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46085 {
46086 - u8 buf[62], *b;
46087 + u8 *buf, *b;
46088 int ret;
46089 struct ir_raw_event ev;
46090
46091 + buf = kmalloc(62, GFP_KERNEL);
46092 +
46093 + if (buf == NULL)
46094 + return -ENOMEM;
46095 +
46096 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46097 buf[1] = 0x08;
46098 buf[2] = 0x8f;
46099 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46100 GET_IR_DATA_VENDOR_REQUEST,
46101 USB_TYPE_VENDOR | USB_DIR_IN,
46102 0x8080, 0,
46103 - buf, sizeof(buf), 500);
46104 + buf, 62, 500);
46105
46106 unlock:
46107 mutex_unlock(&d->i2c_mutex);
46108
46109 - if (ret < 0)
46110 + if (ret < 0) {
46111 + kfree(buf);
46112 return ret;
46113 + }
46114
46115 - if (ret == 1)
46116 + if (ret == 1) {
46117 + kfree(buf);
46118 return 0; /* no key pressed */
46119 + }
46120
46121 /* decoding */
46122 b = buf+1;
46123 @@ -653,6 +686,8 @@ unlock:
46124
46125 ir_raw_event_handle(d->rc_dev);
46126
46127 + kfree(buf);
46128 +
46129 return 1;
46130 }
46131
46132 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46133 index e502a5f..2a27f40 100644
46134 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46135 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46136 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46137 * by passing a very big num_planes value */
46138 uplane = compat_alloc_user_space(num_planes *
46139 sizeof(struct v4l2_plane));
46140 - kp->m.planes = (__force struct v4l2_plane *)uplane;
46141 + kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46142
46143 while (--num_planes >= 0) {
46144 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46145 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46146 if (num_planes == 0)
46147 return 0;
46148
46149 - uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46150 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46151 if (get_user(p, &up->m.planes))
46152 return -EFAULT;
46153 uplane32 = compat_ptr(p);
46154 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46155 get_user(kp->flags, &up->flags) ||
46156 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46157 return -EFAULT;
46158 - kp->base = (__force void *)compat_ptr(tmp);
46159 + kp->base = (__force_kernel void *)compat_ptr(tmp);
46160 return 0;
46161 }
46162
46163 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46164 n * sizeof(struct v4l2_ext_control32)))
46165 return -EFAULT;
46166 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46167 - kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46168 + kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46169 while (--n >= 0) {
46170 u32 id;
46171
46172 @@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46173 {
46174 struct v4l2_ext_control32 __user *ucontrols;
46175 struct v4l2_ext_control __user *kcontrols =
46176 - (__force struct v4l2_ext_control __user *)kp->controls;
46177 + (struct v4l2_ext_control __force_user *)kp->controls;
46178 int n = kp->count;
46179 compat_caddr_t p;
46180
46181 @@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46182 get_user(tmp, &up->edid) ||
46183 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46184 return -EFAULT;
46185 - kp->edid = (__force u8 *)compat_ptr(tmp);
46186 + kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46187 return 0;
46188 }
46189
46190 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46191 index 015f92a..59e311e 100644
46192 --- a/drivers/media/v4l2-core/v4l2-device.c
46193 +++ b/drivers/media/v4l2-core/v4l2-device.c
46194 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46195 EXPORT_SYMBOL_GPL(v4l2_device_put);
46196
46197 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46198 - atomic_t *instance)
46199 + atomic_unchecked_t *instance)
46200 {
46201 - int num = atomic_inc_return(instance) - 1;
46202 + int num = atomic_inc_return_unchecked(instance) - 1;
46203 int len = strlen(basename);
46204
46205 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46206 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46207 index 9ccb19a..d131468 100644
46208 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46209 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46210 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46211 struct file *file, void *fh, void *p);
46212 } u;
46213 void (*debug)(const void *arg, bool write_only);
46214 -};
46215 +} __do_const;
46216 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46217
46218 /* This control needs a priority check */
46219 #define INFO_FL_PRIO (1 << 0)
46220 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46221 struct video_device *vfd = video_devdata(file);
46222 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46223 bool write_only = false;
46224 - struct v4l2_ioctl_info default_info;
46225 + v4l2_ioctl_info_no_const default_info;
46226 const struct v4l2_ioctl_info *info;
46227 void *fh = file->private_data;
46228 struct v4l2_fh *vfh = NULL;
46229 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46230 ret = -EINVAL;
46231 break;
46232 }
46233 - *user_ptr = (void __user *)buf->m.planes;
46234 + *user_ptr = (void __force_user *)buf->m.planes;
46235 *kernel_ptr = (void **)&buf->m.planes;
46236 *array_size = sizeof(struct v4l2_plane) * buf->length;
46237 ret = 1;
46238 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46239 ret = -EINVAL;
46240 break;
46241 }
46242 - *user_ptr = (void __user *)edid->edid;
46243 + *user_ptr = (void __force_user *)edid->edid;
46244 *kernel_ptr = (void **)&edid->edid;
46245 *array_size = edid->blocks * 128;
46246 ret = 1;
46247 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46248 ret = -EINVAL;
46249 break;
46250 }
46251 - *user_ptr = (void __user *)ctrls->controls;
46252 + *user_ptr = (void __force_user *)ctrls->controls;
46253 *kernel_ptr = (void **)&ctrls->controls;
46254 *array_size = sizeof(struct v4l2_ext_control)
46255 * ctrls->count;
46256 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46257 }
46258
46259 if (has_array_args) {
46260 - *kernel_ptr = (void __force *)user_ptr;
46261 + *kernel_ptr = (void __force_kernel *)user_ptr;
46262 if (copy_to_user(user_ptr, mbuf, array_size))
46263 err = -EFAULT;
46264 goto out_array_args;
46265 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46266 index 187f836..679544b 100644
46267 --- a/drivers/message/fusion/mptbase.c
46268 +++ b/drivers/message/fusion/mptbase.c
46269 @@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46270 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46271 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46272
46273 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46274 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46275 +#else
46276 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46277 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46278 +#endif
46279 +
46280 /*
46281 * Rounding UP to nearest 4-kB boundary here...
46282 */
46283 @@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46284 ioc->facts.GlobalCredits);
46285
46286 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46287 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46288 + NULL, NULL);
46289 +#else
46290 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46291 +#endif
46292 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46293 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46294 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46295 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46296 index 0707fa2..70ca794 100644
46297 --- a/drivers/message/fusion/mptsas.c
46298 +++ b/drivers/message/fusion/mptsas.c
46299 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46300 return 0;
46301 }
46302
46303 +static inline void
46304 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46305 +{
46306 + if (phy_info->port_details) {
46307 + phy_info->port_details->rphy = rphy;
46308 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46309 + ioc->name, rphy));
46310 + }
46311 +
46312 + if (rphy) {
46313 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46314 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46315 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46316 + ioc->name, rphy, rphy->dev.release));
46317 + }
46318 +}
46319 +
46320 /* no mutex */
46321 static void
46322 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46323 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46324 return NULL;
46325 }
46326
46327 -static inline void
46328 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46329 -{
46330 - if (phy_info->port_details) {
46331 - phy_info->port_details->rphy = rphy;
46332 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46333 - ioc->name, rphy));
46334 - }
46335 -
46336 - if (rphy) {
46337 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46338 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46339 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46340 - ioc->name, rphy, rphy->dev.release));
46341 - }
46342 -}
46343 -
46344 static inline struct sas_port *
46345 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46346 {
46347 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46348 index b7d87cd..3fb36da 100644
46349 --- a/drivers/message/i2o/i2o_proc.c
46350 +++ b/drivers/message/i2o/i2o_proc.c
46351 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46352 "Array Controller Device"
46353 };
46354
46355 -static char *chtostr(char *tmp, u8 *chars, int n)
46356 -{
46357 - tmp[0] = 0;
46358 - return strncat(tmp, (char *)chars, n);
46359 -}
46360 -
46361 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46362 char *group)
46363 {
46364 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46365 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46366 {
46367 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46368 - static u32 work32[5];
46369 - static u8 *work8 = (u8 *) work32;
46370 - static u16 *work16 = (u16 *) work32;
46371 + u32 work32[5];
46372 + u8 *work8 = (u8 *) work32;
46373 + u16 *work16 = (u16 *) work32;
46374 int token;
46375 u32 hwcap;
46376
46377 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46378 } *result;
46379
46380 i2o_exec_execute_ddm_table ddm_table;
46381 - char tmp[28 + 1];
46382
46383 result = kmalloc(sizeof(*result), GFP_KERNEL);
46384 if (!result)
46385 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46386
46387 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46388 seq_printf(seq, "%-#8x", ddm_table.module_id);
46389 - seq_printf(seq, "%-29s",
46390 - chtostr(tmp, ddm_table.module_name_version, 28));
46391 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46392 seq_printf(seq, "%9d ", ddm_table.data_size);
46393 seq_printf(seq, "%8d", ddm_table.code_size);
46394
46395 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46396
46397 i2o_driver_result_table *result;
46398 i2o_driver_store_table *dst;
46399 - char tmp[28 + 1];
46400
46401 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46402 if (result == NULL)
46403 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46404
46405 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46406 seq_printf(seq, "%-#8x", dst->module_id);
46407 - seq_printf(seq, "%-29s",
46408 - chtostr(tmp, dst->module_name_version, 28));
46409 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46410 + seq_printf(seq, "%-.28s", dst->module_name_version);
46411 + seq_printf(seq, "%-.8s", dst->date);
46412 seq_printf(seq, "%8d ", dst->module_size);
46413 seq_printf(seq, "%8d ", dst->mpb_size);
46414 seq_printf(seq, "0x%04x", dst->module_flags);
46415 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46416 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46417 {
46418 struct i2o_device *d = (struct i2o_device *)seq->private;
46419 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46420 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46421 // == (allow) 512d bytes (max)
46422 - static u16 *work16 = (u16 *) work32;
46423 + u16 *work16 = (u16 *) work32;
46424 int token;
46425 - char tmp[16 + 1];
46426
46427 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46428
46429 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46430 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46431 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46432 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46433 - seq_printf(seq, "Vendor info : %s\n",
46434 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46435 - seq_printf(seq, "Product info : %s\n",
46436 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46437 - seq_printf(seq, "Description : %s\n",
46438 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46439 - seq_printf(seq, "Product rev. : %s\n",
46440 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46441 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46442 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46443 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46444 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46445
46446 seq_printf(seq, "Serial number : ");
46447 print_serial_number(seq, (u8 *) (work32 + 16),
46448 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46449 u8 pad[256]; // allow up to 256 byte (max) serial number
46450 } result;
46451
46452 - char tmp[24 + 1];
46453 -
46454 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46455
46456 if (token < 0) {
46457 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46458 }
46459
46460 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46461 - seq_printf(seq, "Module name : %s\n",
46462 - chtostr(tmp, result.module_name, 24));
46463 - seq_printf(seq, "Module revision : %s\n",
46464 - chtostr(tmp, result.module_rev, 8));
46465 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46466 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46467
46468 seq_printf(seq, "Serial number : ");
46469 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46470 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46471 u8 instance_number[4];
46472 } result;
46473
46474 - char tmp[64 + 1];
46475 -
46476 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46477
46478 if (token < 0) {
46479 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46480 return 0;
46481 }
46482
46483 - seq_printf(seq, "Device name : %s\n",
46484 - chtostr(tmp, result.device_name, 64));
46485 - seq_printf(seq, "Service name : %s\n",
46486 - chtostr(tmp, result.service_name, 64));
46487 - seq_printf(seq, "Physical name : %s\n",
46488 - chtostr(tmp, result.physical_location, 64));
46489 - seq_printf(seq, "Instance number : %s\n",
46490 - chtostr(tmp, result.instance_number, 4));
46491 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46492 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46493 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46494 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46495
46496 return 0;
46497 }
46498 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46499 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46500 {
46501 struct i2o_device *d = (struct i2o_device *)seq->private;
46502 - static u32 work32[12];
46503 - static u16 *work16 = (u16 *) work32;
46504 - static u8 *work8 = (u8 *) work32;
46505 + u32 work32[12];
46506 + u16 *work16 = (u16 *) work32;
46507 + u8 *work8 = (u8 *) work32;
46508 int token;
46509
46510 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46511 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46512 index 92752fb..a7494f6 100644
46513 --- a/drivers/message/i2o/iop.c
46514 +++ b/drivers/message/i2o/iop.c
46515 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46516
46517 spin_lock_irqsave(&c->context_list_lock, flags);
46518
46519 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46520 - atomic_inc(&c->context_list_counter);
46521 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46522 + atomic_inc_unchecked(&c->context_list_counter);
46523
46524 - entry->context = atomic_read(&c->context_list_counter);
46525 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46526
46527 list_add(&entry->list, &c->context_list);
46528
46529 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46530
46531 #if BITS_PER_LONG == 64
46532 spin_lock_init(&c->context_list_lock);
46533 - atomic_set(&c->context_list_counter, 0);
46534 + atomic_set_unchecked(&c->context_list_counter, 0);
46535 INIT_LIST_HEAD(&c->context_list);
46536 #endif
46537
46538 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46539 index b2c7e3b..85aa4764 100644
46540 --- a/drivers/mfd/ab8500-debugfs.c
46541 +++ b/drivers/mfd/ab8500-debugfs.c
46542 @@ -100,7 +100,7 @@ static int irq_last;
46543 static u32 *irq_count;
46544 static int num_irqs;
46545
46546 -static struct device_attribute **dev_attr;
46547 +static device_attribute_no_const **dev_attr;
46548 static char **event_name;
46549
46550 static u8 avg_sample = SAMPLE_16;
46551 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46552 index c880c89..45a7c68 100644
46553 --- a/drivers/mfd/max8925-i2c.c
46554 +++ b/drivers/mfd/max8925-i2c.c
46555 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46556 const struct i2c_device_id *id)
46557 {
46558 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46559 - static struct max8925_chip *chip;
46560 + struct max8925_chip *chip;
46561 struct device_node *node = client->dev.of_node;
46562
46563 if (node && !pdata) {
46564 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46565 index 7612d89..70549c2 100644
46566 --- a/drivers/mfd/tps65910.c
46567 +++ b/drivers/mfd/tps65910.c
46568 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46569 struct tps65910_platform_data *pdata)
46570 {
46571 int ret = 0;
46572 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46573 + struct regmap_irq_chip *tps6591x_irqs_chip;
46574
46575 if (!irq) {
46576 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46577 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46578 index 1b772ef..01e77d33 100644
46579 --- a/drivers/mfd/twl4030-irq.c
46580 +++ b/drivers/mfd/twl4030-irq.c
46581 @@ -34,6 +34,7 @@
46582 #include <linux/of.h>
46583 #include <linux/irqdomain.h>
46584 #include <linux/i2c/twl.h>
46585 +#include <asm/pgtable.h>
46586
46587 #include "twl-core.h"
46588
46589 @@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46590 * Install an irq handler for each of the SIH modules;
46591 * clone dummy irq_chip since PIH can't *do* anything
46592 */
46593 - twl4030_irq_chip = dummy_irq_chip;
46594 - twl4030_irq_chip.name = "twl4030";
46595 + pax_open_kernel();
46596 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46597 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46598
46599 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46600 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46601 + pax_close_kernel();
46602
46603 for (i = irq_base; i < irq_end; i++) {
46604 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46605 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46606 index 464419b..64bae8d 100644
46607 --- a/drivers/misc/c2port/core.c
46608 +++ b/drivers/misc/c2port/core.c
46609 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46610 goto error_idr_alloc;
46611 c2dev->id = ret;
46612
46613 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46614 + pax_open_kernel();
46615 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46616 + pax_close_kernel();
46617
46618 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46619 "c2port%d", c2dev->id);
46620 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46621 index 3f2b625..945e179 100644
46622 --- a/drivers/misc/eeprom/sunxi_sid.c
46623 +++ b/drivers/misc/eeprom/sunxi_sid.c
46624 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46625
46626 platform_set_drvdata(pdev, sid_data);
46627
46628 - sid_bin_attr.size = sid_data->keysize;
46629 + pax_open_kernel();
46630 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46631 + pax_close_kernel();
46632 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46633 return -ENODEV;
46634
46635 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46636 index 36f5d52..32311c3 100644
46637 --- a/drivers/misc/kgdbts.c
46638 +++ b/drivers/misc/kgdbts.c
46639 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46640 char before[BREAK_INSTR_SIZE];
46641 char after[BREAK_INSTR_SIZE];
46642
46643 - probe_kernel_read(before, (char *)kgdbts_break_test,
46644 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46645 BREAK_INSTR_SIZE);
46646 init_simple_test();
46647 ts.tst = plant_and_detach_test;
46648 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46649 /* Activate test with initial breakpoint */
46650 if (!is_early)
46651 kgdb_breakpoint();
46652 - probe_kernel_read(after, (char *)kgdbts_break_test,
46653 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46654 BREAK_INSTR_SIZE);
46655 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46656 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46657 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46658 index 3ef4627..8d00486 100644
46659 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
46660 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46661 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46662 * the lid is closed. This leads to interrupts as soon as a little move
46663 * is done.
46664 */
46665 - atomic_inc(&lis3->count);
46666 + atomic_inc_unchecked(&lis3->count);
46667
46668 wake_up_interruptible(&lis3->misc_wait);
46669 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46670 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46671 if (lis3->pm_dev)
46672 pm_runtime_get_sync(lis3->pm_dev);
46673
46674 - atomic_set(&lis3->count, 0);
46675 + atomic_set_unchecked(&lis3->count, 0);
46676 return 0;
46677 }
46678
46679 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46680 add_wait_queue(&lis3->misc_wait, &wait);
46681 while (true) {
46682 set_current_state(TASK_INTERRUPTIBLE);
46683 - data = atomic_xchg(&lis3->count, 0);
46684 + data = atomic_xchg_unchecked(&lis3->count, 0);
46685 if (data)
46686 break;
46687
46688 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46689 struct lis3lv02d, miscdev);
46690
46691 poll_wait(file, &lis3->misc_wait, wait);
46692 - if (atomic_read(&lis3->count))
46693 + if (atomic_read_unchecked(&lis3->count))
46694 return POLLIN | POLLRDNORM;
46695 return 0;
46696 }
46697 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46698 index c439c82..1f20f57 100644
46699 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
46700 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46701 @@ -297,7 +297,7 @@ struct lis3lv02d {
46702 struct input_polled_dev *idev; /* input device */
46703 struct platform_device *pdev; /* platform device */
46704 struct regulator_bulk_data regulators[2];
46705 - atomic_t count; /* interrupt count after last read */
46706 + atomic_unchecked_t count; /* interrupt count after last read */
46707 union axis_conversion ac; /* hw -> logical axis */
46708 int mapped_btns[3];
46709
46710 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46711 index 2f30bad..c4c13d0 100644
46712 --- a/drivers/misc/sgi-gru/gruhandles.c
46713 +++ b/drivers/misc/sgi-gru/gruhandles.c
46714 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46715 unsigned long nsec;
46716
46717 nsec = CLKS2NSEC(clks);
46718 - atomic_long_inc(&mcs_op_statistics[op].count);
46719 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
46720 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46721 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46722 if (mcs_op_statistics[op].max < nsec)
46723 mcs_op_statistics[op].max = nsec;
46724 }
46725 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46726 index 4f76359..cdfcb2e 100644
46727 --- a/drivers/misc/sgi-gru/gruprocfs.c
46728 +++ b/drivers/misc/sgi-gru/gruprocfs.c
46729 @@ -32,9 +32,9 @@
46730
46731 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46732
46733 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46734 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46735 {
46736 - unsigned long val = atomic_long_read(v);
46737 + unsigned long val = atomic_long_read_unchecked(v);
46738
46739 seq_printf(s, "%16lu %s\n", val, id);
46740 }
46741 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46742
46743 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46744 for (op = 0; op < mcsop_last; op++) {
46745 - count = atomic_long_read(&mcs_op_statistics[op].count);
46746 - total = atomic_long_read(&mcs_op_statistics[op].total);
46747 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46748 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46749 max = mcs_op_statistics[op].max;
46750 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46751 count ? total / count : 0, max);
46752 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46753 index 5c3ce24..4915ccb 100644
46754 --- a/drivers/misc/sgi-gru/grutables.h
46755 +++ b/drivers/misc/sgi-gru/grutables.h
46756 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46757 * GRU statistics.
46758 */
46759 struct gru_stats_s {
46760 - atomic_long_t vdata_alloc;
46761 - atomic_long_t vdata_free;
46762 - atomic_long_t gts_alloc;
46763 - atomic_long_t gts_free;
46764 - atomic_long_t gms_alloc;
46765 - atomic_long_t gms_free;
46766 - atomic_long_t gts_double_allocate;
46767 - atomic_long_t assign_context;
46768 - atomic_long_t assign_context_failed;
46769 - atomic_long_t free_context;
46770 - atomic_long_t load_user_context;
46771 - atomic_long_t load_kernel_context;
46772 - atomic_long_t lock_kernel_context;
46773 - atomic_long_t unlock_kernel_context;
46774 - atomic_long_t steal_user_context;
46775 - atomic_long_t steal_kernel_context;
46776 - atomic_long_t steal_context_failed;
46777 - atomic_long_t nopfn;
46778 - atomic_long_t asid_new;
46779 - atomic_long_t asid_next;
46780 - atomic_long_t asid_wrap;
46781 - atomic_long_t asid_reuse;
46782 - atomic_long_t intr;
46783 - atomic_long_t intr_cbr;
46784 - atomic_long_t intr_tfh;
46785 - atomic_long_t intr_spurious;
46786 - atomic_long_t intr_mm_lock_failed;
46787 - atomic_long_t call_os;
46788 - atomic_long_t call_os_wait_queue;
46789 - atomic_long_t user_flush_tlb;
46790 - atomic_long_t user_unload_context;
46791 - atomic_long_t user_exception;
46792 - atomic_long_t set_context_option;
46793 - atomic_long_t check_context_retarget_intr;
46794 - atomic_long_t check_context_unload;
46795 - atomic_long_t tlb_dropin;
46796 - atomic_long_t tlb_preload_page;
46797 - atomic_long_t tlb_dropin_fail_no_asid;
46798 - atomic_long_t tlb_dropin_fail_upm;
46799 - atomic_long_t tlb_dropin_fail_invalid;
46800 - atomic_long_t tlb_dropin_fail_range_active;
46801 - atomic_long_t tlb_dropin_fail_idle;
46802 - atomic_long_t tlb_dropin_fail_fmm;
46803 - atomic_long_t tlb_dropin_fail_no_exception;
46804 - atomic_long_t tfh_stale_on_fault;
46805 - atomic_long_t mmu_invalidate_range;
46806 - atomic_long_t mmu_invalidate_page;
46807 - atomic_long_t flush_tlb;
46808 - atomic_long_t flush_tlb_gru;
46809 - atomic_long_t flush_tlb_gru_tgh;
46810 - atomic_long_t flush_tlb_gru_zero_asid;
46811 + atomic_long_unchecked_t vdata_alloc;
46812 + atomic_long_unchecked_t vdata_free;
46813 + atomic_long_unchecked_t gts_alloc;
46814 + atomic_long_unchecked_t gts_free;
46815 + atomic_long_unchecked_t gms_alloc;
46816 + atomic_long_unchecked_t gms_free;
46817 + atomic_long_unchecked_t gts_double_allocate;
46818 + atomic_long_unchecked_t assign_context;
46819 + atomic_long_unchecked_t assign_context_failed;
46820 + atomic_long_unchecked_t free_context;
46821 + atomic_long_unchecked_t load_user_context;
46822 + atomic_long_unchecked_t load_kernel_context;
46823 + atomic_long_unchecked_t lock_kernel_context;
46824 + atomic_long_unchecked_t unlock_kernel_context;
46825 + atomic_long_unchecked_t steal_user_context;
46826 + atomic_long_unchecked_t steal_kernel_context;
46827 + atomic_long_unchecked_t steal_context_failed;
46828 + atomic_long_unchecked_t nopfn;
46829 + atomic_long_unchecked_t asid_new;
46830 + atomic_long_unchecked_t asid_next;
46831 + atomic_long_unchecked_t asid_wrap;
46832 + atomic_long_unchecked_t asid_reuse;
46833 + atomic_long_unchecked_t intr;
46834 + atomic_long_unchecked_t intr_cbr;
46835 + atomic_long_unchecked_t intr_tfh;
46836 + atomic_long_unchecked_t intr_spurious;
46837 + atomic_long_unchecked_t intr_mm_lock_failed;
46838 + atomic_long_unchecked_t call_os;
46839 + atomic_long_unchecked_t call_os_wait_queue;
46840 + atomic_long_unchecked_t user_flush_tlb;
46841 + atomic_long_unchecked_t user_unload_context;
46842 + atomic_long_unchecked_t user_exception;
46843 + atomic_long_unchecked_t set_context_option;
46844 + atomic_long_unchecked_t check_context_retarget_intr;
46845 + atomic_long_unchecked_t check_context_unload;
46846 + atomic_long_unchecked_t tlb_dropin;
46847 + atomic_long_unchecked_t tlb_preload_page;
46848 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46849 + atomic_long_unchecked_t tlb_dropin_fail_upm;
46850 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
46851 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
46852 + atomic_long_unchecked_t tlb_dropin_fail_idle;
46853 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
46854 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46855 + atomic_long_unchecked_t tfh_stale_on_fault;
46856 + atomic_long_unchecked_t mmu_invalidate_range;
46857 + atomic_long_unchecked_t mmu_invalidate_page;
46858 + atomic_long_unchecked_t flush_tlb;
46859 + atomic_long_unchecked_t flush_tlb_gru;
46860 + atomic_long_unchecked_t flush_tlb_gru_tgh;
46861 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46862
46863 - atomic_long_t copy_gpa;
46864 - atomic_long_t read_gpa;
46865 + atomic_long_unchecked_t copy_gpa;
46866 + atomic_long_unchecked_t read_gpa;
46867
46868 - atomic_long_t mesq_receive;
46869 - atomic_long_t mesq_receive_none;
46870 - atomic_long_t mesq_send;
46871 - atomic_long_t mesq_send_failed;
46872 - atomic_long_t mesq_noop;
46873 - atomic_long_t mesq_send_unexpected_error;
46874 - atomic_long_t mesq_send_lb_overflow;
46875 - atomic_long_t mesq_send_qlimit_reached;
46876 - atomic_long_t mesq_send_amo_nacked;
46877 - atomic_long_t mesq_send_put_nacked;
46878 - atomic_long_t mesq_page_overflow;
46879 - atomic_long_t mesq_qf_locked;
46880 - atomic_long_t mesq_qf_noop_not_full;
46881 - atomic_long_t mesq_qf_switch_head_failed;
46882 - atomic_long_t mesq_qf_unexpected_error;
46883 - atomic_long_t mesq_noop_unexpected_error;
46884 - atomic_long_t mesq_noop_lb_overflow;
46885 - atomic_long_t mesq_noop_qlimit_reached;
46886 - atomic_long_t mesq_noop_amo_nacked;
46887 - atomic_long_t mesq_noop_put_nacked;
46888 - atomic_long_t mesq_noop_page_overflow;
46889 + atomic_long_unchecked_t mesq_receive;
46890 + atomic_long_unchecked_t mesq_receive_none;
46891 + atomic_long_unchecked_t mesq_send;
46892 + atomic_long_unchecked_t mesq_send_failed;
46893 + atomic_long_unchecked_t mesq_noop;
46894 + atomic_long_unchecked_t mesq_send_unexpected_error;
46895 + atomic_long_unchecked_t mesq_send_lb_overflow;
46896 + atomic_long_unchecked_t mesq_send_qlimit_reached;
46897 + atomic_long_unchecked_t mesq_send_amo_nacked;
46898 + atomic_long_unchecked_t mesq_send_put_nacked;
46899 + atomic_long_unchecked_t mesq_page_overflow;
46900 + atomic_long_unchecked_t mesq_qf_locked;
46901 + atomic_long_unchecked_t mesq_qf_noop_not_full;
46902 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
46903 + atomic_long_unchecked_t mesq_qf_unexpected_error;
46904 + atomic_long_unchecked_t mesq_noop_unexpected_error;
46905 + atomic_long_unchecked_t mesq_noop_lb_overflow;
46906 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
46907 + atomic_long_unchecked_t mesq_noop_amo_nacked;
46908 + atomic_long_unchecked_t mesq_noop_put_nacked;
46909 + atomic_long_unchecked_t mesq_noop_page_overflow;
46910
46911 };
46912
46913 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46914 tghop_invalidate, mcsop_last};
46915
46916 struct mcs_op_statistic {
46917 - atomic_long_t count;
46918 - atomic_long_t total;
46919 + atomic_long_unchecked_t count;
46920 + atomic_long_unchecked_t total;
46921 unsigned long max;
46922 };
46923
46924 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46925
46926 #define STAT(id) do { \
46927 if (gru_options & OPT_STATS) \
46928 - atomic_long_inc(&gru_stats.id); \
46929 + atomic_long_inc_unchecked(&gru_stats.id); \
46930 } while (0)
46931
46932 #ifdef CONFIG_SGI_GRU_DEBUG
46933 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46934 index c862cd4..0d176fe 100644
46935 --- a/drivers/misc/sgi-xp/xp.h
46936 +++ b/drivers/misc/sgi-xp/xp.h
46937 @@ -288,7 +288,7 @@ struct xpc_interface {
46938 xpc_notify_func, void *);
46939 void (*received) (short, int, void *);
46940 enum xp_retval (*partid_to_nasids) (short, void *);
46941 -};
46942 +} __no_const;
46943
46944 extern struct xpc_interface xpc_interface;
46945
46946 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46947 index 01be66d..e3a0c7e 100644
46948 --- a/drivers/misc/sgi-xp/xp_main.c
46949 +++ b/drivers/misc/sgi-xp/xp_main.c
46950 @@ -78,13 +78,13 @@ xpc_notloaded(void)
46951 }
46952
46953 struct xpc_interface xpc_interface = {
46954 - (void (*)(int))xpc_notloaded,
46955 - (void (*)(int))xpc_notloaded,
46956 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46957 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46958 + .connect = (void (*)(int))xpc_notloaded,
46959 + .disconnect = (void (*)(int))xpc_notloaded,
46960 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46961 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46962 void *))xpc_notloaded,
46963 - (void (*)(short, int, void *))xpc_notloaded,
46964 - (enum xp_retval(*)(short, void *))xpc_notloaded
46965 + .received = (void (*)(short, int, void *))xpc_notloaded,
46966 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46967 };
46968 EXPORT_SYMBOL_GPL(xpc_interface);
46969
46970 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46971 index b94d5f7..7f494c5 100644
46972 --- a/drivers/misc/sgi-xp/xpc.h
46973 +++ b/drivers/misc/sgi-xp/xpc.h
46974 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
46975 void (*received_payload) (struct xpc_channel *, void *);
46976 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46977 };
46978 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46979
46980 /* struct xpc_partition act_state values (for XPC HB) */
46981
46982 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46983 /* found in xpc_main.c */
46984 extern struct device *xpc_part;
46985 extern struct device *xpc_chan;
46986 -extern struct xpc_arch_operations xpc_arch_ops;
46987 +extern xpc_arch_operations_no_const xpc_arch_ops;
46988 extern int xpc_disengage_timelimit;
46989 extern int xpc_disengage_timedout;
46990 extern int xpc_activate_IRQ_rcvd;
46991 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46992 index 82dc574..8539ab2 100644
46993 --- a/drivers/misc/sgi-xp/xpc_main.c
46994 +++ b/drivers/misc/sgi-xp/xpc_main.c
46995 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46996 .notifier_call = xpc_system_die,
46997 };
46998
46999 -struct xpc_arch_operations xpc_arch_ops;
47000 +xpc_arch_operations_no_const xpc_arch_ops;
47001
47002 /*
47003 * Timer function to enforce the timelimit on the partition disengage.
47004 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47005
47006 if (((die_args->trapnr == X86_TRAP_MF) ||
47007 (die_args->trapnr == X86_TRAP_XF)) &&
47008 - !user_mode_vm(die_args->regs))
47009 + !user_mode(die_args->regs))
47010 xpc_die_deactivate();
47011
47012 break;
47013 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47014 index a11451f..9e1bbad 100644
47015 --- a/drivers/mmc/card/block.c
47016 +++ b/drivers/mmc/card/block.c
47017 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47018 if (idata->ic.postsleep_min_us)
47019 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47020
47021 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47022 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47023 err = -EFAULT;
47024 goto cmd_rel_host;
47025 }
47026 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47027 index 7911e05..d0f9dda 100644
47028 --- a/drivers/mmc/core/mmc_ops.c
47029 +++ b/drivers/mmc/core/mmc_ops.c
47030 @@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47031 void *data_buf;
47032 int is_on_stack;
47033
47034 - is_on_stack = object_is_on_stack(buf);
47035 + is_on_stack = object_starts_on_stack(buf);
47036 if (is_on_stack) {
47037 /*
47038 * dma onto stack is unsafe/nonportable, but callers to this
47039 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47040 index 01b99e8..5c325e3 100644
47041 --- a/drivers/mmc/host/dw_mmc.h
47042 +++ b/drivers/mmc/host/dw_mmc.h
47043 @@ -265,5 +265,5 @@ struct dw_mci_drv_data {
47044 int (*parse_dt)(struct dw_mci *host);
47045 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47046 struct dw_mci_tuning_data *tuning_data);
47047 -};
47048 +} __do_const;
47049 #endif /* _DW_MMC_H_ */
47050 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47051 index 43af791..86f4c48 100644
47052 --- a/drivers/mmc/host/mmci.c
47053 +++ b/drivers/mmc/host/mmci.c
47054 @@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
47055 mmc->caps |= MMC_CAP_CMD23;
47056
47057 if (variant->busy_detect) {
47058 - mmci_ops.card_busy = mmci_card_busy;
47059 + pax_open_kernel();
47060 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47061 + pax_close_kernel();
47062 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47063 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47064 mmc->max_busy_timeout = 0;
47065 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47066 index 9c2b9cb..cebb09a 100644
47067 --- a/drivers/mmc/host/omap_hsmmc.c
47068 +++ b/drivers/mmc/host/omap_hsmmc.c
47069 @@ -2113,7 +2113,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47070
47071 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47072 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47073 - omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47074 + pax_open_kernel();
47075 + *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47076 + pax_close_kernel();
47077 }
47078
47079 pm_runtime_enable(host->dev);
47080 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47081 index 587ee0e..b3bbcab 100644
47082 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47083 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47084 @@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47085 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47086 }
47087
47088 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47089 - sdhci_esdhc_ops.platform_execute_tuning =
47090 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47091 + pax_open_kernel();
47092 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47093 esdhc_executing_tuning;
47094 + pax_close_kernel();
47095 + }
47096
47097 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47098 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47099 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47100 index 0ce6eb1..8dcce1b 100644
47101 --- a/drivers/mmc/host/sdhci-s3c.c
47102 +++ b/drivers/mmc/host/sdhci-s3c.c
47103 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47104 * we can use overriding functions instead of default.
47105 */
47106 if (sc->no_divider) {
47107 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47108 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47109 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47110 + pax_open_kernel();
47111 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47112 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47113 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47114 + pax_close_kernel();
47115 }
47116
47117 /* It supports additional host capabilities if needed */
47118 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47119 index 423666b..81ff5eb 100644
47120 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47121 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47122 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47123 size_t totlen = 0, thislen;
47124 int ret = 0;
47125 size_t buflen = 0;
47126 - static char *buffer;
47127 + char *buffer;
47128
47129 if (!ECCBUF_SIZE) {
47130 /* We should fall back to a general writev implementation.
47131 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47132 index b3b7ca1..5dd4634 100644
47133 --- a/drivers/mtd/nand/denali.c
47134 +++ b/drivers/mtd/nand/denali.c
47135 @@ -24,6 +24,7 @@
47136 #include <linux/slab.h>
47137 #include <linux/mtd/mtd.h>
47138 #include <linux/module.h>
47139 +#include <linux/slab.h>
47140
47141 #include "denali.h"
47142
47143 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47144 index 959cb9b..8520fe5 100644
47145 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47146 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47147 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47148
47149 /* first try to map the upper buffer directly */
47150 if (virt_addr_valid(this->upper_buf) &&
47151 - !object_is_on_stack(this->upper_buf)) {
47152 + !object_starts_on_stack(this->upper_buf)) {
47153 sg_init_one(sgl, this->upper_buf, this->upper_len);
47154 ret = dma_map_sg(this->dev, sgl, 1, dr);
47155 if (ret == 0)
47156 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47157 index 51b9d6a..52af9a7 100644
47158 --- a/drivers/mtd/nftlmount.c
47159 +++ b/drivers/mtd/nftlmount.c
47160 @@ -24,6 +24,7 @@
47161 #include <asm/errno.h>
47162 #include <linux/delay.h>
47163 #include <linux/slab.h>
47164 +#include <linux/sched.h>
47165 #include <linux/mtd/mtd.h>
47166 #include <linux/mtd/nand.h>
47167 #include <linux/mtd/nftl.h>
47168 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47169 index c23184a..4115c41 100644
47170 --- a/drivers/mtd/sm_ftl.c
47171 +++ b/drivers/mtd/sm_ftl.c
47172 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47173 #define SM_CIS_VENDOR_OFFSET 0x59
47174 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47175 {
47176 - struct attribute_group *attr_group;
47177 + attribute_group_no_const *attr_group;
47178 struct attribute **attributes;
47179 struct sm_sysfs_attribute *vendor_attribute;
47180 char *vendor;
47181 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47182 index a5115fb..81b03f6 100644
47183 --- a/drivers/net/bonding/bond_main.c
47184 +++ b/drivers/net/bonding/bond_main.c
47185 @@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47186 bond_dev_queue_xmit(bond, skb, slave->dev);
47187 } else {
47188 dev_kfree_skb_any(skb);
47189 - atomic_long_inc(&dev->tx_dropped);
47190 + atomic_long_inc_unchecked(&dev->tx_dropped);
47191 }
47192
47193 return NETDEV_TX_OK;
47194 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47195 index 45f09a6..f154f8d 100644
47196 --- a/drivers/net/bonding/bond_netlink.c
47197 +++ b/drivers/net/bonding/bond_netlink.c
47198 @@ -585,7 +585,7 @@ nla_put_failure:
47199 return -EMSGSIZE;
47200 }
47201
47202 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47203 +struct rtnl_link_ops bond_link_ops = {
47204 .kind = "bond",
47205 .priv_size = sizeof(struct bonding),
47206 .setup = bond_setup,
47207 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47208 index 5e40a8b..126bfda 100644
47209 --- a/drivers/net/caif/caif_hsi.c
47210 +++ b/drivers/net/caif/caif_hsi.c
47211 @@ -1445,7 +1445,7 @@ err:
47212 return -ENODEV;
47213 }
47214
47215 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47216 +static struct rtnl_link_ops caif_hsi_link_ops = {
47217 .kind = "cfhsi",
47218 .priv_size = sizeof(struct cfhsi),
47219 .setup = cfhsi_setup,
47220 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47221 index 98d73aa..63ef9da 100644
47222 --- a/drivers/net/can/Kconfig
47223 +++ b/drivers/net/can/Kconfig
47224 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47225
47226 config CAN_FLEXCAN
47227 tristate "Support for Freescale FLEXCAN based chips"
47228 - depends on ARM || PPC
47229 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47230 ---help---
47231 Say Y here if you want to support for Freescale FlexCAN.
47232
47233 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47234 index 4b008c9..2b1151f 100644
47235 --- a/drivers/net/can/dev.c
47236 +++ b/drivers/net/can/dev.c
47237 @@ -872,7 +872,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47238 return -EOPNOTSUPP;
47239 }
47240
47241 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47242 +static struct rtnl_link_ops can_link_ops = {
47243 .kind = "can",
47244 .maxtype = IFLA_CAN_MAX,
47245 .policy = can_policy,
47246 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47247 index 4e94057..32032ff 100644
47248 --- a/drivers/net/can/vcan.c
47249 +++ b/drivers/net/can/vcan.c
47250 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47251 dev->destructor = free_netdev;
47252 }
47253
47254 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47255 +static struct rtnl_link_ops vcan_link_ops = {
47256 .kind = "vcan",
47257 .setup = vcan_setup,
47258 };
47259 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47260 index ff435fb..d408b1f 100644
47261 --- a/drivers/net/dummy.c
47262 +++ b/drivers/net/dummy.c
47263 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47264 return 0;
47265 }
47266
47267 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47268 +static struct rtnl_link_ops dummy_link_ops = {
47269 .kind = "dummy",
47270 .setup = dummy_setup,
47271 .validate = dummy_validate,
47272 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47273 index 1d162cc..b546a75 100644
47274 --- a/drivers/net/ethernet/8390/ax88796.c
47275 +++ b/drivers/net/ethernet/8390/ax88796.c
47276 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47277 if (ax->plat->reg_offsets)
47278 ei_local->reg_offset = ax->plat->reg_offsets;
47279 else {
47280 + resource_size_t _mem_size = mem_size;
47281 + do_div(_mem_size, 0x18);
47282 ei_local->reg_offset = ax->reg_offsets;
47283 for (ret = 0; ret < 0x18; ret++)
47284 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47285 + ax->reg_offsets[ret] = _mem_size * ret;
47286 }
47287
47288 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47289 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47290 index 4efc435..4ab9e14 100644
47291 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47292 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47293 @@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47294 return 0;
47295 }
47296
47297 -static struct net_device_ops altera_tse_netdev_ops = {
47298 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47299 .ndo_open = tse_open,
47300 .ndo_stop = tse_shutdown,
47301 .ndo_start_xmit = tse_start_xmit,
47302 @@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47303 ndev->netdev_ops = &altera_tse_netdev_ops;
47304 altera_tse_set_ethtool_ops(ndev);
47305
47306 + pax_open_kernel();
47307 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47308
47309 if (priv->hash_filter)
47310 altera_tse_netdev_ops.ndo_set_rx_mode =
47311 tse_set_rx_mode_hashfilter;
47312 + pax_close_kernel();
47313
47314 /* Scatter/gather IO is not supported,
47315 * so it is turned off
47316 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47317 index caade30..3e257d9 100644
47318 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47319 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47320 @@ -1072,14 +1072,14 @@ do { \
47321 * operations, everything works on mask values.
47322 */
47323 #define XMDIO_READ(_pdata, _mmd, _reg) \
47324 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47325 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47326 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47327
47328 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47329 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47330
47331 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47332 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47333 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47334 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47335
47336 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47337 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47338 index 8a50b01..39c1ad0 100644
47339 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47340 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47341 @@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47342
47343 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47344
47345 - pdata->hw_if.config_dcb_tc(pdata);
47346 + pdata->hw_if->config_dcb_tc(pdata);
47347
47348 return 0;
47349 }
47350 @@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47351
47352 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47353
47354 - pdata->hw_if.config_dcb_pfc(pdata);
47355 + pdata->hw_if->config_dcb_pfc(pdata);
47356
47357 return 0;
47358 }
47359 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47360 index 6fc5da0..61ac2cb 100644
47361 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47362 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47363 @@ -235,7 +235,7 @@ err_ring:
47364
47365 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47366 {
47367 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47368 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47369 struct xgbe_channel *channel;
47370 struct xgbe_ring *ring;
47371 struct xgbe_ring_data *rdata;
47372 @@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47373
47374 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47375 {
47376 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47377 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47378 struct xgbe_channel *channel;
47379 struct xgbe_ring *ring;
47380 struct xgbe_ring_desc *rdesc;
47381 @@ -505,7 +505,7 @@ err_out:
47382 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47383 {
47384 struct xgbe_prv_data *pdata = channel->pdata;
47385 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47386 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47387 struct xgbe_ring *ring = channel->rx_ring;
47388 struct xgbe_ring_data *rdata;
47389 struct sk_buff *skb = NULL;
47390 @@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47391 DBGPR("<--xgbe_realloc_skb\n");
47392 }
47393
47394 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47395 -{
47396 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47397 -
47398 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47399 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47400 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47401 - desc_if->realloc_skb = xgbe_realloc_skb;
47402 - desc_if->unmap_skb = xgbe_unmap_skb;
47403 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47404 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47405 -
47406 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47407 -}
47408 +const struct xgbe_desc_if default_xgbe_desc_if = {
47409 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47410 + .free_ring_resources = xgbe_free_ring_resources,
47411 + .map_tx_skb = xgbe_map_tx_skb,
47412 + .realloc_skb = xgbe_realloc_skb,
47413 + .unmap_skb = xgbe_unmap_skb,
47414 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47415 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47416 +};
47417 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47418 index 9da3a03..022f15c 100644
47419 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47420 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47421 @@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47422
47423 static int xgbe_init(struct xgbe_prv_data *pdata)
47424 {
47425 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47426 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47427 int ret;
47428
47429 DBGPR("-->xgbe_init\n");
47430 @@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47431 return 0;
47432 }
47433
47434 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47435 -{
47436 - DBGPR("-->xgbe_init_function_ptrs\n");
47437 -
47438 - hw_if->tx_complete = xgbe_tx_complete;
47439 -
47440 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47441 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47442 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47443 - hw_if->set_mac_address = xgbe_set_mac_address;
47444 -
47445 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47446 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47447 -
47448 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47449 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47450 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47451 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47452 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47453 -
47454 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47455 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47456 -
47457 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47458 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47459 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47460 -
47461 - hw_if->enable_tx = xgbe_enable_tx;
47462 - hw_if->disable_tx = xgbe_disable_tx;
47463 - hw_if->enable_rx = xgbe_enable_rx;
47464 - hw_if->disable_rx = xgbe_disable_rx;
47465 -
47466 - hw_if->powerup_tx = xgbe_powerup_tx;
47467 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47468 - hw_if->powerup_rx = xgbe_powerup_rx;
47469 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47470 -
47471 - hw_if->pre_xmit = xgbe_pre_xmit;
47472 - hw_if->dev_read = xgbe_dev_read;
47473 - hw_if->enable_int = xgbe_enable_int;
47474 - hw_if->disable_int = xgbe_disable_int;
47475 - hw_if->init = xgbe_init;
47476 - hw_if->exit = xgbe_exit;
47477 +const struct xgbe_hw_if default_xgbe_hw_if = {
47478 + .tx_complete = xgbe_tx_complete,
47479 +
47480 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47481 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47482 + .add_mac_addresses = xgbe_add_mac_addresses,
47483 + .set_mac_address = xgbe_set_mac_address,
47484 +
47485 + .enable_rx_csum = xgbe_enable_rx_csum,
47486 + .disable_rx_csum = xgbe_disable_rx_csum,
47487 +
47488 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47489 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47490 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47491 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47492 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47493 +
47494 + .read_mmd_regs = xgbe_read_mmd_regs,
47495 + .write_mmd_regs = xgbe_write_mmd_regs,
47496 +
47497 + .set_gmii_speed = xgbe_set_gmii_speed,
47498 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47499 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47500 +
47501 + .enable_tx = xgbe_enable_tx,
47502 + .disable_tx = xgbe_disable_tx,
47503 + .enable_rx = xgbe_enable_rx,
47504 + .disable_rx = xgbe_disable_rx,
47505 +
47506 + .powerup_tx = xgbe_powerup_tx,
47507 + .powerdown_tx = xgbe_powerdown_tx,
47508 + .powerup_rx = xgbe_powerup_rx,
47509 + .powerdown_rx = xgbe_powerdown_rx,
47510 +
47511 + .pre_xmit = xgbe_pre_xmit,
47512 + .dev_read = xgbe_dev_read,
47513 + .enable_int = xgbe_enable_int,
47514 + .disable_int = xgbe_disable_int,
47515 + .init = xgbe_init,
47516 + .exit = xgbe_exit,
47517
47518 /* Descriptor related Sequences have to be initialized here */
47519 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47520 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47521 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47522 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47523 - hw_if->is_last_desc = xgbe_is_last_desc;
47524 - hw_if->is_context_desc = xgbe_is_context_desc;
47525 + .tx_desc_init = xgbe_tx_desc_init,
47526 + .rx_desc_init = xgbe_rx_desc_init,
47527 + .tx_desc_reset = xgbe_tx_desc_reset,
47528 + .rx_desc_reset = xgbe_rx_desc_reset,
47529 + .is_last_desc = xgbe_is_last_desc,
47530 + .is_context_desc = xgbe_is_context_desc,
47531
47532 /* For FLOW ctrl */
47533 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47534 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47535 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47536 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47537
47538 /* For RX coalescing */
47539 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47540 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47541 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47542 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47543 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47544 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47545 + .usec_to_riwt = xgbe_usec_to_riwt,
47546 + .riwt_to_usec = xgbe_riwt_to_usec,
47547
47548 /* For RX and TX threshold config */
47549 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47550 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47551 + .config_rx_threshold = xgbe_config_rx_threshold,
47552 + .config_tx_threshold = xgbe_config_tx_threshold,
47553
47554 /* For RX and TX Store and Forward Mode config */
47555 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47556 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47557 + .config_rsf_mode = xgbe_config_rsf_mode,
47558 + .config_tsf_mode = xgbe_config_tsf_mode,
47559
47560 /* For TX DMA Operating on Second Frame config */
47561 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47562 + .config_osp_mode = xgbe_config_osp_mode,
47563
47564 /* For RX and TX PBL config */
47565 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47566 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47567 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47568 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47569 - hw_if->config_pblx8 = xgbe_config_pblx8;
47570 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47571 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47572 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47573 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47574 + .config_pblx8 = xgbe_config_pblx8,
47575
47576 /* For MMC statistics support */
47577 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47578 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47579 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47580 + .tx_mmc_int = xgbe_tx_mmc_int,
47581 + .rx_mmc_int = xgbe_rx_mmc_int,
47582 + .read_mmc_stats = xgbe_read_mmc_stats,
47583
47584 /* For PTP config */
47585 - hw_if->config_tstamp = xgbe_config_tstamp;
47586 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47587 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47588 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47589 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47590 + .config_tstamp = xgbe_config_tstamp,
47591 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47592 + .set_tstamp_time = xgbe_set_tstamp_time,
47593 + .get_tstamp_time = xgbe_get_tstamp_time,
47594 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47595
47596 /* For Data Center Bridging config */
47597 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47598 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47599 -
47600 - DBGPR("<--xgbe_init_function_ptrs\n");
47601 -}
47602 + .config_dcb_tc = xgbe_config_dcb_tc,
47603 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47604 +};
47605 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47606 index 2349ea9..a83a677 100644
47607 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47608 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47609 @@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47610
47611 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47612 {
47613 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47614 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47615 struct xgbe_channel *channel;
47616 enum xgbe_int int_id;
47617 unsigned int i;
47618 @@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47619
47620 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47621 {
47622 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47623 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47624 struct xgbe_channel *channel;
47625 enum xgbe_int int_id;
47626 unsigned int i;
47627 @@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47628 static irqreturn_t xgbe_isr(int irq, void *data)
47629 {
47630 struct xgbe_prv_data *pdata = data;
47631 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47632 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47633 struct xgbe_channel *channel;
47634 unsigned int dma_isr, dma_ch_isr;
47635 unsigned int mac_isr, mac_tssr;
47636 @@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47637
47638 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47639 {
47640 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47641 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47642
47643 DBGPR("-->xgbe_init_tx_coalesce\n");
47644
47645 @@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47646
47647 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47648 {
47649 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47650 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47651
47652 DBGPR("-->xgbe_init_rx_coalesce\n");
47653
47654 @@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47655
47656 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47657 {
47658 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47659 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47660 struct xgbe_channel *channel;
47661 struct xgbe_ring *ring;
47662 struct xgbe_ring_data *rdata;
47663 @@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47664
47665 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47666 {
47667 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47668 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47669 struct xgbe_channel *channel;
47670 struct xgbe_ring *ring;
47671 struct xgbe_ring_data *rdata;
47672 @@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47673 static void xgbe_adjust_link(struct net_device *netdev)
47674 {
47675 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47676 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47677 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47678 struct phy_device *phydev = pdata->phydev;
47679 int new_state = 0;
47680
47681 @@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47682 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47683 {
47684 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47685 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47686 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47687 unsigned long flags;
47688
47689 DBGPR("-->xgbe_powerdown\n");
47690 @@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47691 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47692 {
47693 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47694 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47695 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47696 unsigned long flags;
47697
47698 DBGPR("-->xgbe_powerup\n");
47699 @@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47700
47701 static int xgbe_start(struct xgbe_prv_data *pdata)
47702 {
47703 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47704 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47705 struct net_device *netdev = pdata->netdev;
47706
47707 DBGPR("-->xgbe_start\n");
47708 @@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47709
47710 static void xgbe_stop(struct xgbe_prv_data *pdata)
47711 {
47712 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47713 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47714 struct net_device *netdev = pdata->netdev;
47715
47716 DBGPR("-->xgbe_stop\n");
47717 @@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47718
47719 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47720 {
47721 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47722 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47723
47724 DBGPR("-->xgbe_restart_dev\n");
47725
47726 @@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47727 return -ERANGE;
47728 }
47729
47730 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47731 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47732
47733 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47734
47735 @@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47736 static int xgbe_open(struct net_device *netdev)
47737 {
47738 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47739 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47740 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47741 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47742 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47743 int ret;
47744
47745 DBGPR("-->xgbe_open\n");
47746 @@ -1170,8 +1170,8 @@ err_phy_init:
47747 static int xgbe_close(struct net_device *netdev)
47748 {
47749 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47750 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47751 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47752 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47753 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47754
47755 DBGPR("-->xgbe_close\n");
47756
47757 @@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47758 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47759 {
47760 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47761 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47762 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47763 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47764 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47765 struct xgbe_channel *channel;
47766 struct xgbe_ring *ring;
47767 struct xgbe_packet_data *packet;
47768 @@ -1275,7 +1275,7 @@ tx_netdev_return:
47769 static void xgbe_set_rx_mode(struct net_device *netdev)
47770 {
47771 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47772 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47773 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47774 unsigned int pr_mode, am_mode;
47775
47776 DBGPR("-->xgbe_set_rx_mode\n");
47777 @@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47778 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47779 {
47780 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47781 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47782 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47783 struct sockaddr *saddr = addr;
47784
47785 DBGPR("-->xgbe_set_mac_address\n");
47786 @@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47787
47788 DBGPR("-->%s\n", __func__);
47789
47790 - pdata->hw_if.read_mmc_stats(pdata);
47791 + pdata->hw_if->read_mmc_stats(pdata);
47792
47793 s->rx_packets = pstats->rxframecount_gb;
47794 s->rx_bytes = pstats->rxoctetcount_gb;
47795 @@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47796 u16 vid)
47797 {
47798 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47799 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47800 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47801
47802 DBGPR("-->%s\n", __func__);
47803
47804 @@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47805 u16 vid)
47806 {
47807 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47808 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47809 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47810
47811 DBGPR("-->%s\n", __func__);
47812
47813 @@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47814 netdev_features_t features)
47815 {
47816 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47817 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47818 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47819 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47820
47821 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47822 @@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47823 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47824 {
47825 struct xgbe_prv_data *pdata = channel->pdata;
47826 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47827 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47828 struct xgbe_ring *ring = channel->rx_ring;
47829 struct xgbe_ring_data *rdata;
47830
47831 @@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47832 static int xgbe_tx_poll(struct xgbe_channel *channel)
47833 {
47834 struct xgbe_prv_data *pdata = channel->pdata;
47835 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47836 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47837 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47838 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47839 struct xgbe_ring *ring = channel->tx_ring;
47840 struct xgbe_ring_data *rdata;
47841 struct xgbe_ring_desc *rdesc;
47842 @@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47843 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47844 {
47845 struct xgbe_prv_data *pdata = channel->pdata;
47846 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47847 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47848 struct xgbe_ring *ring = channel->rx_ring;
47849 struct xgbe_ring_data *rdata;
47850 struct xgbe_packet_data *packet;
47851 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47852 index 49508ec..2617cca 100644
47853 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47854 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47855 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47856
47857 DBGPR("-->%s\n", __func__);
47858
47859 - pdata->hw_if.read_mmc_stats(pdata);
47860 + pdata->hw_if->read_mmc_stats(pdata);
47861 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47862 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47863 *data++ = *(u64 *)stat;
47864 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47865 struct ethtool_coalesce *ec)
47866 {
47867 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47868 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47869 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47870 unsigned int riwt;
47871
47872 DBGPR("-->xgbe_get_coalesce\n");
47873 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47874 struct ethtool_coalesce *ec)
47875 {
47876 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47877 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47878 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47879 unsigned int rx_frames, rx_riwt, rx_usecs;
47880 unsigned int tx_frames, tx_usecs;
47881
47882 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47883 index f5a8fa0..0bb58ff 100644
47884 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47885 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47886 @@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47887 DBGPR("<--xgbe_default_config\n");
47888 }
47889
47890 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47891 -{
47892 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
47893 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
47894 -}
47895 -
47896 static int xgbe_probe(struct platform_device *pdev)
47897 {
47898 struct xgbe_prv_data *pdata;
47899 @@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47900 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47901
47902 /* Set all the function pointers */
47903 - xgbe_init_all_fptrs(pdata);
47904 - hw_if = &pdata->hw_if;
47905 - desc_if = &pdata->desc_if;
47906 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
47907 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
47908
47909 /* Issue software reset to device */
47910 hw_if->exit(pdata);
47911 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47912 index 363b210..b241389 100644
47913 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47914 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47915 @@ -126,7 +126,7 @@
47916 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47917 {
47918 struct xgbe_prv_data *pdata = mii->priv;
47919 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47920 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47921 int mmd_data;
47922
47923 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47924 @@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47925 u16 mmd_val)
47926 {
47927 struct xgbe_prv_data *pdata = mii->priv;
47928 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47929 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47930 int mmd_data = mmd_val;
47931
47932 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47933 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47934 index a1bf9d1c..84adcab 100644
47935 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47936 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47937 @@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47938 tstamp_cc);
47939 u64 nsec;
47940
47941 - nsec = pdata->hw_if.get_tstamp_time(pdata);
47942 + nsec = pdata->hw_if->get_tstamp_time(pdata);
47943
47944 return nsec;
47945 }
47946 @@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47947
47948 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47949
47950 - pdata->hw_if.update_tstamp_addend(pdata, addend);
47951 + pdata->hw_if->update_tstamp_addend(pdata, addend);
47952
47953 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47954
47955 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47956 index 789957d..d7d0245 100644
47957 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47958 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47959 @@ -583,8 +583,8 @@ struct xgbe_prv_data {
47960
47961 int irq_number;
47962
47963 - struct xgbe_hw_if hw_if;
47964 - struct xgbe_desc_if desc_if;
47965 + const struct xgbe_hw_if *hw_if;
47966 + const struct xgbe_desc_if *desc_if;
47967
47968 /* AXI DMA settings */
47969 unsigned int axdomain;
47970 @@ -697,6 +697,9 @@ struct xgbe_prv_data {
47971 #endif
47972 };
47973
47974 +extern const struct xgbe_hw_if default_xgbe_hw_if;
47975 +extern const struct xgbe_desc_if default_xgbe_desc_if;
47976 +
47977 /* Function prototypes*/
47978
47979 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
47980 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47981 index adcacda..fa6e0ae 100644
47982 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47983 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47984 @@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
47985 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
47986 {
47987 /* RX_MODE controlling object */
47988 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
47989 + bnx2x_init_rx_mode_obj(bp);
47990
47991 /* multicast configuration controlling object */
47992 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
47993 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47994 index 7bc2924..2112002 100644
47995 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47996 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47997 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
47998 return rc;
47999 }
48000
48001 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48002 - struct bnx2x_rx_mode_obj *o)
48003 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48004 {
48005 if (CHIP_IS_E1x(bp)) {
48006 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48007 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48008 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48009 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48010 } else {
48011 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48012 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48013 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48014 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48015 }
48016 }
48017
48018 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48019 index e97275f..52e28bc 100644
48020 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48021 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48022 @@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48023
48024 /********************* RX MODE ****************/
48025
48026 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48027 - struct bnx2x_rx_mode_obj *o);
48028 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48029
48030 /**
48031 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48032 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48033 index 31c9f82..e65e986 100644
48034 --- a/drivers/net/ethernet/broadcom/tg3.h
48035 +++ b/drivers/net/ethernet/broadcom/tg3.h
48036 @@ -150,6 +150,7 @@
48037 #define CHIPREV_ID_5750_A0 0x4000
48038 #define CHIPREV_ID_5750_A1 0x4001
48039 #define CHIPREV_ID_5750_A3 0x4003
48040 +#define CHIPREV_ID_5750_C1 0x4201
48041 #define CHIPREV_ID_5750_C2 0x4202
48042 #define CHIPREV_ID_5752_A0_HW 0x5000
48043 #define CHIPREV_ID_5752_A0 0x6000
48044 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48045 index 903466e..b285864 100644
48046 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48047 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48048 @@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
48049 }
48050
48051 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48052 - bna_cb_ioceth_enable,
48053 - bna_cb_ioceth_disable,
48054 - bna_cb_ioceth_hbfail,
48055 - bna_cb_ioceth_reset
48056 + .enable_cbfn = bna_cb_ioceth_enable,
48057 + .disable_cbfn = bna_cb_ioceth_disable,
48058 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48059 + .reset_cbfn = bna_cb_ioceth_reset
48060 };
48061
48062 static void bna_attr_init(struct bna_ioceth *ioceth)
48063 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48064 index 8cffcdf..aadf043 100644
48065 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48066 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48067 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48068 */
48069 struct l2t_skb_cb {
48070 arp_failure_handler_func arp_failure_handler;
48071 -};
48072 +} __no_const;
48073
48074 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48075
48076 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48077 index 279873c..11e1921 100644
48078 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48079 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48080 @@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48081
48082 int i;
48083 struct adapter *ap = netdev2adap(dev);
48084 - static const unsigned int *reg_ranges;
48085 + const unsigned int *reg_ranges;
48086 int arr_size = 0, buf_size = 0;
48087
48088 if (is_t4(ap->params.chip)) {
48089 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48090 index cf8b6ff..274271e 100644
48091 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48092 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48093 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48094 for (i=0; i<ETH_ALEN; i++) {
48095 tmp.addr[i] = dev->dev_addr[i];
48096 }
48097 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48098 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48099 break;
48100
48101 case DE4X5_SET_HWADDR: /* Set the hardware address */
48102 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48103 spin_lock_irqsave(&lp->lock, flags);
48104 memcpy(&statbuf, &lp->pktStats, ioc->len);
48105 spin_unlock_irqrestore(&lp->lock, flags);
48106 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48107 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48108 return -EFAULT;
48109 break;
48110 }
48111 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48112 index d2975fa..8aaec07 100644
48113 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48114 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48115 @@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48116
48117 if (wrapped)
48118 newacc += 65536;
48119 - ACCESS_ONCE(*acc) = newacc;
48120 + ACCESS_ONCE_RW(*acc) = newacc;
48121 }
48122
48123 static void populate_erx_stats(struct be_adapter *adapter,
48124 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48125 index c77fa4a..7fd42fc 100644
48126 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48127 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48128 @@ -30,6 +30,8 @@
48129 #include <linux/netdevice.h>
48130 #include <linux/phy.h>
48131 #include <linux/platform_device.h>
48132 +#include <linux/interrupt.h>
48133 +#include <linux/irqreturn.h>
48134 #include <net/ip.h>
48135
48136 #include "ftgmac100.h"
48137 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48138 index 4ff1adc..0ea6bf4 100644
48139 --- a/drivers/net/ethernet/faraday/ftmac100.c
48140 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48141 @@ -31,6 +31,8 @@
48142 #include <linux/module.h>
48143 #include <linux/netdevice.h>
48144 #include <linux/platform_device.h>
48145 +#include <linux/interrupt.h>
48146 +#include <linux/irqreturn.h>
48147
48148 #include "ftmac100.h"
48149
48150 diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48151 index 76d7070..f6971182 100644
48152 --- a/drivers/net/ethernet/freescale/gianfar_ethtool.c
48153 +++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48154 @@ -1581,7 +1581,7 @@ static int gfar_write_filer_table(struct gfar_private *priv,
48155 return -EBUSY;
48156
48157 /* Fill regular entries */
48158 - for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl);
48159 + for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].prop);
48160 i++)
48161 gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
48162 /* Fill the rest with fall-troughs */
48163 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48164 index 537b621..07f87ce 100644
48165 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48166 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48167 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48168 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48169
48170 /* Update the base adjustement value. */
48171 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48172 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48173 smp_mb(); /* Force the above update. */
48174 }
48175
48176 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48177 index 5fd4b52..87aa34b 100644
48178 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48179 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48180 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48181 }
48182
48183 /* update the base incval used to calculate frequency adjustment */
48184 - ACCESS_ONCE(adapter->base_incval) = incval;
48185 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48186 smp_mb();
48187
48188 /* need lock to prevent incorrect read while modifying cyclecounter */
48189 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48190 index 11ff28b..375d659 100644
48191 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48192 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48193 @@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48194 wmb();
48195
48196 /* we want to dirty this cache line once */
48197 - ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48198 - ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48199 + ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48200 + ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48201
48202 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48203
48204 diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48205 index de10dbb..8b54f29 100644
48206 --- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48207 +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48208 @@ -233,7 +233,8 @@ do { \
48209 extern int mlx4_log_num_mgm_entry_size;
48210 extern int log_mtts_per_seg;
48211
48212 -#define MLX4_MAX_NUM_SLAVES (MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF)
48213 +#define MLX4_MAX_NUM_SLAVES (min(MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF, \
48214 + MLX4_MFUNC_MAX))
48215 #define ALL_SLAVES 0xff
48216
48217 struct mlx4_bitmap {
48218 diff --git a/drivers/net/ethernet/neterion/s2io.c b/drivers/net/ethernet/neterion/s2io.c
48219 index f5e4b82..db0c7a9 100644
48220 --- a/drivers/net/ethernet/neterion/s2io.c
48221 +++ b/drivers/net/ethernet/neterion/s2io.c
48222 @@ -6987,7 +6987,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48223 if (sp->s2io_entries[i].in_use == MSIX_FLG) {
48224 if (sp->s2io_entries[i].type ==
48225 MSIX_RING_TYPE) {
48226 - sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
48227 + snprintf(sp->desc[i],
48228 + sizeof(sp->desc[i]),
48229 + "%s:MSI-X-%d-RX",
48230 dev->name, i);
48231 err = request_irq(sp->entries[i].vector,
48232 s2io_msix_ring_handle,
48233 @@ -6996,7 +6998,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48234 sp->s2io_entries[i].arg);
48235 } else if (sp->s2io_entries[i].type ==
48236 MSIX_ALARM_TYPE) {
48237 - sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
48238 + snprintf(sp->desc[i],
48239 + sizeof(sp->desc[i]),
48240 + "%s:MSI-X-%d-TX",
48241 dev->name, i);
48242 err = request_irq(sp->entries[i].vector,
48243 s2io_msix_fifo_handle,
48244 @@ -8154,7 +8158,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
48245 "%s: UDP Fragmentation Offload(UFO) enabled\n",
48246 dev->name);
48247 /* Initialize device name */
48248 - sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
48249 + snprintf(sp->name, sizeof(sp->name), "%s Neterion %s", dev->name,
48250 + sp->product_name);
48251
48252 if (vlan_tag_strip)
48253 sp->vlan_strip_flag = 1;
48254 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48255 index 2bbd01f..e8baa64 100644
48256 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48257 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48258 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48259 struct __vxge_hw_fifo *fifo;
48260 struct vxge_hw_fifo_config *config;
48261 u32 txdl_size, txdl_per_memblock;
48262 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48263 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48264 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48265 + };
48266 +
48267 struct __vxge_hw_virtualpath *vpath;
48268
48269 if ((vp == NULL) || (attr == NULL)) {
48270 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48271 goto exit;
48272 }
48273
48274 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48275 -
48276 fifo->mempool =
48277 __vxge_hw_mempool_create(vpath->hldev,
48278 fifo->config->memblock_size,
48279 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48280 index 2bb48d5..d1a865d 100644
48281 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48282 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48283 @@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48284 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48285 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48286 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48287 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48288 + pax_open_kernel();
48289 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48290 + pax_close_kernel();
48291 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48292 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48293 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48294 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48295 index be7d7a6..a8983f8 100644
48296 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48297 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48298 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48299 case QLCNIC_NON_PRIV_FUNC:
48300 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48301 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48302 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48303 + pax_open_kernel();
48304 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48305 + pax_close_kernel();
48306 break;
48307 case QLCNIC_PRIV_FUNC:
48308 ahw->op_mode = QLCNIC_PRIV_FUNC;
48309 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48310 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48311 + pax_open_kernel();
48312 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48313 + pax_close_kernel();
48314 break;
48315 case QLCNIC_MGMT_FUNC:
48316 ahw->op_mode = QLCNIC_MGMT_FUNC;
48317 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48318 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48319 + pax_open_kernel();
48320 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48321 + pax_close_kernel();
48322 break;
48323 default:
48324 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48325 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48326 index c9f57fb..208bdc1 100644
48327 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48328 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48329 @@ -1285,7 +1285,7 @@ flash_temp:
48330 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48331 {
48332 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48333 - static const struct qlcnic_dump_operations *fw_dump_ops;
48334 + const struct qlcnic_dump_operations *fw_dump_ops;
48335 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48336 u32 entry_offset, dump, no_entries, buf_offset = 0;
48337 int i, k, ops_cnt, ops_index, dump_size = 0;
48338 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48339 index cf154f7..c948d1b 100644
48340 --- a/drivers/net/ethernet/realtek/r8169.c
48341 +++ b/drivers/net/ethernet/realtek/r8169.c
48342 @@ -788,22 +788,22 @@ struct rtl8169_private {
48343 struct mdio_ops {
48344 void (*write)(struct rtl8169_private *, int, int);
48345 int (*read)(struct rtl8169_private *, int);
48346 - } mdio_ops;
48347 + } __no_const mdio_ops;
48348
48349 struct pll_power_ops {
48350 void (*down)(struct rtl8169_private *);
48351 void (*up)(struct rtl8169_private *);
48352 - } pll_power_ops;
48353 + } __no_const pll_power_ops;
48354
48355 struct jumbo_ops {
48356 void (*enable)(struct rtl8169_private *);
48357 void (*disable)(struct rtl8169_private *);
48358 - } jumbo_ops;
48359 + } __no_const jumbo_ops;
48360
48361 struct csi_ops {
48362 void (*write)(struct rtl8169_private *, int, int);
48363 u32 (*read)(struct rtl8169_private *, int);
48364 - } csi_ops;
48365 + } __no_const csi_ops;
48366
48367 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48368 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48369 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48370 index 6b861e3..204ac86 100644
48371 --- a/drivers/net/ethernet/sfc/ptp.c
48372 +++ b/drivers/net/ethernet/sfc/ptp.c
48373 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48374 ptp->start.dma_addr);
48375
48376 /* Clear flag that signals MC ready */
48377 - ACCESS_ONCE(*start) = 0;
48378 + ACCESS_ONCE_RW(*start) = 0;
48379 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48380 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48381 EFX_BUG_ON_PARANOID(rc);
48382 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48383 index 08c483b..2c4a553 100644
48384 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48385 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48386 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48387
48388 writel(value, ioaddr + MMC_CNTRL);
48389
48390 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48391 - MMC_CNTRL, value);
48392 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48393 +// MMC_CNTRL, value);
48394 }
48395
48396 /* To mask all all interrupts.*/
48397 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48398 index 2f48f79..8ae1a1a 100644
48399 --- a/drivers/net/hyperv/hyperv_net.h
48400 +++ b/drivers/net/hyperv/hyperv_net.h
48401 @@ -171,7 +171,7 @@ struct rndis_device {
48402 enum rndis_device_state state;
48403 bool link_state;
48404 bool link_change;
48405 - atomic_t new_req_id;
48406 + atomic_unchecked_t new_req_id;
48407
48408 spinlock_t request_lock;
48409 struct list_head req_list;
48410 diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
48411 index 7d76c95..63d7a64 100644
48412 --- a/drivers/net/hyperv/netvsc.c
48413 +++ b/drivers/net/hyperv/netvsc.c
48414 @@ -716,7 +716,7 @@ int netvsc_send(struct hv_device *device,
48415 u64 req_id;
48416 unsigned int section_index = NETVSC_INVALID_INDEX;
48417 u32 msg_size = 0;
48418 - struct sk_buff *skb;
48419 + struct sk_buff *skb = NULL;
48420 u16 q_idx = packet->q_idx;
48421
48422
48423 @@ -743,8 +743,6 @@ int netvsc_send(struct hv_device *device,
48424 packet);
48425 skb = (struct sk_buff *)
48426 (unsigned long)packet->send_completion_tid;
48427 - if (skb)
48428 - dev_kfree_skb_any(skb);
48429 packet->page_buf_cnt = 0;
48430 }
48431 }
48432 @@ -807,6 +805,13 @@ int netvsc_send(struct hv_device *device,
48433 packet, ret);
48434 }
48435
48436 + if (ret != 0) {
48437 + if (section_index != NETVSC_INVALID_INDEX)
48438 + netvsc_free_send_slot(net_device, section_index);
48439 + } else if (skb) {
48440 + dev_kfree_skb_any(skb);
48441 + }
48442 +
48443 return ret;
48444 }
48445
48446 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48447 index 2b86f0b..ecc996f 100644
48448 --- a/drivers/net/hyperv/rndis_filter.c
48449 +++ b/drivers/net/hyperv/rndis_filter.c
48450 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48451 * template
48452 */
48453 set = &rndis_msg->msg.set_req;
48454 - set->req_id = atomic_inc_return(&dev->new_req_id);
48455 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48456
48457 /* Add to the request list */
48458 spin_lock_irqsave(&dev->request_lock, flags);
48459 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48460
48461 /* Setup the rndis set */
48462 halt = &request->request_msg.msg.halt_req;
48463 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48464 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48465
48466 /* Ignore return since this msg is optional. */
48467 rndis_filter_send_request(dev, request);
48468 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48469 index 6cbc56a..5f7e6c8 100644
48470 --- a/drivers/net/ieee802154/fakehard.c
48471 +++ b/drivers/net/ieee802154/fakehard.c
48472 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48473 phy->transmit_power = 0xbf;
48474
48475 dev->netdev_ops = &fake_ops;
48476 - dev->ml_priv = &fake_mlme;
48477 + dev->ml_priv = (void *)&fake_mlme;
48478
48479 priv = netdev_priv(dev);
48480 priv->phy = phy;
48481 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48482 index 34f846b..4a0d5b1 100644
48483 --- a/drivers/net/ifb.c
48484 +++ b/drivers/net/ifb.c
48485 @@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48486 return 0;
48487 }
48488
48489 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48490 +static struct rtnl_link_ops ifb_link_ops = {
48491 .kind = "ifb",
48492 .priv_size = sizeof(struct ifb_private),
48493 .setup = ifb_setup,
48494 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48495 index bfb0b6e..5c396ce 100644
48496 --- a/drivers/net/macvlan.c
48497 +++ b/drivers/net/macvlan.c
48498 @@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48499 free_nskb:
48500 kfree_skb(nskb);
48501 err:
48502 - atomic_long_inc(&skb->dev->rx_dropped);
48503 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48504 }
48505
48506 static void macvlan_flush_sources(struct macvlan_port *port,
48507 @@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48508 int macvlan_link_register(struct rtnl_link_ops *ops)
48509 {
48510 /* common fields */
48511 - ops->priv_size = sizeof(struct macvlan_dev);
48512 - ops->validate = macvlan_validate;
48513 - ops->maxtype = IFLA_MACVLAN_MAX;
48514 - ops->policy = macvlan_policy;
48515 - ops->changelink = macvlan_changelink;
48516 - ops->get_size = macvlan_get_size;
48517 - ops->fill_info = macvlan_fill_info;
48518 + pax_open_kernel();
48519 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48520 + *(void **)&ops->validate = macvlan_validate;
48521 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48522 + *(const void **)&ops->policy = macvlan_policy;
48523 + *(void **)&ops->changelink = macvlan_changelink;
48524 + *(void **)&ops->get_size = macvlan_get_size;
48525 + *(void **)&ops->fill_info = macvlan_fill_info;
48526 + pax_close_kernel();
48527
48528 return rtnl_link_register(ops);
48529 };
48530 @@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48531 return NOTIFY_DONE;
48532 }
48533
48534 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48535 +static struct notifier_block macvlan_notifier_block = {
48536 .notifier_call = macvlan_device_event,
48537 };
48538
48539 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48540 index 880cc09..6a68ba6 100644
48541 --- a/drivers/net/macvtap.c
48542 +++ b/drivers/net/macvtap.c
48543 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48544 dev->tx_queue_len = TUN_READQ_SIZE;
48545 }
48546
48547 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48548 +static struct rtnl_link_ops macvtap_link_ops = {
48549 .kind = "macvtap",
48550 .setup = macvtap_setup,
48551 .newlink = macvtap_newlink,
48552 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48553 }
48554
48555 ret = 0;
48556 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48557 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48558 put_user(q->flags, &ifr->ifr_flags))
48559 ret = -EFAULT;
48560 macvtap_put_vlan(vlan);
48561 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48562 return NOTIFY_DONE;
48563 }
48564
48565 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48566 +static struct notifier_block macvtap_notifier_block = {
48567 .notifier_call = macvtap_device_event,
48568 };
48569
48570 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48571 index 34924df..a747360 100644
48572 --- a/drivers/net/nlmon.c
48573 +++ b/drivers/net/nlmon.c
48574 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48575 return 0;
48576 }
48577
48578 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48579 +static struct rtnl_link_ops nlmon_link_ops = {
48580 .kind = "nlmon",
48581 .priv_size = sizeof(struct nlmon),
48582 .setup = nlmon_setup,
48583 diff --git a/drivers/net/ppp/ppp_deflate.c b/drivers/net/ppp/ppp_deflate.c
48584 index 602c625..b5edc7f 100644
48585 --- a/drivers/net/ppp/ppp_deflate.c
48586 +++ b/drivers/net/ppp/ppp_deflate.c
48587 @@ -246,7 +246,7 @@ static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
48588 /*
48589 * See if we managed to reduce the size of the packet.
48590 */
48591 - if (olen < isize) {
48592 + if (olen < isize && olen <= osize) {
48593 state->stats.comp_bytes += olen;
48594 state->stats.comp_packets++;
48595 } else {
48596 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48597 index 794a473..9fd437b 100644
48598 --- a/drivers/net/ppp/ppp_generic.c
48599 +++ b/drivers/net/ppp/ppp_generic.c
48600 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48601 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48602 struct ppp_stats stats;
48603 struct ppp_comp_stats cstats;
48604 - char *vers;
48605
48606 switch (cmd) {
48607 case SIOCGPPPSTATS:
48608 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48609 break;
48610
48611 case SIOCGPPPVER:
48612 - vers = PPP_VERSION;
48613 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48614 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48615 break;
48616 err = 0;
48617 break;
48618 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48619 index 079f7ad..b2a2bfa7 100644
48620 --- a/drivers/net/slip/slhc.c
48621 +++ b/drivers/net/slip/slhc.c
48622 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48623 register struct tcphdr *thp;
48624 register struct iphdr *ip;
48625 register struct cstate *cs;
48626 - int len, hdrlen;
48627 + long len, hdrlen;
48628 unsigned char *cp = icp;
48629
48630 /* We've got a compressed packet; read the change byte */
48631 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48632 index 9c505c4..5d0c879 100644
48633 --- a/drivers/net/team/team.c
48634 +++ b/drivers/net/team/team.c
48635 @@ -2102,7 +2102,7 @@ static unsigned int team_get_num_rx_queues(void)
48636 return TEAM_DEFAULT_NUM_RX_QUEUES;
48637 }
48638
48639 -static struct rtnl_link_ops team_link_ops __read_mostly = {
48640 +static struct rtnl_link_ops team_link_ops = {
48641 .kind = DRV_NAME,
48642 .priv_size = sizeof(struct team),
48643 .setup = team_setup,
48644 @@ -2892,7 +2892,7 @@ static int team_device_event(struct notifier_block *unused,
48645 return NOTIFY_DONE;
48646 }
48647
48648 -static struct notifier_block team_notifier_block __read_mostly = {
48649 +static struct notifier_block team_notifier_block = {
48650 .notifier_call = team_device_event,
48651 };
48652
48653 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48654 index 9dd3746..74f191e 100644
48655 --- a/drivers/net/tun.c
48656 +++ b/drivers/net/tun.c
48657 @@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48658 return -EINVAL;
48659 }
48660
48661 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
48662 +static struct rtnl_link_ops tun_link_ops = {
48663 .kind = DRV_NAME,
48664 .priv_size = sizeof(struct tun_struct),
48665 .setup = tun_setup,
48666 @@ -1868,7 +1868,7 @@ unlock:
48667 }
48668
48669 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48670 - unsigned long arg, int ifreq_len)
48671 + unsigned long arg, size_t ifreq_len)
48672 {
48673 struct tun_file *tfile = file->private_data;
48674 struct tun_struct *tun;
48675 @@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48676 unsigned int ifindex;
48677 int ret;
48678
48679 + if (ifreq_len > sizeof ifr)
48680 + return -EFAULT;
48681 +
48682 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48683 if (copy_from_user(&ifr, argp, ifreq_len))
48684 return -EFAULT;
48685 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48686 index babda7d..e40c90a 100644
48687 --- a/drivers/net/usb/hso.c
48688 +++ b/drivers/net/usb/hso.c
48689 @@ -71,7 +71,7 @@
48690 #include <asm/byteorder.h>
48691 #include <linux/serial_core.h>
48692 #include <linux/serial.h>
48693 -
48694 +#include <asm/local.h>
48695
48696 #define MOD_AUTHOR "Option Wireless"
48697 #define MOD_DESCRIPTION "USB High Speed Option driver"
48698 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48699 struct urb *urb;
48700
48701 urb = serial->rx_urb[0];
48702 - if (serial->port.count > 0) {
48703 + if (atomic_read(&serial->port.count) > 0) {
48704 count = put_rxbuf_data(urb, serial);
48705 if (count == -1)
48706 return;
48707 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48708 DUMP1(urb->transfer_buffer, urb->actual_length);
48709
48710 /* Anyone listening? */
48711 - if (serial->port.count == 0)
48712 + if (atomic_read(&serial->port.count) == 0)
48713 return;
48714
48715 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48716 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48717 tty_port_tty_set(&serial->port, tty);
48718
48719 /* check for port already opened, if not set the termios */
48720 - serial->port.count++;
48721 - if (serial->port.count == 1) {
48722 + if (atomic_inc_return(&serial->port.count) == 1) {
48723 serial->rx_state = RX_IDLE;
48724 /* Force default termio settings */
48725 _hso_serial_set_termios(tty, NULL);
48726 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48727 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48728 if (result) {
48729 hso_stop_serial_device(serial->parent);
48730 - serial->port.count--;
48731 + atomic_dec(&serial->port.count);
48732 kref_put(&serial->parent->ref, hso_serial_ref_free);
48733 }
48734 } else {
48735 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48736
48737 /* reset the rts and dtr */
48738 /* do the actual close */
48739 - serial->port.count--;
48740 + atomic_dec(&serial->port.count);
48741
48742 - if (serial->port.count <= 0) {
48743 - serial->port.count = 0;
48744 + if (atomic_read(&serial->port.count) <= 0) {
48745 + atomic_set(&serial->port.count, 0);
48746 tty_port_tty_set(&serial->port, NULL);
48747 if (!usb_gone)
48748 hso_stop_serial_device(serial->parent);
48749 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48750
48751 /* the actual setup */
48752 spin_lock_irqsave(&serial->serial_lock, flags);
48753 - if (serial->port.count)
48754 + if (atomic_read(&serial->port.count))
48755 _hso_serial_set_termios(tty, old);
48756 else
48757 tty->termios = *old;
48758 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48759 D1("Pending read interrupt on port %d\n", i);
48760 spin_lock(&serial->serial_lock);
48761 if (serial->rx_state == RX_IDLE &&
48762 - serial->port.count > 0) {
48763 + atomic_read(&serial->port.count) > 0) {
48764 /* Setup and send a ctrl req read on
48765 * port i */
48766 if (!serial->rx_urb_filled[0]) {
48767 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48768 /* Start all serial ports */
48769 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48770 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48771 - if (dev2ser(serial_table[i])->port.count) {
48772 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48773 result =
48774 hso_start_serial_device(serial_table[i], GFP_NOIO);
48775 hso_kick_transmit(dev2ser(serial_table[i]));
48776 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48777 index c6554c7..7e2ebd7 100644
48778 --- a/drivers/net/usb/r8152.c
48779 +++ b/drivers/net/usb/r8152.c
48780 @@ -577,7 +577,7 @@ struct r8152 {
48781 void (*unload)(struct r8152 *);
48782 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48783 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48784 - } rtl_ops;
48785 + } __no_const rtl_ops;
48786
48787 int intr_interval;
48788 u32 saved_wolopts;
48789 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48790 index a2515887..6d13233 100644
48791 --- a/drivers/net/usb/sierra_net.c
48792 +++ b/drivers/net/usb/sierra_net.c
48793 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48794 /* atomic counter partially included in MAC address to make sure 2 devices
48795 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48796 */
48797 -static atomic_t iface_counter = ATOMIC_INIT(0);
48798 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48799
48800 /*
48801 * SYNC Timer Delay definition used to set the expiry time
48802 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48803 dev->net->netdev_ops = &sierra_net_device_ops;
48804
48805 /* change MAC addr to include, ifacenum, and to be unique */
48806 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48807 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48808 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48809
48810 /* we will have to manufacture ethernet headers, prepare template */
48811 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48812 index b0bc8ea..3af931b5 100644
48813 --- a/drivers/net/virtio_net.c
48814 +++ b/drivers/net/virtio_net.c
48815 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48816 #define RECEIVE_AVG_WEIGHT 64
48817
48818 /* Minimum alignment for mergeable packet buffers. */
48819 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48820 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48821
48822 #define VIRTNET_DRIVER_VERSION "1.0.0"
48823
48824 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48825 index 42b2d6a5..2a2cb41 100644
48826 --- a/drivers/net/vxlan.c
48827 +++ b/drivers/net/vxlan.c
48828 @@ -2695,7 +2695,7 @@ nla_put_failure:
48829 return -EMSGSIZE;
48830 }
48831
48832 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48833 +static struct rtnl_link_ops vxlan_link_ops = {
48834 .kind = "vxlan",
48835 .maxtype = IFLA_VXLAN_MAX,
48836 .policy = vxlan_policy,
48837 @@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48838 return NOTIFY_DONE;
48839 }
48840
48841 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48842 +static struct notifier_block vxlan_notifier_block = {
48843 .notifier_call = vxlan_lowerdev_event,
48844 };
48845
48846 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48847 index 5920c99..ff2e4a5 100644
48848 --- a/drivers/net/wan/lmc/lmc_media.c
48849 +++ b/drivers/net/wan/lmc/lmc_media.c
48850 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48851 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48852
48853 lmc_media_t lmc_ds3_media = {
48854 - lmc_ds3_init, /* special media init stuff */
48855 - lmc_ds3_default, /* reset to default state */
48856 - lmc_ds3_set_status, /* reset status to state provided */
48857 - lmc_dummy_set_1, /* set clock source */
48858 - lmc_dummy_set2_1, /* set line speed */
48859 - lmc_ds3_set_100ft, /* set cable length */
48860 - lmc_ds3_set_scram, /* set scrambler */
48861 - lmc_ds3_get_link_status, /* get link status */
48862 - lmc_dummy_set_1, /* set link status */
48863 - lmc_ds3_set_crc_length, /* set CRC length */
48864 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48865 - lmc_ds3_watchdog
48866 + .init = lmc_ds3_init, /* special media init stuff */
48867 + .defaults = lmc_ds3_default, /* reset to default state */
48868 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48869 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
48870 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48871 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48872 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48873 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
48874 + .set_link_status = lmc_dummy_set_1, /* set link status */
48875 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48876 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48877 + .watchdog = lmc_ds3_watchdog
48878 };
48879
48880 lmc_media_t lmc_hssi_media = {
48881 - lmc_hssi_init, /* special media init stuff */
48882 - lmc_hssi_default, /* reset to default state */
48883 - lmc_hssi_set_status, /* reset status to state provided */
48884 - lmc_hssi_set_clock, /* set clock source */
48885 - lmc_dummy_set2_1, /* set line speed */
48886 - lmc_dummy_set_1, /* set cable length */
48887 - lmc_dummy_set_1, /* set scrambler */
48888 - lmc_hssi_get_link_status, /* get link status */
48889 - lmc_hssi_set_link_status, /* set link status */
48890 - lmc_hssi_set_crc_length, /* set CRC length */
48891 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48892 - lmc_hssi_watchdog
48893 + .init = lmc_hssi_init, /* special media init stuff */
48894 + .defaults = lmc_hssi_default, /* reset to default state */
48895 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
48896 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48897 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48898 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48899 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48900 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
48901 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
48902 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48903 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48904 + .watchdog = lmc_hssi_watchdog
48905 };
48906
48907 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48908 - lmc_ssi_default, /* reset to default state */
48909 - lmc_ssi_set_status, /* reset status to state provided */
48910 - lmc_ssi_set_clock, /* set clock source */
48911 - lmc_ssi_set_speed, /* set line speed */
48912 - lmc_dummy_set_1, /* set cable length */
48913 - lmc_dummy_set_1, /* set scrambler */
48914 - lmc_ssi_get_link_status, /* get link status */
48915 - lmc_ssi_set_link_status, /* set link status */
48916 - lmc_ssi_set_crc_length, /* set CRC length */
48917 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48918 - lmc_ssi_watchdog
48919 +lmc_media_t lmc_ssi_media = {
48920 + .init = lmc_ssi_init, /* special media init stuff */
48921 + .defaults = lmc_ssi_default, /* reset to default state */
48922 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
48923 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48924 + .set_speed = lmc_ssi_set_speed, /* set line speed */
48925 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48926 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48927 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
48928 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
48929 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48930 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48931 + .watchdog = lmc_ssi_watchdog
48932 };
48933
48934 lmc_media_t lmc_t1_media = {
48935 - lmc_t1_init, /* special media init stuff */
48936 - lmc_t1_default, /* reset to default state */
48937 - lmc_t1_set_status, /* reset status to state provided */
48938 - lmc_t1_set_clock, /* set clock source */
48939 - lmc_dummy_set2_1, /* set line speed */
48940 - lmc_dummy_set_1, /* set cable length */
48941 - lmc_dummy_set_1, /* set scrambler */
48942 - lmc_t1_get_link_status, /* get link status */
48943 - lmc_dummy_set_1, /* set link status */
48944 - lmc_t1_set_crc_length, /* set CRC length */
48945 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48946 - lmc_t1_watchdog
48947 + .init = lmc_t1_init, /* special media init stuff */
48948 + .defaults = lmc_t1_default, /* reset to default state */
48949 + .set_status = lmc_t1_set_status, /* reset status to state provided */
48950 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
48951 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48952 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48953 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48954 + .get_link_status = lmc_t1_get_link_status, /* get link status */
48955 + .set_link_status = lmc_dummy_set_1, /* set link status */
48956 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48957 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48958 + .watchdog = lmc_t1_watchdog
48959 };
48960
48961 static void
48962 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48963 index feacc3b..5bac0de 100644
48964 --- a/drivers/net/wan/z85230.c
48965 +++ b/drivers/net/wan/z85230.c
48966 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48967
48968 struct z8530_irqhandler z8530_sync =
48969 {
48970 - z8530_rx,
48971 - z8530_tx,
48972 - z8530_status
48973 + .rx = z8530_rx,
48974 + .tx = z8530_tx,
48975 + .status = z8530_status
48976 };
48977
48978 EXPORT_SYMBOL(z8530_sync);
48979 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48980 }
48981
48982 static struct z8530_irqhandler z8530_dma_sync = {
48983 - z8530_dma_rx,
48984 - z8530_dma_tx,
48985 - z8530_dma_status
48986 + .rx = z8530_dma_rx,
48987 + .tx = z8530_dma_tx,
48988 + .status = z8530_dma_status
48989 };
48990
48991 static struct z8530_irqhandler z8530_txdma_sync = {
48992 - z8530_rx,
48993 - z8530_dma_tx,
48994 - z8530_dma_status
48995 + .rx = z8530_rx,
48996 + .tx = z8530_dma_tx,
48997 + .status = z8530_dma_status
48998 };
48999
49000 /**
49001 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49002
49003 struct z8530_irqhandler z8530_nop=
49004 {
49005 - z8530_rx_clear,
49006 - z8530_tx_clear,
49007 - z8530_status_clear
49008 + .rx = z8530_rx_clear,
49009 + .tx = z8530_tx_clear,
49010 + .status = z8530_status_clear
49011 };
49012
49013
49014 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49015 index 0b60295..b8bfa5b 100644
49016 --- a/drivers/net/wimax/i2400m/rx.c
49017 +++ b/drivers/net/wimax/i2400m/rx.c
49018 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49019 if (i2400m->rx_roq == NULL)
49020 goto error_roq_alloc;
49021
49022 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49023 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49024 GFP_KERNEL);
49025 if (rd == NULL) {
49026 result = -ENOMEM;
49027 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49028 index e71a2ce..2268d61 100644
49029 --- a/drivers/net/wireless/airo.c
49030 +++ b/drivers/net/wireless/airo.c
49031 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49032 struct airo_info *ai = dev->ml_priv;
49033 int ridcode;
49034 int enabled;
49035 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49036 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49037 unsigned char *iobuf;
49038
49039 /* Only super-user can write RIDs */
49040 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49041 index da92bfa..5a9001a 100644
49042 --- a/drivers/net/wireless/at76c50x-usb.c
49043 +++ b/drivers/net/wireless/at76c50x-usb.c
49044 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49045 }
49046
49047 /* Convert timeout from the DFU status to jiffies */
49048 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49049 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49050 {
49051 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49052 | (s->poll_timeout[1] << 8)
49053 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49054 index 676bd4e..0b807a3 100644
49055 --- a/drivers/net/wireless/ath/ath10k/htc.c
49056 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49057 @@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
49058 /* registered target arrival callback from the HIF layer */
49059 int ath10k_htc_init(struct ath10k *ar)
49060 {
49061 - struct ath10k_hif_cb htc_callbacks;
49062 + static struct ath10k_hif_cb htc_callbacks = {
49063 + .rx_completion = ath10k_htc_rx_completion_handler,
49064 + .tx_completion = ath10k_htc_tx_completion_handler,
49065 + };
49066 struct ath10k_htc_ep *ep = NULL;
49067 struct ath10k_htc *htc = &ar->htc;
49068
49069 @@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
49070 ath10k_htc_reset_endpoint_states(htc);
49071
49072 /* setup HIF layer callbacks */
49073 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49074 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49075 htc->ar = ar;
49076
49077 /* Get HIF default pipe for HTC message exchange */
49078 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49079 index 527179c..a890150 100644
49080 --- a/drivers/net/wireless/ath/ath10k/htc.h
49081 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49082 @@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
49083
49084 struct ath10k_htc_ops {
49085 void (*target_send_suspend_complete)(struct ath10k *ar);
49086 -};
49087 +} __no_const;
49088
49089 struct ath10k_htc_ep_ops {
49090 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49091 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49092 void (*ep_tx_credits)(struct ath10k *);
49093 -};
49094 +} __no_const;
49095
49096 /* service connection information */
49097 struct ath10k_htc_svc_conn_req {
49098 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49099 index 2a93519..7052786 100644
49100 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49101 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49102 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49103 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49104 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49105
49106 - ACCESS_ONCE(ads->ds_link) = i->link;
49107 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49108 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49109 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49110
49111 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49112 ctl6 = SM(i->keytype, AR_EncrType);
49113 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49114
49115 if ((i->is_first || i->is_last) &&
49116 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49117 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49118 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49119 | set11nTries(i->rates, 1)
49120 | set11nTries(i->rates, 2)
49121 | set11nTries(i->rates, 3)
49122 | (i->dur_update ? AR_DurUpdateEna : 0)
49123 | SM(0, AR_BurstDur);
49124
49125 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49126 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49127 | set11nRate(i->rates, 1)
49128 | set11nRate(i->rates, 2)
49129 | set11nRate(i->rates, 3);
49130 } else {
49131 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49132 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49133 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49134 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49135 }
49136
49137 if (!i->is_first) {
49138 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49139 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49140 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49141 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49142 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49143 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49144 return;
49145 }
49146
49147 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49148 break;
49149 }
49150
49151 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49152 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49153 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49154 | SM(i->txpower, AR_XmitPower0)
49155 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49156 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49157 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49158 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49159
49160 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49161 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49162 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49163 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49164
49165 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49166 return;
49167
49168 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49169 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49170 | set11nPktDurRTSCTS(i->rates, 1);
49171
49172 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49173 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49174 | set11nPktDurRTSCTS(i->rates, 3);
49175
49176 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49177 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49178 | set11nRateFlags(i->rates, 1)
49179 | set11nRateFlags(i->rates, 2)
49180 | set11nRateFlags(i->rates, 3)
49181 | SM(i->rtscts_rate, AR_RTSCTSRate);
49182
49183 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49184 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49185 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49186 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49187 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49188 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49189 }
49190
49191 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49192 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49193 index 057b165..98ae88f 100644
49194 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49195 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49196 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49197 (i->qcu << AR_TxQcuNum_S) | desc_len;
49198
49199 checksum += val;
49200 - ACCESS_ONCE(ads->info) = val;
49201 + ACCESS_ONCE_RW(ads->info) = val;
49202
49203 checksum += i->link;
49204 - ACCESS_ONCE(ads->link) = i->link;
49205 + ACCESS_ONCE_RW(ads->link) = i->link;
49206
49207 checksum += i->buf_addr[0];
49208 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49209 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49210 checksum += i->buf_addr[1];
49211 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49212 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49213 checksum += i->buf_addr[2];
49214 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49215 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49216 checksum += i->buf_addr[3];
49217 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49218 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49219
49220 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49221 - ACCESS_ONCE(ads->ctl3) = val;
49222 + ACCESS_ONCE_RW(ads->ctl3) = val;
49223 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49224 - ACCESS_ONCE(ads->ctl5) = val;
49225 + ACCESS_ONCE_RW(ads->ctl5) = val;
49226 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49227 - ACCESS_ONCE(ads->ctl7) = val;
49228 + ACCESS_ONCE_RW(ads->ctl7) = val;
49229 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49230 - ACCESS_ONCE(ads->ctl9) = val;
49231 + ACCESS_ONCE_RW(ads->ctl9) = val;
49232
49233 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49234 - ACCESS_ONCE(ads->ctl10) = checksum;
49235 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49236
49237 if (i->is_first || i->is_last) {
49238 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49239 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49240 | set11nTries(i->rates, 1)
49241 | set11nTries(i->rates, 2)
49242 | set11nTries(i->rates, 3)
49243 | (i->dur_update ? AR_DurUpdateEna : 0)
49244 | SM(0, AR_BurstDur);
49245
49246 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49247 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49248 | set11nRate(i->rates, 1)
49249 | set11nRate(i->rates, 2)
49250 | set11nRate(i->rates, 3);
49251 } else {
49252 - ACCESS_ONCE(ads->ctl13) = 0;
49253 - ACCESS_ONCE(ads->ctl14) = 0;
49254 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49255 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49256 }
49257
49258 ads->ctl20 = 0;
49259 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49260
49261 ctl17 = SM(i->keytype, AR_EncrType);
49262 if (!i->is_first) {
49263 - ACCESS_ONCE(ads->ctl11) = 0;
49264 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49265 - ACCESS_ONCE(ads->ctl15) = 0;
49266 - ACCESS_ONCE(ads->ctl16) = 0;
49267 - ACCESS_ONCE(ads->ctl17) = ctl17;
49268 - ACCESS_ONCE(ads->ctl18) = 0;
49269 - ACCESS_ONCE(ads->ctl19) = 0;
49270 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49271 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49272 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49273 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49274 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49275 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49276 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49277 return;
49278 }
49279
49280 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49281 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49282 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49283 | SM(i->txpower, AR_XmitPower0)
49284 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49285 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49286 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49287 ctl12 |= SM(val, AR_PAPRDChainMask);
49288
49289 - ACCESS_ONCE(ads->ctl12) = ctl12;
49290 - ACCESS_ONCE(ads->ctl17) = ctl17;
49291 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49292 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49293
49294 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49295 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49296 | set11nPktDurRTSCTS(i->rates, 1);
49297
49298 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49299 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49300 | set11nPktDurRTSCTS(i->rates, 3);
49301
49302 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49303 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49304 | set11nRateFlags(i->rates, 1)
49305 | set11nRateFlags(i->rates, 2)
49306 | set11nRateFlags(i->rates, 3)
49307 | SM(i->rtscts_rate, AR_RTSCTSRate);
49308
49309 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49310 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49311
49312 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49313 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49314 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49315 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49316 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49317 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49318 }
49319
49320 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49321 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49322 index e8e8dd2..030f80e 100644
49323 --- a/drivers/net/wireless/ath/ath9k/hw.h
49324 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49325 @@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49326
49327 /* ANI */
49328 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49329 -};
49330 +} __no_const;
49331
49332 /**
49333 * struct ath_spec_scan - parameters for Atheros spectral scan
49334 @@ -708,7 +708,7 @@ struct ath_hw_ops {
49335 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49336 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49337 #endif
49338 -};
49339 +} __no_const;
49340
49341 struct ath_nf_limits {
49342 s16 max;
49343 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49344 index 4f18a6b..b07d92f 100644
49345 --- a/drivers/net/wireless/ath/ath9k/main.c
49346 +++ b/drivers/net/wireless/ath/ath9k/main.c
49347 @@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49348 if (!ath9k_is_chanctx_enabled())
49349 return;
49350
49351 - ath9k_ops.hw_scan = ath9k_hw_scan;
49352 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49353 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49354 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49355 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49356 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49357 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49358 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49359 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49360 - ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49361 + pax_open_kernel();
49362 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49363 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49364 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49365 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49366 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49367 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49368 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49369 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49370 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49371 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49372 + pax_close_kernel();
49373 }
49374
49375 #endif
49376 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49377 index 058a9f2..d5cb1ba 100644
49378 --- a/drivers/net/wireless/b43/phy_lp.c
49379 +++ b/drivers/net/wireless/b43/phy_lp.c
49380 @@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49381 {
49382 struct ssb_bus *bus = dev->dev->sdev->bus;
49383
49384 - static const struct b206x_channel *chandata = NULL;
49385 + const struct b206x_channel *chandata = NULL;
49386 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49387 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49388 u16 old_comm15, scale;
49389 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49390 index dc1d20c..f7a4f06 100644
49391 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49392 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49393 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49394 */
49395 if (il3945_mod_params.disable_hw_scan) {
49396 D_INFO("Disabling hw_scan\n");
49397 - il3945_mac_ops.hw_scan = NULL;
49398 + pax_open_kernel();
49399 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49400 + pax_close_kernel();
49401 }
49402
49403 D_INFO("*** LOAD DRIVER ***\n");
49404 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49405 index 0ffb6ff..c0b7f0e 100644
49406 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49407 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49408 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49409 {
49410 struct iwl_priv *priv = file->private_data;
49411 char buf[64];
49412 - int buf_size;
49413 + size_t buf_size;
49414 u32 offset, len;
49415
49416 memset(buf, 0, sizeof(buf));
49417 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49418 struct iwl_priv *priv = file->private_data;
49419
49420 char buf[8];
49421 - int buf_size;
49422 + size_t buf_size;
49423 u32 reset_flag;
49424
49425 memset(buf, 0, sizeof(buf));
49426 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49427 {
49428 struct iwl_priv *priv = file->private_data;
49429 char buf[8];
49430 - int buf_size;
49431 + size_t buf_size;
49432 int ht40;
49433
49434 memset(buf, 0, sizeof(buf));
49435 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49436 {
49437 struct iwl_priv *priv = file->private_data;
49438 char buf[8];
49439 - int buf_size;
49440 + size_t buf_size;
49441 int value;
49442
49443 memset(buf, 0, sizeof(buf));
49444 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49445 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49446 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49447
49448 -static const char *fmt_value = " %-30s %10u\n";
49449 -static const char *fmt_hex = " %-30s 0x%02X\n";
49450 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49451 -static const char *fmt_header =
49452 +static const char fmt_value[] = " %-30s %10u\n";
49453 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49454 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49455 +static const char fmt_header[] =
49456 "%-32s current cumulative delta max\n";
49457
49458 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49459 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49460 {
49461 struct iwl_priv *priv = file->private_data;
49462 char buf[8];
49463 - int buf_size;
49464 + size_t buf_size;
49465 int clear;
49466
49467 memset(buf, 0, sizeof(buf));
49468 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49469 {
49470 struct iwl_priv *priv = file->private_data;
49471 char buf[8];
49472 - int buf_size;
49473 + size_t buf_size;
49474 int trace;
49475
49476 memset(buf, 0, sizeof(buf));
49477 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49478 {
49479 struct iwl_priv *priv = file->private_data;
49480 char buf[8];
49481 - int buf_size;
49482 + size_t buf_size;
49483 int missed;
49484
49485 memset(buf, 0, sizeof(buf));
49486 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49487
49488 struct iwl_priv *priv = file->private_data;
49489 char buf[8];
49490 - int buf_size;
49491 + size_t buf_size;
49492 int plcp;
49493
49494 memset(buf, 0, sizeof(buf));
49495 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49496
49497 struct iwl_priv *priv = file->private_data;
49498 char buf[8];
49499 - int buf_size;
49500 + size_t buf_size;
49501 int flush;
49502
49503 memset(buf, 0, sizeof(buf));
49504 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49505
49506 struct iwl_priv *priv = file->private_data;
49507 char buf[8];
49508 - int buf_size;
49509 + size_t buf_size;
49510 int rts;
49511
49512 if (!priv->cfg->ht_params)
49513 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49514 {
49515 struct iwl_priv *priv = file->private_data;
49516 char buf[8];
49517 - int buf_size;
49518 + size_t buf_size;
49519
49520 memset(buf, 0, sizeof(buf));
49521 buf_size = min(count, sizeof(buf) - 1);
49522 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49523 struct iwl_priv *priv = file->private_data;
49524 u32 event_log_flag;
49525 char buf[8];
49526 - int buf_size;
49527 + size_t buf_size;
49528
49529 /* check that the interface is up */
49530 if (!iwl_is_ready(priv))
49531 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49532 struct iwl_priv *priv = file->private_data;
49533 char buf[8];
49534 u32 calib_disabled;
49535 - int buf_size;
49536 + size_t buf_size;
49537
49538 memset(buf, 0, sizeof(buf));
49539 buf_size = min(count, sizeof(buf) - 1);
49540 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49541 index dd2f3f8..fb1ae88 100644
49542 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49543 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49544 @@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49545 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49546
49547 char buf[8];
49548 - int buf_size;
49549 + size_t buf_size;
49550 u32 reset_flag;
49551
49552 memset(buf, 0, sizeof(buf));
49553 @@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49554 {
49555 struct iwl_trans *trans = file->private_data;
49556 char buf[8];
49557 - int buf_size;
49558 + size_t buf_size;
49559 int csr;
49560
49561 memset(buf, 0, sizeof(buf));
49562 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49563 index c9ad4cf..49a2fa0 100644
49564 --- a/drivers/net/wireless/mac80211_hwsim.c
49565 +++ b/drivers/net/wireless/mac80211_hwsim.c
49566 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49567 if (channels < 1)
49568 return -EINVAL;
49569
49570 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49571 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49572 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49573 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49574 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49575 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49576 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49577 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49578 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49579 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49580 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49581 - mac80211_hwsim_assign_vif_chanctx;
49582 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49583 - mac80211_hwsim_unassign_vif_chanctx;
49584 + pax_open_kernel();
49585 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49586 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49587 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49588 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49589 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49590 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49591 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49592 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49593 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49594 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49595 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49596 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49597 + pax_close_kernel();
49598
49599 spin_lock_init(&hwsim_radio_lock);
49600 INIT_LIST_HEAD(&hwsim_radios);
49601 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49602 index 1a4facd..a2ecbbd 100644
49603 --- a/drivers/net/wireless/rndis_wlan.c
49604 +++ b/drivers/net/wireless/rndis_wlan.c
49605 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49606
49607 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49608
49609 - if (rts_threshold < 0 || rts_threshold > 2347)
49610 + if (rts_threshold > 2347)
49611 rts_threshold = 2347;
49612
49613 tmp = cpu_to_le32(rts_threshold);
49614 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49615 index d13f25c..2573994 100644
49616 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49617 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49618 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49619 * for hardware which doesn't support hardware
49620 * sequence counting.
49621 */
49622 - atomic_t seqno;
49623 + atomic_unchecked_t seqno;
49624 };
49625
49626 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49627 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49628 index 66ff364..3ce34f7 100644
49629 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49630 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49631 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49632 * sequence counter given by mac80211.
49633 */
49634 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49635 - seqno = atomic_add_return(0x10, &intf->seqno);
49636 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49637 else
49638 - seqno = atomic_read(&intf->seqno);
49639 + seqno = atomic_read_unchecked(&intf->seqno);
49640
49641 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49642 hdr->seq_ctrl |= cpu_to_le16(seqno);
49643 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49644 index b661f896..ddf7d2b 100644
49645 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49646 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49647 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49648
49649 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49650
49651 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49652 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49653 + pax_open_kernel();
49654 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49655 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49656 + pax_close_kernel();
49657
49658 wl1251_info("using dedicated interrupt line");
49659 } else {
49660 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49661 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49662 + pax_open_kernel();
49663 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49664 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49665 + pax_close_kernel();
49666
49667 wl1251_info("using SDIO interrupt");
49668 }
49669 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49670 index 0bccf12..3d95068 100644
49671 --- a/drivers/net/wireless/ti/wl12xx/main.c
49672 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49673 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49674 sizeof(wl->conf.mem));
49675
49676 /* read data preparation is only needed by wl127x */
49677 - wl->ops->prepare_read = wl127x_prepare_read;
49678 + pax_open_kernel();
49679 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49680 + pax_close_kernel();
49681
49682 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49683 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49684 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49685 sizeof(wl->conf.mem));
49686
49687 /* read data preparation is only needed by wl127x */
49688 - wl->ops->prepare_read = wl127x_prepare_read;
49689 + pax_open_kernel();
49690 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49691 + pax_close_kernel();
49692
49693 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49694 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49695 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49696 index 7af1936..128bb35 100644
49697 --- a/drivers/net/wireless/ti/wl18xx/main.c
49698 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49699 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49700 }
49701
49702 if (!checksum_param) {
49703 - wl18xx_ops.set_rx_csum = NULL;
49704 - wl18xx_ops.init_vif = NULL;
49705 + pax_open_kernel();
49706 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49707 + *(void **)&wl18xx_ops.init_vif = NULL;
49708 + pax_close_kernel();
49709 }
49710
49711 /* Enable 11a Band only if we have 5G antennas */
49712 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49713 index a912dc0..a8225ba 100644
49714 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49715 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49716 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49717 {
49718 struct zd_usb *usb = urb->context;
49719 struct zd_usb_interrupt *intr = &usb->intr;
49720 - int len;
49721 + unsigned int len;
49722 u16 int_num;
49723
49724 ZD_ASSERT(in_interrupt());
49725 diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
49726 index d752d1c..23e3203 100644
49727 --- a/drivers/net/xen-netback/interface.c
49728 +++ b/drivers/net/xen-netback/interface.c
49729 @@ -578,6 +578,7 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
49730 goto err_rx_unbind;
49731 }
49732 queue->task = task;
49733 + get_task_struct(task);
49734
49735 task = kthread_create(xenvif_dealloc_kthread,
49736 (void *)queue, "%s-dealloc", queue->name);
49737 @@ -634,6 +635,7 @@ void xenvif_disconnect(struct xenvif *vif)
49738
49739 if (queue->task) {
49740 kthread_stop(queue->task);
49741 + put_task_struct(queue->task);
49742 queue->task = NULL;
49743 }
49744
49745 diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
49746 index c39aace..e18728d 100644
49747 --- a/drivers/net/xen-netback/netback.c
49748 +++ b/drivers/net/xen-netback/netback.c
49749 @@ -2111,8 +2111,7 @@ int xenvif_kthread_guest_rx(void *data)
49750 */
49751 if (unlikely(vif->disabled && queue->id == 0)) {
49752 xenvif_carrier_off(vif);
49753 - xenvif_rx_queue_purge(queue);
49754 - continue;
49755 + break;
49756 }
49757
49758 if (!skb_queue_empty(&queue->rx_queue))
49759 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49760 index 683671a..4519fc2 100644
49761 --- a/drivers/nfc/nfcwilink.c
49762 +++ b/drivers/nfc/nfcwilink.c
49763 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49764
49765 static int nfcwilink_probe(struct platform_device *pdev)
49766 {
49767 - static struct nfcwilink *drv;
49768 + struct nfcwilink *drv;
49769 int rc;
49770 __u32 protocols;
49771
49772 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49773 index d93b2b6..ae50401 100644
49774 --- a/drivers/oprofile/buffer_sync.c
49775 +++ b/drivers/oprofile/buffer_sync.c
49776 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49777 if (cookie == NO_COOKIE)
49778 offset = pc;
49779 if (cookie == INVALID_COOKIE) {
49780 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49781 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49782 offset = pc;
49783 }
49784 if (cookie != last_cookie) {
49785 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49786 /* add userspace sample */
49787
49788 if (!mm) {
49789 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49790 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49791 return 0;
49792 }
49793
49794 cookie = lookup_dcookie(mm, s->eip, &offset);
49795
49796 if (cookie == INVALID_COOKIE) {
49797 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49798 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49799 return 0;
49800 }
49801
49802 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49803 /* ignore backtraces if failed to add a sample */
49804 if (state == sb_bt_start) {
49805 state = sb_bt_ignore;
49806 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49807 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49808 }
49809 }
49810 release_mm(mm);
49811 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49812 index c0cc4e7..44d4e54 100644
49813 --- a/drivers/oprofile/event_buffer.c
49814 +++ b/drivers/oprofile/event_buffer.c
49815 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49816 }
49817
49818 if (buffer_pos == buffer_size) {
49819 - atomic_inc(&oprofile_stats.event_lost_overflow);
49820 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49821 return;
49822 }
49823
49824 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49825 index ed2c3ec..deda85a 100644
49826 --- a/drivers/oprofile/oprof.c
49827 +++ b/drivers/oprofile/oprof.c
49828 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49829 if (oprofile_ops.switch_events())
49830 return;
49831
49832 - atomic_inc(&oprofile_stats.multiplex_counter);
49833 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49834 start_switch_worker();
49835 }
49836
49837 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49838 index ee2cfce..7f8f699 100644
49839 --- a/drivers/oprofile/oprofile_files.c
49840 +++ b/drivers/oprofile/oprofile_files.c
49841 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49842
49843 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49844
49845 -static ssize_t timeout_read(struct file *file, char __user *buf,
49846 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49847 size_t count, loff_t *offset)
49848 {
49849 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49850 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49851 index 59659ce..6c860a0 100644
49852 --- a/drivers/oprofile/oprofile_stats.c
49853 +++ b/drivers/oprofile/oprofile_stats.c
49854 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49855 cpu_buf->sample_invalid_eip = 0;
49856 }
49857
49858 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49859 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49860 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49861 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49862 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49863 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49864 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49865 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49866 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49867 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49868 }
49869
49870
49871 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49872 index 1fc622b..8c48fc3 100644
49873 --- a/drivers/oprofile/oprofile_stats.h
49874 +++ b/drivers/oprofile/oprofile_stats.h
49875 @@ -13,11 +13,11 @@
49876 #include <linux/atomic.h>
49877
49878 struct oprofile_stat_struct {
49879 - atomic_t sample_lost_no_mm;
49880 - atomic_t sample_lost_no_mapping;
49881 - atomic_t bt_lost_no_mapping;
49882 - atomic_t event_lost_overflow;
49883 - atomic_t multiplex_counter;
49884 + atomic_unchecked_t sample_lost_no_mm;
49885 + atomic_unchecked_t sample_lost_no_mapping;
49886 + atomic_unchecked_t bt_lost_no_mapping;
49887 + atomic_unchecked_t event_lost_overflow;
49888 + atomic_unchecked_t multiplex_counter;
49889 };
49890
49891 extern struct oprofile_stat_struct oprofile_stats;
49892 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49893 index 3f49345..c750d0b 100644
49894 --- a/drivers/oprofile/oprofilefs.c
49895 +++ b/drivers/oprofile/oprofilefs.c
49896 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49897
49898 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49899 {
49900 - atomic_t *val = file->private_data;
49901 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49902 + atomic_unchecked_t *val = file->private_data;
49903 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49904 }
49905
49906
49907 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49908
49909
49910 int oprofilefs_create_ro_atomic(struct dentry *root,
49911 - char const *name, atomic_t *val)
49912 + char const *name, atomic_unchecked_t *val)
49913 {
49914 return __oprofilefs_create_file(root, name,
49915 &atomic_ro_fops, 0444, val);
49916 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49917 index bdef916..88c7dee 100644
49918 --- a/drivers/oprofile/timer_int.c
49919 +++ b/drivers/oprofile/timer_int.c
49920 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49921 return NOTIFY_OK;
49922 }
49923
49924 -static struct notifier_block __refdata oprofile_cpu_notifier = {
49925 +static struct notifier_block oprofile_cpu_notifier = {
49926 .notifier_call = oprofile_cpu_notify,
49927 };
49928
49929 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49930 index 3b47080..6cd05dd 100644
49931 --- a/drivers/parport/procfs.c
49932 +++ b/drivers/parport/procfs.c
49933 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49934
49935 *ppos += len;
49936
49937 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49938 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49939 }
49940
49941 #ifdef CONFIG_PARPORT_1284
49942 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49943
49944 *ppos += len;
49945
49946 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49947 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49948 }
49949 #endif /* IEEE1284.3 support. */
49950
49951 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49952 index 6ca2399..68d866b 100644
49953 --- a/drivers/pci/hotplug/acpiphp_ibm.c
49954 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
49955 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49956 goto init_cleanup;
49957 }
49958
49959 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49960 + pax_open_kernel();
49961 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49962 + pax_close_kernel();
49963 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49964
49965 return retval;
49966 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49967 index 66b7bbe..26bee78 100644
49968 --- a/drivers/pci/hotplug/cpcihp_generic.c
49969 +++ b/drivers/pci/hotplug/cpcihp_generic.c
49970 @@ -73,7 +73,6 @@ static u16 port;
49971 static unsigned int enum_bit;
49972 static u8 enum_mask;
49973
49974 -static struct cpci_hp_controller_ops generic_hpc_ops;
49975 static struct cpci_hp_controller generic_hpc;
49976
49977 static int __init validate_parameters(void)
49978 @@ -139,6 +138,10 @@ static int query_enum(void)
49979 return ((value & enum_mask) == enum_mask);
49980 }
49981
49982 +static struct cpci_hp_controller_ops generic_hpc_ops = {
49983 + .query_enum = query_enum,
49984 +};
49985 +
49986 static int __init cpcihp_generic_init(void)
49987 {
49988 int status;
49989 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49990 pci_dev_put(dev);
49991
49992 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49993 - generic_hpc_ops.query_enum = query_enum;
49994 generic_hpc.ops = &generic_hpc_ops;
49995
49996 status = cpci_hp_register_controller(&generic_hpc);
49997 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49998 index 7ecf34e..effed62 100644
49999 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50000 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50001 @@ -59,7 +59,6 @@
50002 /* local variables */
50003 static bool debug;
50004 static bool poll;
50005 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50006 static struct cpci_hp_controller zt5550_hpc;
50007
50008 /* Primary cPCI bus bridge device */
50009 @@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
50010 return 0;
50011 }
50012
50013 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50014 + .query_enum = zt5550_hc_query_enum,
50015 +};
50016 +
50017 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50018 {
50019 int status;
50020 @@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50021 dbg("returned from zt5550_hc_config");
50022
50023 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50024 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50025 zt5550_hpc.ops = &zt5550_hpc_ops;
50026 if (!poll) {
50027 zt5550_hpc.irq = hc_dev->irq;
50028 zt5550_hpc.irq_flags = IRQF_SHARED;
50029 zt5550_hpc.dev_id = hc_dev;
50030
50031 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50032 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50033 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50034 + pax_open_kernel();
50035 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50036 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50037 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50038 + pax_open_kernel();
50039 } else {
50040 info("using ENUM# polling mode");
50041 }
50042 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50043 index 1e08ff8c..3cd145f 100644
50044 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50045 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50046 @@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
50047
50048 void compaq_nvram_init (void __iomem *rom_start)
50049 {
50050 +#ifndef CONFIG_PAX_KERNEXEC
50051 if (rom_start)
50052 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50053 +#endif
50054
50055 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50056
50057 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50058 index 56d8486..f26113f 100644
50059 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50060 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50061 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50062 return -EINVAL;
50063 }
50064
50065 - slot->ops->owner = owner;
50066 - slot->ops->mod_name = mod_name;
50067 + pax_open_kernel();
50068 + *(struct module **)&slot->ops->owner = owner;
50069 + *(const char **)&slot->ops->mod_name = mod_name;
50070 + pax_close_kernel();
50071
50072 mutex_lock(&pci_hp_mutex);
50073 /*
50074 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50075 index 07aa722..84514b4 100644
50076 --- a/drivers/pci/hotplug/pciehp_core.c
50077 +++ b/drivers/pci/hotplug/pciehp_core.c
50078 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50079 struct slot *slot = ctrl->slot;
50080 struct hotplug_slot *hotplug = NULL;
50081 struct hotplug_slot_info *info = NULL;
50082 - struct hotplug_slot_ops *ops = NULL;
50083 + hotplug_slot_ops_no_const *ops = NULL;
50084 char name[SLOT_NAME_SIZE];
50085 int retval = -ENOMEM;
50086
50087 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50088 index 084587d..4a8f9df 100644
50089 --- a/drivers/pci/msi.c
50090 +++ b/drivers/pci/msi.c
50091 @@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50092 {
50093 struct attribute **msi_attrs;
50094 struct attribute *msi_attr;
50095 - struct device_attribute *msi_dev_attr;
50096 - struct attribute_group *msi_irq_group;
50097 + device_attribute_no_const *msi_dev_attr;
50098 + attribute_group_no_const *msi_irq_group;
50099 const struct attribute_group **msi_irq_groups;
50100 struct msi_desc *entry;
50101 int ret = -ENOMEM;
50102 @@ -549,7 +549,7 @@ error_attrs:
50103 count = 0;
50104 msi_attr = msi_attrs[count];
50105 while (msi_attr) {
50106 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50107 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50108 kfree(msi_attr->name);
50109 kfree(msi_dev_attr);
50110 ++count;
50111 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50112 index 2c6643f..3a6d8e0 100644
50113 --- a/drivers/pci/pci-sysfs.c
50114 +++ b/drivers/pci/pci-sysfs.c
50115 @@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50116 {
50117 /* allocate attribute structure, piggyback attribute name */
50118 int name_len = write_combine ? 13 : 10;
50119 - struct bin_attribute *res_attr;
50120 + bin_attribute_no_const *res_attr;
50121 int retval;
50122
50123 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50124 @@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50125 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50126 {
50127 int retval;
50128 - struct bin_attribute *attr;
50129 + bin_attribute_no_const *attr;
50130
50131 /* If the device has VPD, try to expose it in sysfs. */
50132 if (dev->vpd) {
50133 @@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50134 {
50135 int retval;
50136 int rom_size = 0;
50137 - struct bin_attribute *attr;
50138 + bin_attribute_no_const *attr;
50139
50140 if (!sysfs_initialized)
50141 return -EACCES;
50142 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50143 index b5defca..e3664cc 100644
50144 --- a/drivers/pci/pci.h
50145 +++ b/drivers/pci/pci.h
50146 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
50147 struct pci_vpd {
50148 unsigned int len;
50149 const struct pci_vpd_ops *ops;
50150 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50151 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50152 };
50153
50154 int pci_vpd_pci22_init(struct pci_dev *dev);
50155 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50156 index e1e7026..d28dd33 100644
50157 --- a/drivers/pci/pcie/aspm.c
50158 +++ b/drivers/pci/pcie/aspm.c
50159 @@ -27,9 +27,9 @@
50160 #define MODULE_PARAM_PREFIX "pcie_aspm."
50161
50162 /* Note: those are not register definitions */
50163 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50164 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50165 -#define ASPM_STATE_L1 (4) /* L1 state */
50166 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50167 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50168 +#define ASPM_STATE_L1 (4U) /* L1 state */
50169 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50170 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50171
50172 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50173 index 3010ffc..5e2e133 100644
50174 --- a/drivers/pci/probe.c
50175 +++ b/drivers/pci/probe.c
50176 @@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50177 struct pci_bus_region region, inverted_region;
50178 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50179
50180 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50181 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50182
50183 /* No printks while decoding is disabled! */
50184 if (!dev->mmio_always_on) {
50185 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50186 index 3f155e7..0f4b1f0 100644
50187 --- a/drivers/pci/proc.c
50188 +++ b/drivers/pci/proc.c
50189 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50190 static int __init pci_proc_init(void)
50191 {
50192 struct pci_dev *dev = NULL;
50193 +
50194 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50195 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50196 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50197 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50198 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50199 +#endif
50200 +#else
50201 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50202 +#endif
50203 proc_create("devices", 0, proc_bus_pci_dir,
50204 &proc_bus_pci_dev_operations);
50205 proc_initialized = 1;
50206 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50207 index d866db8..c827d1f 100644
50208 --- a/drivers/platform/chrome/chromeos_laptop.c
50209 +++ b/drivers/platform/chrome/chromeos_laptop.c
50210 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50211 .callback = chromeos_laptop_dmi_matched, \
50212 .driver_data = (void *)&board_
50213
50214 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50215 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50216 {
50217 .ident = "Samsung Series 5 550",
50218 .matches = {
50219 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50220 index c5af23b..3d62d5e 100644
50221 --- a/drivers/platform/x86/alienware-wmi.c
50222 +++ b/drivers/platform/x86/alienware-wmi.c
50223 @@ -150,7 +150,7 @@ struct wmax_led_args {
50224 } __packed;
50225
50226 static struct platform_device *platform_device;
50227 -static struct device_attribute *zone_dev_attrs;
50228 +static device_attribute_no_const *zone_dev_attrs;
50229 static struct attribute **zone_attrs;
50230 static struct platform_zone *zone_data;
50231
50232 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50233 }
50234 };
50235
50236 -static struct attribute_group zone_attribute_group = {
50237 +static attribute_group_no_const zone_attribute_group = {
50238 .name = "rgb_zones",
50239 };
50240
50241 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50242 index 21fc932..ee9394a 100644
50243 --- a/drivers/platform/x86/asus-wmi.c
50244 +++ b/drivers/platform/x86/asus-wmi.c
50245 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50246 int err;
50247 u32 retval = -1;
50248
50249 +#ifdef CONFIG_GRKERNSEC_KMEM
50250 + return -EPERM;
50251 +#endif
50252 +
50253 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50254
50255 if (err < 0)
50256 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50257 int err;
50258 u32 retval = -1;
50259
50260 +#ifdef CONFIG_GRKERNSEC_KMEM
50261 + return -EPERM;
50262 +#endif
50263 +
50264 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50265 &retval);
50266
50267 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50268 union acpi_object *obj;
50269 acpi_status status;
50270
50271 +#ifdef CONFIG_GRKERNSEC_KMEM
50272 + return -EPERM;
50273 +#endif
50274 +
50275 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50276 1, asus->debug.method_id,
50277 &input, &output);
50278 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50279 index 62f8030..c7f2a45 100644
50280 --- a/drivers/platform/x86/msi-laptop.c
50281 +++ b/drivers/platform/x86/msi-laptop.c
50282 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50283
50284 if (!quirks->ec_read_only) {
50285 /* allow userland write sysfs file */
50286 - dev_attr_bluetooth.store = store_bluetooth;
50287 - dev_attr_wlan.store = store_wlan;
50288 - dev_attr_threeg.store = store_threeg;
50289 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50290 - dev_attr_wlan.attr.mode |= S_IWUSR;
50291 - dev_attr_threeg.attr.mode |= S_IWUSR;
50292 + pax_open_kernel();
50293 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50294 + *(void **)&dev_attr_wlan.store = store_wlan;
50295 + *(void **)&dev_attr_threeg.store = store_threeg;
50296 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50297 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50298 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50299 + pax_close_kernel();
50300 }
50301
50302 /* disable hardware control by fn key */
50303 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50304 index 70222f2..8c8ce66 100644
50305 --- a/drivers/platform/x86/msi-wmi.c
50306 +++ b/drivers/platform/x86/msi-wmi.c
50307 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50308 static void msi_wmi_notify(u32 value, void *context)
50309 {
50310 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50311 - static struct key_entry *key;
50312 + struct key_entry *key;
50313 union acpi_object *obj;
50314 acpi_status status;
50315
50316 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50317 index 26ad9ff..7c52909 100644
50318 --- a/drivers/platform/x86/sony-laptop.c
50319 +++ b/drivers/platform/x86/sony-laptop.c
50320 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50321 }
50322
50323 /* High speed charging function */
50324 -static struct device_attribute *hsc_handle;
50325 +static device_attribute_no_const *hsc_handle;
50326
50327 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50328 struct device_attribute *attr,
50329 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50330 }
50331
50332 /* low battery function */
50333 -static struct device_attribute *lowbatt_handle;
50334 +static device_attribute_no_const *lowbatt_handle;
50335
50336 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50337 struct device_attribute *attr,
50338 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50339 }
50340
50341 /* fan speed function */
50342 -static struct device_attribute *fan_handle, *hsf_handle;
50343 +static device_attribute_no_const *fan_handle, *hsf_handle;
50344
50345 static ssize_t sony_nc_hsfan_store(struct device *dev,
50346 struct device_attribute *attr,
50347 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50348 }
50349
50350 /* USB charge function */
50351 -static struct device_attribute *uc_handle;
50352 +static device_attribute_no_const *uc_handle;
50353
50354 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50355 struct device_attribute *attr,
50356 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50357 }
50358
50359 /* Panel ID function */
50360 -static struct device_attribute *panel_handle;
50361 +static device_attribute_no_const *panel_handle;
50362
50363 static ssize_t sony_nc_panelid_show(struct device *dev,
50364 struct device_attribute *attr, char *buffer)
50365 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50366 }
50367
50368 /* smart connect function */
50369 -static struct device_attribute *sc_handle;
50370 +static device_attribute_no_const *sc_handle;
50371
50372 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50373 struct device_attribute *attr,
50374 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50375 index cf0f893..5955997 100644
50376 --- a/drivers/platform/x86/thinkpad_acpi.c
50377 +++ b/drivers/platform/x86/thinkpad_acpi.c
50378 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50379 return 0;
50380 }
50381
50382 -void static hotkey_mask_warn_incomplete_mask(void)
50383 +static void hotkey_mask_warn_incomplete_mask(void)
50384 {
50385 /* log only what the user can fix... */
50386 const u32 wantedmask = hotkey_driver_mask &
50387 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50388 && !tp_features.bright_unkfw)
50389 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50390 }
50391 +}
50392
50393 #undef TPACPI_COMPARE_KEY
50394 #undef TPACPI_MAY_SEND_KEY
50395 -}
50396
50397 /*
50398 * Polling driver
50399 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50400 index 438d4c7..ca8a2fb 100644
50401 --- a/drivers/pnp/pnpbios/bioscalls.c
50402 +++ b/drivers/pnp/pnpbios/bioscalls.c
50403 @@ -59,7 +59,7 @@ do { \
50404 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50405 } while(0)
50406
50407 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50408 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50409 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50410
50411 /*
50412 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50413
50414 cpu = get_cpu();
50415 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50416 +
50417 + pax_open_kernel();
50418 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50419 + pax_close_kernel();
50420
50421 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50422 spin_lock_irqsave(&pnp_bios_lock, flags);
50423 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50424 :"memory");
50425 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50426
50427 + pax_open_kernel();
50428 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50429 + pax_close_kernel();
50430 +
50431 put_cpu();
50432
50433 /* If we get here and this is set then the PnP BIOS faulted on us. */
50434 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50435 return status;
50436 }
50437
50438 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50439 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50440 {
50441 int i;
50442
50443 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50444 pnp_bios_callpoint.offset = header->fields.pm16offset;
50445 pnp_bios_callpoint.segment = PNP_CS16;
50446
50447 + pax_open_kernel();
50448 +
50449 for_each_possible_cpu(i) {
50450 struct desc_struct *gdt = get_cpu_gdt_table(i);
50451 if (!gdt)
50452 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50453 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50454 (unsigned long)__va(header->fields.pm16dseg));
50455 }
50456 +
50457 + pax_close_kernel();
50458 }
50459 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50460 index 0c52e2a..3421ab7 100644
50461 --- a/drivers/power/pda_power.c
50462 +++ b/drivers/power/pda_power.c
50463 @@ -37,7 +37,11 @@ static int polling;
50464
50465 #if IS_ENABLED(CONFIG_USB_PHY)
50466 static struct usb_phy *transceiver;
50467 -static struct notifier_block otg_nb;
50468 +static int otg_handle_notification(struct notifier_block *nb,
50469 + unsigned long event, void *unused);
50470 +static struct notifier_block otg_nb = {
50471 + .notifier_call = otg_handle_notification
50472 +};
50473 #endif
50474
50475 static struct regulator *ac_draw;
50476 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50477
50478 #if IS_ENABLED(CONFIG_USB_PHY)
50479 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50480 - otg_nb.notifier_call = otg_handle_notification;
50481 ret = usb_register_notifier(transceiver, &otg_nb);
50482 if (ret) {
50483 dev_err(dev, "failure to register otg notifier\n");
50484 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50485 index cc439fd..8fa30df 100644
50486 --- a/drivers/power/power_supply.h
50487 +++ b/drivers/power/power_supply.h
50488 @@ -16,12 +16,12 @@ struct power_supply;
50489
50490 #ifdef CONFIG_SYSFS
50491
50492 -extern void power_supply_init_attrs(struct device_type *dev_type);
50493 +extern void power_supply_init_attrs(void);
50494 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50495
50496 #else
50497
50498 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50499 +static inline void power_supply_init_attrs(void) {}
50500 #define power_supply_uevent NULL
50501
50502 #endif /* CONFIG_SYSFS */
50503 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50504 index 694e8cd..9f03483 100644
50505 --- a/drivers/power/power_supply_core.c
50506 +++ b/drivers/power/power_supply_core.c
50507 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50508 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50509 EXPORT_SYMBOL_GPL(power_supply_notifier);
50510
50511 -static struct device_type power_supply_dev_type;
50512 +extern const struct attribute_group *power_supply_attr_groups[];
50513 +static struct device_type power_supply_dev_type = {
50514 + .groups = power_supply_attr_groups,
50515 +};
50516
50517 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50518 struct power_supply *supply)
50519 @@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50520 return PTR_ERR(power_supply_class);
50521
50522 power_supply_class->dev_uevent = power_supply_uevent;
50523 - power_supply_init_attrs(&power_supply_dev_type);
50524 + power_supply_init_attrs();
50525
50526 return 0;
50527 }
50528 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50529 index 62653f5..d0bb485 100644
50530 --- a/drivers/power/power_supply_sysfs.c
50531 +++ b/drivers/power/power_supply_sysfs.c
50532 @@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50533 .is_visible = power_supply_attr_is_visible,
50534 };
50535
50536 -static const struct attribute_group *power_supply_attr_groups[] = {
50537 +const struct attribute_group *power_supply_attr_groups[] = {
50538 &power_supply_attr_group,
50539 NULL,
50540 };
50541
50542 -void power_supply_init_attrs(struct device_type *dev_type)
50543 +void power_supply_init_attrs(void)
50544 {
50545 int i;
50546
50547 - dev_type->groups = power_supply_attr_groups;
50548 -
50549 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50550 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50551 }
50552 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50553 index 84419af..268ede8 100644
50554 --- a/drivers/powercap/powercap_sys.c
50555 +++ b/drivers/powercap/powercap_sys.c
50556 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50557 struct device_attribute name_attr;
50558 };
50559
50560 +static ssize_t show_constraint_name(struct device *dev,
50561 + struct device_attribute *dev_attr,
50562 + char *buf);
50563 +
50564 static struct powercap_constraint_attr
50565 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50566 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50567 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50568 + .power_limit_attr = {
50569 + .attr = {
50570 + .name = NULL,
50571 + .mode = S_IWUSR | S_IRUGO
50572 + },
50573 + .show = show_constraint_power_limit_uw,
50574 + .store = store_constraint_power_limit_uw
50575 + },
50576 +
50577 + .time_window_attr = {
50578 + .attr = {
50579 + .name = NULL,
50580 + .mode = S_IWUSR | S_IRUGO
50581 + },
50582 + .show = show_constraint_time_window_us,
50583 + .store = store_constraint_time_window_us
50584 + },
50585 +
50586 + .max_power_attr = {
50587 + .attr = {
50588 + .name = NULL,
50589 + .mode = S_IRUGO
50590 + },
50591 + .show = show_constraint_max_power_uw,
50592 + .store = NULL
50593 + },
50594 +
50595 + .min_power_attr = {
50596 + .attr = {
50597 + .name = NULL,
50598 + .mode = S_IRUGO
50599 + },
50600 + .show = show_constraint_min_power_uw,
50601 + .store = NULL
50602 + },
50603 +
50604 + .max_time_window_attr = {
50605 + .attr = {
50606 + .name = NULL,
50607 + .mode = S_IRUGO
50608 + },
50609 + .show = show_constraint_max_time_window_us,
50610 + .store = NULL
50611 + },
50612 +
50613 + .min_time_window_attr = {
50614 + .attr = {
50615 + .name = NULL,
50616 + .mode = S_IRUGO
50617 + },
50618 + .show = show_constraint_min_time_window_us,
50619 + .store = NULL
50620 + },
50621 +
50622 + .name_attr = {
50623 + .attr = {
50624 + .name = NULL,
50625 + .mode = S_IRUGO
50626 + },
50627 + .show = show_constraint_name,
50628 + .store = NULL
50629 + }
50630 + }
50631 +};
50632
50633 /* A list of powercap control_types */
50634 static LIST_HEAD(powercap_cntrl_list);
50635 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50636 }
50637
50638 static int create_constraint_attribute(int id, const char *name,
50639 - int mode,
50640 - struct device_attribute *dev_attr,
50641 - ssize_t (*show)(struct device *,
50642 - struct device_attribute *, char *),
50643 - ssize_t (*store)(struct device *,
50644 - struct device_attribute *,
50645 - const char *, size_t)
50646 - )
50647 + struct device_attribute *dev_attr)
50648 {
50649 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50650
50651 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50652 - id, name);
50653 - if (!dev_attr->attr.name)
50654 + if (!name)
50655 return -ENOMEM;
50656 - dev_attr->attr.mode = mode;
50657 - dev_attr->show = show;
50658 - dev_attr->store = store;
50659 +
50660 + pax_open_kernel();
50661 + *(const char **)&dev_attr->attr.name = name;
50662 + pax_close_kernel();
50663
50664 return 0;
50665 }
50666 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50667
50668 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50669 ret = create_constraint_attribute(i, "power_limit_uw",
50670 - S_IWUSR | S_IRUGO,
50671 - &constraint_attrs[i].power_limit_attr,
50672 - show_constraint_power_limit_uw,
50673 - store_constraint_power_limit_uw);
50674 + &constraint_attrs[i].power_limit_attr);
50675 if (ret)
50676 goto err_alloc;
50677 ret = create_constraint_attribute(i, "time_window_us",
50678 - S_IWUSR | S_IRUGO,
50679 - &constraint_attrs[i].time_window_attr,
50680 - show_constraint_time_window_us,
50681 - store_constraint_time_window_us);
50682 + &constraint_attrs[i].time_window_attr);
50683 if (ret)
50684 goto err_alloc;
50685 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50686 - &constraint_attrs[i].name_attr,
50687 - show_constraint_name,
50688 - NULL);
50689 + ret = create_constraint_attribute(i, "name",
50690 + &constraint_attrs[i].name_attr);
50691 if (ret)
50692 goto err_alloc;
50693 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50694 - &constraint_attrs[i].max_power_attr,
50695 - show_constraint_max_power_uw,
50696 - NULL);
50697 + ret = create_constraint_attribute(i, "max_power_uw",
50698 + &constraint_attrs[i].max_power_attr);
50699 if (ret)
50700 goto err_alloc;
50701 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50702 - &constraint_attrs[i].min_power_attr,
50703 - show_constraint_min_power_uw,
50704 - NULL);
50705 + ret = create_constraint_attribute(i, "min_power_uw",
50706 + &constraint_attrs[i].min_power_attr);
50707 if (ret)
50708 goto err_alloc;
50709 ret = create_constraint_attribute(i, "max_time_window_us",
50710 - S_IRUGO,
50711 - &constraint_attrs[i].max_time_window_attr,
50712 - show_constraint_max_time_window_us,
50713 - NULL);
50714 + &constraint_attrs[i].max_time_window_attr);
50715 if (ret)
50716 goto err_alloc;
50717 ret = create_constraint_attribute(i, "min_time_window_us",
50718 - S_IRUGO,
50719 - &constraint_attrs[i].min_time_window_attr,
50720 - show_constraint_min_time_window_us,
50721 - NULL);
50722 + &constraint_attrs[i].min_time_window_attr);
50723 if (ret)
50724 goto err_alloc;
50725
50726 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50727 power_zone->zone_dev_attrs[count++] =
50728 &dev_attr_max_energy_range_uj.attr;
50729 if (power_zone->ops->get_energy_uj) {
50730 + pax_open_kernel();
50731 if (power_zone->ops->reset_energy_uj)
50732 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50733 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50734 else
50735 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50736 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50737 + pax_close_kernel();
50738 power_zone->zone_dev_attrs[count++] =
50739 &dev_attr_energy_uj.attr;
50740 }
50741 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50742 index 9c5d414..c7900ce 100644
50743 --- a/drivers/ptp/ptp_private.h
50744 +++ b/drivers/ptp/ptp_private.h
50745 @@ -51,7 +51,7 @@ struct ptp_clock {
50746 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50747 wait_queue_head_t tsev_wq;
50748 int defunct; /* tells readers to go away when clock is being removed */
50749 - struct device_attribute *pin_dev_attr;
50750 + device_attribute_no_const *pin_dev_attr;
50751 struct attribute **pin_attr;
50752 struct attribute_group pin_attr_group;
50753 };
50754 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50755 index 302e626..12579af 100644
50756 --- a/drivers/ptp/ptp_sysfs.c
50757 +++ b/drivers/ptp/ptp_sysfs.c
50758 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50759 goto no_pin_attr;
50760
50761 for (i = 0; i < n_pins; i++) {
50762 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50763 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50764 sysfs_attr_init(&da->attr);
50765 da->attr.name = info->pin_config[i].name;
50766 da->attr.mode = 0644;
50767 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50768 index cd87c0c..715ecbe 100644
50769 --- a/drivers/regulator/core.c
50770 +++ b/drivers/regulator/core.c
50771 @@ -3567,7 +3567,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50772 {
50773 const struct regulation_constraints *constraints = NULL;
50774 const struct regulator_init_data *init_data;
50775 - static atomic_t regulator_no = ATOMIC_INIT(0);
50776 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50777 struct regulator_dev *rdev;
50778 struct device *dev;
50779 int ret, i;
50780 @@ -3641,7 +3641,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50781 rdev->dev.class = &regulator_class;
50782 rdev->dev.parent = dev;
50783 dev_set_name(&rdev->dev, "regulator.%d",
50784 - atomic_inc_return(&regulator_no) - 1);
50785 + atomic_inc_return_unchecked(&regulator_no) - 1);
50786 ret = device_register(&rdev->dev);
50787 if (ret != 0) {
50788 put_device(&rdev->dev);
50789 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50790 index 7eee2ca..4024513 100644
50791 --- a/drivers/regulator/max8660.c
50792 +++ b/drivers/regulator/max8660.c
50793 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50794 max8660->shadow_regs[MAX8660_OVER1] = 5;
50795 } else {
50796 /* Otherwise devices can be toggled via software */
50797 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50798 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50799 + pax_open_kernel();
50800 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50801 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50802 + pax_close_kernel();
50803 }
50804
50805 /*
50806 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50807 index dbedf17..18ff6b7 100644
50808 --- a/drivers/regulator/max8973-regulator.c
50809 +++ b/drivers/regulator/max8973-regulator.c
50810 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50811 if (!pdata || !pdata->enable_ext_control) {
50812 max->desc.enable_reg = MAX8973_VOUT;
50813 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50814 - max->ops.enable = regulator_enable_regmap;
50815 - max->ops.disable = regulator_disable_regmap;
50816 - max->ops.is_enabled = regulator_is_enabled_regmap;
50817 + pax_open_kernel();
50818 + *(void **)&max->ops.enable = regulator_enable_regmap;
50819 + *(void **)&max->ops.disable = regulator_disable_regmap;
50820 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50821 + pax_close_kernel();
50822 }
50823
50824 if (pdata) {
50825 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50826 index 793b662..85f74cd 100644
50827 --- a/drivers/regulator/mc13892-regulator.c
50828 +++ b/drivers/regulator/mc13892-regulator.c
50829 @@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50830 mc13xxx_unlock(mc13892);
50831
50832 /* update mc13892_vcam ops */
50833 + pax_open_kernel();
50834 memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50835 sizeof(struct regulator_ops));
50836 - mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50837 - mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50838 + *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50839 + *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50840 + pax_close_kernel();
50841 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50842
50843 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50844 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50845 index 5b2e761..c8c8a4a 100644
50846 --- a/drivers/rtc/rtc-cmos.c
50847 +++ b/drivers/rtc/rtc-cmos.c
50848 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50849 hpet_rtc_timer_init();
50850
50851 /* export at least the first block of NVRAM */
50852 - nvram.size = address_space - NVRAM_OFFSET;
50853 + pax_open_kernel();
50854 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50855 + pax_close_kernel();
50856 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50857 if (retval < 0) {
50858 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50859 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50860 index d049393..bb20be0 100644
50861 --- a/drivers/rtc/rtc-dev.c
50862 +++ b/drivers/rtc/rtc-dev.c
50863 @@ -16,6 +16,7 @@
50864 #include <linux/module.h>
50865 #include <linux/rtc.h>
50866 #include <linux/sched.h>
50867 +#include <linux/grsecurity.h>
50868 #include "rtc-core.h"
50869
50870 static dev_t rtc_devt;
50871 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50872 if (copy_from_user(&tm, uarg, sizeof(tm)))
50873 return -EFAULT;
50874
50875 + gr_log_timechange();
50876 +
50877 return rtc_set_time(rtc, &tm);
50878
50879 case RTC_PIE_ON:
50880 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50881 index bb43cf7..ee4d274 100644
50882 --- a/drivers/rtc/rtc-ds1307.c
50883 +++ b/drivers/rtc/rtc-ds1307.c
50884 @@ -107,7 +107,7 @@ struct ds1307 {
50885 u8 offset; /* register's offset */
50886 u8 regs[11];
50887 u16 nvram_offset;
50888 - struct bin_attribute *nvram;
50889 + bin_attribute_no_const *nvram;
50890 enum ds_type type;
50891 unsigned long flags;
50892 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50893 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50894 index 11880c1..b823aa4 100644
50895 --- a/drivers/rtc/rtc-m48t59.c
50896 +++ b/drivers/rtc/rtc-m48t59.c
50897 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50898 if (IS_ERR(m48t59->rtc))
50899 return PTR_ERR(m48t59->rtc);
50900
50901 - m48t59_nvram_attr.size = pdata->offset;
50902 + pax_open_kernel();
50903 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50904 + pax_close_kernel();
50905
50906 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50907 if (ret)
50908 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50909 index e693af6..2e525b6 100644
50910 --- a/drivers/scsi/bfa/bfa_fcpim.h
50911 +++ b/drivers/scsi/bfa/bfa_fcpim.h
50912 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
50913
50914 struct bfa_itn_s {
50915 bfa_isr_func_t isr;
50916 -};
50917 +} __no_const;
50918
50919 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50920 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50921 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50922 index 0f19455..ef7adb5 100644
50923 --- a/drivers/scsi/bfa/bfa_fcs.c
50924 +++ b/drivers/scsi/bfa/bfa_fcs.c
50925 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50926 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50927
50928 static struct bfa_fcs_mod_s fcs_modules[] = {
50929 - { bfa_fcs_port_attach, NULL, NULL },
50930 - { bfa_fcs_uf_attach, NULL, NULL },
50931 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50932 - bfa_fcs_fabric_modexit },
50933 + {
50934 + .attach = bfa_fcs_port_attach,
50935 + .modinit = NULL,
50936 + .modexit = NULL
50937 + },
50938 + {
50939 + .attach = bfa_fcs_uf_attach,
50940 + .modinit = NULL,
50941 + .modexit = NULL
50942 + },
50943 + {
50944 + .attach = bfa_fcs_fabric_attach,
50945 + .modinit = bfa_fcs_fabric_modinit,
50946 + .modexit = bfa_fcs_fabric_modexit
50947 + },
50948 };
50949
50950 /*
50951 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50952 index ff75ef8..2dfe00a 100644
50953 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
50954 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50955 @@ -89,15 +89,26 @@ static struct {
50956 void (*offline) (struct bfa_fcs_lport_s *port);
50957 } __port_action[] = {
50958 {
50959 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50960 - bfa_fcs_lport_unknown_offline}, {
50961 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50962 - bfa_fcs_lport_fab_offline}, {
50963 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50964 - bfa_fcs_lport_n2n_offline}, {
50965 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50966 - bfa_fcs_lport_loop_offline},
50967 - };
50968 + .init = bfa_fcs_lport_unknown_init,
50969 + .online = bfa_fcs_lport_unknown_online,
50970 + .offline = bfa_fcs_lport_unknown_offline
50971 + },
50972 + {
50973 + .init = bfa_fcs_lport_fab_init,
50974 + .online = bfa_fcs_lport_fab_online,
50975 + .offline = bfa_fcs_lport_fab_offline
50976 + },
50977 + {
50978 + .init = bfa_fcs_lport_n2n_init,
50979 + .online = bfa_fcs_lport_n2n_online,
50980 + .offline = bfa_fcs_lport_n2n_offline
50981 + },
50982 + {
50983 + .init = bfa_fcs_lport_loop_init,
50984 + .online = bfa_fcs_lport_loop_online,
50985 + .offline = bfa_fcs_lport_loop_offline
50986 + },
50987 +};
50988
50989 /*
50990 * fcs_port_sm FCS logical port state machine
50991 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50992 index a38aafa0..fe8f03b 100644
50993 --- a/drivers/scsi/bfa/bfa_ioc.h
50994 +++ b/drivers/scsi/bfa/bfa_ioc.h
50995 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50996 bfa_ioc_disable_cbfn_t disable_cbfn;
50997 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50998 bfa_ioc_reset_cbfn_t reset_cbfn;
50999 -};
51000 +} __no_const;
51001
51002 /*
51003 * IOC event notification mechanism.
51004 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51005 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51006 enum bfi_ioc_state fwstate);
51007 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51008 -};
51009 +} __no_const;
51010
51011 /*
51012 * Queue element to wait for room in request queue. FIFO order is
51013 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51014 index a14c784..6de6790 100644
51015 --- a/drivers/scsi/bfa/bfa_modules.h
51016 +++ b/drivers/scsi/bfa/bfa_modules.h
51017 @@ -78,12 +78,12 @@ enum {
51018 \
51019 extern struct bfa_module_s hal_mod_ ## __mod; \
51020 struct bfa_module_s hal_mod_ ## __mod = { \
51021 - bfa_ ## __mod ## _meminfo, \
51022 - bfa_ ## __mod ## _attach, \
51023 - bfa_ ## __mod ## _detach, \
51024 - bfa_ ## __mod ## _start, \
51025 - bfa_ ## __mod ## _stop, \
51026 - bfa_ ## __mod ## _iocdisable, \
51027 + .meminfo = bfa_ ## __mod ## _meminfo, \
51028 + .attach = bfa_ ## __mod ## _attach, \
51029 + .detach = bfa_ ## __mod ## _detach, \
51030 + .start = bfa_ ## __mod ## _start, \
51031 + .stop = bfa_ ## __mod ## _stop, \
51032 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51033 }
51034
51035 #define BFA_CACHELINE_SZ (256)
51036 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51037 index 045c4e1..13de803 100644
51038 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51039 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51040 @@ -33,8 +33,8 @@
51041 */
51042 #include "libfcoe.h"
51043
51044 -static atomic_t ctlr_num;
51045 -static atomic_t fcf_num;
51046 +static atomic_unchecked_t ctlr_num;
51047 +static atomic_unchecked_t fcf_num;
51048
51049 /*
51050 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51051 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51052 if (!ctlr)
51053 goto out;
51054
51055 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51056 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51057 ctlr->f = f;
51058 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51059 INIT_LIST_HEAD(&ctlr->fcfs);
51060 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51061 fcf->dev.parent = &ctlr->dev;
51062 fcf->dev.bus = &fcoe_bus_type;
51063 fcf->dev.type = &fcoe_fcf_device_type;
51064 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51065 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51066 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51067
51068 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51069 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51070 {
51071 int error;
51072
51073 - atomic_set(&ctlr_num, 0);
51074 - atomic_set(&fcf_num, 0);
51075 + atomic_set_unchecked(&ctlr_num, 0);
51076 + atomic_set_unchecked(&fcf_num, 0);
51077
51078 error = bus_register(&fcoe_bus_type);
51079 if (error)
51080 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51081 index 6de80e3..a11e0ac 100644
51082 --- a/drivers/scsi/hosts.c
51083 +++ b/drivers/scsi/hosts.c
51084 @@ -42,7 +42,7 @@
51085 #include "scsi_logging.h"
51086
51087
51088 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51089 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51090
51091
51092 static void scsi_host_cls_release(struct device *dev)
51093 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51094 * subtract one because we increment first then return, but we need to
51095 * know what the next host number was before increment
51096 */
51097 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51098 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51099 shost->dma_channel = 0xff;
51100
51101 /* These three are default values which can be overridden */
51102 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51103 index cef5d49..01e280e 100644
51104 --- a/drivers/scsi/hpsa.c
51105 +++ b/drivers/scsi/hpsa.c
51106 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51107 unsigned long flags;
51108
51109 if (h->transMethod & CFGTBL_Trans_io_accel1)
51110 - return h->access.command_completed(h, q);
51111 + return h->access->command_completed(h, q);
51112
51113 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51114 - return h->access.command_completed(h, q);
51115 + return h->access->command_completed(h, q);
51116
51117 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51118 a = rq->head[rq->current_entry];
51119 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51120 while (!list_empty(&h->reqQ)) {
51121 c = list_entry(h->reqQ.next, struct CommandList, list);
51122 /* can't do anything if fifo is full */
51123 - if ((h->access.fifo_full(h))) {
51124 + if ((h->access->fifo_full(h))) {
51125 h->fifo_recently_full = 1;
51126 dev_warn(&h->pdev->dev, "fifo full\n");
51127 break;
51128 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51129
51130 /* Tell the controller execute command */
51131 spin_unlock_irqrestore(&h->lock, *flags);
51132 - h->access.submit_command(h, c);
51133 + h->access->submit_command(h, c);
51134 spin_lock_irqsave(&h->lock, *flags);
51135 }
51136 }
51137 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51138
51139 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51140 {
51141 - return h->access.command_completed(h, q);
51142 + return h->access->command_completed(h, q);
51143 }
51144
51145 static inline bool interrupt_pending(struct ctlr_info *h)
51146 {
51147 - return h->access.intr_pending(h);
51148 + return h->access->intr_pending(h);
51149 }
51150
51151 static inline long interrupt_not_for_us(struct ctlr_info *h)
51152 {
51153 - return (h->access.intr_pending(h) == 0) ||
51154 + return (h->access->intr_pending(h) == 0) ||
51155 (h->interrupts_enabled == 0);
51156 }
51157
51158 @@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51159 if (prod_index < 0)
51160 return -ENODEV;
51161 h->product_name = products[prod_index].product_name;
51162 - h->access = *(products[prod_index].access);
51163 + h->access = products[prod_index].access;
51164
51165 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51166 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51167 @@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51168 unsigned long flags;
51169 u32 lockup_detected;
51170
51171 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51172 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51173 spin_lock_irqsave(&h->lock, flags);
51174 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51175 if (!lockup_detected) {
51176 @@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
51177 }
51178
51179 /* make sure the board interrupts are off */
51180 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51181 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51182
51183 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51184 goto clean2;
51185 @@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
51186 * fake ones to scoop up any residual completions.
51187 */
51188 spin_lock_irqsave(&h->lock, flags);
51189 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51190 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51191 spin_unlock_irqrestore(&h->lock, flags);
51192 free_irqs(h);
51193 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51194 @@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
51195 dev_info(&h->pdev->dev, "Board READY.\n");
51196 dev_info(&h->pdev->dev,
51197 "Waiting for stale completions to drain.\n");
51198 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51199 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51200 msleep(10000);
51201 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51202 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51203
51204 rc = controller_reset_failed(h->cfgtable);
51205 if (rc)
51206 @@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
51207 h->drv_req_rescan = 0;
51208
51209 /* Turn the interrupts on so we can service requests */
51210 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51211 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51212
51213 hpsa_hba_inquiry(h);
51214 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51215 @@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51216 * To write all data in the battery backed cache to disks
51217 */
51218 hpsa_flush_cache(h);
51219 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51220 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51221 hpsa_free_irqs_and_disable_msix(h);
51222 }
51223
51224 @@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51225 CFGTBL_Trans_enable_directed_msix |
51226 (trans_support & (CFGTBL_Trans_io_accel1 |
51227 CFGTBL_Trans_io_accel2));
51228 - struct access_method access = SA5_performant_access;
51229 + struct access_method *access = &SA5_performant_access;
51230
51231 /* This is a bit complicated. There are 8 registers on
51232 * the controller which we write to to tell it 8 different
51233 @@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51234 * perform the superfluous readl() after each command submission.
51235 */
51236 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51237 - access = SA5_performant_access_no_read;
51238 + access = &SA5_performant_access_no_read;
51239
51240 /* Controller spec: zero out this buffer. */
51241 for (i = 0; i < h->nreply_queues; i++)
51242 @@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51243 * enable outbound interrupt coalescing in accelerator mode;
51244 */
51245 if (trans_support & CFGTBL_Trans_io_accel1) {
51246 - access = SA5_ioaccel_mode1_access;
51247 + access = &SA5_ioaccel_mode1_access;
51248 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51249 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51250 } else {
51251 if (trans_support & CFGTBL_Trans_io_accel2) {
51252 - access = SA5_ioaccel_mode2_access;
51253 + access = &SA5_ioaccel_mode2_access;
51254 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51255 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51256 }
51257 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51258 index 24472ce..8782caf 100644
51259 --- a/drivers/scsi/hpsa.h
51260 +++ b/drivers/scsi/hpsa.h
51261 @@ -127,7 +127,7 @@ struct ctlr_info {
51262 unsigned int msix_vector;
51263 unsigned int msi_vector;
51264 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51265 - struct access_method access;
51266 + struct access_method *access;
51267 char hba_mode_enabled;
51268
51269 /* queue and queue Info */
51270 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51271 }
51272
51273 static struct access_method SA5_access = {
51274 - SA5_submit_command,
51275 - SA5_intr_mask,
51276 - SA5_fifo_full,
51277 - SA5_intr_pending,
51278 - SA5_completed,
51279 + .submit_command = SA5_submit_command,
51280 + .set_intr_mask = SA5_intr_mask,
51281 + .fifo_full = SA5_fifo_full,
51282 + .intr_pending = SA5_intr_pending,
51283 + .command_completed = SA5_completed,
51284 };
51285
51286 static struct access_method SA5_ioaccel_mode1_access = {
51287 - SA5_submit_command,
51288 - SA5_performant_intr_mask,
51289 - SA5_fifo_full,
51290 - SA5_ioaccel_mode1_intr_pending,
51291 - SA5_ioaccel_mode1_completed,
51292 + .submit_command = SA5_submit_command,
51293 + .set_intr_mask = SA5_performant_intr_mask,
51294 + .fifo_full = SA5_fifo_full,
51295 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51296 + .command_completed = SA5_ioaccel_mode1_completed,
51297 };
51298
51299 static struct access_method SA5_ioaccel_mode2_access = {
51300 - SA5_submit_command_ioaccel2,
51301 - SA5_performant_intr_mask,
51302 - SA5_fifo_full,
51303 - SA5_performant_intr_pending,
51304 - SA5_performant_completed,
51305 + .submit_command = SA5_submit_command_ioaccel2,
51306 + .set_intr_mask = SA5_performant_intr_mask,
51307 + .fifo_full = SA5_fifo_full,
51308 + .intr_pending = SA5_performant_intr_pending,
51309 + .command_completed = SA5_performant_completed,
51310 };
51311
51312 static struct access_method SA5_performant_access = {
51313 - SA5_submit_command,
51314 - SA5_performant_intr_mask,
51315 - SA5_fifo_full,
51316 - SA5_performant_intr_pending,
51317 - SA5_performant_completed,
51318 + .submit_command = SA5_submit_command,
51319 + .set_intr_mask = SA5_performant_intr_mask,
51320 + .fifo_full = SA5_fifo_full,
51321 + .intr_pending = SA5_performant_intr_pending,
51322 + .command_completed = SA5_performant_completed,
51323 };
51324
51325 static struct access_method SA5_performant_access_no_read = {
51326 - SA5_submit_command_no_read,
51327 - SA5_performant_intr_mask,
51328 - SA5_fifo_full,
51329 - SA5_performant_intr_pending,
51330 - SA5_performant_completed,
51331 + .submit_command = SA5_submit_command_no_read,
51332 + .set_intr_mask = SA5_performant_intr_mask,
51333 + .fifo_full = SA5_fifo_full,
51334 + .intr_pending = SA5_performant_intr_pending,
51335 + .command_completed = SA5_performant_completed,
51336 };
51337
51338 struct board_type {
51339 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51340 index 1b3a094..068e683 100644
51341 --- a/drivers/scsi/libfc/fc_exch.c
51342 +++ b/drivers/scsi/libfc/fc_exch.c
51343 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51344 u16 pool_max_index;
51345
51346 struct {
51347 - atomic_t no_free_exch;
51348 - atomic_t no_free_exch_xid;
51349 - atomic_t xid_not_found;
51350 - atomic_t xid_busy;
51351 - atomic_t seq_not_found;
51352 - atomic_t non_bls_resp;
51353 + atomic_unchecked_t no_free_exch;
51354 + atomic_unchecked_t no_free_exch_xid;
51355 + atomic_unchecked_t xid_not_found;
51356 + atomic_unchecked_t xid_busy;
51357 + atomic_unchecked_t seq_not_found;
51358 + atomic_unchecked_t non_bls_resp;
51359 } stats;
51360 };
51361
51362 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51363 /* allocate memory for exchange */
51364 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51365 if (!ep) {
51366 - atomic_inc(&mp->stats.no_free_exch);
51367 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51368 goto out;
51369 }
51370 memset(ep, 0, sizeof(*ep));
51371 @@ -874,7 +874,7 @@ out:
51372 return ep;
51373 err:
51374 spin_unlock_bh(&pool->lock);
51375 - atomic_inc(&mp->stats.no_free_exch_xid);
51376 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51377 mempool_free(ep, mp->ep_pool);
51378 return NULL;
51379 }
51380 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51381 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51382 ep = fc_exch_find(mp, xid);
51383 if (!ep) {
51384 - atomic_inc(&mp->stats.xid_not_found);
51385 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51386 reject = FC_RJT_OX_ID;
51387 goto out;
51388 }
51389 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51390 ep = fc_exch_find(mp, xid);
51391 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51392 if (ep) {
51393 - atomic_inc(&mp->stats.xid_busy);
51394 + atomic_inc_unchecked(&mp->stats.xid_busy);
51395 reject = FC_RJT_RX_ID;
51396 goto rel;
51397 }
51398 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51399 }
51400 xid = ep->xid; /* get our XID */
51401 } else if (!ep) {
51402 - atomic_inc(&mp->stats.xid_not_found);
51403 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51404 reject = FC_RJT_RX_ID; /* XID not found */
51405 goto out;
51406 }
51407 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51408 } else {
51409 sp = &ep->seq;
51410 if (sp->id != fh->fh_seq_id) {
51411 - atomic_inc(&mp->stats.seq_not_found);
51412 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51413 if (f_ctl & FC_FC_END_SEQ) {
51414 /*
51415 * Update sequence_id based on incoming last
51416 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51417
51418 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51419 if (!ep) {
51420 - atomic_inc(&mp->stats.xid_not_found);
51421 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51422 goto out;
51423 }
51424 if (ep->esb_stat & ESB_ST_COMPLETE) {
51425 - atomic_inc(&mp->stats.xid_not_found);
51426 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51427 goto rel;
51428 }
51429 if (ep->rxid == FC_XID_UNKNOWN)
51430 ep->rxid = ntohs(fh->fh_rx_id);
51431 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51432 - atomic_inc(&mp->stats.xid_not_found);
51433 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51434 goto rel;
51435 }
51436 if (ep->did != ntoh24(fh->fh_s_id) &&
51437 ep->did != FC_FID_FLOGI) {
51438 - atomic_inc(&mp->stats.xid_not_found);
51439 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51440 goto rel;
51441 }
51442 sof = fr_sof(fp);
51443 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51444 sp->ssb_stat |= SSB_ST_RESP;
51445 sp->id = fh->fh_seq_id;
51446 } else if (sp->id != fh->fh_seq_id) {
51447 - atomic_inc(&mp->stats.seq_not_found);
51448 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51449 goto rel;
51450 }
51451
51452 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51453 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51454
51455 if (!sp)
51456 - atomic_inc(&mp->stats.xid_not_found);
51457 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51458 else
51459 - atomic_inc(&mp->stats.non_bls_resp);
51460 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51461
51462 fc_frame_free(fp);
51463 }
51464 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51465
51466 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51467 mp = ema->mp;
51468 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51469 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51470 st->fc_no_free_exch_xid +=
51471 - atomic_read(&mp->stats.no_free_exch_xid);
51472 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51473 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51474 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51475 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51476 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51477 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51478 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51479 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51480 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51481 }
51482 }
51483 EXPORT_SYMBOL(fc_exch_update_stats);
51484 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51485 index 766098a..1c6c971 100644
51486 --- a/drivers/scsi/libsas/sas_ata.c
51487 +++ b/drivers/scsi/libsas/sas_ata.c
51488 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51489 .postreset = ata_std_postreset,
51490 .error_handler = ata_std_error_handler,
51491 .post_internal_cmd = sas_ata_post_internal,
51492 - .qc_defer = ata_std_qc_defer,
51493 + .qc_defer = ata_std_qc_defer,
51494 .qc_prep = ata_noop_qc_prep,
51495 .qc_issue = sas_ata_qc_issue,
51496 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51497 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51498 index 434e903..5a4a79b 100644
51499 --- a/drivers/scsi/lpfc/lpfc.h
51500 +++ b/drivers/scsi/lpfc/lpfc.h
51501 @@ -430,7 +430,7 @@ struct lpfc_vport {
51502 struct dentry *debug_nodelist;
51503 struct dentry *vport_debugfs_root;
51504 struct lpfc_debugfs_trc *disc_trc;
51505 - atomic_t disc_trc_cnt;
51506 + atomic_unchecked_t disc_trc_cnt;
51507 #endif
51508 uint8_t stat_data_enabled;
51509 uint8_t stat_data_blocked;
51510 @@ -880,8 +880,8 @@ struct lpfc_hba {
51511 struct timer_list fabric_block_timer;
51512 unsigned long bit_flags;
51513 #define FABRIC_COMANDS_BLOCKED 0
51514 - atomic_t num_rsrc_err;
51515 - atomic_t num_cmd_success;
51516 + atomic_unchecked_t num_rsrc_err;
51517 + atomic_unchecked_t num_cmd_success;
51518 unsigned long last_rsrc_error_time;
51519 unsigned long last_ramp_down_time;
51520 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51521 @@ -916,7 +916,7 @@ struct lpfc_hba {
51522
51523 struct dentry *debug_slow_ring_trc;
51524 struct lpfc_debugfs_trc *slow_ring_trc;
51525 - atomic_t slow_ring_trc_cnt;
51526 + atomic_unchecked_t slow_ring_trc_cnt;
51527 /* iDiag debugfs sub-directory */
51528 struct dentry *idiag_root;
51529 struct dentry *idiag_pci_cfg;
51530 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51531 index 786a2af..562c6a2 100644
51532 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51533 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51534 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51535
51536 #include <linux/debugfs.h>
51537
51538 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51539 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51540 static unsigned long lpfc_debugfs_start_time = 0L;
51541
51542 /* iDiag */
51543 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51544 lpfc_debugfs_enable = 0;
51545
51546 len = 0;
51547 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51548 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51549 (lpfc_debugfs_max_disc_trc - 1);
51550 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51551 dtp = vport->disc_trc + i;
51552 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51553 lpfc_debugfs_enable = 0;
51554
51555 len = 0;
51556 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51557 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51558 (lpfc_debugfs_max_slow_ring_trc - 1);
51559 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51560 dtp = phba->slow_ring_trc + i;
51561 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51562 !vport || !vport->disc_trc)
51563 return;
51564
51565 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51566 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51567 (lpfc_debugfs_max_disc_trc - 1);
51568 dtp = vport->disc_trc + index;
51569 dtp->fmt = fmt;
51570 dtp->data1 = data1;
51571 dtp->data2 = data2;
51572 dtp->data3 = data3;
51573 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51574 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51575 dtp->jif = jiffies;
51576 #endif
51577 return;
51578 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51579 !phba || !phba->slow_ring_trc)
51580 return;
51581
51582 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51583 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51584 (lpfc_debugfs_max_slow_ring_trc - 1);
51585 dtp = phba->slow_ring_trc + index;
51586 dtp->fmt = fmt;
51587 dtp->data1 = data1;
51588 dtp->data2 = data2;
51589 dtp->data3 = data3;
51590 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51591 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51592 dtp->jif = jiffies;
51593 #endif
51594 return;
51595 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51596 "slow_ring buffer\n");
51597 goto debug_failed;
51598 }
51599 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51600 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51601 memset(phba->slow_ring_trc, 0,
51602 (sizeof(struct lpfc_debugfs_trc) *
51603 lpfc_debugfs_max_slow_ring_trc));
51604 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51605 "buffer\n");
51606 goto debug_failed;
51607 }
51608 - atomic_set(&vport->disc_trc_cnt, 0);
51609 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51610
51611 snprintf(name, sizeof(name), "discovery_trace");
51612 vport->debug_disc_trc =
51613 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51614 index 0b2c53a..aec2b45 100644
51615 --- a/drivers/scsi/lpfc/lpfc_init.c
51616 +++ b/drivers/scsi/lpfc/lpfc_init.c
51617 @@ -11290,8 +11290,10 @@ lpfc_init(void)
51618 "misc_register returned with status %d", error);
51619
51620 if (lpfc_enable_npiv) {
51621 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51622 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51623 + pax_open_kernel();
51624 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51625 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51626 + pax_close_kernel();
51627 }
51628 lpfc_transport_template =
51629 fc_attach_transport(&lpfc_transport_functions);
51630 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51631 index b99399f..d29dc75 100644
51632 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51633 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51634 @@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51635 unsigned long expires;
51636
51637 spin_lock_irqsave(&phba->hbalock, flags);
51638 - atomic_inc(&phba->num_rsrc_err);
51639 + atomic_inc_unchecked(&phba->num_rsrc_err);
51640 phba->last_rsrc_error_time = jiffies;
51641
51642 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51643 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51644 unsigned long num_rsrc_err, num_cmd_success;
51645 int i;
51646
51647 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51648 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51649 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51650 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51651
51652 /*
51653 * The error and success command counters are global per
51654 @@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51655 }
51656 }
51657 lpfc_destroy_vport_work_array(phba, vports);
51658 - atomic_set(&phba->num_rsrc_err, 0);
51659 - atomic_set(&phba->num_cmd_success, 0);
51660 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51661 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51662 }
51663
51664 /**
51665 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51666 index c80ed04..e674f01 100644
51667 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51668 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51669 @@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51670 {
51671 struct scsi_device *sdev = to_scsi_device(dev);
51672 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51673 - static struct _raid_device *raid_device;
51674 + struct _raid_device *raid_device;
51675 unsigned long flags;
51676 Mpi2RaidVolPage0_t vol_pg0;
51677 Mpi2ConfigReply_t mpi_reply;
51678 @@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51679 {
51680 struct scsi_device *sdev = to_scsi_device(dev);
51681 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51682 - static struct _raid_device *raid_device;
51683 + struct _raid_device *raid_device;
51684 unsigned long flags;
51685 Mpi2RaidVolPage0_t vol_pg0;
51686 Mpi2ConfigReply_t mpi_reply;
51687 @@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51688 Mpi2EventDataIrOperationStatus_t *event_data =
51689 (Mpi2EventDataIrOperationStatus_t *)
51690 fw_event->event_data;
51691 - static struct _raid_device *raid_device;
51692 + struct _raid_device *raid_device;
51693 unsigned long flags;
51694 u16 handle;
51695
51696 @@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51697 u64 sas_address;
51698 struct _sas_device *sas_device;
51699 struct _sas_node *expander_device;
51700 - static struct _raid_device *raid_device;
51701 + struct _raid_device *raid_device;
51702 u8 retry_count;
51703 unsigned long flags;
51704
51705 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51706 index bcb64eb..f08cf71 100644
51707 --- a/drivers/scsi/pmcraid.c
51708 +++ b/drivers/scsi/pmcraid.c
51709 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51710 res->scsi_dev = scsi_dev;
51711 scsi_dev->hostdata = res;
51712 res->change_detected = 0;
51713 - atomic_set(&res->read_failures, 0);
51714 - atomic_set(&res->write_failures, 0);
51715 + atomic_set_unchecked(&res->read_failures, 0);
51716 + atomic_set_unchecked(&res->write_failures, 0);
51717 rc = 0;
51718 }
51719 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51720 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51721
51722 /* If this was a SCSI read/write command keep count of errors */
51723 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51724 - atomic_inc(&res->read_failures);
51725 + atomic_inc_unchecked(&res->read_failures);
51726 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51727 - atomic_inc(&res->write_failures);
51728 + atomic_inc_unchecked(&res->write_failures);
51729
51730 if (!RES_IS_GSCSI(res->cfg_entry) &&
51731 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51732 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51733 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51734 * hrrq_id assigned here in queuecommand
51735 */
51736 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51737 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51738 pinstance->num_hrrq;
51739 cmd->cmd_done = pmcraid_io_done;
51740
51741 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51742 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51743 * hrrq_id assigned here in queuecommand
51744 */
51745 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51746 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51747 pinstance->num_hrrq;
51748
51749 if (request_size) {
51750 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51751
51752 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51753 /* add resources only after host is added into system */
51754 - if (!atomic_read(&pinstance->expose_resources))
51755 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51756 return;
51757
51758 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51759 @@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51760 init_waitqueue_head(&pinstance->reset_wait_q);
51761
51762 atomic_set(&pinstance->outstanding_cmds, 0);
51763 - atomic_set(&pinstance->last_message_id, 0);
51764 - atomic_set(&pinstance->expose_resources, 0);
51765 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51766 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51767
51768 INIT_LIST_HEAD(&pinstance->free_res_q);
51769 INIT_LIST_HEAD(&pinstance->used_res_q);
51770 @@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51771 /* Schedule worker thread to handle CCN and take care of adding and
51772 * removing devices to OS
51773 */
51774 - atomic_set(&pinstance->expose_resources, 1);
51775 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51776 schedule_work(&pinstance->worker_q);
51777 return rc;
51778
51779 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51780 index e1d150f..6c6df44 100644
51781 --- a/drivers/scsi/pmcraid.h
51782 +++ b/drivers/scsi/pmcraid.h
51783 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51784 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51785
51786 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51787 - atomic_t last_message_id;
51788 + atomic_unchecked_t last_message_id;
51789
51790 /* configuration table */
51791 struct pmcraid_config_table *cfg_table;
51792 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51793 atomic_t outstanding_cmds;
51794
51795 /* should add/delete resources to mid-layer now ?*/
51796 - atomic_t expose_resources;
51797 + atomic_unchecked_t expose_resources;
51798
51799
51800
51801 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51802 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51803 };
51804 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51805 - atomic_t read_failures; /* count of failed READ commands */
51806 - atomic_t write_failures; /* count of failed WRITE commands */
51807 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51808 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51809
51810 /* To indicate add/delete/modify during CCN */
51811 u8 change_detected;
51812 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51813 index 82b92c4..3178171 100644
51814 --- a/drivers/scsi/qla2xxx/qla_attr.c
51815 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51816 @@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51817 return 0;
51818 }
51819
51820 -struct fc_function_template qla2xxx_transport_functions = {
51821 +fc_function_template_no_const qla2xxx_transport_functions = {
51822
51823 .show_host_node_name = 1,
51824 .show_host_port_name = 1,
51825 @@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51826 .bsg_timeout = qla24xx_bsg_timeout,
51827 };
51828
51829 -struct fc_function_template qla2xxx_transport_vport_functions = {
51830 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51831
51832 .show_host_node_name = 1,
51833 .show_host_port_name = 1,
51834 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51835 index b1865a7..a7723d3 100644
51836 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51837 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51838 @@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51839 struct device_attribute;
51840 extern struct device_attribute *qla2x00_host_attrs[];
51841 struct fc_function_template;
51842 -extern struct fc_function_template qla2xxx_transport_functions;
51843 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51844 +extern fc_function_template_no_const qla2xxx_transport_functions;
51845 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51846 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51847 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51848 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51849 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51850 index db3dbd9..2492392 100644
51851 --- a/drivers/scsi/qla2xxx/qla_os.c
51852 +++ b/drivers/scsi/qla2xxx/qla_os.c
51853 @@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51854 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51855 /* Ok, a 64bit DMA mask is applicable. */
51856 ha->flags.enable_64bit_addressing = 1;
51857 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51858 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51859 + pax_open_kernel();
51860 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51861 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51862 + pax_close_kernel();
51863 return;
51864 }
51865 }
51866 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51867 index 8f6d0fb..1b21097 100644
51868 --- a/drivers/scsi/qla4xxx/ql4_def.h
51869 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51870 @@ -305,7 +305,7 @@ struct ddb_entry {
51871 * (4000 only) */
51872 atomic_t relogin_timer; /* Max Time to wait for
51873 * relogin to complete */
51874 - atomic_t relogin_retry_count; /* Num of times relogin has been
51875 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51876 * retried */
51877 uint32_t default_time2wait; /* Default Min time between
51878 * relogins (+aens) */
51879 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51880 index 199fcf7..3c3a918 100644
51881 --- a/drivers/scsi/qla4xxx/ql4_os.c
51882 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51883 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51884 */
51885 if (!iscsi_is_session_online(cls_sess)) {
51886 /* Reset retry relogin timer */
51887 - atomic_inc(&ddb_entry->relogin_retry_count);
51888 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51889 DEBUG2(ql4_printk(KERN_INFO, ha,
51890 "%s: index[%d] relogin timed out-retrying"
51891 " relogin (%d), retry (%d)\n", __func__,
51892 ddb_entry->fw_ddb_index,
51893 - atomic_read(&ddb_entry->relogin_retry_count),
51894 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51895 ddb_entry->default_time2wait + 4));
51896 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51897 atomic_set(&ddb_entry->retry_relogin_timer,
51898 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51899
51900 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51901 atomic_set(&ddb_entry->relogin_timer, 0);
51902 - atomic_set(&ddb_entry->relogin_retry_count, 0);
51903 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51904 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51905 ddb_entry->default_relogin_timeout =
51906 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51907 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51908 index 79c77b4..ef6ec0b 100644
51909 --- a/drivers/scsi/scsi.c
51910 +++ b/drivers/scsi/scsi.c
51911 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51912 struct Scsi_Host *host = cmd->device->host;
51913 int rtn = 0;
51914
51915 - atomic_inc(&cmd->device->iorequest_cnt);
51916 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51917
51918 /* check if the device is still usable */
51919 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51920 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51921 index 17fb051..937fbbd 100644
51922 --- a/drivers/scsi/scsi_lib.c
51923 +++ b/drivers/scsi/scsi_lib.c
51924 @@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51925 shost = sdev->host;
51926 scsi_init_cmd_errh(cmd);
51927 cmd->result = DID_NO_CONNECT << 16;
51928 - atomic_inc(&cmd->device->iorequest_cnt);
51929 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51930
51931 /*
51932 * SCSI request completion path will do scsi_device_unbusy(),
51933 @@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51934
51935 INIT_LIST_HEAD(&cmd->eh_entry);
51936
51937 - atomic_inc(&cmd->device->iodone_cnt);
51938 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
51939 if (cmd->result)
51940 - atomic_inc(&cmd->device->ioerr_cnt);
51941 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51942
51943 disposition = scsi_decide_disposition(cmd);
51944 if (disposition != SUCCESS &&
51945 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51946 index f4cb7b3..dfa79c4 100644
51947 --- a/drivers/scsi/scsi_sysfs.c
51948 +++ b/drivers/scsi/scsi_sysfs.c
51949 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51950 char *buf) \
51951 { \
51952 struct scsi_device *sdev = to_scsi_device(dev); \
51953 - unsigned long long count = atomic_read(&sdev->field); \
51954 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
51955 return snprintf(buf, 20, "0x%llx\n", count); \
51956 } \
51957 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51958 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51959 index 5d6f348..18778a6b 100644
51960 --- a/drivers/scsi/scsi_transport_fc.c
51961 +++ b/drivers/scsi/scsi_transport_fc.c
51962 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51963 * Netlink Infrastructure
51964 */
51965
51966 -static atomic_t fc_event_seq;
51967 +static atomic_unchecked_t fc_event_seq;
51968
51969 /**
51970 * fc_get_event_number - Obtain the next sequential FC event number
51971 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51972 u32
51973 fc_get_event_number(void)
51974 {
51975 - return atomic_add_return(1, &fc_event_seq);
51976 + return atomic_add_return_unchecked(1, &fc_event_seq);
51977 }
51978 EXPORT_SYMBOL(fc_get_event_number);
51979
51980 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51981 {
51982 int error;
51983
51984 - atomic_set(&fc_event_seq, 0);
51985 + atomic_set_unchecked(&fc_event_seq, 0);
51986
51987 error = transport_class_register(&fc_host_class);
51988 if (error)
51989 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51990 char *cp;
51991
51992 *val = simple_strtoul(buf, &cp, 0);
51993 - if ((*cp && (*cp != '\n')) || (*val < 0))
51994 + if (*cp && (*cp != '\n'))
51995 return -EINVAL;
51996 /*
51997 * Check for overflow; dev_loss_tmo is u32
51998 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51999 index 67d43e3..8cee73c 100644
52000 --- a/drivers/scsi/scsi_transport_iscsi.c
52001 +++ b/drivers/scsi/scsi_transport_iscsi.c
52002 @@ -79,7 +79,7 @@ struct iscsi_internal {
52003 struct transport_container session_cont;
52004 };
52005
52006 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52007 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52008 static struct workqueue_struct *iscsi_eh_timer_workq;
52009
52010 static DEFINE_IDA(iscsi_sess_ida);
52011 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52012 int err;
52013
52014 ihost = shost->shost_data;
52015 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52016 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52017
52018 if (target_id == ISCSI_MAX_TARGET) {
52019 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52020 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52021 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52022 ISCSI_TRANSPORT_VERSION);
52023
52024 - atomic_set(&iscsi_session_nr, 0);
52025 + atomic_set_unchecked(&iscsi_session_nr, 0);
52026
52027 err = class_register(&iscsi_transport_class);
52028 if (err)
52029 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52030 index ae45bd9..c32a586 100644
52031 --- a/drivers/scsi/scsi_transport_srp.c
52032 +++ b/drivers/scsi/scsi_transport_srp.c
52033 @@ -35,7 +35,7 @@
52034 #include "scsi_priv.h"
52035
52036 struct srp_host_attrs {
52037 - atomic_t next_port_id;
52038 + atomic_unchecked_t next_port_id;
52039 };
52040 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52041
52042 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52043 struct Scsi_Host *shost = dev_to_shost(dev);
52044 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52045
52046 - atomic_set(&srp_host->next_port_id, 0);
52047 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52048 return 0;
52049 }
52050
52051 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52052 rport_fast_io_fail_timedout);
52053 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52054
52055 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52056 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52057 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52058
52059 transport_setup_device(&rport->dev);
52060 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52061 index cfba74c..4cdf6a1 100644
52062 --- a/drivers/scsi/sd.c
52063 +++ b/drivers/scsi/sd.c
52064 @@ -2818,9 +2818,11 @@ static int sd_revalidate_disk(struct gendisk *disk)
52065 */
52066 sd_set_flush_flag(sdkp);
52067
52068 - max_xfer = min_not_zero(queue_max_hw_sectors(sdkp->disk->queue),
52069 - sdkp->max_xfer_blocks);
52070 + max_xfer = sdkp->max_xfer_blocks;
52071 max_xfer <<= ilog2(sdp->sector_size) - 9;
52072 +
52073 + max_xfer = min_not_zero(queue_max_hw_sectors(sdkp->disk->queue),
52074 + max_xfer);
52075 blk_queue_max_hw_sectors(sdkp->disk->queue, max_xfer);
52076 set_capacity(disk, sdkp->capacity);
52077 sd_config_write_same(sdkp);
52078 @@ -3022,7 +3024,7 @@ static int sd_probe(struct device *dev)
52079 sdkp->disk = gd;
52080 sdkp->index = index;
52081 atomic_set(&sdkp->openers, 0);
52082 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52083 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52084
52085 if (!sdp->request_queue->rq_timeout) {
52086 if (sdp->type != TYPE_MOD)
52087 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52088 index 6035444..c82edd4 100644
52089 --- a/drivers/scsi/sg.c
52090 +++ b/drivers/scsi/sg.c
52091 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52092 sdp->disk->disk_name,
52093 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52094 NULL,
52095 - (char *)arg);
52096 + (char __user *)arg);
52097 case BLKTRACESTART:
52098 return blk_trace_startstop(sdp->device->request_queue, 1);
52099 case BLKTRACESTOP:
52100 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52101 index 11a5043..e36f04c 100644
52102 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52103 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52104 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52105 return i;
52106 }
52107
52108 -static struct bin_attribute fuse_bin_attr = {
52109 +static bin_attribute_no_const fuse_bin_attr = {
52110 .attr = { .name = "fuse", .mode = S_IRUGO, },
52111 .read = fuse_read,
52112 };
52113 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52114 index 50f20f2..6bd81e0 100644
52115 --- a/drivers/spi/spi.c
52116 +++ b/drivers/spi/spi.c
52117 @@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
52118 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52119
52120 /* portable code must never pass more than 32 bytes */
52121 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52122 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52123
52124 static u8 *buf;
52125
52126 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52127 index b41429f..2de5373 100644
52128 --- a/drivers/staging/android/timed_output.c
52129 +++ b/drivers/staging/android/timed_output.c
52130 @@ -25,7 +25,7 @@
52131 #include "timed_output.h"
52132
52133 static struct class *timed_output_class;
52134 -static atomic_t device_count;
52135 +static atomic_unchecked_t device_count;
52136
52137 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52138 char *buf)
52139 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52140 timed_output_class = class_create(THIS_MODULE, "timed_output");
52141 if (IS_ERR(timed_output_class))
52142 return PTR_ERR(timed_output_class);
52143 - atomic_set(&device_count, 0);
52144 + atomic_set_unchecked(&device_count, 0);
52145 timed_output_class->dev_groups = timed_output_groups;
52146 }
52147
52148 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52149 if (ret < 0)
52150 return ret;
52151
52152 - tdev->index = atomic_inc_return(&device_count);
52153 + tdev->index = atomic_inc_return_unchecked(&device_count);
52154 tdev->dev = device_create(timed_output_class, NULL,
52155 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52156 if (IS_ERR(tdev->dev))
52157 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52158 index 001348c..cfaac8a 100644
52159 --- a/drivers/staging/gdm724x/gdm_tty.c
52160 +++ b/drivers/staging/gdm724x/gdm_tty.c
52161 @@ -44,7 +44,7 @@
52162 #define gdm_tty_send_control(n, r, v, d, l) (\
52163 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52164
52165 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52166 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52167
52168 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52169 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52170 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52171 index 9cb222e..8766f26 100644
52172 --- a/drivers/staging/imx-drm/imx-drm-core.c
52173 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52174 @@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52175 if (imxdrm->pipes >= MAX_CRTC)
52176 return -EINVAL;
52177
52178 - if (imxdrm->drm->open_count)
52179 + if (local_read(&imxdrm->drm->open_count))
52180 return -EBUSY;
52181
52182 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52183 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52184 index 503b2d7..c904931 100644
52185 --- a/drivers/staging/line6/driver.c
52186 +++ b/drivers/staging/line6/driver.c
52187 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52188 {
52189 struct usb_device *usbdev = line6->usbdev;
52190 int ret;
52191 - unsigned char len;
52192 + unsigned char *plen;
52193
52194 /* query the serial number: */
52195 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52196 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52197 return ret;
52198 }
52199
52200 + plen = kmalloc(1, GFP_KERNEL);
52201 + if (plen == NULL)
52202 + return -ENOMEM;
52203 +
52204 /* Wait for data length. We'll get 0xff until length arrives. */
52205 do {
52206 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52207 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52208 USB_DIR_IN,
52209 - 0x0012, 0x0000, &len, 1,
52210 + 0x0012, 0x0000, plen, 1,
52211 LINE6_TIMEOUT * HZ);
52212 if (ret < 0) {
52213 dev_err(line6->ifcdev,
52214 "receive length failed (error %d)\n", ret);
52215 + kfree(plen);
52216 return ret;
52217 }
52218 - } while (len == 0xff);
52219 + } while (*plen == 0xff);
52220
52221 - if (len != datalen) {
52222 + if (*plen != datalen) {
52223 /* should be equal or something went wrong */
52224 dev_err(line6->ifcdev,
52225 "length mismatch (expected %d, got %d)\n",
52226 - (int)datalen, (int)len);
52227 + (int)datalen, (int)*plen);
52228 + kfree(plen);
52229 return -EINVAL;
52230 }
52231 + kfree(plen);
52232
52233 /* receive the result: */
52234 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52235 @@ -520,7 +527,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52236 {
52237 struct usb_device *usbdev = line6->usbdev;
52238 int ret;
52239 - unsigned char status;
52240 + unsigned char *status;
52241
52242 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52243 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
52244 @@ -533,26 +540,34 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52245 return ret;
52246 }
52247
52248 + status = kmalloc(1, GFP_KERNEL);
52249 + if (status == NULL)
52250 + return -ENOMEM;
52251 +
52252 do {
52253 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
52254 0x67,
52255 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52256 USB_DIR_IN,
52257 0x0012, 0x0000,
52258 - &status, 1, LINE6_TIMEOUT * HZ);
52259 + status, 1, LINE6_TIMEOUT * HZ);
52260
52261 if (ret < 0) {
52262 dev_err(line6->ifcdev,
52263 "receiving status failed (error %d)\n", ret);
52264 + kfree(status);
52265 return ret;
52266 }
52267 - } while (status == 0xff);
52268 + } while (*status == 0xff);
52269
52270 - if (status != 0) {
52271 + if (*status != 0) {
52272 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
52273 + kfree(status);
52274 return -EINVAL;
52275 }
52276
52277 + kfree(status);
52278 +
52279 return 0;
52280 }
52281
52282 diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
52283 index 6943715..0a93632 100644
52284 --- a/drivers/staging/line6/toneport.c
52285 +++ b/drivers/staging/line6/toneport.c
52286 @@ -11,6 +11,7 @@
52287 */
52288
52289 #include <linux/wait.h>
52290 +#include <linux/slab.h>
52291 #include <sound/control.h>
52292
52293 #include "audio.h"
52294 @@ -307,14 +308,20 @@ static void toneport_destruct(struct usb_interface *interface)
52295 */
52296 static void toneport_setup(struct usb_line6_toneport *toneport)
52297 {
52298 - int ticks;
52299 + int *ticks;
52300 struct usb_line6 *line6 = &toneport->line6;
52301 struct usb_device *usbdev = line6->usbdev;
52302 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
52303
52304 + ticks = kmalloc(sizeof(int), GFP_KERNEL);
52305 + if (ticks == NULL)
52306 + return;
52307 +
52308 /* sync time on device with host: */
52309 - ticks = (int)get_seconds();
52310 - line6_write_data(line6, 0x80c6, &ticks, 4);
52311 + *ticks = (int)get_seconds();
52312 + line6_write_data(line6, 0x80c6, ticks, sizeof(int));
52313 +
52314 + kfree(ticks);
52315
52316 /* enable device: */
52317 toneport_send_cmd(usbdev, 0x0301, 0x0000);
52318 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52319 index a94f336..6a1924d 100644
52320 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52321 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52322 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52323 return 0;
52324 }
52325
52326 -sfw_test_client_ops_t brw_test_client;
52327 -void brw_init_test_client(void)
52328 -{
52329 - brw_test_client.tso_init = brw_client_init;
52330 - brw_test_client.tso_fini = brw_client_fini;
52331 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52332 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52333 +sfw_test_client_ops_t brw_test_client = {
52334 + .tso_init = brw_client_init,
52335 + .tso_fini = brw_client_fini,
52336 + .tso_prep_rpc = brw_client_prep_rpc,
52337 + .tso_done_rpc = brw_client_done_rpc,
52338 };
52339
52340 srpc_service_t brw_test_service;
52341 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52342 index df04ab7..1deb1ac 100644
52343 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52344 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52345 @@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52346
52347 extern sfw_test_client_ops_t ping_test_client;
52348 extern srpc_service_t ping_test_service;
52349 -extern void ping_init_test_client(void);
52350 extern void ping_init_test_service(void);
52351
52352 extern sfw_test_client_ops_t brw_test_client;
52353 extern srpc_service_t brw_test_service;
52354 -extern void brw_init_test_client(void);
52355 extern void brw_init_test_service(void);
52356
52357
52358 @@ -1681,12 +1679,10 @@ sfw_startup (void)
52359 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52360 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52361
52362 - brw_init_test_client();
52363 brw_init_test_service();
52364 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52365 LASSERT (rc == 0);
52366
52367 - ping_init_test_client();
52368 ping_init_test_service();
52369 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52370 LASSERT (rc == 0);
52371 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52372 index 750cac4..e4d751f 100644
52373 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52374 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52375 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52376 return 0;
52377 }
52378
52379 -sfw_test_client_ops_t ping_test_client;
52380 -void ping_init_test_client(void)
52381 -{
52382 - ping_test_client.tso_init = ping_client_init;
52383 - ping_test_client.tso_fini = ping_client_fini;
52384 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52385 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52386 -}
52387 +sfw_test_client_ops_t ping_test_client = {
52388 + .tso_init = ping_client_init,
52389 + .tso_fini = ping_client_fini,
52390 + .tso_prep_rpc = ping_client_prep_rpc,
52391 + .tso_done_rpc = ping_client_done_rpc,
52392 +};
52393
52394 srpc_service_t ping_test_service;
52395 void ping_init_test_service(void)
52396 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52397 index 14ac46f..eca2c16 100644
52398 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52399 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52400 @@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52401 ldlm_completion_callback lcs_completion;
52402 ldlm_blocking_callback lcs_blocking;
52403 ldlm_glimpse_callback lcs_glimpse;
52404 -};
52405 +} __no_const;
52406
52407 /* ldlm_lockd.c */
52408 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52409 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52410 index 2a88b80..62e7e5f 100644
52411 --- a/drivers/staging/lustre/lustre/include/obd.h
52412 +++ b/drivers/staging/lustre/lustre/include/obd.h
52413 @@ -1362,7 +1362,7 @@ struct md_ops {
52414 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52415 * wrapper function in include/linux/obd_class.h.
52416 */
52417 -};
52418 +} __no_const;
52419
52420 struct lsm_operations {
52421 void (*lsm_free)(struct lov_stripe_md *);
52422 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52423 index b798daa..b28ca8f 100644
52424 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52425 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52426 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52427 int added = (mode == LCK_NL);
52428 int overlaps = 0;
52429 int splitted = 0;
52430 - const struct ldlm_callback_suite null_cbs = { NULL };
52431 + const struct ldlm_callback_suite null_cbs = { };
52432
52433 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52434 *flags, new->l_policy_data.l_flock.owner,
52435 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52436 index bbe2c68..c6b4275 100644
52437 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52438 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52439 @@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52440 void __user *buffer, size_t *lenp, loff_t *ppos)
52441 {
52442 int rc, max_delay_cs;
52443 - struct ctl_table dummy = *table;
52444 + ctl_table_no_const dummy = *table;
52445 long d;
52446
52447 dummy.data = &max_delay_cs;
52448 @@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52449 void __user *buffer, size_t *lenp, loff_t *ppos)
52450 {
52451 int rc, min_delay_cs;
52452 - struct ctl_table dummy = *table;
52453 + ctl_table_no_const dummy = *table;
52454 long d;
52455
52456 dummy.data = &min_delay_cs;
52457 @@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52458 void __user *buffer, size_t *lenp, loff_t *ppos)
52459 {
52460 int rc, backoff;
52461 - struct ctl_table dummy = *table;
52462 + ctl_table_no_const dummy = *table;
52463
52464 dummy.data = &backoff;
52465 dummy.proc_handler = &proc_dointvec;
52466 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52467 index 2c4fc74..b04ca79 100644
52468 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52469 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52470 @@ -315,11 +315,11 @@ out:
52471
52472
52473 struct cfs_psdev_ops libcfs_psdev_ops = {
52474 - libcfs_psdev_open,
52475 - libcfs_psdev_release,
52476 - NULL,
52477 - NULL,
52478 - libcfs_ioctl
52479 + .p_open = libcfs_psdev_open,
52480 + .p_close = libcfs_psdev_release,
52481 + .p_read = NULL,
52482 + .p_write = NULL,
52483 + .p_ioctl = libcfs_ioctl
52484 };
52485
52486 extern int insert_proc(void);
52487 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52488 index b0bb709..0117c96 100644
52489 --- a/drivers/staging/lustre/lustre/llite/dir.c
52490 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52491 @@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52492 int mode;
52493 int err;
52494
52495 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52496 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52497 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52498 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52499 lump);
52500 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52501 index b2b6c3c..302e4e4 100644
52502 --- a/drivers/staging/octeon/ethernet-rx.c
52503 +++ b/drivers/staging/octeon/ethernet-rx.c
52504 @@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52505 /* Increment RX stats for virtual ports */
52506 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52507 #ifdef CONFIG_64BIT
52508 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52509 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52510 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52511 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52512 #else
52513 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52514 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52515 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52516 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52517 #endif
52518 }
52519 netif_receive_skb(skb);
52520 @@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52521 dev->name);
52522 */
52523 #ifdef CONFIG_64BIT
52524 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52525 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52526 #else
52527 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52528 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52529 #endif
52530 dev_kfree_skb_irq(skb);
52531 }
52532 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52533 index 8f9e3fb..d283fb9 100644
52534 --- a/drivers/staging/octeon/ethernet.c
52535 +++ b/drivers/staging/octeon/ethernet.c
52536 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52537 * since the RX tasklet also increments it.
52538 */
52539 #ifdef CONFIG_64BIT
52540 - atomic64_add(rx_status.dropped_packets,
52541 - (atomic64_t *)&priv->stats.rx_dropped);
52542 + atomic64_add_unchecked(rx_status.dropped_packets,
52543 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52544 #else
52545 - atomic_add(rx_status.dropped_packets,
52546 - (atomic_t *)&priv->stats.rx_dropped);
52547 + atomic_add_unchecked(rx_status.dropped_packets,
52548 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52549 #endif
52550 }
52551
52552 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52553 index 9191993..30e9817 100644
52554 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52555 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52556 @@ -225,7 +225,7 @@ struct hal_ops {
52557
52558 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52559 void (*hal_reset_security_engine)(struct adapter *adapter);
52560 -};
52561 +} __no_const;
52562
52563 enum rt_eeprom_type {
52564 EEPROM_93C46,
52565 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52566 index 070cc03..6806e37 100644
52567 --- a/drivers/staging/rtl8712/rtl871x_io.h
52568 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52569 @@ -108,7 +108,7 @@ struct _io_ops {
52570 u8 *pmem);
52571 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52572 u8 *pmem);
52573 -};
52574 +} __no_const;
52575
52576 struct io_req {
52577 struct list_head list;
52578 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52579 index 2bf2e2f..84421c9 100644
52580 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52581 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52582 @@ -228,7 +228,7 @@ typedef struct {
52583 void (*device_resume)(ulong busNo, ulong devNo);
52584 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52585 ulong *maxSize);
52586 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52587 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52588
52589 /* These functions live inside visorchipset, and will be called to indicate
52590 * responses to specific events (by code outside of visorchipset).
52591 @@ -243,7 +243,7 @@ typedef struct {
52592 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52593 void (*device_pause)(ulong busNo, ulong devNo, int response);
52594 void (*device_resume)(ulong busNo, ulong devNo, int response);
52595 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52596 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52597
52598 /** Register functions (in the bus driver) to get called by visorchipset
52599 * whenever a bus or device appears for which this service partition is
52600 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52601 index ae0dade..803d53a 100644
52602 --- a/drivers/staging/vt6655/hostap.c
52603 +++ b/drivers/staging/vt6655/hostap.c
52604 @@ -65,14 +65,13 @@
52605 *
52606 */
52607
52608 +static net_device_ops_no_const apdev_netdev_ops;
52609 +
52610 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52611 {
52612 struct vnt_private *apdev_priv;
52613 struct net_device *dev = pDevice->dev;
52614 int ret;
52615 - const struct net_device_ops apdev_netdev_ops = {
52616 - .ndo_start_xmit = pDevice->tx_80211,
52617 - };
52618
52619 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52620
52621 @@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52622 *apdev_priv = *pDevice;
52623 eth_hw_addr_inherit(pDevice->apdev, dev);
52624
52625 + /* only half broken now */
52626 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52627 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52628
52629 pDevice->apdev->type = ARPHRD_IEEE80211;
52630 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52631 index e7e9372..161f530 100644
52632 --- a/drivers/target/sbp/sbp_target.c
52633 +++ b/drivers/target/sbp/sbp_target.c
52634 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52635
52636 #define SESSION_MAINTENANCE_INTERVAL HZ
52637
52638 -static atomic_t login_id = ATOMIC_INIT(0);
52639 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52640
52641 static void session_maintenance_work(struct work_struct *);
52642 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52643 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52644 login->lun = se_lun;
52645 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52646 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52647 - login->login_id = atomic_inc_return(&login_id);
52648 + login->login_id = atomic_inc_return_unchecked(&login_id);
52649
52650 login->tgt_agt = sbp_target_agent_register(login);
52651 if (IS_ERR(login->tgt_agt)) {
52652 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52653 index 24fa5d1..fae56f1 100644
52654 --- a/drivers/target/target_core_device.c
52655 +++ b/drivers/target/target_core_device.c
52656 @@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52657 spin_lock_init(&dev->se_tmr_lock);
52658 spin_lock_init(&dev->qf_cmd_lock);
52659 sema_init(&dev->caw_sem, 1);
52660 - atomic_set(&dev->dev_ordered_id, 0);
52661 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52662 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52663 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52664 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52665 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52666 index be877bf..7be9cd4 100644
52667 --- a/drivers/target/target_core_transport.c
52668 +++ b/drivers/target/target_core_transport.c
52669 @@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52670 * Used to determine when ORDERED commands should go from
52671 * Dormant to Active status.
52672 */
52673 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52674 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52675 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52676 cmd->se_ordered_id, cmd->sam_task_attr,
52677 dev->transport->name);
52678 diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52679 index edc1cce..769e4cb 100644
52680 --- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52681 +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52682 @@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52683 platform_set_drvdata(pdev, priv);
52684
52685 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52686 - int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52687 - int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52688 + pax_open_kernel();
52689 + *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52690 + *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52691 + pax_close_kernel();
52692 }
52693 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52694 priv, &int3400_thermal_ops,
52695 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52696 index 62143ba..ae21165 100644
52697 --- a/drivers/thermal/of-thermal.c
52698 +++ b/drivers/thermal/of-thermal.c
52699 @@ -30,6 +30,7 @@
52700 #include <linux/err.h>
52701 #include <linux/export.h>
52702 #include <linux/string.h>
52703 +#include <linux/mm.h>
52704
52705 #include "thermal_core.h"
52706
52707 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52708 tz->get_trend = get_trend;
52709 tz->sensor_data = data;
52710
52711 - tzd->ops->get_temp = of_thermal_get_temp;
52712 - tzd->ops->get_trend = of_thermal_get_trend;
52713 + pax_open_kernel();
52714 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52715 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52716 + pax_close_kernel();
52717 mutex_unlock(&tzd->lock);
52718
52719 return tzd;
52720 @@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52721 return;
52722
52723 mutex_lock(&tzd->lock);
52724 - tzd->ops->get_temp = NULL;
52725 - tzd->ops->get_trend = NULL;
52726 + pax_open_kernel();
52727 + *(void **)&tzd->ops->get_temp = NULL;
52728 + *(void **)&tzd->ops->get_trend = NULL;
52729 + pax_close_kernel();
52730
52731 tz->get_temp = NULL;
52732 tz->get_trend = NULL;
52733 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52734 index fd66f57..48e6376 100644
52735 --- a/drivers/tty/cyclades.c
52736 +++ b/drivers/tty/cyclades.c
52737 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52738 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52739 info->port.count);
52740 #endif
52741 - info->port.count++;
52742 + atomic_inc(&info->port.count);
52743 #ifdef CY_DEBUG_COUNT
52744 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52745 - current->pid, info->port.count);
52746 + current->pid, atomic_read(&info->port.count));
52747 #endif
52748
52749 /*
52750 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52751 for (j = 0; j < cy_card[i].nports; j++) {
52752 info = &cy_card[i].ports[j];
52753
52754 - if (info->port.count) {
52755 + if (atomic_read(&info->port.count)) {
52756 /* XXX is the ldisc num worth this? */
52757 struct tty_struct *tty;
52758 struct tty_ldisc *ld;
52759 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52760 index 4fcec1d..5a036f7 100644
52761 --- a/drivers/tty/hvc/hvc_console.c
52762 +++ b/drivers/tty/hvc/hvc_console.c
52763 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52764
52765 spin_lock_irqsave(&hp->port.lock, flags);
52766 /* Check and then increment for fast path open. */
52767 - if (hp->port.count++ > 0) {
52768 + if (atomic_inc_return(&hp->port.count) > 1) {
52769 spin_unlock_irqrestore(&hp->port.lock, flags);
52770 hvc_kick();
52771 return 0;
52772 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52773
52774 spin_lock_irqsave(&hp->port.lock, flags);
52775
52776 - if (--hp->port.count == 0) {
52777 + if (atomic_dec_return(&hp->port.count) == 0) {
52778 spin_unlock_irqrestore(&hp->port.lock, flags);
52779 /* We are done with the tty pointer now. */
52780 tty_port_tty_set(&hp->port, NULL);
52781 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52782 */
52783 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52784 } else {
52785 - if (hp->port.count < 0)
52786 + if (atomic_read(&hp->port.count) < 0)
52787 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52788 - hp->vtermno, hp->port.count);
52789 + hp->vtermno, atomic_read(&hp->port.count));
52790 spin_unlock_irqrestore(&hp->port.lock, flags);
52791 }
52792 }
52793 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52794 * open->hangup case this can be called after the final close so prevent
52795 * that from happening for now.
52796 */
52797 - if (hp->port.count <= 0) {
52798 + if (atomic_read(&hp->port.count) <= 0) {
52799 spin_unlock_irqrestore(&hp->port.lock, flags);
52800 return;
52801 }
52802
52803 - hp->port.count = 0;
52804 + atomic_set(&hp->port.count, 0);
52805 spin_unlock_irqrestore(&hp->port.lock, flags);
52806 tty_port_tty_set(&hp->port, NULL);
52807
52808 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52809 return -EPIPE;
52810
52811 /* FIXME what's this (unprotected) check for? */
52812 - if (hp->port.count <= 0)
52813 + if (atomic_read(&hp->port.count) <= 0)
52814 return -EIO;
52815
52816 spin_lock_irqsave(&hp->lock, flags);
52817 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52818 index 81e939e..95ead10 100644
52819 --- a/drivers/tty/hvc/hvcs.c
52820 +++ b/drivers/tty/hvc/hvcs.c
52821 @@ -83,6 +83,7 @@
52822 #include <asm/hvcserver.h>
52823 #include <asm/uaccess.h>
52824 #include <asm/vio.h>
52825 +#include <asm/local.h>
52826
52827 /*
52828 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52829 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52830
52831 spin_lock_irqsave(&hvcsd->lock, flags);
52832
52833 - if (hvcsd->port.count > 0) {
52834 + if (atomic_read(&hvcsd->port.count) > 0) {
52835 spin_unlock_irqrestore(&hvcsd->lock, flags);
52836 printk(KERN_INFO "HVCS: vterm state unchanged. "
52837 "The hvcs device node is still in use.\n");
52838 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52839 }
52840 }
52841
52842 - hvcsd->port.count = 0;
52843 + atomic_set(&hvcsd->port.count, 0);
52844 hvcsd->port.tty = tty;
52845 tty->driver_data = hvcsd;
52846
52847 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52848 unsigned long flags;
52849
52850 spin_lock_irqsave(&hvcsd->lock, flags);
52851 - hvcsd->port.count++;
52852 + atomic_inc(&hvcsd->port.count);
52853 hvcsd->todo_mask |= HVCS_SCHED_READ;
52854 spin_unlock_irqrestore(&hvcsd->lock, flags);
52855
52856 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52857 hvcsd = tty->driver_data;
52858
52859 spin_lock_irqsave(&hvcsd->lock, flags);
52860 - if (--hvcsd->port.count == 0) {
52861 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52862
52863 vio_disable_interrupts(hvcsd->vdev);
52864
52865 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52866
52867 free_irq(irq, hvcsd);
52868 return;
52869 - } else if (hvcsd->port.count < 0) {
52870 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52871 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52872 " is missmanaged.\n",
52873 - hvcsd->vdev->unit_address, hvcsd->port.count);
52874 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52875 }
52876
52877 spin_unlock_irqrestore(&hvcsd->lock, flags);
52878 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52879
52880 spin_lock_irqsave(&hvcsd->lock, flags);
52881 /* Preserve this so that we know how many kref refs to put */
52882 - temp_open_count = hvcsd->port.count;
52883 + temp_open_count = atomic_read(&hvcsd->port.count);
52884
52885 /*
52886 * Don't kref put inside the spinlock because the destruction
52887 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52888 tty->driver_data = NULL;
52889 hvcsd->port.tty = NULL;
52890
52891 - hvcsd->port.count = 0;
52892 + atomic_set(&hvcsd->port.count, 0);
52893
52894 /* This will drop any buffered data on the floor which is OK in a hangup
52895 * scenario. */
52896 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52897 * the middle of a write operation? This is a crummy place to do this
52898 * but we want to keep it all in the spinlock.
52899 */
52900 - if (hvcsd->port.count <= 0) {
52901 + if (atomic_read(&hvcsd->port.count) <= 0) {
52902 spin_unlock_irqrestore(&hvcsd->lock, flags);
52903 return -ENODEV;
52904 }
52905 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52906 {
52907 struct hvcs_struct *hvcsd = tty->driver_data;
52908
52909 - if (!hvcsd || hvcsd->port.count <= 0)
52910 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52911 return 0;
52912
52913 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52914 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52915 index 4190199..06d5bfa 100644
52916 --- a/drivers/tty/hvc/hvsi.c
52917 +++ b/drivers/tty/hvc/hvsi.c
52918 @@ -85,7 +85,7 @@ struct hvsi_struct {
52919 int n_outbuf;
52920 uint32_t vtermno;
52921 uint32_t virq;
52922 - atomic_t seqno; /* HVSI packet sequence number */
52923 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52924 uint16_t mctrl;
52925 uint8_t state; /* HVSI protocol state */
52926 uint8_t flags;
52927 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52928
52929 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52930 packet.hdr.len = sizeof(struct hvsi_query_response);
52931 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52932 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52933 packet.verb = VSV_SEND_VERSION_NUMBER;
52934 packet.u.version = HVSI_VERSION;
52935 packet.query_seqno = query_seqno+1;
52936 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52937
52938 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52939 packet.hdr.len = sizeof(struct hvsi_query);
52940 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52941 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52942 packet.verb = verb;
52943
52944 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52945 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52946 int wrote;
52947
52948 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52949 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52950 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52951 packet.hdr.len = sizeof(struct hvsi_control);
52952 packet.verb = VSV_SET_MODEM_CTL;
52953 packet.mask = HVSI_TSDTR;
52954 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52955 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52956
52957 packet.hdr.type = VS_DATA_PACKET_HEADER;
52958 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52959 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52960 packet.hdr.len = count + sizeof(struct hvsi_header);
52961 memcpy(&packet.data, buf, count);
52962
52963 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52964 struct hvsi_control packet __ALIGNED__;
52965
52966 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52967 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52968 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52969 packet.hdr.len = 6;
52970 packet.verb = VSV_CLOSE_PROTOCOL;
52971
52972 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52973
52974 tty_port_tty_set(&hp->port, tty);
52975 spin_lock_irqsave(&hp->lock, flags);
52976 - hp->port.count++;
52977 + atomic_inc(&hp->port.count);
52978 atomic_set(&hp->seqno, 0);
52979 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52980 spin_unlock_irqrestore(&hp->lock, flags);
52981 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52982
52983 spin_lock_irqsave(&hp->lock, flags);
52984
52985 - if (--hp->port.count == 0) {
52986 + if (atomic_dec_return(&hp->port.count) == 0) {
52987 tty_port_tty_set(&hp->port, NULL);
52988 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52989
52990 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52991
52992 spin_lock_irqsave(&hp->lock, flags);
52993 }
52994 - } else if (hp->port.count < 0)
52995 + } else if (atomic_read(&hp->port.count) < 0)
52996 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52997 - hp - hvsi_ports, hp->port.count);
52998 + hp - hvsi_ports, atomic_read(&hp->port.count));
52999
53000 spin_unlock_irqrestore(&hp->lock, flags);
53001 }
53002 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53003 tty_port_tty_set(&hp->port, NULL);
53004
53005 spin_lock_irqsave(&hp->lock, flags);
53006 - hp->port.count = 0;
53007 + atomic_set(&hp->port.count, 0);
53008 hp->n_outbuf = 0;
53009 spin_unlock_irqrestore(&hp->lock, flags);
53010 }
53011 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53012 index 7ae6c29..05c6dba 100644
53013 --- a/drivers/tty/hvc/hvsi_lib.c
53014 +++ b/drivers/tty/hvc/hvsi_lib.c
53015 @@ -8,7 +8,7 @@
53016
53017 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53018 {
53019 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53020 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53021
53022 /* Assumes that always succeeds, works in practice */
53023 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53024 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53025
53026 /* Reset state */
53027 pv->established = 0;
53028 - atomic_set(&pv->seqno, 0);
53029 + atomic_set_unchecked(&pv->seqno, 0);
53030
53031 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53032
53033 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53034 index 345cebb..d5a1e9e 100644
53035 --- a/drivers/tty/ipwireless/tty.c
53036 +++ b/drivers/tty/ipwireless/tty.c
53037 @@ -28,6 +28,7 @@
53038 #include <linux/tty_driver.h>
53039 #include <linux/tty_flip.h>
53040 #include <linux/uaccess.h>
53041 +#include <asm/local.h>
53042
53043 #include "tty.h"
53044 #include "network.h"
53045 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53046 return -ENODEV;
53047
53048 mutex_lock(&tty->ipw_tty_mutex);
53049 - if (tty->port.count == 0)
53050 + if (atomic_read(&tty->port.count) == 0)
53051 tty->tx_bytes_queued = 0;
53052
53053 - tty->port.count++;
53054 + atomic_inc(&tty->port.count);
53055
53056 tty->port.tty = linux_tty;
53057 linux_tty->driver_data = tty;
53058 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53059
53060 static void do_ipw_close(struct ipw_tty *tty)
53061 {
53062 - tty->port.count--;
53063 -
53064 - if (tty->port.count == 0) {
53065 + if (atomic_dec_return(&tty->port.count) == 0) {
53066 struct tty_struct *linux_tty = tty->port.tty;
53067
53068 if (linux_tty != NULL) {
53069 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53070 return;
53071
53072 mutex_lock(&tty->ipw_tty_mutex);
53073 - if (tty->port.count == 0) {
53074 + if (atomic_read(&tty->port.count) == 0) {
53075 mutex_unlock(&tty->ipw_tty_mutex);
53076 return;
53077 }
53078 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53079
53080 mutex_lock(&tty->ipw_tty_mutex);
53081
53082 - if (!tty->port.count) {
53083 + if (!atomic_read(&tty->port.count)) {
53084 mutex_unlock(&tty->ipw_tty_mutex);
53085 return;
53086 }
53087 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53088 return -ENODEV;
53089
53090 mutex_lock(&tty->ipw_tty_mutex);
53091 - if (!tty->port.count) {
53092 + if (!atomic_read(&tty->port.count)) {
53093 mutex_unlock(&tty->ipw_tty_mutex);
53094 return -EINVAL;
53095 }
53096 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53097 if (!tty)
53098 return -ENODEV;
53099
53100 - if (!tty->port.count)
53101 + if (!atomic_read(&tty->port.count))
53102 return -EINVAL;
53103
53104 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53105 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53106 if (!tty)
53107 return 0;
53108
53109 - if (!tty->port.count)
53110 + if (!atomic_read(&tty->port.count))
53111 return 0;
53112
53113 return tty->tx_bytes_queued;
53114 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53115 if (!tty)
53116 return -ENODEV;
53117
53118 - if (!tty->port.count)
53119 + if (!atomic_read(&tty->port.count))
53120 return -EINVAL;
53121
53122 return get_control_lines(tty);
53123 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53124 if (!tty)
53125 return -ENODEV;
53126
53127 - if (!tty->port.count)
53128 + if (!atomic_read(&tty->port.count))
53129 return -EINVAL;
53130
53131 return set_control_lines(tty, set, clear);
53132 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53133 if (!tty)
53134 return -ENODEV;
53135
53136 - if (!tty->port.count)
53137 + if (!atomic_read(&tty->port.count))
53138 return -EINVAL;
53139
53140 /* FIXME: Exactly how is the tty object locked here .. */
53141 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53142 * are gone */
53143 mutex_lock(&ttyj->ipw_tty_mutex);
53144 }
53145 - while (ttyj->port.count)
53146 + while (atomic_read(&ttyj->port.count))
53147 do_ipw_close(ttyj);
53148 ipwireless_disassociate_network_ttys(network,
53149 ttyj->channel_idx);
53150 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53151 index 14c54e0..1efd4f2 100644
53152 --- a/drivers/tty/moxa.c
53153 +++ b/drivers/tty/moxa.c
53154 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53155 }
53156
53157 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53158 - ch->port.count++;
53159 + atomic_inc(&ch->port.count);
53160 tty->driver_data = ch;
53161 tty_port_tty_set(&ch->port, tty);
53162 mutex_lock(&ch->port.mutex);
53163 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53164 index c434376..114ce13 100644
53165 --- a/drivers/tty/n_gsm.c
53166 +++ b/drivers/tty/n_gsm.c
53167 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53168 spin_lock_init(&dlci->lock);
53169 mutex_init(&dlci->mutex);
53170 dlci->fifo = &dlci->_fifo;
53171 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53172 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53173 kfree(dlci);
53174 return NULL;
53175 }
53176 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53177 struct gsm_dlci *dlci = tty->driver_data;
53178 struct tty_port *port = &dlci->port;
53179
53180 - port->count++;
53181 + atomic_inc(&port->count);
53182 tty_port_tty_set(port, tty);
53183
53184 dlci->modem_rx = 0;
53185 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53186 index 47ca0f3..3c0b803 100644
53187 --- a/drivers/tty/n_tty.c
53188 +++ b/drivers/tty/n_tty.c
53189 @@ -115,7 +115,7 @@ struct n_tty_data {
53190 int minimum_to_wake;
53191
53192 /* consumer-published */
53193 - size_t read_tail;
53194 + size_t read_tail __intentional_overflow(-1);
53195 size_t line_start;
53196
53197 /* protected by output lock */
53198 @@ -2523,6 +2523,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53199 {
53200 *ops = tty_ldisc_N_TTY;
53201 ops->owner = NULL;
53202 - ops->refcount = ops->flags = 0;
53203 + atomic_set(&ops->refcount, 0);
53204 + ops->flags = 0;
53205 }
53206 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53207 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53208 index 7c4447a..70fbc1e 100644
53209 --- a/drivers/tty/pty.c
53210 +++ b/drivers/tty/pty.c
53211 @@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
53212 panic("Couldn't register Unix98 pts driver");
53213
53214 /* Now create the /dev/ptmx special device */
53215 + pax_open_kernel();
53216 tty_default_fops(&ptmx_fops);
53217 - ptmx_fops.open = ptmx_open;
53218 + *(void **)&ptmx_fops.open = ptmx_open;
53219 + pax_close_kernel();
53220
53221 cdev_init(&ptmx_cdev, &ptmx_fops);
53222 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53223 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53224 index 383c4c7..d408e21 100644
53225 --- a/drivers/tty/rocket.c
53226 +++ b/drivers/tty/rocket.c
53227 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53228 tty->driver_data = info;
53229 tty_port_tty_set(port, tty);
53230
53231 - if (port->count++ == 0) {
53232 + if (atomic_inc_return(&port->count) == 1) {
53233 atomic_inc(&rp_num_ports_open);
53234
53235 #ifdef ROCKET_DEBUG_OPEN
53236 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53237 #endif
53238 }
53239 #ifdef ROCKET_DEBUG_OPEN
53240 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53241 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53242 #endif
53243
53244 /*
53245 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53246 spin_unlock_irqrestore(&info->port.lock, flags);
53247 return;
53248 }
53249 - if (info->port.count)
53250 + if (atomic_read(&info->port.count))
53251 atomic_dec(&rp_num_ports_open);
53252 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53253 spin_unlock_irqrestore(&info->port.lock, flags);
53254 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53255 index aa28209..e08fb85 100644
53256 --- a/drivers/tty/serial/ioc4_serial.c
53257 +++ b/drivers/tty/serial/ioc4_serial.c
53258 @@ -437,7 +437,7 @@ struct ioc4_soft {
53259 } is_intr_info[MAX_IOC4_INTR_ENTS];
53260
53261 /* Number of entries active in the above array */
53262 - atomic_t is_num_intrs;
53263 + atomic_unchecked_t is_num_intrs;
53264 } is_intr_type[IOC4_NUM_INTR_TYPES];
53265
53266 /* is_ir_lock must be held while
53267 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53268 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53269 || (type == IOC4_OTHER_INTR_TYPE)));
53270
53271 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53272 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53273 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53274
53275 /* Save off the lower level interrupt handler */
53276 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53277
53278 soft = arg;
53279 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53280 - num_intrs = (int)atomic_read(
53281 + num_intrs = (int)atomic_read_unchecked(
53282 &soft->is_intr_type[intr_type].is_num_intrs);
53283
53284 this_mir = this_ir = pending_intrs(soft, intr_type);
53285 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53286 index 129dc5b..1da5bb8 100644
53287 --- a/drivers/tty/serial/kgdb_nmi.c
53288 +++ b/drivers/tty/serial/kgdb_nmi.c
53289 @@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53290 * I/O utilities that messages sent to the console will automatically
53291 * be displayed on the dbg_io.
53292 */
53293 - dbg_io_ops->is_console = true;
53294 + pax_open_kernel();
53295 + *(int *)&dbg_io_ops->is_console = true;
53296 + pax_close_kernel();
53297
53298 return 0;
53299 }
53300 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53301 index a260cde..6b2b5ce 100644
53302 --- a/drivers/tty/serial/kgdboc.c
53303 +++ b/drivers/tty/serial/kgdboc.c
53304 @@ -24,8 +24,9 @@
53305 #define MAX_CONFIG_LEN 40
53306
53307 static struct kgdb_io kgdboc_io_ops;
53308 +static struct kgdb_io kgdboc_io_ops_console;
53309
53310 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53311 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53312 static int configured = -1;
53313
53314 static char config[MAX_CONFIG_LEN];
53315 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53316 kgdboc_unregister_kbd();
53317 if (configured == 1)
53318 kgdb_unregister_io_module(&kgdboc_io_ops);
53319 + else if (configured == 2)
53320 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53321 }
53322
53323 static int configure_kgdboc(void)
53324 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53325 int err;
53326 char *cptr = config;
53327 struct console *cons;
53328 + int is_console = 0;
53329
53330 err = kgdboc_option_setup(config);
53331 if (err || !strlen(config) || isspace(config[0]))
53332 goto noconfig;
53333
53334 err = -ENODEV;
53335 - kgdboc_io_ops.is_console = 0;
53336 kgdb_tty_driver = NULL;
53337
53338 kgdboc_use_kms = 0;
53339 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53340 int idx;
53341 if (cons->device && cons->device(cons, &idx) == p &&
53342 idx == tty_line) {
53343 - kgdboc_io_ops.is_console = 1;
53344 + is_console = 1;
53345 break;
53346 }
53347 cons = cons->next;
53348 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53349 kgdb_tty_line = tty_line;
53350
53351 do_register:
53352 - err = kgdb_register_io_module(&kgdboc_io_ops);
53353 + if (is_console) {
53354 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53355 + configured = 2;
53356 + } else {
53357 + err = kgdb_register_io_module(&kgdboc_io_ops);
53358 + configured = 1;
53359 + }
53360 if (err)
53361 goto noconfig;
53362
53363 @@ -205,8 +214,6 @@ do_register:
53364 if (err)
53365 goto nmi_con_failed;
53366
53367 - configured = 1;
53368 -
53369 return 0;
53370
53371 nmi_con_failed:
53372 @@ -223,7 +230,7 @@ noconfig:
53373 static int __init init_kgdboc(void)
53374 {
53375 /* Already configured? */
53376 - if (configured == 1)
53377 + if (configured >= 1)
53378 return 0;
53379
53380 return configure_kgdboc();
53381 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53382 if (config[len - 1] == '\n')
53383 config[len - 1] = '\0';
53384
53385 - if (configured == 1)
53386 + if (configured >= 1)
53387 cleanup_kgdboc();
53388
53389 /* Go and configure with the new params. */
53390 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53391 .post_exception = kgdboc_post_exp_handler,
53392 };
53393
53394 +static struct kgdb_io kgdboc_io_ops_console = {
53395 + .name = "kgdboc",
53396 + .read_char = kgdboc_get_char,
53397 + .write_char = kgdboc_put_char,
53398 + .pre_exception = kgdboc_pre_exp_handler,
53399 + .post_exception = kgdboc_post_exp_handler,
53400 + .is_console = 1
53401 +};
53402 +
53403 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53404 /* This is only available if kgdboc is a built in for early debugging */
53405 static int __init kgdboc_early_init(char *opt)
53406 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53407 index 4b6c783..9a19db3 100644
53408 --- a/drivers/tty/serial/msm_serial.c
53409 +++ b/drivers/tty/serial/msm_serial.c
53410 @@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53411 .cons = MSM_CONSOLE,
53412 };
53413
53414 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53415 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53416
53417 static const struct of_device_id msm_uartdm_table[] = {
53418 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53419 @@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53420 int irq;
53421
53422 if (pdev->id == -1)
53423 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53424 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53425
53426 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53427 return -ENXIO;
53428 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53429 index 587d63b..48423a6 100644
53430 --- a/drivers/tty/serial/samsung.c
53431 +++ b/drivers/tty/serial/samsung.c
53432 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53433 }
53434 }
53435
53436 +static int s3c64xx_serial_startup(struct uart_port *port);
53437 static int s3c24xx_serial_startup(struct uart_port *port)
53438 {
53439 struct s3c24xx_uart_port *ourport = to_ourport(port);
53440 int ret;
53441
53442 + /* Startup sequence is different for s3c64xx and higher SoC's */
53443 + if (s3c24xx_serial_has_interrupt_mask(port))
53444 + return s3c64xx_serial_startup(port);
53445 +
53446 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53447 port, (unsigned long long)port->mapbase, port->membase);
53448
53449 @@ -1159,10 +1164,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53450 /* setup info for port */
53451 port->dev = &platdev->dev;
53452
53453 - /* Startup sequence is different for s3c64xx and higher SoC's */
53454 - if (s3c24xx_serial_has_interrupt_mask(port))
53455 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53456 -
53457 port->uartclk = 1;
53458
53459 if (cfg->uart_flags & UPF_CONS_FLOW) {
53460 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53461 index a28dee9..168ba47 100644
53462 --- a/drivers/tty/serial/serial_core.c
53463 +++ b/drivers/tty/serial/serial_core.c
53464 @@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53465
53466 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53467
53468 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53469 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53470 return;
53471
53472 /*
53473 @@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53474 uart_flush_buffer(tty);
53475 uart_shutdown(tty, state);
53476 spin_lock_irqsave(&port->lock, flags);
53477 - port->count = 0;
53478 + atomic_set(&port->count, 0);
53479 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53480 spin_unlock_irqrestore(&port->lock, flags);
53481 tty_port_tty_set(port, NULL);
53482 @@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53483 goto end;
53484 }
53485
53486 - port->count++;
53487 + atomic_inc(&port->count);
53488 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53489 retval = -ENXIO;
53490 goto err_dec_count;
53491 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53492 end:
53493 return retval;
53494 err_dec_count:
53495 - port->count--;
53496 + atomic_dec(&port->count);
53497 mutex_unlock(&port->mutex);
53498 goto end;
53499 }
53500 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53501 index b799170..87dafd5 100644
53502 --- a/drivers/tty/synclink.c
53503 +++ b/drivers/tty/synclink.c
53504 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53505
53506 if (debug_level >= DEBUG_LEVEL_INFO)
53507 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53508 - __FILE__,__LINE__, info->device_name, info->port.count);
53509 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53510
53511 if (tty_port_close_start(&info->port, tty, filp) == 0)
53512 goto cleanup;
53513 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53514 cleanup:
53515 if (debug_level >= DEBUG_LEVEL_INFO)
53516 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53517 - tty->driver->name, info->port.count);
53518 + tty->driver->name, atomic_read(&info->port.count));
53519
53520 } /* end of mgsl_close() */
53521
53522 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53523
53524 mgsl_flush_buffer(tty);
53525 shutdown(info);
53526 -
53527 - info->port.count = 0;
53528 +
53529 + atomic_set(&info->port.count, 0);
53530 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53531 info->port.tty = NULL;
53532
53533 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53534
53535 if (debug_level >= DEBUG_LEVEL_INFO)
53536 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53537 - __FILE__,__LINE__, tty->driver->name, port->count );
53538 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53539
53540 spin_lock_irqsave(&info->irq_spinlock, flags);
53541 - port->count--;
53542 + atomic_dec(&port->count);
53543 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53544 port->blocked_open++;
53545
53546 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53547
53548 if (debug_level >= DEBUG_LEVEL_INFO)
53549 printk("%s(%d):block_til_ready 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 tty_unlock(tty);
53554 schedule();
53555 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53556
53557 /* FIXME: Racy on hangup during close wait */
53558 if (!tty_hung_up_p(filp))
53559 - port->count++;
53560 + atomic_inc(&port->count);
53561 port->blocked_open--;
53562
53563 if (debug_level >= DEBUG_LEVEL_INFO)
53564 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53565 - __FILE__,__LINE__, tty->driver->name, port->count );
53566 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53567
53568 if (!retval)
53569 port->flags |= ASYNC_NORMAL_ACTIVE;
53570 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53571
53572 if (debug_level >= DEBUG_LEVEL_INFO)
53573 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53574 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53575 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53576
53577 /* If port is closing, signal caller to try again */
53578 if (info->port.flags & ASYNC_CLOSING){
53579 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53580 spin_unlock_irqrestore(&info->netlock, flags);
53581 goto cleanup;
53582 }
53583 - info->port.count++;
53584 + atomic_inc(&info->port.count);
53585 spin_unlock_irqrestore(&info->netlock, flags);
53586
53587 - if (info->port.count == 1) {
53588 + if (atomic_read(&info->port.count) == 1) {
53589 /* 1st open on this device, init hardware */
53590 retval = startup(info);
53591 if (retval < 0)
53592 @@ -3442,8 +3442,8 @@ cleanup:
53593 if (retval) {
53594 if (tty->count == 1)
53595 info->port.tty = NULL; /* tty layer will release tty struct */
53596 - if(info->port.count)
53597 - info->port.count--;
53598 + if (atomic_read(&info->port.count))
53599 + atomic_dec(&info->port.count);
53600 }
53601
53602 return retval;
53603 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53604 unsigned short new_crctype;
53605
53606 /* return error if TTY interface open */
53607 - if (info->port.count)
53608 + if (atomic_read(&info->port.count))
53609 return -EBUSY;
53610
53611 switch (encoding)
53612 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53613
53614 /* arbitrate between network and tty opens */
53615 spin_lock_irqsave(&info->netlock, flags);
53616 - if (info->port.count != 0 || info->netcount != 0) {
53617 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53618 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53619 spin_unlock_irqrestore(&info->netlock, flags);
53620 return -EBUSY;
53621 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53622 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53623
53624 /* return error if TTY interface open */
53625 - if (info->port.count)
53626 + if (atomic_read(&info->port.count))
53627 return -EBUSY;
53628
53629 if (cmd != SIOCWANDEV)
53630 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53631 index 0e8c39b..e0cb171 100644
53632 --- a/drivers/tty/synclink_gt.c
53633 +++ b/drivers/tty/synclink_gt.c
53634 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53635 tty->driver_data = info;
53636 info->port.tty = tty;
53637
53638 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53639 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53640
53641 /* If port is closing, signal caller to try again */
53642 if (info->port.flags & ASYNC_CLOSING){
53643 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53644 mutex_unlock(&info->port.mutex);
53645 goto cleanup;
53646 }
53647 - info->port.count++;
53648 + atomic_inc(&info->port.count);
53649 spin_unlock_irqrestore(&info->netlock, flags);
53650
53651 - if (info->port.count == 1) {
53652 + if (atomic_read(&info->port.count) == 1) {
53653 /* 1st open on this device, init hardware */
53654 retval = startup(info);
53655 if (retval < 0) {
53656 @@ -715,8 +715,8 @@ cleanup:
53657 if (retval) {
53658 if (tty->count == 1)
53659 info->port.tty = NULL; /* tty layer will release tty struct */
53660 - if(info->port.count)
53661 - info->port.count--;
53662 + if(atomic_read(&info->port.count))
53663 + atomic_dec(&info->port.count);
53664 }
53665
53666 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53667 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53668
53669 if (sanity_check(info, tty->name, "close"))
53670 return;
53671 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53672 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53673
53674 if (tty_port_close_start(&info->port, tty, filp) == 0)
53675 goto cleanup;
53676 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53677 tty_port_close_end(&info->port, tty);
53678 info->port.tty = NULL;
53679 cleanup:
53680 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53681 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53682 }
53683
53684 static void hangup(struct tty_struct *tty)
53685 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53686 shutdown(info);
53687
53688 spin_lock_irqsave(&info->port.lock, flags);
53689 - info->port.count = 0;
53690 + atomic_set(&info->port.count, 0);
53691 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53692 info->port.tty = NULL;
53693 spin_unlock_irqrestore(&info->port.lock, flags);
53694 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53695 unsigned short new_crctype;
53696
53697 /* return error if TTY interface open */
53698 - if (info->port.count)
53699 + if (atomic_read(&info->port.count))
53700 return -EBUSY;
53701
53702 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53703 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53704
53705 /* arbitrate between network and tty opens */
53706 spin_lock_irqsave(&info->netlock, flags);
53707 - if (info->port.count != 0 || info->netcount != 0) {
53708 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53709 DBGINFO(("%s hdlc_open busy\n", dev->name));
53710 spin_unlock_irqrestore(&info->netlock, flags);
53711 return -EBUSY;
53712 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53713 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53714
53715 /* return error if TTY interface open */
53716 - if (info->port.count)
53717 + if (atomic_read(&info->port.count))
53718 return -EBUSY;
53719
53720 if (cmd != SIOCWANDEV)
53721 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53722 if (port == NULL)
53723 continue;
53724 spin_lock(&port->lock);
53725 - if ((port->port.count || port->netcount) &&
53726 + if ((atomic_read(&port->port.count) || port->netcount) &&
53727 port->pending_bh && !port->bh_running &&
53728 !port->bh_requested) {
53729 DBGISR(("%s bh queued\n", port->device_name));
53730 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53731 add_wait_queue(&port->open_wait, &wait);
53732
53733 spin_lock_irqsave(&info->lock, flags);
53734 - port->count--;
53735 + atomic_dec(&port->count);
53736 spin_unlock_irqrestore(&info->lock, flags);
53737 port->blocked_open++;
53738
53739 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53740 remove_wait_queue(&port->open_wait, &wait);
53741
53742 if (!tty_hung_up_p(filp))
53743 - port->count++;
53744 + atomic_inc(&port->count);
53745 port->blocked_open--;
53746
53747 if (!retval)
53748 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53749 index c3f9091..abe4601 100644
53750 --- a/drivers/tty/synclinkmp.c
53751 +++ b/drivers/tty/synclinkmp.c
53752 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53753
53754 if (debug_level >= DEBUG_LEVEL_INFO)
53755 printk("%s(%d):%s open(), old ref count = %d\n",
53756 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53757 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53758
53759 /* If port is closing, signal caller to try again */
53760 if (info->port.flags & ASYNC_CLOSING){
53761 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53762 spin_unlock_irqrestore(&info->netlock, flags);
53763 goto cleanup;
53764 }
53765 - info->port.count++;
53766 + atomic_inc(&info->port.count);
53767 spin_unlock_irqrestore(&info->netlock, flags);
53768
53769 - if (info->port.count == 1) {
53770 + if (atomic_read(&info->port.count) == 1) {
53771 /* 1st open on this device, init hardware */
53772 retval = startup(info);
53773 if (retval < 0)
53774 @@ -796,8 +796,8 @@ cleanup:
53775 if (retval) {
53776 if (tty->count == 1)
53777 info->port.tty = NULL; /* tty layer will release tty struct */
53778 - if(info->port.count)
53779 - info->port.count--;
53780 + if(atomic_read(&info->port.count))
53781 + atomic_dec(&info->port.count);
53782 }
53783
53784 return retval;
53785 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53786
53787 if (debug_level >= DEBUG_LEVEL_INFO)
53788 printk("%s(%d):%s close() entry, count=%d\n",
53789 - __FILE__,__LINE__, info->device_name, info->port.count);
53790 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53791
53792 if (tty_port_close_start(&info->port, tty, filp) == 0)
53793 goto cleanup;
53794 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53795 cleanup:
53796 if (debug_level >= DEBUG_LEVEL_INFO)
53797 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53798 - tty->driver->name, info->port.count);
53799 + tty->driver->name, atomic_read(&info->port.count));
53800 }
53801
53802 /* Called by tty_hangup() when a hangup is signaled.
53803 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53804 shutdown(info);
53805
53806 spin_lock_irqsave(&info->port.lock, flags);
53807 - info->port.count = 0;
53808 + atomic_set(&info->port.count, 0);
53809 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53810 info->port.tty = NULL;
53811 spin_unlock_irqrestore(&info->port.lock, flags);
53812 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53813 unsigned short new_crctype;
53814
53815 /* return error if TTY interface open */
53816 - if (info->port.count)
53817 + if (atomic_read(&info->port.count))
53818 return -EBUSY;
53819
53820 switch (encoding)
53821 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53822
53823 /* arbitrate between network and tty opens */
53824 spin_lock_irqsave(&info->netlock, flags);
53825 - if (info->port.count != 0 || info->netcount != 0) {
53826 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53827 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53828 spin_unlock_irqrestore(&info->netlock, flags);
53829 return -EBUSY;
53830 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53831 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53832
53833 /* return error if TTY interface open */
53834 - if (info->port.count)
53835 + if (atomic_read(&info->port.count))
53836 return -EBUSY;
53837
53838 if (cmd != SIOCWANDEV)
53839 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53840 * do not request bottom half processing if the
53841 * device is not open in a normal mode.
53842 */
53843 - if ( port && (port->port.count || port->netcount) &&
53844 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53845 port->pending_bh && !port->bh_running &&
53846 !port->bh_requested ) {
53847 if ( debug_level >= DEBUG_LEVEL_ISR )
53848 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53849
53850 if (debug_level >= DEBUG_LEVEL_INFO)
53851 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53852 - __FILE__,__LINE__, tty->driver->name, port->count );
53853 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53854
53855 spin_lock_irqsave(&info->lock, flags);
53856 - port->count--;
53857 + atomic_dec(&port->count);
53858 spin_unlock_irqrestore(&info->lock, flags);
53859 port->blocked_open++;
53860
53861 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53862
53863 if (debug_level >= DEBUG_LEVEL_INFO)
53864 printk("%s(%d):%s block_til_ready() count=%d\n",
53865 - __FILE__,__LINE__, tty->driver->name, port->count );
53866 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53867
53868 tty_unlock(tty);
53869 schedule();
53870 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53871 set_current_state(TASK_RUNNING);
53872 remove_wait_queue(&port->open_wait, &wait);
53873 if (!tty_hung_up_p(filp))
53874 - port->count++;
53875 + atomic_inc(&port->count);
53876 port->blocked_open--;
53877
53878 if (debug_level >= DEBUG_LEVEL_INFO)
53879 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53880 - __FILE__,__LINE__, tty->driver->name, port->count );
53881 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53882
53883 if (!retval)
53884 port->flags |= ASYNC_NORMAL_ACTIVE;
53885 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53886 index 42bad18..447d7a2 100644
53887 --- a/drivers/tty/sysrq.c
53888 +++ b/drivers/tty/sysrq.c
53889 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53890 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53891 size_t count, loff_t *ppos)
53892 {
53893 - if (count) {
53894 + if (count && capable(CAP_SYS_ADMIN)) {
53895 char c;
53896
53897 if (get_user(c, buf))
53898 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53899 index 0508a1d..b610592 100644
53900 --- a/drivers/tty/tty_io.c
53901 +++ b/drivers/tty/tty_io.c
53902 @@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53903
53904 void tty_default_fops(struct file_operations *fops)
53905 {
53906 - *fops = tty_fops;
53907 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53908 }
53909
53910 /*
53911 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53912 index 2d822aa..a566234 100644
53913 --- a/drivers/tty/tty_ldisc.c
53914 +++ b/drivers/tty/tty_ldisc.c
53915 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53916 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53917 tty_ldiscs[disc] = new_ldisc;
53918 new_ldisc->num = disc;
53919 - new_ldisc->refcount = 0;
53920 + atomic_set(&new_ldisc->refcount, 0);
53921 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53922
53923 return ret;
53924 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53925 return -EINVAL;
53926
53927 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53928 - if (tty_ldiscs[disc]->refcount)
53929 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53930 ret = -EBUSY;
53931 else
53932 tty_ldiscs[disc] = NULL;
53933 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53934 if (ldops) {
53935 ret = ERR_PTR(-EAGAIN);
53936 if (try_module_get(ldops->owner)) {
53937 - ldops->refcount++;
53938 + atomic_inc(&ldops->refcount);
53939 ret = ldops;
53940 }
53941 }
53942 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53943 unsigned long flags;
53944
53945 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53946 - ldops->refcount--;
53947 + atomic_dec(&ldops->refcount);
53948 module_put(ldops->owner);
53949 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53950 }
53951 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53952 index 1b93357..ea9f82c 100644
53953 --- a/drivers/tty/tty_port.c
53954 +++ b/drivers/tty/tty_port.c
53955 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53956 unsigned long flags;
53957
53958 spin_lock_irqsave(&port->lock, flags);
53959 - port->count = 0;
53960 + atomic_set(&port->count, 0);
53961 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53962 tty = port->tty;
53963 if (tty)
53964 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53965
53966 /* The port lock protects the port counts */
53967 spin_lock_irqsave(&port->lock, flags);
53968 - port->count--;
53969 + atomic_dec(&port->count);
53970 port->blocked_open++;
53971 spin_unlock_irqrestore(&port->lock, flags);
53972
53973 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53974 we must not mess that up further */
53975 spin_lock_irqsave(&port->lock, flags);
53976 if (!tty_hung_up_p(filp))
53977 - port->count++;
53978 + atomic_inc(&port->count);
53979 port->blocked_open--;
53980 if (retval == 0)
53981 port->flags |= ASYNC_NORMAL_ACTIVE;
53982 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53983 return 0;
53984 }
53985
53986 - if (tty->count == 1 && port->count != 1) {
53987 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53988 printk(KERN_WARNING
53989 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53990 - port->count);
53991 - port->count = 1;
53992 + atomic_read(&port->count));
53993 + atomic_set(&port->count, 1);
53994 }
53995 - if (--port->count < 0) {
53996 + if (atomic_dec_return(&port->count) < 0) {
53997 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53998 - port->count);
53999 - port->count = 0;
54000 + atomic_read(&port->count));
54001 + atomic_set(&port->count, 0);
54002 }
54003
54004 - if (port->count) {
54005 + if (atomic_read(&port->count)) {
54006 spin_unlock_irqrestore(&port->lock, flags);
54007 return 0;
54008 }
54009 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54010 struct file *filp)
54011 {
54012 spin_lock_irq(&port->lock);
54013 - ++port->count;
54014 + atomic_inc(&port->count);
54015 spin_unlock_irq(&port->lock);
54016 tty_port_tty_set(port, tty);
54017
54018 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54019 index c039cfe..0b463b0 100644
54020 --- a/drivers/tty/vt/keyboard.c
54021 +++ b/drivers/tty/vt/keyboard.c
54022 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54023 kbd->kbdmode == VC_OFF) &&
54024 value != KVAL(K_SAK))
54025 return; /* SAK is allowed even in raw mode */
54026 +
54027 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54028 + {
54029 + void *func = fn_handler[value];
54030 + if (func == fn_show_state || func == fn_show_ptregs ||
54031 + func == fn_show_mem)
54032 + return;
54033 + }
54034 +#endif
54035 +
54036 fn_handler[value](vc);
54037 }
54038
54039 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54040 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54041 return -EFAULT;
54042
54043 - if (!capable(CAP_SYS_TTY_CONFIG))
54044 - perm = 0;
54045 -
54046 switch (cmd) {
54047 case KDGKBENT:
54048 /* Ensure another thread doesn't free it under us */
54049 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54050 spin_unlock_irqrestore(&kbd_event_lock, flags);
54051 return put_user(val, &user_kbe->kb_value);
54052 case KDSKBENT:
54053 + if (!capable(CAP_SYS_TTY_CONFIG))
54054 + perm = 0;
54055 +
54056 if (!perm)
54057 return -EPERM;
54058 if (!i && v == K_NOSUCHMAP) {
54059 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54060 int i, j, k;
54061 int ret;
54062
54063 - if (!capable(CAP_SYS_TTY_CONFIG))
54064 - perm = 0;
54065 -
54066 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54067 if (!kbs) {
54068 ret = -ENOMEM;
54069 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54070 kfree(kbs);
54071 return ((p && *p) ? -EOVERFLOW : 0);
54072 case KDSKBSENT:
54073 + if (!capable(CAP_SYS_TTY_CONFIG))
54074 + perm = 0;
54075 +
54076 if (!perm) {
54077 ret = -EPERM;
54078 goto reterr;
54079 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54080 index 60fa627..7214965 100644
54081 --- a/drivers/uio/uio.c
54082 +++ b/drivers/uio/uio.c
54083 @@ -25,6 +25,7 @@
54084 #include <linux/kobject.h>
54085 #include <linux/cdev.h>
54086 #include <linux/uio_driver.h>
54087 +#include <asm/local.h>
54088
54089 #define UIO_MAX_DEVICES (1U << MINORBITS)
54090
54091 @@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
54092 struct device_attribute *attr, char *buf)
54093 {
54094 struct uio_device *idev = dev_get_drvdata(dev);
54095 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54096 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54097 }
54098 static DEVICE_ATTR_RO(event);
54099
54100 @@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
54101 {
54102 struct uio_device *idev = info->uio_dev;
54103
54104 - atomic_inc(&idev->event);
54105 + atomic_inc_unchecked(&idev->event);
54106 wake_up_interruptible(&idev->wait);
54107 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54108 }
54109 @@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54110 }
54111
54112 listener->dev = idev;
54113 - listener->event_count = atomic_read(&idev->event);
54114 + listener->event_count = atomic_read_unchecked(&idev->event);
54115 filep->private_data = listener;
54116
54117 if (idev->info->open) {
54118 @@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54119 return -EIO;
54120
54121 poll_wait(filep, &idev->wait, wait);
54122 - if (listener->event_count != atomic_read(&idev->event))
54123 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54124 return POLLIN | POLLRDNORM;
54125 return 0;
54126 }
54127 @@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54128 do {
54129 set_current_state(TASK_INTERRUPTIBLE);
54130
54131 - event_count = atomic_read(&idev->event);
54132 + event_count = atomic_read_unchecked(&idev->event);
54133 if (event_count != listener->event_count) {
54134 if (copy_to_user(buf, &event_count, count))
54135 retval = -EFAULT;
54136 @@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54137 static int uio_find_mem_index(struct vm_area_struct *vma)
54138 {
54139 struct uio_device *idev = vma->vm_private_data;
54140 + unsigned long size;
54141
54142 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54143 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54144 + size = idev->info->mem[vma->vm_pgoff].size;
54145 + if (size == 0)
54146 + return -1;
54147 + if (vma->vm_end - vma->vm_start > size)
54148 return -1;
54149 return (int)vma->vm_pgoff;
54150 }
54151 @@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
54152 idev->owner = owner;
54153 idev->info = info;
54154 init_waitqueue_head(&idev->wait);
54155 - atomic_set(&idev->event, 0);
54156 + atomic_set_unchecked(&idev->event, 0);
54157
54158 ret = uio_get_minor(idev);
54159 if (ret)
54160 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54161 index 813d4d3..a71934f 100644
54162 --- a/drivers/usb/atm/cxacru.c
54163 +++ b/drivers/usb/atm/cxacru.c
54164 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54165 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54166 if (ret < 2)
54167 return -EINVAL;
54168 - if (index < 0 || index > 0x7f)
54169 + if (index > 0x7f)
54170 return -EINVAL;
54171 pos += tmp;
54172
54173 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54174 index dada014..1d0d517 100644
54175 --- a/drivers/usb/atm/usbatm.c
54176 +++ b/drivers/usb/atm/usbatm.c
54177 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54178 if (printk_ratelimit())
54179 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54180 __func__, vpi, vci);
54181 - atomic_inc(&vcc->stats->rx_err);
54182 + atomic_inc_unchecked(&vcc->stats->rx_err);
54183 return;
54184 }
54185
54186 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54187 if (length > ATM_MAX_AAL5_PDU) {
54188 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54189 __func__, length, vcc);
54190 - atomic_inc(&vcc->stats->rx_err);
54191 + atomic_inc_unchecked(&vcc->stats->rx_err);
54192 goto out;
54193 }
54194
54195 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54196 if (sarb->len < pdu_length) {
54197 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54198 __func__, pdu_length, sarb->len, vcc);
54199 - atomic_inc(&vcc->stats->rx_err);
54200 + atomic_inc_unchecked(&vcc->stats->rx_err);
54201 goto out;
54202 }
54203
54204 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54205 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54206 __func__, vcc);
54207 - atomic_inc(&vcc->stats->rx_err);
54208 + atomic_inc_unchecked(&vcc->stats->rx_err);
54209 goto out;
54210 }
54211
54212 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54213 if (printk_ratelimit())
54214 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54215 __func__, length);
54216 - atomic_inc(&vcc->stats->rx_drop);
54217 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54218 goto out;
54219 }
54220
54221 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54222
54223 vcc->push(vcc, skb);
54224
54225 - atomic_inc(&vcc->stats->rx);
54226 + atomic_inc_unchecked(&vcc->stats->rx);
54227 out:
54228 skb_trim(sarb, 0);
54229 }
54230 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54231 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54232
54233 usbatm_pop(vcc, skb);
54234 - atomic_inc(&vcc->stats->tx);
54235 + atomic_inc_unchecked(&vcc->stats->tx);
54236
54237 skb = skb_dequeue(&instance->sndqueue);
54238 }
54239 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54240 if (!left--)
54241 return sprintf(page,
54242 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54243 - atomic_read(&atm_dev->stats.aal5.tx),
54244 - atomic_read(&atm_dev->stats.aal5.tx_err),
54245 - atomic_read(&atm_dev->stats.aal5.rx),
54246 - atomic_read(&atm_dev->stats.aal5.rx_err),
54247 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54248 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54249 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54250 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54251 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54252 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54253
54254 if (!left--) {
54255 if (instance->disconnected)
54256 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54257 index 2a3bbdf..91d72cf 100644
54258 --- a/drivers/usb/core/devices.c
54259 +++ b/drivers/usb/core/devices.c
54260 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54261 * time it gets called.
54262 */
54263 static struct device_connect_event {
54264 - atomic_t count;
54265 + atomic_unchecked_t count;
54266 wait_queue_head_t wait;
54267 } device_event = {
54268 .count = ATOMIC_INIT(1),
54269 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54270
54271 void usbfs_conn_disc_event(void)
54272 {
54273 - atomic_add(2, &device_event.count);
54274 + atomic_add_unchecked(2, &device_event.count);
54275 wake_up(&device_event.wait);
54276 }
54277
54278 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54279
54280 poll_wait(file, &device_event.wait, wait);
54281
54282 - event_count = atomic_read(&device_event.count);
54283 + event_count = atomic_read_unchecked(&device_event.count);
54284 if (file->f_version != event_count) {
54285 file->f_version = event_count;
54286 return POLLIN | POLLRDNORM;
54287 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54288 index 0b59731..46ee7d1 100644
54289 --- a/drivers/usb/core/devio.c
54290 +++ b/drivers/usb/core/devio.c
54291 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54292 struct usb_dev_state *ps = file->private_data;
54293 struct usb_device *dev = ps->dev;
54294 ssize_t ret = 0;
54295 - unsigned len;
54296 + size_t len;
54297 loff_t pos;
54298 int i;
54299
54300 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54301 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54302 struct usb_config_descriptor *config =
54303 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54304 - unsigned int length = le16_to_cpu(config->wTotalLength);
54305 + size_t length = le16_to_cpu(config->wTotalLength);
54306
54307 if (*ppos < pos + length) {
54308
54309 /* The descriptor may claim to be longer than it
54310 * really is. Here is the actual allocated length. */
54311 - unsigned alloclen =
54312 + size_t alloclen =
54313 le16_to_cpu(dev->config[i].desc.wTotalLength);
54314
54315 - len = length - (*ppos - pos);
54316 + len = length + pos - *ppos;
54317 if (len > nbytes)
54318 len = nbytes;
54319
54320 /* Simply don't write (skip over) unallocated parts */
54321 if (alloclen > (*ppos - pos)) {
54322 - alloclen -= (*ppos - pos);
54323 + alloclen = alloclen + pos - *ppos;
54324 if (copy_to_user(buf,
54325 dev->rawdescriptors[i] + (*ppos - pos),
54326 min(len, alloclen))) {
54327 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54328 index a6efb41..6f72549b 100644
54329 --- a/drivers/usb/core/hcd.c
54330 +++ b/drivers/usb/core/hcd.c
54331 @@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54332 */
54333 usb_get_urb(urb);
54334 atomic_inc(&urb->use_count);
54335 - atomic_inc(&urb->dev->urbnum);
54336 + atomic_inc_unchecked(&urb->dev->urbnum);
54337 usbmon_urb_submit(&hcd->self, urb);
54338
54339 /* NOTE requirements on root-hub callers (usbfs and the hub
54340 @@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54341 urb->hcpriv = NULL;
54342 INIT_LIST_HEAD(&urb->urb_list);
54343 atomic_dec(&urb->use_count);
54344 - atomic_dec(&urb->dev->urbnum);
54345 + atomic_dec_unchecked(&urb->dev->urbnum);
54346 if (atomic_read(&urb->reject))
54347 wake_up(&usb_kill_urb_queue);
54348 usb_put_urb(urb);
54349 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54350 index b649fef..c7107a0 100644
54351 --- a/drivers/usb/core/hub.c
54352 +++ b/drivers/usb/core/hub.c
54353 @@ -26,6 +26,7 @@
54354 #include <linux/mutex.h>
54355 #include <linux/random.h>
54356 #include <linux/pm_qos.h>
54357 +#include <linux/grsecurity.h>
54358
54359 #include <asm/uaccess.h>
54360 #include <asm/byteorder.h>
54361 @@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54362 goto done;
54363 return;
54364 }
54365 +
54366 + if (gr_handle_new_usb())
54367 + goto done;
54368 +
54369 if (hub_is_superspeed(hub->hdev))
54370 unit_load = 150;
54371 else
54372 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54373 index f7b7713..23d07ec 100644
54374 --- a/drivers/usb/core/message.c
54375 +++ b/drivers/usb/core/message.c
54376 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54377 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54378 * error number.
54379 */
54380 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54381 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54382 __u8 requesttype, __u16 value, __u16 index, void *data,
54383 __u16 size, int timeout)
54384 {
54385 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54386 * If successful, 0. Otherwise a negative error number. The number of actual
54387 * bytes transferred will be stored in the @actual_length parameter.
54388 */
54389 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54390 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54391 void *data, int len, int *actual_length, int timeout)
54392 {
54393 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54394 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54395 * bytes transferred will be stored in the @actual_length parameter.
54396 *
54397 */
54398 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54399 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54400 void *data, int len, int *actual_length, int timeout)
54401 {
54402 struct urb *urb;
54403 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54404 index 1236c60..d47a51c 100644
54405 --- a/drivers/usb/core/sysfs.c
54406 +++ b/drivers/usb/core/sysfs.c
54407 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54408 struct usb_device *udev;
54409
54410 udev = to_usb_device(dev);
54411 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54412 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54413 }
54414 static DEVICE_ATTR_RO(urbnum);
54415
54416 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54417 index 2dd2362..1135437 100644
54418 --- a/drivers/usb/core/usb.c
54419 +++ b/drivers/usb/core/usb.c
54420 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54421 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54422 dev->state = USB_STATE_ATTACHED;
54423 dev->lpm_disable_count = 1;
54424 - atomic_set(&dev->urbnum, 0);
54425 + atomic_set_unchecked(&dev->urbnum, 0);
54426
54427 INIT_LIST_HEAD(&dev->ep0.urb_list);
54428 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54429 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54430 index 8cfc319..4868255 100644
54431 --- a/drivers/usb/early/ehci-dbgp.c
54432 +++ b/drivers/usb/early/ehci-dbgp.c
54433 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54434
54435 #ifdef CONFIG_KGDB
54436 static struct kgdb_io kgdbdbgp_io_ops;
54437 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54438 +static struct kgdb_io kgdbdbgp_io_ops_console;
54439 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54440 #else
54441 #define dbgp_kgdb_mode (0)
54442 #endif
54443 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54444 .write_char = kgdbdbgp_write_char,
54445 };
54446
54447 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54448 + .name = "kgdbdbgp",
54449 + .read_char = kgdbdbgp_read_char,
54450 + .write_char = kgdbdbgp_write_char,
54451 + .is_console = 1
54452 +};
54453 +
54454 static int kgdbdbgp_wait_time;
54455
54456 static int __init kgdbdbgp_parse_config(char *str)
54457 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54458 ptr++;
54459 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54460 }
54461 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54462 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54463 + if (early_dbgp_console.index != -1)
54464 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54465 + else
54466 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54467
54468 return 0;
54469 }
54470 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54471 index f7b2032..fbb340c 100644
54472 --- a/drivers/usb/gadget/function/f_uac1.c
54473 +++ b/drivers/usb/gadget/function/f_uac1.c
54474 @@ -14,6 +14,7 @@
54475 #include <linux/module.h>
54476 #include <linux/device.h>
54477 #include <linux/atomic.h>
54478 +#include <linux/module.h>
54479
54480 #include "u_uac1.h"
54481
54482 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54483 index 491082a..dfd7d17 100644
54484 --- a/drivers/usb/gadget/function/u_serial.c
54485 +++ b/drivers/usb/gadget/function/u_serial.c
54486 @@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54487 spin_lock_irq(&port->port_lock);
54488
54489 /* already open? Great. */
54490 - if (port->port.count) {
54491 + if (atomic_read(&port->port.count)) {
54492 status = 0;
54493 - port->port.count++;
54494 + atomic_inc(&port->port.count);
54495
54496 /* currently opening/closing? wait ... */
54497 } else if (port->openclose) {
54498 @@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54499 tty->driver_data = port;
54500 port->port.tty = tty;
54501
54502 - port->port.count = 1;
54503 + atomic_set(&port->port.count, 1);
54504 port->openclose = false;
54505
54506 /* if connected, start the I/O stream */
54507 @@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54508
54509 spin_lock_irq(&port->port_lock);
54510
54511 - if (port->port.count != 1) {
54512 - if (port->port.count == 0)
54513 + if (atomic_read(&port->port.count) != 1) {
54514 + if (atomic_read(&port->port.count) == 0)
54515 WARN_ON(1);
54516 else
54517 - --port->port.count;
54518 + atomic_dec(&port->port.count);
54519 goto exit;
54520 }
54521
54522 @@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54523 * and sleep if necessary
54524 */
54525 port->openclose = true;
54526 - port->port.count = 0;
54527 + atomic_set(&port->port.count, 0);
54528
54529 gser = port->port_usb;
54530 if (gser && gser->disconnect)
54531 @@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54532 int cond;
54533
54534 spin_lock_irq(&port->port_lock);
54535 - cond = (port->port.count == 0) && !port->openclose;
54536 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54537 spin_unlock_irq(&port->port_lock);
54538 return cond;
54539 }
54540 @@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54541 /* if it's already open, start I/O ... and notify the serial
54542 * protocol about open/close status (connect/disconnect).
54543 */
54544 - if (port->port.count) {
54545 + if (atomic_read(&port->port.count)) {
54546 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54547 gs_start_io(port);
54548 if (gser->connect)
54549 @@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54550
54551 port->port_usb = NULL;
54552 gser->ioport = NULL;
54553 - if (port->port.count > 0 || port->openclose) {
54554 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54555 wake_up_interruptible(&port->drain_wait);
54556 if (port->port.tty)
54557 tty_hangup(port->port.tty);
54558 @@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54559
54560 /* finally, free any unused/unusable I/O buffers */
54561 spin_lock_irqsave(&port->port_lock, flags);
54562 - if (port->port.count == 0 && !port->openclose)
54563 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54564 gs_buf_free(&port->port_write_buf);
54565 gs_free_requests(gser->out, &port->read_pool, NULL);
54566 gs_free_requests(gser->out, &port->read_queue, NULL);
54567 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54568 index a44a07f..ecea924 100644
54569 --- a/drivers/usb/gadget/function/u_uac1.c
54570 +++ b/drivers/usb/gadget/function/u_uac1.c
54571 @@ -17,6 +17,7 @@
54572 #include <linux/ctype.h>
54573 #include <linux/random.h>
54574 #include <linux/syscalls.h>
54575 +#include <linux/module.h>
54576
54577 #include "u_uac1.h"
54578
54579 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54580 index 5728829..fefc6bf 100644
54581 --- a/drivers/usb/host/ehci-hub.c
54582 +++ b/drivers/usb/host/ehci-hub.c
54583 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54584 urb->transfer_flags = URB_DIR_IN;
54585 usb_get_urb(urb);
54586 atomic_inc(&urb->use_count);
54587 - atomic_inc(&urb->dev->urbnum);
54588 + atomic_inc_unchecked(&urb->dev->urbnum);
54589 urb->setup_dma = dma_map_single(
54590 hcd->self.controller,
54591 urb->setup_packet,
54592 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54593 urb->status = -EINPROGRESS;
54594 usb_get_urb(urb);
54595 atomic_inc(&urb->use_count);
54596 - atomic_inc(&urb->dev->urbnum);
54597 + atomic_inc_unchecked(&urb->dev->urbnum);
54598 retval = submit_single_step_set_feature(hcd, urb, 0);
54599 if (!retval && !wait_for_completion_timeout(&done,
54600 msecs_to_jiffies(2000))) {
54601 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54602 index 1db0626..4948782 100644
54603 --- a/drivers/usb/host/hwa-hc.c
54604 +++ b/drivers/usb/host/hwa-hc.c
54605 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54606 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54607 struct wahc *wa = &hwahc->wa;
54608 struct device *dev = &wa->usb_iface->dev;
54609 - u8 mas_le[UWB_NUM_MAS/8];
54610 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54611 +
54612 + if (mas_le == NULL)
54613 + return -ENOMEM;
54614
54615 /* Set the stream index */
54616 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54617 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54618 WUSB_REQ_SET_WUSB_MAS,
54619 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54620 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54621 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54622 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54623 if (result < 0)
54624 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54625 out:
54626 + kfree(mas_le);
54627 +
54628 return result;
54629 }
54630
54631 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54632 index b3d245e..99549ed 100644
54633 --- a/drivers/usb/misc/appledisplay.c
54634 +++ b/drivers/usb/misc/appledisplay.c
54635 @@ -84,7 +84,7 @@ struct appledisplay {
54636 struct mutex sysfslock; /* concurrent read and write */
54637 };
54638
54639 -static atomic_t count_displays = ATOMIC_INIT(0);
54640 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54641 static struct workqueue_struct *wq;
54642
54643 static void appledisplay_complete(struct urb *urb)
54644 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54645
54646 /* Register backlight device */
54647 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54648 - atomic_inc_return(&count_displays) - 1);
54649 + atomic_inc_return_unchecked(&count_displays) - 1);
54650 memset(&props, 0, sizeof(struct backlight_properties));
54651 props.type = BACKLIGHT_RAW;
54652 props.max_brightness = 0xff;
54653 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54654 index 29fa1c3..a57b08e 100644
54655 --- a/drivers/usb/serial/console.c
54656 +++ b/drivers/usb/serial/console.c
54657 @@ -125,7 +125,7 @@ static int usb_console_setup(struct console *co, char *options)
54658
54659 info->port = port;
54660
54661 - ++port->port.count;
54662 + atomic_inc(&port->port.count);
54663 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54664 if (serial->type->set_termios) {
54665 /*
54666 @@ -173,7 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
54667 }
54668 /* Now that any required fake tty operations are completed restore
54669 * the tty port count */
54670 - --port->port.count;
54671 + atomic_dec(&port->port.count);
54672 /* The console is special in terms of closing the device so
54673 * indicate this port is now acting as a system console. */
54674 port->port.console = 1;
54675 @@ -186,7 +186,7 @@ static int usb_console_setup(struct console *co, char *options)
54676 put_tty:
54677 tty_kref_put(tty);
54678 reset_open_count:
54679 - port->port.count = 0;
54680 + atomic_set(&port->port.count, 0);
54681 usb_autopm_put_interface(serial->interface);
54682 error_get_interface:
54683 usb_serial_put(serial);
54684 @@ -197,7 +197,7 @@ static int usb_console_setup(struct console *co, char *options)
54685 static void usb_console_write(struct console *co,
54686 const char *buf, unsigned count)
54687 {
54688 - static struct usbcons_info *info = &usbcons_info;
54689 + struct usbcons_info *info = &usbcons_info;
54690 struct usb_serial_port *port = info->port;
54691 struct usb_serial *serial;
54692 int retval = -ENODEV;
54693 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54694 index 307e339..6aa97cb 100644
54695 --- a/drivers/usb/storage/usb.h
54696 +++ b/drivers/usb/storage/usb.h
54697 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54698 __u8 useProtocol;
54699 __u8 useTransport;
54700 int (*initFunction)(struct us_data *);
54701 -};
54702 +} __do_const;
54703
54704
54705 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54706 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54707 index a863a98..d272795 100644
54708 --- a/drivers/usb/usbip/vhci.h
54709 +++ b/drivers/usb/usbip/vhci.h
54710 @@ -83,7 +83,7 @@ struct vhci_hcd {
54711 unsigned resuming:1;
54712 unsigned long re_timeout;
54713
54714 - atomic_t seqnum;
54715 + atomic_unchecked_t seqnum;
54716
54717 /*
54718 * NOTE:
54719 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54720 index c02374b..32d47a9 100644
54721 --- a/drivers/usb/usbip/vhci_hcd.c
54722 +++ b/drivers/usb/usbip/vhci_hcd.c
54723 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54724
54725 spin_lock(&vdev->priv_lock);
54726
54727 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54728 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54729 if (priv->seqnum == 0xffff)
54730 dev_info(&urb->dev->dev, "seqnum max\n");
54731
54732 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54733 return -ENOMEM;
54734 }
54735
54736 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54737 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54738 if (unlink->seqnum == 0xffff)
54739 pr_info("seqnum max\n");
54740
54741 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54742 vdev->rhport = rhport;
54743 }
54744
54745 - atomic_set(&vhci->seqnum, 0);
54746 + atomic_set_unchecked(&vhci->seqnum, 0);
54747 spin_lock_init(&vhci->lock);
54748
54749 hcd->power_budget = 0; /* no limit */
54750 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54751 index 00e4a54..d676f85 100644
54752 --- a/drivers/usb/usbip/vhci_rx.c
54753 +++ b/drivers/usb/usbip/vhci_rx.c
54754 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54755 if (!urb) {
54756 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54757 pr_info("max seqnum %d\n",
54758 - atomic_read(&the_controller->seqnum));
54759 + atomic_read_unchecked(&the_controller->seqnum));
54760 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54761 return;
54762 }
54763 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54764 index edc7267..9f65ce2 100644
54765 --- a/drivers/usb/wusbcore/wa-hc.h
54766 +++ b/drivers/usb/wusbcore/wa-hc.h
54767 @@ -240,7 +240,7 @@ struct wahc {
54768 spinlock_t xfer_list_lock;
54769 struct work_struct xfer_enqueue_work;
54770 struct work_struct xfer_error_work;
54771 - atomic_t xfer_id_count;
54772 + atomic_unchecked_t xfer_id_count;
54773
54774 kernel_ulong_t quirks;
54775 };
54776 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54777 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54778 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54779 wa->dto_in_use = 0;
54780 - atomic_set(&wa->xfer_id_count, 1);
54781 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54782 /* init the buf in URBs */
54783 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54784 usb_init_urb(&(wa->buf_in_urbs[index]));
54785 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54786 index 69af4fd..da390d7 100644
54787 --- a/drivers/usb/wusbcore/wa-xfer.c
54788 +++ b/drivers/usb/wusbcore/wa-xfer.c
54789 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54790 */
54791 static void wa_xfer_id_init(struct wa_xfer *xfer)
54792 {
54793 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54794 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54795 }
54796
54797 /* Return the xfer's ID. */
54798 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54799 index f018d8d..ccab63f 100644
54800 --- a/drivers/vfio/vfio.c
54801 +++ b/drivers/vfio/vfio.c
54802 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54803 return 0;
54804
54805 /* TODO Prevent device auto probing */
54806 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54807 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54808 iommu_group_id(group->iommu_group));
54809
54810 return 0;
54811 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54812 index 5174eba..451e6bc 100644
54813 --- a/drivers/vhost/vringh.c
54814 +++ b/drivers/vhost/vringh.c
54815 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54816 /* Userspace access helpers: in this case, addresses are really userspace. */
54817 static inline int getu16_user(u16 *val, const u16 *p)
54818 {
54819 - return get_user(*val, (__force u16 __user *)p);
54820 + return get_user(*val, (u16 __force_user *)p);
54821 }
54822
54823 static inline int putu16_user(u16 *p, u16 val)
54824 {
54825 - return put_user(val, (__force u16 __user *)p);
54826 + return put_user(val, (u16 __force_user *)p);
54827 }
54828
54829 static inline int copydesc_user(void *dst, const void *src, size_t len)
54830 {
54831 - return copy_from_user(dst, (__force void __user *)src, len) ?
54832 + return copy_from_user(dst, (void __force_user *)src, len) ?
54833 -EFAULT : 0;
54834 }
54835
54836 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54837 const struct vring_used_elem *src,
54838 unsigned int num)
54839 {
54840 - return copy_to_user((__force void __user *)dst, src,
54841 + return copy_to_user((void __force_user *)dst, src,
54842 sizeof(*dst) * num) ? -EFAULT : 0;
54843 }
54844
54845 static inline int xfer_from_user(void *src, void *dst, size_t len)
54846 {
54847 - return copy_from_user(dst, (__force void __user *)src, len) ?
54848 + return copy_from_user(dst, (void __force_user *)src, len) ?
54849 -EFAULT : 0;
54850 }
54851
54852 static inline int xfer_to_user(void *dst, void *src, size_t len)
54853 {
54854 - return copy_to_user((__force void __user *)dst, src, len) ?
54855 + return copy_to_user((void __force_user *)dst, src, len) ?
54856 -EFAULT : 0;
54857 }
54858
54859 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54860 vrh->last_used_idx = 0;
54861 vrh->vring.num = num;
54862 /* vring expects kernel addresses, but only used via accessors. */
54863 - vrh->vring.desc = (__force struct vring_desc *)desc;
54864 - vrh->vring.avail = (__force struct vring_avail *)avail;
54865 - vrh->vring.used = (__force struct vring_used *)used;
54866 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54867 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54868 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54869 return 0;
54870 }
54871 EXPORT_SYMBOL(vringh_init_user);
54872 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54873
54874 static inline int putu16_kern(u16 *p, u16 val)
54875 {
54876 - ACCESS_ONCE(*p) = val;
54877 + ACCESS_ONCE_RW(*p) = val;
54878 return 0;
54879 }
54880
54881 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54882 index 84a110a..96312c3 100644
54883 --- a/drivers/video/backlight/kb3886_bl.c
54884 +++ b/drivers/video/backlight/kb3886_bl.c
54885 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54886 static unsigned long kb3886bl_flags;
54887 #define KB3886BL_SUSPENDED 0x01
54888
54889 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54890 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54891 {
54892 .ident = "Sahara Touch-iT",
54893 .matches = {
54894 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54895 index 1b0b233..6f34c2c 100644
54896 --- a/drivers/video/fbdev/arcfb.c
54897 +++ b/drivers/video/fbdev/arcfb.c
54898 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54899 return -ENOSPC;
54900
54901 err = 0;
54902 - if ((count + p) > fbmemlength) {
54903 + if (count > (fbmemlength - p)) {
54904 count = fbmemlength - p;
54905 err = -ENOSPC;
54906 }
54907 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54908 index aedf2fb..47c9aca 100644
54909 --- a/drivers/video/fbdev/aty/aty128fb.c
54910 +++ b/drivers/video/fbdev/aty/aty128fb.c
54911 @@ -149,7 +149,7 @@ enum {
54912 };
54913
54914 /* Must match above enum */
54915 -static char * const r128_family[] = {
54916 +static const char * const r128_family[] = {
54917 "AGP",
54918 "PCI",
54919 "PRO AGP",
54920 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54921 index 37ec09b..98f8862 100644
54922 --- a/drivers/video/fbdev/aty/atyfb_base.c
54923 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54924 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54925 par->accel_flags = var->accel_flags; /* hack */
54926
54927 if (var->accel_flags) {
54928 - info->fbops->fb_sync = atyfb_sync;
54929 + pax_open_kernel();
54930 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54931 + pax_close_kernel();
54932 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54933 } else {
54934 - info->fbops->fb_sync = NULL;
54935 + pax_open_kernel();
54936 + *(void **)&info->fbops->fb_sync = NULL;
54937 + pax_close_kernel();
54938 info->flags |= FBINFO_HWACCEL_DISABLED;
54939 }
54940
54941 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54942 index 2fa0317..4983f2a 100644
54943 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54944 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54945 @@ -8,6 +8,7 @@
54946 #include "../core/fb_draw.h"
54947
54948 #include <asm/io.h>
54949 +#include <asm/pgtable.h>
54950
54951 #ifdef __sparc__
54952 #include <asm/fbio.h>
54953 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54954 info->sprite.buf_align = 16; /* and 64 lines tall. */
54955 info->sprite.flags = FB_PIXMAP_IO;
54956
54957 - info->fbops->fb_cursor = atyfb_cursor;
54958 + pax_open_kernel();
54959 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54960 + pax_close_kernel();
54961
54962 return 0;
54963 }
54964 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54965 index d6cab1f..112f680 100644
54966 --- a/drivers/video/fbdev/core/fb_defio.c
54967 +++ b/drivers/video/fbdev/core/fb_defio.c
54968 @@ -207,7 +207,9 @@ void fb_deferred_io_init(struct fb_info *info)
54969
54970 BUG_ON(!fbdefio);
54971 mutex_init(&fbdefio->lock);
54972 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54973 + pax_open_kernel();
54974 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54975 + pax_close_kernel();
54976 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54977 INIT_LIST_HEAD(&fbdefio->pagelist);
54978 if (fbdefio->delay == 0) /* set a default of 1 s */
54979 @@ -238,7 +240,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54980 page->mapping = NULL;
54981 }
54982
54983 - info->fbops->fb_mmap = NULL;
54984 + *(void **)&info->fbops->fb_mmap = NULL;
54985 mutex_destroy(&fbdefio->lock);
54986 }
54987 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54988 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54989 index 0705d88..d9429bf 100644
54990 --- a/drivers/video/fbdev/core/fbmem.c
54991 +++ b/drivers/video/fbdev/core/fbmem.c
54992 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54993 __u32 data;
54994 int err;
54995
54996 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54997 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54998
54999 data = (__u32) (unsigned long) fix->smem_start;
55000 err |= put_user(data, &fix32->smem_start);
55001 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55002 index 4254336..282567e 100644
55003 --- a/drivers/video/fbdev/hyperv_fb.c
55004 +++ b/drivers/video/fbdev/hyperv_fb.c
55005 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55006 static inline int synthvid_send(struct hv_device *hdev,
55007 struct synthvid_msg *msg)
55008 {
55009 - static atomic64_t request_id = ATOMIC64_INIT(0);
55010 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55011 int ret;
55012
55013 msg->pipe_hdr.type = PIPE_MSG_DATA;
55014 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55015
55016 ret = vmbus_sendpacket(hdev->channel, msg,
55017 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55018 - atomic64_inc_return(&request_id),
55019 + atomic64_inc_return_unchecked(&request_id),
55020 VM_PKT_DATA_INBAND, 0);
55021
55022 if (ret)
55023 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55024 index 7672d2e..b56437f 100644
55025 --- a/drivers/video/fbdev/i810/i810_accel.c
55026 +++ b/drivers/video/fbdev/i810/i810_accel.c
55027 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55028 }
55029 }
55030 printk("ringbuffer lockup!!!\n");
55031 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55032 i810_report_error(mmio);
55033 par->dev_flags |= LOCKUP;
55034 info->pixmap.scan_align = 1;
55035 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55036 index a01147f..5d896f8 100644
55037 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55038 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55039 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55040
55041 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55042 struct matrox_switch matrox_mystique = {
55043 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55044 + .preinit = MGA1064_preinit,
55045 + .reset = MGA1064_reset,
55046 + .init = MGA1064_init,
55047 + .restore = MGA1064_restore,
55048 };
55049 EXPORT_SYMBOL(matrox_mystique);
55050 #endif
55051
55052 #ifdef CONFIG_FB_MATROX_G
55053 struct matrox_switch matrox_G100 = {
55054 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55055 + .preinit = MGAG100_preinit,
55056 + .reset = MGAG100_reset,
55057 + .init = MGAG100_init,
55058 + .restore = MGAG100_restore,
55059 };
55060 EXPORT_SYMBOL(matrox_G100);
55061 #endif
55062 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55063 index 195ad7c..09743fc 100644
55064 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55065 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55066 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55067 }
55068
55069 struct matrox_switch matrox_millennium = {
55070 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55071 + .preinit = Ti3026_preinit,
55072 + .reset = Ti3026_reset,
55073 + .init = Ti3026_init,
55074 + .restore = Ti3026_restore
55075 };
55076 EXPORT_SYMBOL(matrox_millennium);
55077 #endif
55078 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55079 index fe92eed..106e085 100644
55080 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55081 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55082 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55083 struct mb862xxfb_par *par = info->par;
55084
55085 if (info->var.bits_per_pixel == 32) {
55086 - info->fbops->fb_fillrect = cfb_fillrect;
55087 - info->fbops->fb_copyarea = cfb_copyarea;
55088 - info->fbops->fb_imageblit = cfb_imageblit;
55089 + pax_open_kernel();
55090 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55091 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55092 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55093 + pax_close_kernel();
55094 } else {
55095 outreg(disp, GC_L0EM, 3);
55096 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55097 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55098 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55099 + pax_open_kernel();
55100 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55101 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55102 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55103 + pax_close_kernel();
55104 }
55105 outreg(draw, GDC_REG_DRAW_BASE, 0);
55106 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55107 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55108 index def0412..fed6529 100644
55109 --- a/drivers/video/fbdev/nvidia/nvidia.c
55110 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55111 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55112 info->fix.line_length = (info->var.xres_virtual *
55113 info->var.bits_per_pixel) >> 3;
55114 if (info->var.accel_flags) {
55115 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55116 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55117 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55118 - info->fbops->fb_sync = nvidiafb_sync;
55119 + pax_open_kernel();
55120 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55121 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55122 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55123 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55124 + pax_close_kernel();
55125 info->pixmap.scan_align = 4;
55126 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55127 info->flags |= FBINFO_READS_FAST;
55128 NVResetGraphics(info);
55129 } else {
55130 - info->fbops->fb_imageblit = cfb_imageblit;
55131 - info->fbops->fb_fillrect = cfb_fillrect;
55132 - info->fbops->fb_copyarea = cfb_copyarea;
55133 - info->fbops->fb_sync = NULL;
55134 + pax_open_kernel();
55135 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55136 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55137 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55138 + *(void **)&info->fbops->fb_sync = NULL;
55139 + pax_close_kernel();
55140 info->pixmap.scan_align = 1;
55141 info->flags |= FBINFO_HWACCEL_DISABLED;
55142 info->flags &= ~FBINFO_READS_FAST;
55143 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55144 info->pixmap.size = 8 * 1024;
55145 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55146
55147 - if (!hwcur)
55148 - info->fbops->fb_cursor = NULL;
55149 + if (!hwcur) {
55150 + pax_open_kernel();
55151 + *(void **)&info->fbops->fb_cursor = NULL;
55152 + pax_close_kernel();
55153 + }
55154
55155 info->var.accel_flags = (!noaccel);
55156
55157 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55158 index 2412a0d..294215b 100644
55159 --- a/drivers/video/fbdev/omap2/dss/display.c
55160 +++ b/drivers/video/fbdev/omap2/dss/display.c
55161 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55162 if (dssdev->name == NULL)
55163 dssdev->name = dssdev->alias;
55164
55165 + pax_open_kernel();
55166 if (drv && drv->get_resolution == NULL)
55167 - drv->get_resolution = omapdss_default_get_resolution;
55168 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55169 if (drv && drv->get_recommended_bpp == NULL)
55170 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55171 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55172 if (drv && drv->get_timings == NULL)
55173 - drv->get_timings = omapdss_default_get_timings;
55174 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55175 + pax_close_kernel();
55176
55177 mutex_lock(&panel_list_mutex);
55178 list_add_tail(&dssdev->panel_list, &panel_list);
55179 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55180 index 83433cb..71e9b98 100644
55181 --- a/drivers/video/fbdev/s1d13xxxfb.c
55182 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55183 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55184
55185 switch(prod_id) {
55186 case S1D13506_PROD_ID: /* activate acceleration */
55187 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55188 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55189 + pax_open_kernel();
55190 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55191 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55192 + pax_close_kernel();
55193 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55194 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55195 break;
55196 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55197 index 2bcc84a..29dd1ea 100644
55198 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55199 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55200 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55201 }
55202
55203 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55204 - lcdc_sys_write_index,
55205 - lcdc_sys_write_data,
55206 - lcdc_sys_read_data,
55207 + .write_index = lcdc_sys_write_index,
55208 + .write_data = lcdc_sys_write_data,
55209 + .read_data = lcdc_sys_read_data,
55210 };
55211
55212 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55213 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55214 index d513ed6..90b0de9 100644
55215 --- a/drivers/video/fbdev/smscufx.c
55216 +++ b/drivers/video/fbdev/smscufx.c
55217 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55218 fb_deferred_io_cleanup(info);
55219 kfree(info->fbdefio);
55220 info->fbdefio = NULL;
55221 - info->fbops->fb_mmap = ufx_ops_mmap;
55222 + pax_open_kernel();
55223 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55224 + pax_close_kernel();
55225 }
55226
55227 pr_debug("released /dev/fb%d user=%d count=%d",
55228 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55229 index 046d51d..be564da 100644
55230 --- a/drivers/video/fbdev/udlfb.c
55231 +++ b/drivers/video/fbdev/udlfb.c
55232 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55233 dlfb_urb_completion(urb);
55234
55235 error:
55236 - atomic_add(bytes_sent, &dev->bytes_sent);
55237 - atomic_add(bytes_identical, &dev->bytes_identical);
55238 - atomic_add(width*height*2, &dev->bytes_rendered);
55239 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55240 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55241 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55242 end_cycles = get_cycles();
55243 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55244 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55245 >> 10)), /* Kcycles */
55246 &dev->cpu_kcycles_used);
55247
55248 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55249 dlfb_urb_completion(urb);
55250
55251 error:
55252 - atomic_add(bytes_sent, &dev->bytes_sent);
55253 - atomic_add(bytes_identical, &dev->bytes_identical);
55254 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55255 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55256 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55257 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55258 end_cycles = get_cycles();
55259 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55260 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55261 >> 10)), /* Kcycles */
55262 &dev->cpu_kcycles_used);
55263 }
55264 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55265 fb_deferred_io_cleanup(info);
55266 kfree(info->fbdefio);
55267 info->fbdefio = NULL;
55268 - info->fbops->fb_mmap = dlfb_ops_mmap;
55269 + pax_open_kernel();
55270 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55271 + pax_close_kernel();
55272 }
55273
55274 pr_warn("released /dev/fb%d user=%d count=%d\n",
55275 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55276 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55277 struct dlfb_data *dev = fb_info->par;
55278 return snprintf(buf, PAGE_SIZE, "%u\n",
55279 - atomic_read(&dev->bytes_rendered));
55280 + atomic_read_unchecked(&dev->bytes_rendered));
55281 }
55282
55283 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55284 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55285 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55286 struct dlfb_data *dev = fb_info->par;
55287 return snprintf(buf, PAGE_SIZE, "%u\n",
55288 - atomic_read(&dev->bytes_identical));
55289 + atomic_read_unchecked(&dev->bytes_identical));
55290 }
55291
55292 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55293 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55294 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55295 struct dlfb_data *dev = fb_info->par;
55296 return snprintf(buf, PAGE_SIZE, "%u\n",
55297 - atomic_read(&dev->bytes_sent));
55298 + atomic_read_unchecked(&dev->bytes_sent));
55299 }
55300
55301 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55302 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55303 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55304 struct dlfb_data *dev = fb_info->par;
55305 return snprintf(buf, PAGE_SIZE, "%u\n",
55306 - atomic_read(&dev->cpu_kcycles_used));
55307 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55308 }
55309
55310 static ssize_t edid_show(
55311 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55312 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55313 struct dlfb_data *dev = fb_info->par;
55314
55315 - atomic_set(&dev->bytes_rendered, 0);
55316 - atomic_set(&dev->bytes_identical, 0);
55317 - atomic_set(&dev->bytes_sent, 0);
55318 - atomic_set(&dev->cpu_kcycles_used, 0);
55319 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55320 + atomic_set_unchecked(&dev->bytes_identical, 0);
55321 + atomic_set_unchecked(&dev->bytes_sent, 0);
55322 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55323
55324 return count;
55325 }
55326 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55327 index 509d452..7c9d2de 100644
55328 --- a/drivers/video/fbdev/uvesafb.c
55329 +++ b/drivers/video/fbdev/uvesafb.c
55330 @@ -19,6 +19,7 @@
55331 #include <linux/io.h>
55332 #include <linux/mutex.h>
55333 #include <linux/slab.h>
55334 +#include <linux/moduleloader.h>
55335 #include <video/edid.h>
55336 #include <video/uvesafb.h>
55337 #ifdef CONFIG_X86
55338 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55339 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55340 par->pmi_setpal = par->ypan = 0;
55341 } else {
55342 +
55343 +#ifdef CONFIG_PAX_KERNEXEC
55344 +#ifdef CONFIG_MODULES
55345 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55346 +#endif
55347 + if (!par->pmi_code) {
55348 + par->pmi_setpal = par->ypan = 0;
55349 + return 0;
55350 + }
55351 +#endif
55352 +
55353 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55354 + task->t.regs.edi);
55355 +
55356 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55357 + pax_open_kernel();
55358 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55359 + pax_close_kernel();
55360 +
55361 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55362 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55363 +#else
55364 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55365 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55366 +#endif
55367 +
55368 printk(KERN_INFO "uvesafb: protected mode interface info at "
55369 "%04x:%04x\n",
55370 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55371 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55372 par->ypan = ypan;
55373
55374 if (par->pmi_setpal || par->ypan) {
55375 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55376 if (__supported_pte_mask & _PAGE_NX) {
55377 par->pmi_setpal = par->ypan = 0;
55378 printk(KERN_WARNING "uvesafb: NX protection is active, "
55379 "better not use the PMI.\n");
55380 - } else {
55381 + } else
55382 +#endif
55383 uvesafb_vbe_getpmi(task, par);
55384 - }
55385 }
55386 #else
55387 /* The protected mode interface is not available on non-x86. */
55388 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55389 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55390
55391 /* Disable blanking if the user requested so. */
55392 - if (!blank)
55393 - info->fbops->fb_blank = NULL;
55394 + if (!blank) {
55395 + pax_open_kernel();
55396 + *(void **)&info->fbops->fb_blank = NULL;
55397 + pax_close_kernel();
55398 + }
55399
55400 /*
55401 * Find out how much IO memory is required for the mode with
55402 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55403 info->flags = FBINFO_FLAG_DEFAULT |
55404 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55405
55406 - if (!par->ypan)
55407 - info->fbops->fb_pan_display = NULL;
55408 + if (!par->ypan) {
55409 + pax_open_kernel();
55410 + *(void **)&info->fbops->fb_pan_display = NULL;
55411 + pax_close_kernel();
55412 + }
55413 }
55414
55415 static void uvesafb_init_mtrr(struct fb_info *info)
55416 @@ -1787,6 +1817,11 @@ out_mode:
55417 out:
55418 kfree(par->vbe_modes);
55419
55420 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55421 + if (par->pmi_code)
55422 + module_free_exec(NULL, par->pmi_code);
55423 +#endif
55424 +
55425 framebuffer_release(info);
55426 return err;
55427 }
55428 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55429 kfree(par->vbe_state_orig);
55430 kfree(par->vbe_state_saved);
55431
55432 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55433 + if (par->pmi_code)
55434 + module_free_exec(NULL, par->pmi_code);
55435 +#endif
55436 +
55437 framebuffer_release(info);
55438 }
55439 return 0;
55440 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55441 index 6170e7f..dd63031 100644
55442 --- a/drivers/video/fbdev/vesafb.c
55443 +++ b/drivers/video/fbdev/vesafb.c
55444 @@ -9,6 +9,7 @@
55445 */
55446
55447 #include <linux/module.h>
55448 +#include <linux/moduleloader.h>
55449 #include <linux/kernel.h>
55450 #include <linux/errno.h>
55451 #include <linux/string.h>
55452 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55453 static int vram_total; /* Set total amount of memory */
55454 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55455 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55456 -static void (*pmi_start)(void) __read_mostly;
55457 -static void (*pmi_pal) (void) __read_mostly;
55458 +static void (*pmi_start)(void) __read_only;
55459 +static void (*pmi_pal) (void) __read_only;
55460 static int depth __read_mostly;
55461 static int vga_compat __read_mostly;
55462 /* --------------------------------------------------------------------- */
55463 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55464 unsigned int size_remap;
55465 unsigned int size_total;
55466 char *option = NULL;
55467 + void *pmi_code = NULL;
55468
55469 /* ignore error return of fb_get_options */
55470 fb_get_options("vesafb", &option);
55471 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55472 size_remap = size_total;
55473 vesafb_fix.smem_len = size_remap;
55474
55475 -#ifndef __i386__
55476 - screen_info.vesapm_seg = 0;
55477 -#endif
55478 -
55479 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55480 printk(KERN_WARNING
55481 "vesafb: cannot reserve video memory at 0x%lx\n",
55482 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55483 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55484 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55485
55486 +#ifdef __i386__
55487 +
55488 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55489 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55490 + if (!pmi_code)
55491 +#elif !defined(CONFIG_PAX_KERNEXEC)
55492 + if (0)
55493 +#endif
55494 +
55495 +#endif
55496 + screen_info.vesapm_seg = 0;
55497 +
55498 if (screen_info.vesapm_seg) {
55499 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55500 - screen_info.vesapm_seg,screen_info.vesapm_off);
55501 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55502 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55503 }
55504
55505 if (screen_info.vesapm_seg < 0xc000)
55506 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55507
55508 if (ypan || pmi_setpal) {
55509 unsigned short *pmi_base;
55510 +
55511 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55512 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55513 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55514 +
55515 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55516 + pax_open_kernel();
55517 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55518 +#else
55519 + pmi_code = pmi_base;
55520 +#endif
55521 +
55522 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55523 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55524 +
55525 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55526 + pmi_start = ktva_ktla(pmi_start);
55527 + pmi_pal = ktva_ktla(pmi_pal);
55528 + pax_close_kernel();
55529 +#endif
55530 +
55531 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55532 if (pmi_base[3]) {
55533 printk(KERN_INFO "vesafb: pmi: ports = ");
55534 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55535 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55536 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55537
55538 - if (!ypan)
55539 - info->fbops->fb_pan_display = NULL;
55540 + if (!ypan) {
55541 + pax_open_kernel();
55542 + *(void **)&info->fbops->fb_pan_display = NULL;
55543 + pax_close_kernel();
55544 + }
55545
55546 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55547 err = -ENOMEM;
55548 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55549 fb_info(info, "%s frame buffer device\n", info->fix.id);
55550 return 0;
55551 err:
55552 +
55553 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55554 + module_free_exec(NULL, pmi_code);
55555 +#endif
55556 +
55557 if (info->screen_base)
55558 iounmap(info->screen_base);
55559 framebuffer_release(info);
55560 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55561 index 88714ae..16c2e11 100644
55562 --- a/drivers/video/fbdev/via/via_clock.h
55563 +++ b/drivers/video/fbdev/via/via_clock.h
55564 @@ -56,7 +56,7 @@ struct via_clock {
55565
55566 void (*set_engine_pll_state)(u8 state);
55567 void (*set_engine_pll)(struct via_pll_config config);
55568 -};
55569 +} __no_const;
55570
55571
55572 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55573 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55574 index 3c14e43..2630570 100644
55575 --- a/drivers/video/logo/logo_linux_clut224.ppm
55576 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55577 @@ -2,1603 +2,1123 @@ P3
55578 # Standard 224-color Linux logo
55579 80 80
55580 255
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 - 0 0 0 0 0 0 0 0 0 0 0 0
55585 - 0 0 0 0 0 0 0 0 0 0 0 0
55586 - 0 0 0 0 0 0 0 0 0 0 0 0
55587 - 0 0 0 0 0 0 0 0 0 0 0 0
55588 - 0 0 0 0 0 0 0 0 0 0 0 0
55589 - 0 0 0 0 0 0 0 0 0 0 0 0
55590 - 6 6 6 6 6 6 10 10 10 10 10 10
55591 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
55604 - 0 0 0 0 0 0 0 0 0 0 0 0
55605 - 0 0 0 0 0 0 0 0 0 0 0 0
55606 - 0 0 0 0 0 0 0 0 0 0 0 0
55607 - 0 0 0 0 0 0 0 0 0 0 0 0
55608 - 0 0 0 0 0 0 0 0 0 0 0 0
55609 - 0 0 0 6 6 6 10 10 10 14 14 14
55610 - 22 22 22 26 26 26 30 30 30 34 34 34
55611 - 30 30 30 30 30 30 26 26 26 18 18 18
55612 - 14 14 14 10 10 10 6 6 6 0 0 0
55613 - 0 0 0 0 0 0 0 0 0 0 0 0
55614 - 0 0 0 0 0 0 0 0 0 0 0 0
55615 - 0 0 0 0 0 0 0 0 0 0 0 0
55616 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
55623 - 0 0 0 0 0 0 0 0 0 0 0 0
55624 - 0 0 0 0 0 0 0 0 0 0 0 0
55625 - 0 0 0 0 0 0 0 0 0 0 0 0
55626 - 0 0 0 0 0 0 0 0 0 0 0 0
55627 - 0 0 0 0 0 0 0 0 0 0 0 0
55628 - 0 0 0 0 0 0 0 0 0 0 0 0
55629 - 6 6 6 14 14 14 26 26 26 42 42 42
55630 - 54 54 54 66 66 66 78 78 78 78 78 78
55631 - 78 78 78 74 74 74 66 66 66 54 54 54
55632 - 42 42 42 26 26 26 18 18 18 10 10 10
55633 - 6 6 6 0 0 0 0 0 0 0 0 0
55634 - 0 0 0 0 0 0 0 0 0 0 0 0
55635 - 0 0 0 0 0 0 0 0 0 0 0 0
55636 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
55643 - 0 0 0 0 0 0 0 0 0 0 0 0
55644 - 0 0 0 0 0 0 0 0 0 0 0 0
55645 - 0 0 0 0 0 0 0 0 0 0 0 0
55646 - 0 0 0 0 0 0 0 0 0 0 0 0
55647 - 0 0 0 0 0 0 0 0 0 0 0 0
55648 - 0 0 0 0 0 0 0 0 0 10 10 10
55649 - 22 22 22 42 42 42 66 66 66 86 86 86
55650 - 66 66 66 38 38 38 38 38 38 22 22 22
55651 - 26 26 26 34 34 34 54 54 54 66 66 66
55652 - 86 86 86 70 70 70 46 46 46 26 26 26
55653 - 14 14 14 6 6 6 0 0 0 0 0 0
55654 - 0 0 0 0 0 0 0 0 0 0 0 0
55655 - 0 0 0 0 0 0 0 0 0 0 0 0
55656 - 0 0 0 0 0 0 0 0 0 0 0 0
55657 - 0 0 0 0 0 0 0 0 0 0 0 0
55658 - 0 0 0 0 0 0 0 0 0 0 0 0
55659 - 0 0 0 0 0 0 0 0 0 0 0 0
55660 - 0 0 0 0 0 0 0 0 0 0 0 0
55661 - 0 0 0 0 0 0 0 0 0 0 0 0
55662 - 0 0 1 0 0 1 0 0 1 0 0 0
55663 - 0 0 0 0 0 0 0 0 0 0 0 0
55664 - 0 0 0 0 0 0 0 0 0 0 0 0
55665 - 0 0 0 0 0 0 0 0 0 0 0 0
55666 - 0 0 0 0 0 0 0 0 0 0 0 0
55667 - 0 0 0 0 0 0 0 0 0 0 0 0
55668 - 0 0 0 0 0 0 10 10 10 26 26 26
55669 - 50 50 50 82 82 82 58 58 58 6 6 6
55670 - 2 2 6 2 2 6 2 2 6 2 2 6
55671 - 2 2 6 2 2 6 2 2 6 2 2 6
55672 - 6 6 6 54 54 54 86 86 86 66 66 66
55673 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
55683 - 0 0 0 0 0 0 0 0 0 0 0 0
55684 - 0 0 0 0 0 0 0 0 0 0 0 0
55685 - 0 0 0 0 0 0 0 0 0 0 0 0
55686 - 0 0 0 0 0 0 0 0 0 0 0 0
55687 - 0 0 0 0 0 0 0 0 0 0 0 0
55688 - 0 0 0 6 6 6 22 22 22 50 50 50
55689 - 78 78 78 34 34 34 2 2 6 2 2 6
55690 - 2 2 6 2 2 6 2 2 6 2 2 6
55691 - 2 2 6 2 2 6 2 2 6 2 2 6
55692 - 2 2 6 2 2 6 6 6 6 70 70 70
55693 - 78 78 78 46 46 46 22 22 22 6 6 6
55694 - 0 0 0 0 0 0 0 0 0 0 0 0
55695 - 0 0 0 0 0 0 0 0 0 0 0 0
55696 - 0 0 0 0 0 0 0 0 0 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 0 0 1 0 0 1 0 0 1 0 0 0
55703 - 0 0 0 0 0 0 0 0 0 0 0 0
55704 - 0 0 0 0 0 0 0 0 0 0 0 0
55705 - 0 0 0 0 0 0 0 0 0 0 0 0
55706 - 0 0 0 0 0 0 0 0 0 0 0 0
55707 - 0 0 0 0 0 0 0 0 0 0 0 0
55708 - 6 6 6 18 18 18 42 42 42 82 82 82
55709 - 26 26 26 2 2 6 2 2 6 2 2 6
55710 - 2 2 6 2 2 6 2 2 6 2 2 6
55711 - 2 2 6 2 2 6 2 2 6 14 14 14
55712 - 46 46 46 34 34 34 6 6 6 2 2 6
55713 - 42 42 42 78 78 78 42 42 42 18 18 18
55714 - 6 6 6 0 0 0 0 0 0 0 0 0
55715 - 0 0 0 0 0 0 0 0 0 0 0 0
55716 - 0 0 0 0 0 0 0 0 0 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 0 0 0
55722 - 0 0 1 0 0 0 0 0 1 0 0 0
55723 - 0 0 0 0 0 0 0 0 0 0 0 0
55724 - 0 0 0 0 0 0 0 0 0 0 0 0
55725 - 0 0 0 0 0 0 0 0 0 0 0 0
55726 - 0 0 0 0 0 0 0 0 0 0 0 0
55727 - 0 0 0 0 0 0 0 0 0 0 0 0
55728 - 10 10 10 30 30 30 66 66 66 58 58 58
55729 - 2 2 6 2 2 6 2 2 6 2 2 6
55730 - 2 2 6 2 2 6 2 2 6 2 2 6
55731 - 2 2 6 2 2 6 2 2 6 26 26 26
55732 - 86 86 86 101 101 101 46 46 46 10 10 10
55733 - 2 2 6 58 58 58 70 70 70 34 34 34
55734 - 10 10 10 0 0 0 0 0 0 0 0 0
55735 - 0 0 0 0 0 0 0 0 0 0 0 0
55736 - 0 0 0 0 0 0 0 0 0 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 0 0 0
55742 - 0 0 1 0 0 1 0 0 1 0 0 0
55743 - 0 0 0 0 0 0 0 0 0 0 0 0
55744 - 0 0 0 0 0 0 0 0 0 0 0 0
55745 - 0 0 0 0 0 0 0 0 0 0 0 0
55746 - 0 0 0 0 0 0 0 0 0 0 0 0
55747 - 0 0 0 0 0 0 0 0 0 0 0 0
55748 - 14 14 14 42 42 42 86 86 86 10 10 10
55749 - 2 2 6 2 2 6 2 2 6 2 2 6
55750 - 2 2 6 2 2 6 2 2 6 2 2 6
55751 - 2 2 6 2 2 6 2 2 6 30 30 30
55752 - 94 94 94 94 94 94 58 58 58 26 26 26
55753 - 2 2 6 6 6 6 78 78 78 54 54 54
55754 - 22 22 22 6 6 6 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 0 0 0
55762 - 0 0 0 0 0 0 0 0 0 0 0 0
55763 - 0 0 0 0 0 0 0 0 0 0 0 0
55764 - 0 0 0 0 0 0 0 0 0 0 0 0
55765 - 0 0 0 0 0 0 0 0 0 0 0 0
55766 - 0 0 0 0 0 0 0 0 0 0 0 0
55767 - 0 0 0 0 0 0 0 0 0 6 6 6
55768 - 22 22 22 62 62 62 62 62 62 2 2 6
55769 - 2 2 6 2 2 6 2 2 6 2 2 6
55770 - 2 2 6 2 2 6 2 2 6 2 2 6
55771 - 2 2 6 2 2 6 2 2 6 26 26 26
55772 - 54 54 54 38 38 38 18 18 18 10 10 10
55773 - 2 2 6 2 2 6 34 34 34 82 82 82
55774 - 38 38 38 14 14 14 0 0 0 0 0 0
55775 - 0 0 0 0 0 0 0 0 0 0 0 0
55776 - 0 0 0 0 0 0 0 0 0 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 0 0 0
55782 - 0 0 0 0 0 1 0 0 1 0 0 0
55783 - 0 0 0 0 0 0 0 0 0 0 0 0
55784 - 0 0 0 0 0 0 0 0 0 0 0 0
55785 - 0 0 0 0 0 0 0 0 0 0 0 0
55786 - 0 0 0 0 0 0 0 0 0 0 0 0
55787 - 0 0 0 0 0 0 0 0 0 6 6 6
55788 - 30 30 30 78 78 78 30 30 30 2 2 6
55789 - 2 2 6 2 2 6 2 2 6 2 2 6
55790 - 2 2 6 2 2 6 2 2 6 2 2 6
55791 - 2 2 6 2 2 6 2 2 6 10 10 10
55792 - 10 10 10 2 2 6 2 2 6 2 2 6
55793 - 2 2 6 2 2 6 2 2 6 78 78 78
55794 - 50 50 50 18 18 18 6 6 6 0 0 0
55795 - 0 0 0 0 0 0 0 0 0 0 0 0
55796 - 0 0 0 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 0 0 0
55802 - 0 0 1 0 0 0 0 0 0 0 0 0
55803 - 0 0 0 0 0 0 0 0 0 0 0 0
55804 - 0 0 0 0 0 0 0 0 0 0 0 0
55805 - 0 0 0 0 0 0 0 0 0 0 0 0
55806 - 0 0 0 0 0 0 0 0 0 0 0 0
55807 - 0 0 0 0 0 0 0 0 0 10 10 10
55808 - 38 38 38 86 86 86 14 14 14 2 2 6
55809 - 2 2 6 2 2 6 2 2 6 2 2 6
55810 - 2 2 6 2 2 6 2 2 6 2 2 6
55811 - 2 2 6 2 2 6 2 2 6 2 2 6
55812 - 2 2 6 2 2 6 2 2 6 2 2 6
55813 - 2 2 6 2 2 6 2 2 6 54 54 54
55814 - 66 66 66 26 26 26 6 6 6 0 0 0
55815 - 0 0 0 0 0 0 0 0 0 0 0 0
55816 - 0 0 0 0 0 0 0 0 0 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 0 0 0
55822 - 0 0 0 0 0 1 0 0 1 0 0 0
55823 - 0 0 0 0 0 0 0 0 0 0 0 0
55824 - 0 0 0 0 0 0 0 0 0 0 0 0
55825 - 0 0 0 0 0 0 0 0 0 0 0 0
55826 - 0 0 0 0 0 0 0 0 0 0 0 0
55827 - 0 0 0 0 0 0 0 0 0 14 14 14
55828 - 42 42 42 82 82 82 2 2 6 2 2 6
55829 - 2 2 6 6 6 6 10 10 10 2 2 6
55830 - 2 2 6 2 2 6 2 2 6 2 2 6
55831 - 2 2 6 2 2 6 2 2 6 6 6 6
55832 - 14 14 14 10 10 10 2 2 6 2 2 6
55833 - 2 2 6 2 2 6 2 2 6 18 18 18
55834 - 82 82 82 34 34 34 10 10 10 0 0 0
55835 - 0 0 0 0 0 0 0 0 0 0 0 0
55836 - 0 0 0 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 0 0 0
55842 - 0 0 1 0 0 0 0 0 0 0 0 0
55843 - 0 0 0 0 0 0 0 0 0 0 0 0
55844 - 0 0 0 0 0 0 0 0 0 0 0 0
55845 - 0 0 0 0 0 0 0 0 0 0 0 0
55846 - 0 0 0 0 0 0 0 0 0 0 0 0
55847 - 0 0 0 0 0 0 0 0 0 14 14 14
55848 - 46 46 46 86 86 86 2 2 6 2 2 6
55849 - 6 6 6 6 6 6 22 22 22 34 34 34
55850 - 6 6 6 2 2 6 2 2 6 2 2 6
55851 - 2 2 6 2 2 6 18 18 18 34 34 34
55852 - 10 10 10 50 50 50 22 22 22 2 2 6
55853 - 2 2 6 2 2 6 2 2 6 10 10 10
55854 - 86 86 86 42 42 42 14 14 14 0 0 0
55855 - 0 0 0 0 0 0 0 0 0 0 0 0
55856 - 0 0 0 0 0 0 0 0 0 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 0 0 0
55862 - 0 0 1 0 0 1 0 0 1 0 0 0
55863 - 0 0 0 0 0 0 0 0 0 0 0 0
55864 - 0 0 0 0 0 0 0 0 0 0 0 0
55865 - 0 0 0 0 0 0 0 0 0 0 0 0
55866 - 0 0 0 0 0 0 0 0 0 0 0 0
55867 - 0 0 0 0 0 0 0 0 0 14 14 14
55868 - 46 46 46 86 86 86 2 2 6 2 2 6
55869 - 38 38 38 116 116 116 94 94 94 22 22 22
55870 - 22 22 22 2 2 6 2 2 6 2 2 6
55871 - 14 14 14 86 86 86 138 138 138 162 162 162
55872 -154 154 154 38 38 38 26 26 26 6 6 6
55873 - 2 2 6 2 2 6 2 2 6 2 2 6
55874 - 86 86 86 46 46 46 14 14 14 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 0 0 0
55882 - 0 0 0 0 0 0 0 0 0 0 0 0
55883 - 0 0 0 0 0 0 0 0 0 0 0 0
55884 - 0 0 0 0 0 0 0 0 0 0 0 0
55885 - 0 0 0 0 0 0 0 0 0 0 0 0
55886 - 0 0 0 0 0 0 0 0 0 0 0 0
55887 - 0 0 0 0 0 0 0 0 0 14 14 14
55888 - 46 46 46 86 86 86 2 2 6 14 14 14
55889 -134 134 134 198 198 198 195 195 195 116 116 116
55890 - 10 10 10 2 2 6 2 2 6 6 6 6
55891 -101 98 89 187 187 187 210 210 210 218 218 218
55892 -214 214 214 134 134 134 14 14 14 6 6 6
55893 - 2 2 6 2 2 6 2 2 6 2 2 6
55894 - 86 86 86 50 50 50 18 18 18 6 6 6
55895 - 0 0 0 0 0 0 0 0 0 0 0 0
55896 - 0 0 0 0 0 0 0 0 0 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 0 0 0 0 0 0 0 0 1 0 0 0
55902 - 0 0 1 0 0 1 0 0 1 0 0 0
55903 - 0 0 0 0 0 0 0 0 0 0 0 0
55904 - 0 0 0 0 0 0 0 0 0 0 0 0
55905 - 0 0 0 0 0 0 0 0 0 0 0 0
55906 - 0 0 0 0 0 0 0 0 0 0 0 0
55907 - 0 0 0 0 0 0 0 0 0 14 14 14
55908 - 46 46 46 86 86 86 2 2 6 54 54 54
55909 -218 218 218 195 195 195 226 226 226 246 246 246
55910 - 58 58 58 2 2 6 2 2 6 30 30 30
55911 -210 210 210 253 253 253 174 174 174 123 123 123
55912 -221 221 221 234 234 234 74 74 74 2 2 6
55913 - 2 2 6 2 2 6 2 2 6 2 2 6
55914 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
55922 - 0 0 0 0 0 0 0 0 0 0 0 0
55923 - 0 0 0 0 0 0 0 0 0 0 0 0
55924 - 0 0 0 0 0 0 0 0 0 0 0 0
55925 - 0 0 0 0 0 0 0 0 0 0 0 0
55926 - 0 0 0 0 0 0 0 0 0 0 0 0
55927 - 0 0 0 0 0 0 0 0 0 14 14 14
55928 - 46 46 46 82 82 82 2 2 6 106 106 106
55929 -170 170 170 26 26 26 86 86 86 226 226 226
55930 -123 123 123 10 10 10 14 14 14 46 46 46
55931 -231 231 231 190 190 190 6 6 6 70 70 70
55932 - 90 90 90 238 238 238 158 158 158 2 2 6
55933 - 2 2 6 2 2 6 2 2 6 2 2 6
55934 - 70 70 70 58 58 58 22 22 22 6 6 6
55935 - 0 0 0 0 0 0 0 0 0 0 0 0
55936 - 0 0 0 0 0 0 0 0 0 0 0 0
55937 - 0 0 0 0 0 0 0 0 0 0 0 0
55938 - 0 0 0 0 0 0 0 0 0 0 0 0
55939 - 0 0 0 0 0 0 0 0 0 0 0 0
55940 - 0 0 0 0 0 0 0 0 0 0 0 0
55941 - 0 0 0 0 0 0 0 0 1 0 0 0
55942 - 0 0 1 0 0 1 0 0 1 0 0 0
55943 - 0 0 0 0 0 0 0 0 0 0 0 0
55944 - 0 0 0 0 0 0 0 0 0 0 0 0
55945 - 0 0 0 0 0 0 0 0 0 0 0 0
55946 - 0 0 0 0 0 0 0 0 0 0 0 0
55947 - 0 0 0 0 0 0 0 0 0 14 14 14
55948 - 42 42 42 86 86 86 6 6 6 116 116 116
55949 -106 106 106 6 6 6 70 70 70 149 149 149
55950 -128 128 128 18 18 18 38 38 38 54 54 54
55951 -221 221 221 106 106 106 2 2 6 14 14 14
55952 - 46 46 46 190 190 190 198 198 198 2 2 6
55953 - 2 2 6 2 2 6 2 2 6 2 2 6
55954 - 74 74 74 62 62 62 22 22 22 6 6 6
55955 - 0 0 0 0 0 0 0 0 0 0 0 0
55956 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
55962 - 0 0 1 0 0 0 0 0 1 0 0 0
55963 - 0 0 0 0 0 0 0 0 0 0 0 0
55964 - 0 0 0 0 0 0 0 0 0 0 0 0
55965 - 0 0 0 0 0 0 0 0 0 0 0 0
55966 - 0 0 0 0 0 0 0 0 0 0 0 0
55967 - 0 0 0 0 0 0 0 0 0 14 14 14
55968 - 42 42 42 94 94 94 14 14 14 101 101 101
55969 -128 128 128 2 2 6 18 18 18 116 116 116
55970 -118 98 46 121 92 8 121 92 8 98 78 10
55971 -162 162 162 106 106 106 2 2 6 2 2 6
55972 - 2 2 6 195 195 195 195 195 195 6 6 6
55973 - 2 2 6 2 2 6 2 2 6 2 2 6
55974 - 74 74 74 62 62 62 22 22 22 6 6 6
55975 - 0 0 0 0 0 0 0 0 0 0 0 0
55976 - 0 0 0 0 0 0 0 0 0 0 0 0
55977 - 0 0 0 0 0 0 0 0 0 0 0 0
55978 - 0 0 0 0 0 0 0 0 0 0 0 0
55979 - 0 0 0 0 0 0 0 0 0 0 0 0
55980 - 0 0 0 0 0 0 0 0 0 0 0 0
55981 - 0 0 0 0 0 0 0 0 1 0 0 1
55982 - 0 0 1 0 0 0 0 0 1 0 0 0
55983 - 0 0 0 0 0 0 0 0 0 0 0 0
55984 - 0 0 0 0 0 0 0 0 0 0 0 0
55985 - 0 0 0 0 0 0 0 0 0 0 0 0
55986 - 0 0 0 0 0 0 0 0 0 0 0 0
55987 - 0 0 0 0 0 0 0 0 0 10 10 10
55988 - 38 38 38 90 90 90 14 14 14 58 58 58
55989 -210 210 210 26 26 26 54 38 6 154 114 10
55990 -226 170 11 236 186 11 225 175 15 184 144 12
55991 -215 174 15 175 146 61 37 26 9 2 2 6
55992 - 70 70 70 246 246 246 138 138 138 2 2 6
55993 - 2 2 6 2 2 6 2 2 6 2 2 6
55994 - 70 70 70 66 66 66 26 26 26 6 6 6
55995 - 0 0 0 0 0 0 0 0 0 0 0 0
55996 - 0 0 0 0 0 0 0 0 0 0 0 0
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 0 0 0 0 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 0 0 0
56002 - 0 0 0 0 0 0 0 0 0 0 0 0
56003 - 0 0 0 0 0 0 0 0 0 0 0 0
56004 - 0 0 0 0 0 0 0 0 0 0 0 0
56005 - 0 0 0 0 0 0 0 0 0 0 0 0
56006 - 0 0 0 0 0 0 0 0 0 0 0 0
56007 - 0 0 0 0 0 0 0 0 0 10 10 10
56008 - 38 38 38 86 86 86 14 14 14 10 10 10
56009 -195 195 195 188 164 115 192 133 9 225 175 15
56010 -239 182 13 234 190 10 232 195 16 232 200 30
56011 -245 207 45 241 208 19 232 195 16 184 144 12
56012 -218 194 134 211 206 186 42 42 42 2 2 6
56013 - 2 2 6 2 2 6 2 2 6 2 2 6
56014 - 50 50 50 74 74 74 30 30 30 6 6 6
56015 - 0 0 0 0 0 0 0 0 0 0 0 0
56016 - 0 0 0 0 0 0 0 0 0 0 0 0
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 0 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 0 0 0
56022 - 0 0 0 0 0 0 0 0 0 0 0 0
56023 - 0 0 0 0 0 0 0 0 0 0 0 0
56024 - 0 0 0 0 0 0 0 0 0 0 0 0
56025 - 0 0 0 0 0 0 0 0 0 0 0 0
56026 - 0 0 0 0 0 0 0 0 0 0 0 0
56027 - 0 0 0 0 0 0 0 0 0 10 10 10
56028 - 34 34 34 86 86 86 14 14 14 2 2 6
56029 -121 87 25 192 133 9 219 162 10 239 182 13
56030 -236 186 11 232 195 16 241 208 19 244 214 54
56031 -246 218 60 246 218 38 246 215 20 241 208 19
56032 -241 208 19 226 184 13 121 87 25 2 2 6
56033 - 2 2 6 2 2 6 2 2 6 2 2 6
56034 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
56042 - 0 0 0 0 0 0 0 0 0 0 0 0
56043 - 0 0 0 0 0 0 0 0 0 0 0 0
56044 - 0 0 0 0 0 0 0 0 0 0 0 0
56045 - 0 0 0 0 0 0 0 0 0 0 0 0
56046 - 0 0 0 0 0 0 0 0 0 0 0 0
56047 - 0 0 0 0 0 0 0 0 0 10 10 10
56048 - 34 34 34 82 82 82 30 30 30 61 42 6
56049 -180 123 7 206 145 10 230 174 11 239 182 13
56050 -234 190 10 238 202 15 241 208 19 246 218 74
56051 -246 218 38 246 215 20 246 215 20 246 215 20
56052 -226 184 13 215 174 15 184 144 12 6 6 6
56053 - 2 2 6 2 2 6 2 2 6 2 2 6
56054 - 26 26 26 94 94 94 42 42 42 14 14 14
56055 - 0 0 0 0 0 0 0 0 0 0 0 0
56056 - 0 0 0 0 0 0 0 0 0 0 0 0
56057 - 0 0 0 0 0 0 0 0 0 0 0 0
56058 - 0 0 0 0 0 0 0 0 0 0 0 0
56059 - 0 0 0 0 0 0 0 0 0 0 0 0
56060 - 0 0 0 0 0 0 0 0 0 0 0 0
56061 - 0 0 0 0 0 0 0 0 0 0 0 0
56062 - 0 0 0 0 0 0 0 0 0 0 0 0
56063 - 0 0 0 0 0 0 0 0 0 0 0 0
56064 - 0 0 0 0 0 0 0 0 0 0 0 0
56065 - 0 0 0 0 0 0 0 0 0 0 0 0
56066 - 0 0 0 0 0 0 0 0 0 0 0 0
56067 - 0 0 0 0 0 0 0 0 0 10 10 10
56068 - 30 30 30 78 78 78 50 50 50 104 69 6
56069 -192 133 9 216 158 10 236 178 12 236 186 11
56070 -232 195 16 241 208 19 244 214 54 245 215 43
56071 -246 215 20 246 215 20 241 208 19 198 155 10
56072 -200 144 11 216 158 10 156 118 10 2 2 6
56073 - 2 2 6 2 2 6 2 2 6 2 2 6
56074 - 6 6 6 90 90 90 54 54 54 18 18 18
56075 - 6 6 6 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 0 0 0
56082 - 0 0 0 0 0 0 0 0 0 0 0 0
56083 - 0 0 0 0 0 0 0 0 0 0 0 0
56084 - 0 0 0 0 0 0 0 0 0 0 0 0
56085 - 0 0 0 0 0 0 0 0 0 0 0 0
56086 - 0 0 0 0 0 0 0 0 0 0 0 0
56087 - 0 0 0 0 0 0 0 0 0 10 10 10
56088 - 30 30 30 78 78 78 46 46 46 22 22 22
56089 -137 92 6 210 162 10 239 182 13 238 190 10
56090 -238 202 15 241 208 19 246 215 20 246 215 20
56091 -241 208 19 203 166 17 185 133 11 210 150 10
56092 -216 158 10 210 150 10 102 78 10 2 2 6
56093 - 6 6 6 54 54 54 14 14 14 2 2 6
56094 - 2 2 6 62 62 62 74 74 74 30 30 30
56095 - 10 10 10 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 0 0 0
56102 - 0 0 0 0 0 0 0 0 0 0 0 0
56103 - 0 0 0 0 0 0 0 0 0 0 0 0
56104 - 0 0 0 0 0 0 0 0 0 0 0 0
56105 - 0 0 0 0 0 0 0 0 0 0 0 0
56106 - 0 0 0 0 0 0 0 0 0 0 0 0
56107 - 0 0 0 0 0 0 0 0 0 10 10 10
56108 - 34 34 34 78 78 78 50 50 50 6 6 6
56109 - 94 70 30 139 102 15 190 146 13 226 184 13
56110 -232 200 30 232 195 16 215 174 15 190 146 13
56111 -168 122 10 192 133 9 210 150 10 213 154 11
56112 -202 150 34 182 157 106 101 98 89 2 2 6
56113 - 2 2 6 78 78 78 116 116 116 58 58 58
56114 - 2 2 6 22 22 22 90 90 90 46 46 46
56115 - 18 18 18 6 6 6 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 0 0 0
56122 - 0 0 0 0 0 0 0 0 0 0 0 0
56123 - 0 0 0 0 0 0 0 0 0 0 0 0
56124 - 0 0 0 0 0 0 0 0 0 0 0 0
56125 - 0 0 0 0 0 0 0 0 0 0 0 0
56126 - 0 0 0 0 0 0 0 0 0 0 0 0
56127 - 0 0 0 0 0 0 0 0 0 10 10 10
56128 - 38 38 38 86 86 86 50 50 50 6 6 6
56129 -128 128 128 174 154 114 156 107 11 168 122 10
56130 -198 155 10 184 144 12 197 138 11 200 144 11
56131 -206 145 10 206 145 10 197 138 11 188 164 115
56132 -195 195 195 198 198 198 174 174 174 14 14 14
56133 - 2 2 6 22 22 22 116 116 116 116 116 116
56134 - 22 22 22 2 2 6 74 74 74 70 70 70
56135 - 30 30 30 10 10 10 0 0 0 0 0 0
56136 - 0 0 0 0 0 0 0 0 0 0 0 0
56137 - 0 0 0 0 0 0 0 0 0 0 0 0
56138 - 0 0 0 0 0 0 0 0 0 0 0 0
56139 - 0 0 0 0 0 0 0 0 0 0 0 0
56140 - 0 0 0 0 0 0 0 0 0 0 0 0
56141 - 0 0 0 0 0 0 0 0 0 0 0 0
56142 - 0 0 0 0 0 0 0 0 0 0 0 0
56143 - 0 0 0 0 0 0 0 0 0 0 0 0
56144 - 0 0 0 0 0 0 0 0 0 0 0 0
56145 - 0 0 0 0 0 0 0 0 0 0 0 0
56146 - 0 0 0 0 0 0 0 0 0 0 0 0
56147 - 0 0 0 0 0 0 6 6 6 18 18 18
56148 - 50 50 50 101 101 101 26 26 26 10 10 10
56149 -138 138 138 190 190 190 174 154 114 156 107 11
56150 -197 138 11 200 144 11 197 138 11 192 133 9
56151 -180 123 7 190 142 34 190 178 144 187 187 187
56152 -202 202 202 221 221 221 214 214 214 66 66 66
56153 - 2 2 6 2 2 6 50 50 50 62 62 62
56154 - 6 6 6 2 2 6 10 10 10 90 90 90
56155 - 50 50 50 18 18 18 6 6 6 0 0 0
56156 - 0 0 0 0 0 0 0 0 0 0 0 0
56157 - 0 0 0 0 0 0 0 0 0 0 0 0
56158 - 0 0 0 0 0 0 0 0 0 0 0 0
56159 - 0 0 0 0 0 0 0 0 0 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 0 0 0 0 0 0 0 0 0
56162 - 0 0 0 0 0 0 0 0 0 0 0 0
56163 - 0 0 0 0 0 0 0 0 0 0 0 0
56164 - 0 0 0 0 0 0 0 0 0 0 0 0
56165 - 0 0 0 0 0 0 0 0 0 0 0 0
56166 - 0 0 0 0 0 0 0 0 0 0 0 0
56167 - 0 0 0 0 0 0 10 10 10 34 34 34
56168 - 74 74 74 74 74 74 2 2 6 6 6 6
56169 -144 144 144 198 198 198 190 190 190 178 166 146
56170 -154 121 60 156 107 11 156 107 11 168 124 44
56171 -174 154 114 187 187 187 190 190 190 210 210 210
56172 -246 246 246 253 253 253 253 253 253 182 182 182
56173 - 6 6 6 2 2 6 2 2 6 2 2 6
56174 - 2 2 6 2 2 6 2 2 6 62 62 62
56175 - 74 74 74 34 34 34 14 14 14 0 0 0
56176 - 0 0 0 0 0 0 0 0 0 0 0 0
56177 - 0 0 0 0 0 0 0 0 0 0 0 0
56178 - 0 0 0 0 0 0 0 0 0 0 0 0
56179 - 0 0 0 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 0 0 0 0 0 0 0 0 0 0 0 0
56182 - 0 0 0 0 0 0 0 0 0 0 0 0
56183 - 0 0 0 0 0 0 0 0 0 0 0 0
56184 - 0 0 0 0 0 0 0 0 0 0 0 0
56185 - 0 0 0 0 0 0 0 0 0 0 0 0
56186 - 0 0 0 0 0 0 0 0 0 0 0 0
56187 - 0 0 0 10 10 10 22 22 22 54 54 54
56188 - 94 94 94 18 18 18 2 2 6 46 46 46
56189 -234 234 234 221 221 221 190 190 190 190 190 190
56190 -190 190 190 187 187 187 187 187 187 190 190 190
56191 -190 190 190 195 195 195 214 214 214 242 242 242
56192 -253 253 253 253 253 253 253 253 253 253 253 253
56193 - 82 82 82 2 2 6 2 2 6 2 2 6
56194 - 2 2 6 2 2 6 2 2 6 14 14 14
56195 - 86 86 86 54 54 54 22 22 22 6 6 6
56196 - 0 0 0 0 0 0 0 0 0 0 0 0
56197 - 0 0 0 0 0 0 0 0 0 0 0 0
56198 - 0 0 0 0 0 0 0 0 0 0 0 0
56199 - 0 0 0 0 0 0 0 0 0 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 0 0 0
56201 - 0 0 0 0 0 0 0 0 0 0 0 0
56202 - 0 0 0 0 0 0 0 0 0 0 0 0
56203 - 0 0 0 0 0 0 0 0 0 0 0 0
56204 - 0 0 0 0 0 0 0 0 0 0 0 0
56205 - 0 0 0 0 0 0 0 0 0 0 0 0
56206 - 0 0 0 0 0 0 0 0 0 0 0 0
56207 - 6 6 6 18 18 18 46 46 46 90 90 90
56208 - 46 46 46 18 18 18 6 6 6 182 182 182
56209 -253 253 253 246 246 246 206 206 206 190 190 190
56210 -190 190 190 190 190 190 190 190 190 190 190 190
56211 -206 206 206 231 231 231 250 250 250 253 253 253
56212 -253 253 253 253 253 253 253 253 253 253 253 253
56213 -202 202 202 14 14 14 2 2 6 2 2 6
56214 - 2 2 6 2 2 6 2 2 6 2 2 6
56215 - 42 42 42 86 86 86 42 42 42 18 18 18
56216 - 6 6 6 0 0 0 0 0 0 0 0 0
56217 - 0 0 0 0 0 0 0 0 0 0 0 0
56218 - 0 0 0 0 0 0 0 0 0 0 0 0
56219 - 0 0 0 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 0 0 0
56221 - 0 0 0 0 0 0 0 0 0 0 0 0
56222 - 0 0 0 0 0 0 0 0 0 0 0 0
56223 - 0 0 0 0 0 0 0 0 0 0 0 0
56224 - 0 0 0 0 0 0 0 0 0 0 0 0
56225 - 0 0 0 0 0 0 0 0 0 0 0 0
56226 - 0 0 0 0 0 0 0 0 0 6 6 6
56227 - 14 14 14 38 38 38 74 74 74 66 66 66
56228 - 2 2 6 6 6 6 90 90 90 250 250 250
56229 -253 253 253 253 253 253 238 238 238 198 198 198
56230 -190 190 190 190 190 190 195 195 195 221 221 221
56231 -246 246 246 253 253 253 253 253 253 253 253 253
56232 -253 253 253 253 253 253 253 253 253 253 253 253
56233 -253 253 253 82 82 82 2 2 6 2 2 6
56234 - 2 2 6 2 2 6 2 2 6 2 2 6
56235 - 2 2 6 78 78 78 70 70 70 34 34 34
56236 - 14 14 14 6 6 6 0 0 0 0 0 0
56237 - 0 0 0 0 0 0 0 0 0 0 0 0
56238 - 0 0 0 0 0 0 0 0 0 0 0 0
56239 - 0 0 0 0 0 0 0 0 0 0 0 0
56240 - 0 0 0 0 0 0 0 0 0 0 0 0
56241 - 0 0 0 0 0 0 0 0 0 0 0 0
56242 - 0 0 0 0 0 0 0 0 0 0 0 0
56243 - 0 0 0 0 0 0 0 0 0 0 0 0
56244 - 0 0 0 0 0 0 0 0 0 0 0 0
56245 - 0 0 0 0 0 0 0 0 0 0 0 0
56246 - 0 0 0 0 0 0 0 0 0 14 14 14
56247 - 34 34 34 66 66 66 78 78 78 6 6 6
56248 - 2 2 6 18 18 18 218 218 218 253 253 253
56249 -253 253 253 253 253 253 253 253 253 246 246 246
56250 -226 226 226 231 231 231 246 246 246 253 253 253
56251 -253 253 253 253 253 253 253 253 253 253 253 253
56252 -253 253 253 253 253 253 253 253 253 253 253 253
56253 -253 253 253 178 178 178 2 2 6 2 2 6
56254 - 2 2 6 2 2 6 2 2 6 2 2 6
56255 - 2 2 6 18 18 18 90 90 90 62 62 62
56256 - 30 30 30 10 10 10 0 0 0 0 0 0
56257 - 0 0 0 0 0 0 0 0 0 0 0 0
56258 - 0 0 0 0 0 0 0 0 0 0 0 0
56259 - 0 0 0 0 0 0 0 0 0 0 0 0
56260 - 0 0 0 0 0 0 0 0 0 0 0 0
56261 - 0 0 0 0 0 0 0 0 0 0 0 0
56262 - 0 0 0 0 0 0 0 0 0 0 0 0
56263 - 0 0 0 0 0 0 0 0 0 0 0 0
56264 - 0 0 0 0 0 0 0 0 0 0 0 0
56265 - 0 0 0 0 0 0 0 0 0 0 0 0
56266 - 0 0 0 0 0 0 10 10 10 26 26 26
56267 - 58 58 58 90 90 90 18 18 18 2 2 6
56268 - 2 2 6 110 110 110 253 253 253 253 253 253
56269 -253 253 253 253 253 253 253 253 253 253 253 253
56270 -250 250 250 253 253 253 253 253 253 253 253 253
56271 -253 253 253 253 253 253 253 253 253 253 253 253
56272 -253 253 253 253 253 253 253 253 253 253 253 253
56273 -253 253 253 231 231 231 18 18 18 2 2 6
56274 - 2 2 6 2 2 6 2 2 6 2 2 6
56275 - 2 2 6 2 2 6 18 18 18 94 94 94
56276 - 54 54 54 26 26 26 10 10 10 0 0 0
56277 - 0 0 0 0 0 0 0 0 0 0 0 0
56278 - 0 0 0 0 0 0 0 0 0 0 0 0
56279 - 0 0 0 0 0 0 0 0 0 0 0 0
56280 - 0 0 0 0 0 0 0 0 0 0 0 0
56281 - 0 0 0 0 0 0 0 0 0 0 0 0
56282 - 0 0 0 0 0 0 0 0 0 0 0 0
56283 - 0 0 0 0 0 0 0 0 0 0 0 0
56284 - 0 0 0 0 0 0 0 0 0 0 0 0
56285 - 0 0 0 0 0 0 0 0 0 0 0 0
56286 - 0 0 0 6 6 6 22 22 22 50 50 50
56287 - 90 90 90 26 26 26 2 2 6 2 2 6
56288 - 14 14 14 195 195 195 250 250 250 253 253 253
56289 -253 253 253 253 253 253 253 253 253 253 253 253
56290 -253 253 253 253 253 253 253 253 253 253 253 253
56291 -253 253 253 253 253 253 253 253 253 253 253 253
56292 -253 253 253 253 253 253 253 253 253 253 253 253
56293 -250 250 250 242 242 242 54 54 54 2 2 6
56294 - 2 2 6 2 2 6 2 2 6 2 2 6
56295 - 2 2 6 2 2 6 2 2 6 38 38 38
56296 - 86 86 86 50 50 50 22 22 22 6 6 6
56297 - 0 0 0 0 0 0 0 0 0 0 0 0
56298 - 0 0 0 0 0 0 0 0 0 0 0 0
56299 - 0 0 0 0 0 0 0 0 0 0 0 0
56300 - 0 0 0 0 0 0 0 0 0 0 0 0
56301 - 0 0 0 0 0 0 0 0 0 0 0 0
56302 - 0 0 0 0 0 0 0 0 0 0 0 0
56303 - 0 0 0 0 0 0 0 0 0 0 0 0
56304 - 0 0 0 0 0 0 0 0 0 0 0 0
56305 - 0 0 0 0 0 0 0 0 0 0 0 0
56306 - 6 6 6 14 14 14 38 38 38 82 82 82
56307 - 34 34 34 2 2 6 2 2 6 2 2 6
56308 - 42 42 42 195 195 195 246 246 246 253 253 253
56309 -253 253 253 253 253 253 253 253 253 250 250 250
56310 -242 242 242 242 242 242 250 250 250 253 253 253
56311 -253 253 253 253 253 253 253 253 253 253 253 253
56312 -253 253 253 250 250 250 246 246 246 238 238 238
56313 -226 226 226 231 231 231 101 101 101 6 6 6
56314 - 2 2 6 2 2 6 2 2 6 2 2 6
56315 - 2 2 6 2 2 6 2 2 6 2 2 6
56316 - 38 38 38 82 82 82 42 42 42 14 14 14
56317 - 6 6 6 0 0 0 0 0 0 0 0 0
56318 - 0 0 0 0 0 0 0 0 0 0 0 0
56319 - 0 0 0 0 0 0 0 0 0 0 0 0
56320 - 0 0 0 0 0 0 0 0 0 0 0 0
56321 - 0 0 0 0 0 0 0 0 0 0 0 0
56322 - 0 0 0 0 0 0 0 0 0 0 0 0
56323 - 0 0 0 0 0 0 0 0 0 0 0 0
56324 - 0 0 0 0 0 0 0 0 0 0 0 0
56325 - 0 0 0 0 0 0 0 0 0 0 0 0
56326 - 10 10 10 26 26 26 62 62 62 66 66 66
56327 - 2 2 6 2 2 6 2 2 6 6 6 6
56328 - 70 70 70 170 170 170 206 206 206 234 234 234
56329 -246 246 246 250 250 250 250 250 250 238 238 238
56330 -226 226 226 231 231 231 238 238 238 250 250 250
56331 -250 250 250 250 250 250 246 246 246 231 231 231
56332 -214 214 214 206 206 206 202 202 202 202 202 202
56333 -198 198 198 202 202 202 182 182 182 18 18 18
56334 - 2 2 6 2 2 6 2 2 6 2 2 6
56335 - 2 2 6 2 2 6 2 2 6 2 2 6
56336 - 2 2 6 62 62 62 66 66 66 30 30 30
56337 - 10 10 10 0 0 0 0 0 0 0 0 0
56338 - 0 0 0 0 0 0 0 0 0 0 0 0
56339 - 0 0 0 0 0 0 0 0 0 0 0 0
56340 - 0 0 0 0 0 0 0 0 0 0 0 0
56341 - 0 0 0 0 0 0 0 0 0 0 0 0
56342 - 0 0 0 0 0 0 0 0 0 0 0 0
56343 - 0 0 0 0 0 0 0 0 0 0 0 0
56344 - 0 0 0 0 0 0 0 0 0 0 0 0
56345 - 0 0 0 0 0 0 0 0 0 0 0 0
56346 - 14 14 14 42 42 42 82 82 82 18 18 18
56347 - 2 2 6 2 2 6 2 2 6 10 10 10
56348 - 94 94 94 182 182 182 218 218 218 242 242 242
56349 -250 250 250 253 253 253 253 253 253 250 250 250
56350 -234 234 234 253 253 253 253 253 253 253 253 253
56351 -253 253 253 253 253 253 253 253 253 246 246 246
56352 -238 238 238 226 226 226 210 210 210 202 202 202
56353 -195 195 195 195 195 195 210 210 210 158 158 158
56354 - 6 6 6 14 14 14 50 50 50 14 14 14
56355 - 2 2 6 2 2 6 2 2 6 2 2 6
56356 - 2 2 6 6 6 6 86 86 86 46 46 46
56357 - 18 18 18 6 6 6 0 0 0 0 0 0
56358 - 0 0 0 0 0 0 0 0 0 0 0 0
56359 - 0 0 0 0 0 0 0 0 0 0 0 0
56360 - 0 0 0 0 0 0 0 0 0 0 0 0
56361 - 0 0 0 0 0 0 0 0 0 0 0 0
56362 - 0 0 0 0 0 0 0 0 0 0 0 0
56363 - 0 0 0 0 0 0 0 0 0 0 0 0
56364 - 0 0 0 0 0 0 0 0 0 0 0 0
56365 - 0 0 0 0 0 0 0 0 0 6 6 6
56366 - 22 22 22 54 54 54 70 70 70 2 2 6
56367 - 2 2 6 10 10 10 2 2 6 22 22 22
56368 -166 166 166 231 231 231 250 250 250 253 253 253
56369 -253 253 253 253 253 253 253 253 253 250 250 250
56370 -242 242 242 253 253 253 253 253 253 253 253 253
56371 -253 253 253 253 253 253 253 253 253 253 253 253
56372 -253 253 253 253 253 253 253 253 253 246 246 246
56373 -231 231 231 206 206 206 198 198 198 226 226 226
56374 - 94 94 94 2 2 6 6 6 6 38 38 38
56375 - 30 30 30 2 2 6 2 2 6 2 2 6
56376 - 2 2 6 2 2 6 62 62 62 66 66 66
56377 - 26 26 26 10 10 10 0 0 0 0 0 0
56378 - 0 0 0 0 0 0 0 0 0 0 0 0
56379 - 0 0 0 0 0 0 0 0 0 0 0 0
56380 - 0 0 0 0 0 0 0 0 0 0 0 0
56381 - 0 0 0 0 0 0 0 0 0 0 0 0
56382 - 0 0 0 0 0 0 0 0 0 0 0 0
56383 - 0 0 0 0 0 0 0 0 0 0 0 0
56384 - 0 0 0 0 0 0 0 0 0 0 0 0
56385 - 0 0 0 0 0 0 0 0 0 10 10 10
56386 - 30 30 30 74 74 74 50 50 50 2 2 6
56387 - 26 26 26 26 26 26 2 2 6 106 106 106
56388 -238 238 238 253 253 253 253 253 253 253 253 253
56389 -253 253 253 253 253 253 253 253 253 253 253 253
56390 -253 253 253 253 253 253 253 253 253 253 253 253
56391 -253 253 253 253 253 253 253 253 253 253 253 253
56392 -253 253 253 253 253 253 253 253 253 253 253 253
56393 -253 253 253 246 246 246 218 218 218 202 202 202
56394 -210 210 210 14 14 14 2 2 6 2 2 6
56395 - 30 30 30 22 22 22 2 2 6 2 2 6
56396 - 2 2 6 2 2 6 18 18 18 86 86 86
56397 - 42 42 42 14 14 14 0 0 0 0 0 0
56398 - 0 0 0 0 0 0 0 0 0 0 0 0
56399 - 0 0 0 0 0 0 0 0 0 0 0 0
56400 - 0 0 0 0 0 0 0 0 0 0 0 0
56401 - 0 0 0 0 0 0 0 0 0 0 0 0
56402 - 0 0 0 0 0 0 0 0 0 0 0 0
56403 - 0 0 0 0 0 0 0 0 0 0 0 0
56404 - 0 0 0 0 0 0 0 0 0 0 0 0
56405 - 0 0 0 0 0 0 0 0 0 14 14 14
56406 - 42 42 42 90 90 90 22 22 22 2 2 6
56407 - 42 42 42 2 2 6 18 18 18 218 218 218
56408 -253 253 253 253 253 253 253 253 253 253 253 253
56409 -253 253 253 253 253 253 253 253 253 253 253 253
56410 -253 253 253 253 253 253 253 253 253 253 253 253
56411 -253 253 253 253 253 253 253 253 253 253 253 253
56412 -253 253 253 253 253 253 253 253 253 253 253 253
56413 -253 253 253 253 253 253 250 250 250 221 221 221
56414 -218 218 218 101 101 101 2 2 6 14 14 14
56415 - 18 18 18 38 38 38 10 10 10 2 2 6
56416 - 2 2 6 2 2 6 2 2 6 78 78 78
56417 - 58 58 58 22 22 22 6 6 6 0 0 0
56418 - 0 0 0 0 0 0 0 0 0 0 0 0
56419 - 0 0 0 0 0 0 0 0 0 0 0 0
56420 - 0 0 0 0 0 0 0 0 0 0 0 0
56421 - 0 0 0 0 0 0 0 0 0 0 0 0
56422 - 0 0 0 0 0 0 0 0 0 0 0 0
56423 - 0 0 0 0 0 0 0 0 0 0 0 0
56424 - 0 0 0 0 0 0 0 0 0 0 0 0
56425 - 0 0 0 0 0 0 6 6 6 18 18 18
56426 - 54 54 54 82 82 82 2 2 6 26 26 26
56427 - 22 22 22 2 2 6 123 123 123 253 253 253
56428 -253 253 253 253 253 253 253 253 253 253 253 253
56429 -253 253 253 253 253 253 253 253 253 253 253 253
56430 -253 253 253 253 253 253 253 253 253 253 253 253
56431 -253 253 253 253 253 253 253 253 253 253 253 253
56432 -253 253 253 253 253 253 253 253 253 253 253 253
56433 -253 253 253 253 253 253 253 253 253 250 250 250
56434 -238 238 238 198 198 198 6 6 6 38 38 38
56435 - 58 58 58 26 26 26 38 38 38 2 2 6
56436 - 2 2 6 2 2 6 2 2 6 46 46 46
56437 - 78 78 78 30 30 30 10 10 10 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 0 0 0
56439 - 0 0 0 0 0 0 0 0 0 0 0 0
56440 - 0 0 0 0 0 0 0 0 0 0 0 0
56441 - 0 0 0 0 0 0 0 0 0 0 0 0
56442 - 0 0 0 0 0 0 0 0 0 0 0 0
56443 - 0 0 0 0 0 0 0 0 0 0 0 0
56444 - 0 0 0 0 0 0 0 0 0 0 0 0
56445 - 0 0 0 0 0 0 10 10 10 30 30 30
56446 - 74 74 74 58 58 58 2 2 6 42 42 42
56447 - 2 2 6 22 22 22 231 231 231 253 253 253
56448 -253 253 253 253 253 253 253 253 253 253 253 253
56449 -253 253 253 253 253 253 253 253 253 250 250 250
56450 -253 253 253 253 253 253 253 253 253 253 253 253
56451 -253 253 253 253 253 253 253 253 253 253 253 253
56452 -253 253 253 253 253 253 253 253 253 253 253 253
56453 -253 253 253 253 253 253 253 253 253 253 253 253
56454 -253 253 253 246 246 246 46 46 46 38 38 38
56455 - 42 42 42 14 14 14 38 38 38 14 14 14
56456 - 2 2 6 2 2 6 2 2 6 6 6 6
56457 - 86 86 86 46 46 46 14 14 14 0 0 0
56458 - 0 0 0 0 0 0 0 0 0 0 0 0
56459 - 0 0 0 0 0 0 0 0 0 0 0 0
56460 - 0 0 0 0 0 0 0 0 0 0 0 0
56461 - 0 0 0 0 0 0 0 0 0 0 0 0
56462 - 0 0 0 0 0 0 0 0 0 0 0 0
56463 - 0 0 0 0 0 0 0 0 0 0 0 0
56464 - 0 0 0 0 0 0 0 0 0 0 0 0
56465 - 0 0 0 6 6 6 14 14 14 42 42 42
56466 - 90 90 90 18 18 18 18 18 18 26 26 26
56467 - 2 2 6 116 116 116 253 253 253 253 253 253
56468 -253 253 253 253 253 253 253 253 253 253 253 253
56469 -253 253 253 253 253 253 250 250 250 238 238 238
56470 -253 253 253 253 253 253 253 253 253 253 253 253
56471 -253 253 253 253 253 253 253 253 253 253 253 253
56472 -253 253 253 253 253 253 253 253 253 253 253 253
56473 -253 253 253 253 253 253 253 253 253 253 253 253
56474 -253 253 253 253 253 253 94 94 94 6 6 6
56475 - 2 2 6 2 2 6 10 10 10 34 34 34
56476 - 2 2 6 2 2 6 2 2 6 2 2 6
56477 - 74 74 74 58 58 58 22 22 22 6 6 6
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 0 0 0 0 0 0 0 0 0 0 0 0
56480 - 0 0 0 0 0 0 0 0 0 0 0 0
56481 - 0 0 0 0 0 0 0 0 0 0 0 0
56482 - 0 0 0 0 0 0 0 0 0 0 0 0
56483 - 0 0 0 0 0 0 0 0 0 0 0 0
56484 - 0 0 0 0 0 0 0 0 0 0 0 0
56485 - 0 0 0 10 10 10 26 26 26 66 66 66
56486 - 82 82 82 2 2 6 38 38 38 6 6 6
56487 - 14 14 14 210 210 210 253 253 253 253 253 253
56488 -253 253 253 253 253 253 253 253 253 253 253 253
56489 -253 253 253 253 253 253 246 246 246 242 242 242
56490 -253 253 253 253 253 253 253 253 253 253 253 253
56491 -253 253 253 253 253 253 253 253 253 253 253 253
56492 -253 253 253 253 253 253 253 253 253 253 253 253
56493 -253 253 253 253 253 253 253 253 253 253 253 253
56494 -253 253 253 253 253 253 144 144 144 2 2 6
56495 - 2 2 6 2 2 6 2 2 6 46 46 46
56496 - 2 2 6 2 2 6 2 2 6 2 2 6
56497 - 42 42 42 74 74 74 30 30 30 10 10 10
56498 - 0 0 0 0 0 0 0 0 0 0 0 0
56499 - 0 0 0 0 0 0 0 0 0 0 0 0
56500 - 0 0 0 0 0 0 0 0 0 0 0 0
56501 - 0 0 0 0 0 0 0 0 0 0 0 0
56502 - 0 0 0 0 0 0 0 0 0 0 0 0
56503 - 0 0 0 0 0 0 0 0 0 0 0 0
56504 - 0 0 0 0 0 0 0 0 0 0 0 0
56505 - 6 6 6 14 14 14 42 42 42 90 90 90
56506 - 26 26 26 6 6 6 42 42 42 2 2 6
56507 - 74 74 74 250 250 250 253 253 253 253 253 253
56508 -253 253 253 253 253 253 253 253 253 253 253 253
56509 -253 253 253 253 253 253 242 242 242 242 242 242
56510 -253 253 253 253 253 253 253 253 253 253 253 253
56511 -253 253 253 253 253 253 253 253 253 253 253 253
56512 -253 253 253 253 253 253 253 253 253 253 253 253
56513 -253 253 253 253 253 253 253 253 253 253 253 253
56514 -253 253 253 253 253 253 182 182 182 2 2 6
56515 - 2 2 6 2 2 6 2 2 6 46 46 46
56516 - 2 2 6 2 2 6 2 2 6 2 2 6
56517 - 10 10 10 86 86 86 38 38 38 10 10 10
56518 - 0 0 0 0 0 0 0 0 0 0 0 0
56519 - 0 0 0 0 0 0 0 0 0 0 0 0
56520 - 0 0 0 0 0 0 0 0 0 0 0 0
56521 - 0 0 0 0 0 0 0 0 0 0 0 0
56522 - 0 0 0 0 0 0 0 0 0 0 0 0
56523 - 0 0 0 0 0 0 0 0 0 0 0 0
56524 - 0 0 0 0 0 0 0 0 0 0 0 0
56525 - 10 10 10 26 26 26 66 66 66 82 82 82
56526 - 2 2 6 22 22 22 18 18 18 2 2 6
56527 -149 149 149 253 253 253 253 253 253 253 253 253
56528 -253 253 253 253 253 253 253 253 253 253 253 253
56529 -253 253 253 253 253 253 234 234 234 242 242 242
56530 -253 253 253 253 253 253 253 253 253 253 253 253
56531 -253 253 253 253 253 253 253 253 253 253 253 253
56532 -253 253 253 253 253 253 253 253 253 253 253 253
56533 -253 253 253 253 253 253 253 253 253 253 253 253
56534 -253 253 253 253 253 253 206 206 206 2 2 6
56535 - 2 2 6 2 2 6 2 2 6 38 38 38
56536 - 2 2 6 2 2 6 2 2 6 2 2 6
56537 - 6 6 6 86 86 86 46 46 46 14 14 14
56538 - 0 0 0 0 0 0 0 0 0 0 0 0
56539 - 0 0 0 0 0 0 0 0 0 0 0 0
56540 - 0 0 0 0 0 0 0 0 0 0 0 0
56541 - 0 0 0 0 0 0 0 0 0 0 0 0
56542 - 0 0 0 0 0 0 0 0 0 0 0 0
56543 - 0 0 0 0 0 0 0 0 0 0 0 0
56544 - 0 0 0 0 0 0 0 0 0 6 6 6
56545 - 18 18 18 46 46 46 86 86 86 18 18 18
56546 - 2 2 6 34 34 34 10 10 10 6 6 6
56547 -210 210 210 253 253 253 253 253 253 253 253 253
56548 -253 253 253 253 253 253 253 253 253 253 253 253
56549 -253 253 253 253 253 253 234 234 234 242 242 242
56550 -253 253 253 253 253 253 253 253 253 253 253 253
56551 -253 253 253 253 253 253 253 253 253 253 253 253
56552 -253 253 253 253 253 253 253 253 253 253 253 253
56553 -253 253 253 253 253 253 253 253 253 253 253 253
56554 -253 253 253 253 253 253 221 221 221 6 6 6
56555 - 2 2 6 2 2 6 6 6 6 30 30 30
56556 - 2 2 6 2 2 6 2 2 6 2 2 6
56557 - 2 2 6 82 82 82 54 54 54 18 18 18
56558 - 6 6 6 0 0 0 0 0 0 0 0 0
56559 - 0 0 0 0 0 0 0 0 0 0 0 0
56560 - 0 0 0 0 0 0 0 0 0 0 0 0
56561 - 0 0 0 0 0 0 0 0 0 0 0 0
56562 - 0 0 0 0 0 0 0 0 0 0 0 0
56563 - 0 0 0 0 0 0 0 0 0 0 0 0
56564 - 0 0 0 0 0 0 0 0 0 10 10 10
56565 - 26 26 26 66 66 66 62 62 62 2 2 6
56566 - 2 2 6 38 38 38 10 10 10 26 26 26
56567 -238 238 238 253 253 253 253 253 253 253 253 253
56568 -253 253 253 253 253 253 253 253 253 253 253 253
56569 -253 253 253 253 253 253 231 231 231 238 238 238
56570 -253 253 253 253 253 253 253 253 253 253 253 253
56571 -253 253 253 253 253 253 253 253 253 253 253 253
56572 -253 253 253 253 253 253 253 253 253 253 253 253
56573 -253 253 253 253 253 253 253 253 253 253 253 253
56574 -253 253 253 253 253 253 231 231 231 6 6 6
56575 - 2 2 6 2 2 6 10 10 10 30 30 30
56576 - 2 2 6 2 2 6 2 2 6 2 2 6
56577 - 2 2 6 66 66 66 58 58 58 22 22 22
56578 - 6 6 6 0 0 0 0 0 0 0 0 0
56579 - 0 0 0 0 0 0 0 0 0 0 0 0
56580 - 0 0 0 0 0 0 0 0 0 0 0 0
56581 - 0 0 0 0 0 0 0 0 0 0 0 0
56582 - 0 0 0 0 0 0 0 0 0 0 0 0
56583 - 0 0 0 0 0 0 0 0 0 0 0 0
56584 - 0 0 0 0 0 0 0 0 0 10 10 10
56585 - 38 38 38 78 78 78 6 6 6 2 2 6
56586 - 2 2 6 46 46 46 14 14 14 42 42 42
56587 -246 246 246 253 253 253 253 253 253 253 253 253
56588 -253 253 253 253 253 253 253 253 253 253 253 253
56589 -253 253 253 253 253 253 231 231 231 242 242 242
56590 -253 253 253 253 253 253 253 253 253 253 253 253
56591 -253 253 253 253 253 253 253 253 253 253 253 253
56592 -253 253 253 253 253 253 253 253 253 253 253 253
56593 -253 253 253 253 253 253 253 253 253 253 253 253
56594 -253 253 253 253 253 253 234 234 234 10 10 10
56595 - 2 2 6 2 2 6 22 22 22 14 14 14
56596 - 2 2 6 2 2 6 2 2 6 2 2 6
56597 - 2 2 6 66 66 66 62 62 62 22 22 22
56598 - 6 6 6 0 0 0 0 0 0 0 0 0
56599 - 0 0 0 0 0 0 0 0 0 0 0 0
56600 - 0 0 0 0 0 0 0 0 0 0 0 0
56601 - 0 0 0 0 0 0 0 0 0 0 0 0
56602 - 0 0 0 0 0 0 0 0 0 0 0 0
56603 - 0 0 0 0 0 0 0 0 0 0 0 0
56604 - 0 0 0 0 0 0 6 6 6 18 18 18
56605 - 50 50 50 74 74 74 2 2 6 2 2 6
56606 - 14 14 14 70 70 70 34 34 34 62 62 62
56607 -250 250 250 253 253 253 253 253 253 253 253 253
56608 -253 253 253 253 253 253 253 253 253 253 253 253
56609 -253 253 253 253 253 253 231 231 231 246 246 246
56610 -253 253 253 253 253 253 253 253 253 253 253 253
56611 -253 253 253 253 253 253 253 253 253 253 253 253
56612 -253 253 253 253 253 253 253 253 253 253 253 253
56613 -253 253 253 253 253 253 253 253 253 253 253 253
56614 -253 253 253 253 253 253 234 234 234 14 14 14
56615 - 2 2 6 2 2 6 30 30 30 2 2 6
56616 - 2 2 6 2 2 6 2 2 6 2 2 6
56617 - 2 2 6 66 66 66 62 62 62 22 22 22
56618 - 6 6 6 0 0 0 0 0 0 0 0 0
56619 - 0 0 0 0 0 0 0 0 0 0 0 0
56620 - 0 0 0 0 0 0 0 0 0 0 0 0
56621 - 0 0 0 0 0 0 0 0 0 0 0 0
56622 - 0 0 0 0 0 0 0 0 0 0 0 0
56623 - 0 0 0 0 0 0 0 0 0 0 0 0
56624 - 0 0 0 0 0 0 6 6 6 18 18 18
56625 - 54 54 54 62 62 62 2 2 6 2 2 6
56626 - 2 2 6 30 30 30 46 46 46 70 70 70
56627 -250 250 250 253 253 253 253 253 253 253 253 253
56628 -253 253 253 253 253 253 253 253 253 253 253 253
56629 -253 253 253 253 253 253 231 231 231 246 246 246
56630 -253 253 253 253 253 253 253 253 253 253 253 253
56631 -253 253 253 253 253 253 253 253 253 253 253 253
56632 -253 253 253 253 253 253 253 253 253 253 253 253
56633 -253 253 253 253 253 253 253 253 253 253 253 253
56634 -253 253 253 253 253 253 226 226 226 10 10 10
56635 - 2 2 6 6 6 6 30 30 30 2 2 6
56636 - 2 2 6 2 2 6 2 2 6 2 2 6
56637 - 2 2 6 66 66 66 58 58 58 22 22 22
56638 - 6 6 6 0 0 0 0 0 0 0 0 0
56639 - 0 0 0 0 0 0 0 0 0 0 0 0
56640 - 0 0 0 0 0 0 0 0 0 0 0 0
56641 - 0 0 0 0 0 0 0 0 0 0 0 0
56642 - 0 0 0 0 0 0 0 0 0 0 0 0
56643 - 0 0 0 0 0 0 0 0 0 0 0 0
56644 - 0 0 0 0 0 0 6 6 6 22 22 22
56645 - 58 58 58 62 62 62 2 2 6 2 2 6
56646 - 2 2 6 2 2 6 30 30 30 78 78 78
56647 -250 250 250 253 253 253 253 253 253 253 253 253
56648 -253 253 253 253 253 253 253 253 253 253 253 253
56649 -253 253 253 253 253 253 231 231 231 246 246 246
56650 -253 253 253 253 253 253 253 253 253 253 253 253
56651 -253 253 253 253 253 253 253 253 253 253 253 253
56652 -253 253 253 253 253 253 253 253 253 253 253 253
56653 -253 253 253 253 253 253 253 253 253 253 253 253
56654 -253 253 253 253 253 253 206 206 206 2 2 6
56655 - 22 22 22 34 34 34 18 14 6 22 22 22
56656 - 26 26 26 18 18 18 6 6 6 2 2 6
56657 - 2 2 6 82 82 82 54 54 54 18 18 18
56658 - 6 6 6 0 0 0 0 0 0 0 0 0
56659 - 0 0 0 0 0 0 0 0 0 0 0 0
56660 - 0 0 0 0 0 0 0 0 0 0 0 0
56661 - 0 0 0 0 0 0 0 0 0 0 0 0
56662 - 0 0 0 0 0 0 0 0 0 0 0 0
56663 - 0 0 0 0 0 0 0 0 0 0 0 0
56664 - 0 0 0 0 0 0 6 6 6 26 26 26
56665 - 62 62 62 106 106 106 74 54 14 185 133 11
56666 -210 162 10 121 92 8 6 6 6 62 62 62
56667 -238 238 238 253 253 253 253 253 253 253 253 253
56668 -253 253 253 253 253 253 253 253 253 253 253 253
56669 -253 253 253 253 253 253 231 231 231 246 246 246
56670 -253 253 253 253 253 253 253 253 253 253 253 253
56671 -253 253 253 253 253 253 253 253 253 253 253 253
56672 -253 253 253 253 253 253 253 253 253 253 253 253
56673 -253 253 253 253 253 253 253 253 253 253 253 253
56674 -253 253 253 253 253 253 158 158 158 18 18 18
56675 - 14 14 14 2 2 6 2 2 6 2 2 6
56676 - 6 6 6 18 18 18 66 66 66 38 38 38
56677 - 6 6 6 94 94 94 50 50 50 18 18 18
56678 - 6 6 6 0 0 0 0 0 0 0 0 0
56679 - 0 0 0 0 0 0 0 0 0 0 0 0
56680 - 0 0 0 0 0 0 0 0 0 0 0 0
56681 - 0 0 0 0 0 0 0 0 0 0 0 0
56682 - 0 0 0 0 0 0 0 0 0 0 0 0
56683 - 0 0 0 0 0 0 0 0 0 6 6 6
56684 - 10 10 10 10 10 10 18 18 18 38 38 38
56685 - 78 78 78 142 134 106 216 158 10 242 186 14
56686 -246 190 14 246 190 14 156 118 10 10 10 10
56687 - 90 90 90 238 238 238 253 253 253 253 253 253
56688 -253 253 253 253 253 253 253 253 253 253 253 253
56689 -253 253 253 253 253 253 231 231 231 250 250 250
56690 -253 253 253 253 253 253 253 253 253 253 253 253
56691 -253 253 253 253 253 253 253 253 253 253 253 253
56692 -253 253 253 253 253 253 253 253 253 253 253 253
56693 -253 253 253 253 253 253 253 253 253 246 230 190
56694 -238 204 91 238 204 91 181 142 44 37 26 9
56695 - 2 2 6 2 2 6 2 2 6 2 2 6
56696 - 2 2 6 2 2 6 38 38 38 46 46 46
56697 - 26 26 26 106 106 106 54 54 54 18 18 18
56698 - 6 6 6 0 0 0 0 0 0 0 0 0
56699 - 0 0 0 0 0 0 0 0 0 0 0 0
56700 - 0 0 0 0 0 0 0 0 0 0 0 0
56701 - 0 0 0 0 0 0 0 0 0 0 0 0
56702 - 0 0 0 0 0 0 0 0 0 0 0 0
56703 - 0 0 0 6 6 6 14 14 14 22 22 22
56704 - 30 30 30 38 38 38 50 50 50 70 70 70
56705 -106 106 106 190 142 34 226 170 11 242 186 14
56706 -246 190 14 246 190 14 246 190 14 154 114 10
56707 - 6 6 6 74 74 74 226 226 226 253 253 253
56708 -253 253 253 253 253 253 253 253 253 253 253 253
56709 -253 253 253 253 253 253 231 231 231 250 250 250
56710 -253 253 253 253 253 253 253 253 253 253 253 253
56711 -253 253 253 253 253 253 253 253 253 253 253 253
56712 -253 253 253 253 253 253 253 253 253 253 253 253
56713 -253 253 253 253 253 253 253 253 253 228 184 62
56714 -241 196 14 241 208 19 232 195 16 38 30 10
56715 - 2 2 6 2 2 6 2 2 6 2 2 6
56716 - 2 2 6 6 6 6 30 30 30 26 26 26
56717 -203 166 17 154 142 90 66 66 66 26 26 26
56718 - 6 6 6 0 0 0 0 0 0 0 0 0
56719 - 0 0 0 0 0 0 0 0 0 0 0 0
56720 - 0 0 0 0 0 0 0 0 0 0 0 0
56721 - 0 0 0 0 0 0 0 0 0 0 0 0
56722 - 0 0 0 0 0 0 0 0 0 0 0 0
56723 - 6 6 6 18 18 18 38 38 38 58 58 58
56724 - 78 78 78 86 86 86 101 101 101 123 123 123
56725 -175 146 61 210 150 10 234 174 13 246 186 14
56726 -246 190 14 246 190 14 246 190 14 238 190 10
56727 -102 78 10 2 2 6 46 46 46 198 198 198
56728 -253 253 253 253 253 253 253 253 253 253 253 253
56729 -253 253 253 253 253 253 234 234 234 242 242 242
56730 -253 253 253 253 253 253 253 253 253 253 253 253
56731 -253 253 253 253 253 253 253 253 253 253 253 253
56732 -253 253 253 253 253 253 253 253 253 253 253 253
56733 -253 253 253 253 253 253 253 253 253 224 178 62
56734 -242 186 14 241 196 14 210 166 10 22 18 6
56735 - 2 2 6 2 2 6 2 2 6 2 2 6
56736 - 2 2 6 2 2 6 6 6 6 121 92 8
56737 -238 202 15 232 195 16 82 82 82 34 34 34
56738 - 10 10 10 0 0 0 0 0 0 0 0 0
56739 - 0 0 0 0 0 0 0 0 0 0 0 0
56740 - 0 0 0 0 0 0 0 0 0 0 0 0
56741 - 0 0 0 0 0 0 0 0 0 0 0 0
56742 - 0 0 0 0 0 0 0 0 0 0 0 0
56743 - 14 14 14 38 38 38 70 70 70 154 122 46
56744 -190 142 34 200 144 11 197 138 11 197 138 11
56745 -213 154 11 226 170 11 242 186 14 246 190 14
56746 -246 190 14 246 190 14 246 190 14 246 190 14
56747 -225 175 15 46 32 6 2 2 6 22 22 22
56748 -158 158 158 250 250 250 253 253 253 253 253 253
56749 -253 253 253 253 253 253 253 253 253 253 253 253
56750 -253 253 253 253 253 253 253 253 253 253 253 253
56751 -253 253 253 253 253 253 253 253 253 253 253 253
56752 -253 253 253 253 253 253 253 253 253 253 253 253
56753 -253 253 253 250 250 250 242 242 242 224 178 62
56754 -239 182 13 236 186 11 213 154 11 46 32 6
56755 - 2 2 6 2 2 6 2 2 6 2 2 6
56756 - 2 2 6 2 2 6 61 42 6 225 175 15
56757 -238 190 10 236 186 11 112 100 78 42 42 42
56758 - 14 14 14 0 0 0 0 0 0 0 0 0
56759 - 0 0 0 0 0 0 0 0 0 0 0 0
56760 - 0 0 0 0 0 0 0 0 0 0 0 0
56761 - 0 0 0 0 0 0 0 0 0 0 0 0
56762 - 0 0 0 0 0 0 0 0 0 6 6 6
56763 - 22 22 22 54 54 54 154 122 46 213 154 11
56764 -226 170 11 230 174 11 226 170 11 226 170 11
56765 -236 178 12 242 186 14 246 190 14 246 190 14
56766 -246 190 14 246 190 14 246 190 14 246 190 14
56767 -241 196 14 184 144 12 10 10 10 2 2 6
56768 - 6 6 6 116 116 116 242 242 242 253 253 253
56769 -253 253 253 253 253 253 253 253 253 253 253 253
56770 -253 253 253 253 253 253 253 253 253 253 253 253
56771 -253 253 253 253 253 253 253 253 253 253 253 253
56772 -253 253 253 253 253 253 253 253 253 253 253 253
56773 -253 253 253 231 231 231 198 198 198 214 170 54
56774 -236 178 12 236 178 12 210 150 10 137 92 6
56775 - 18 14 6 2 2 6 2 2 6 2 2 6
56776 - 6 6 6 70 47 6 200 144 11 236 178 12
56777 -239 182 13 239 182 13 124 112 88 58 58 58
56778 - 22 22 22 6 6 6 0 0 0 0 0 0
56779 - 0 0 0 0 0 0 0 0 0 0 0 0
56780 - 0 0 0 0 0 0 0 0 0 0 0 0
56781 - 0 0 0 0 0 0 0 0 0 0 0 0
56782 - 0 0 0 0 0 0 0 0 0 10 10 10
56783 - 30 30 30 70 70 70 180 133 36 226 170 11
56784 -239 182 13 242 186 14 242 186 14 246 186 14
56785 -246 190 14 246 190 14 246 190 14 246 190 14
56786 -246 190 14 246 190 14 246 190 14 246 190 14
56787 -246 190 14 232 195 16 98 70 6 2 2 6
56788 - 2 2 6 2 2 6 66 66 66 221 221 221
56789 -253 253 253 253 253 253 253 253 253 253 253 253
56790 -253 253 253 253 253 253 253 253 253 253 253 253
56791 -253 253 253 253 253 253 253 253 253 253 253 253
56792 -253 253 253 253 253 253 253 253 253 253 253 253
56793 -253 253 253 206 206 206 198 198 198 214 166 58
56794 -230 174 11 230 174 11 216 158 10 192 133 9
56795 -163 110 8 116 81 8 102 78 10 116 81 8
56796 -167 114 7 197 138 11 226 170 11 239 182 13
56797 -242 186 14 242 186 14 162 146 94 78 78 78
56798 - 34 34 34 14 14 14 6 6 6 0 0 0
56799 - 0 0 0 0 0 0 0 0 0 0 0 0
56800 - 0 0 0 0 0 0 0 0 0 0 0 0
56801 - 0 0 0 0 0 0 0 0 0 0 0 0
56802 - 0 0 0 0 0 0 0 0 0 6 6 6
56803 - 30 30 30 78 78 78 190 142 34 226 170 11
56804 -239 182 13 246 190 14 246 190 14 246 190 14
56805 -246 190 14 246 190 14 246 190 14 246 190 14
56806 -246 190 14 246 190 14 246 190 14 246 190 14
56807 -246 190 14 241 196 14 203 166 17 22 18 6
56808 - 2 2 6 2 2 6 2 2 6 38 38 38
56809 -218 218 218 253 253 253 253 253 253 253 253 253
56810 -253 253 253 253 253 253 253 253 253 253 253 253
56811 -253 253 253 253 253 253 253 253 253 253 253 253
56812 -253 253 253 253 253 253 253 253 253 253 253 253
56813 -250 250 250 206 206 206 198 198 198 202 162 69
56814 -226 170 11 236 178 12 224 166 10 210 150 10
56815 -200 144 11 197 138 11 192 133 9 197 138 11
56816 -210 150 10 226 170 11 242 186 14 246 190 14
56817 -246 190 14 246 186 14 225 175 15 124 112 88
56818 - 62 62 62 30 30 30 14 14 14 6 6 6
56819 - 0 0 0 0 0 0 0 0 0 0 0 0
56820 - 0 0 0 0 0 0 0 0 0 0 0 0
56821 - 0 0 0 0 0 0 0 0 0 0 0 0
56822 - 0 0 0 0 0 0 0 0 0 10 10 10
56823 - 30 30 30 78 78 78 174 135 50 224 166 10
56824 -239 182 13 246 190 14 246 190 14 246 190 14
56825 -246 190 14 246 190 14 246 190 14 246 190 14
56826 -246 190 14 246 190 14 246 190 14 246 190 14
56827 -246 190 14 246 190 14 241 196 14 139 102 15
56828 - 2 2 6 2 2 6 2 2 6 2 2 6
56829 - 78 78 78 250 250 250 253 253 253 253 253 253
56830 -253 253 253 253 253 253 253 253 253 253 253 253
56831 -253 253 253 253 253 253 253 253 253 253 253 253
56832 -253 253 253 253 253 253 253 253 253 253 253 253
56833 -250 250 250 214 214 214 198 198 198 190 150 46
56834 -219 162 10 236 178 12 234 174 13 224 166 10
56835 -216 158 10 213 154 11 213 154 11 216 158 10
56836 -226 170 11 239 182 13 246 190 14 246 190 14
56837 -246 190 14 246 190 14 242 186 14 206 162 42
56838 -101 101 101 58 58 58 30 30 30 14 14 14
56839 - 6 6 6 0 0 0 0 0 0 0 0 0
56840 - 0 0 0 0 0 0 0 0 0 0 0 0
56841 - 0 0 0 0 0 0 0 0 0 0 0 0
56842 - 0 0 0 0 0 0 0 0 0 10 10 10
56843 - 30 30 30 74 74 74 174 135 50 216 158 10
56844 -236 178 12 246 190 14 246 190 14 246 190 14
56845 -246 190 14 246 190 14 246 190 14 246 190 14
56846 -246 190 14 246 190 14 246 190 14 246 190 14
56847 -246 190 14 246 190 14 241 196 14 226 184 13
56848 - 61 42 6 2 2 6 2 2 6 2 2 6
56849 - 22 22 22 238 238 238 253 253 253 253 253 253
56850 -253 253 253 253 253 253 253 253 253 253 253 253
56851 -253 253 253 253 253 253 253 253 253 253 253 253
56852 -253 253 253 253 253 253 253 253 253 253 253 253
56853 -253 253 253 226 226 226 187 187 187 180 133 36
56854 -216 158 10 236 178 12 239 182 13 236 178 12
56855 -230 174 11 226 170 11 226 170 11 230 174 11
56856 -236 178 12 242 186 14 246 190 14 246 190 14
56857 -246 190 14 246 190 14 246 186 14 239 182 13
56858 -206 162 42 106 106 106 66 66 66 34 34 34
56859 - 14 14 14 6 6 6 0 0 0 0 0 0
56860 - 0 0 0 0 0 0 0 0 0 0 0 0
56861 - 0 0 0 0 0 0 0 0 0 0 0 0
56862 - 0 0 0 0 0 0 0 0 0 6 6 6
56863 - 26 26 26 70 70 70 163 133 67 213 154 11
56864 -236 178 12 246 190 14 246 190 14 246 190 14
56865 -246 190 14 246 190 14 246 190 14 246 190 14
56866 -246 190 14 246 190 14 246 190 14 246 190 14
56867 -246 190 14 246 190 14 246 190 14 241 196 14
56868 -190 146 13 18 14 6 2 2 6 2 2 6
56869 - 46 46 46 246 246 246 253 253 253 253 253 253
56870 -253 253 253 253 253 253 253 253 253 253 253 253
56871 -253 253 253 253 253 253 253 253 253 253 253 253
56872 -253 253 253 253 253 253 253 253 253 253 253 253
56873 -253 253 253 221 221 221 86 86 86 156 107 11
56874 -216 158 10 236 178 12 242 186 14 246 186 14
56875 -242 186 14 239 182 13 239 182 13 242 186 14
56876 -242 186 14 246 186 14 246 190 14 246 190 14
56877 -246 190 14 246 190 14 246 190 14 246 190 14
56878 -242 186 14 225 175 15 142 122 72 66 66 66
56879 - 30 30 30 10 10 10 0 0 0 0 0 0
56880 - 0 0 0 0 0 0 0 0 0 0 0 0
56881 - 0 0 0 0 0 0 0 0 0 0 0 0
56882 - 0 0 0 0 0 0 0 0 0 6 6 6
56883 - 26 26 26 70 70 70 163 133 67 210 150 10
56884 -236 178 12 246 190 14 246 190 14 246 190 14
56885 -246 190 14 246 190 14 246 190 14 246 190 14
56886 -246 190 14 246 190 14 246 190 14 246 190 14
56887 -246 190 14 246 190 14 246 190 14 246 190 14
56888 -232 195 16 121 92 8 34 34 34 106 106 106
56889 -221 221 221 253 253 253 253 253 253 253 253 253
56890 -253 253 253 253 253 253 253 253 253 253 253 253
56891 -253 253 253 253 253 253 253 253 253 253 253 253
56892 -253 253 253 253 253 253 253 253 253 253 253 253
56893 -242 242 242 82 82 82 18 14 6 163 110 8
56894 -216 158 10 236 178 12 242 186 14 246 190 14
56895 -246 190 14 246 190 14 246 190 14 246 190 14
56896 -246 190 14 246 190 14 246 190 14 246 190 14
56897 -246 190 14 246 190 14 246 190 14 246 190 14
56898 -246 190 14 246 190 14 242 186 14 163 133 67
56899 - 46 46 46 18 18 18 6 6 6 0 0 0
56900 - 0 0 0 0 0 0 0 0 0 0 0 0
56901 - 0 0 0 0 0 0 0 0 0 0 0 0
56902 - 0 0 0 0 0 0 0 0 0 10 10 10
56903 - 30 30 30 78 78 78 163 133 67 210 150 10
56904 -236 178 12 246 186 14 246 190 14 246 190 14
56905 -246 190 14 246 190 14 246 190 14 246 190 14
56906 -246 190 14 246 190 14 246 190 14 246 190 14
56907 -246 190 14 246 190 14 246 190 14 246 190 14
56908 -241 196 14 215 174 15 190 178 144 253 253 253
56909 -253 253 253 253 253 253 253 253 253 253 253 253
56910 -253 253 253 253 253 253 253 253 253 253 253 253
56911 -253 253 253 253 253 253 253 253 253 253 253 253
56912 -253 253 253 253 253 253 253 253 253 218 218 218
56913 - 58 58 58 2 2 6 22 18 6 167 114 7
56914 -216 158 10 236 178 12 246 186 14 246 190 14
56915 -246 190 14 246 190 14 246 190 14 246 190 14
56916 -246 190 14 246 190 14 246 190 14 246 190 14
56917 -246 190 14 246 190 14 246 190 14 246 190 14
56918 -246 190 14 246 186 14 242 186 14 190 150 46
56919 - 54 54 54 22 22 22 6 6 6 0 0 0
56920 - 0 0 0 0 0 0 0 0 0 0 0 0
56921 - 0 0 0 0 0 0 0 0 0 0 0 0
56922 - 0 0 0 0 0 0 0 0 0 14 14 14
56923 - 38 38 38 86 86 86 180 133 36 213 154 11
56924 -236 178 12 246 186 14 246 190 14 246 190 14
56925 -246 190 14 246 190 14 246 190 14 246 190 14
56926 -246 190 14 246 190 14 246 190 14 246 190 14
56927 -246 190 14 246 190 14 246 190 14 246 190 14
56928 -246 190 14 232 195 16 190 146 13 214 214 214
56929 -253 253 253 253 253 253 253 253 253 253 253 253
56930 -253 253 253 253 253 253 253 253 253 253 253 253
56931 -253 253 253 253 253 253 253 253 253 253 253 253
56932 -253 253 253 250 250 250 170 170 170 26 26 26
56933 - 2 2 6 2 2 6 37 26 9 163 110 8
56934 -219 162 10 239 182 13 246 186 14 246 190 14
56935 -246 190 14 246 190 14 246 190 14 246 190 14
56936 -246 190 14 246 190 14 246 190 14 246 190 14
56937 -246 190 14 246 190 14 246 190 14 246 190 14
56938 -246 186 14 236 178 12 224 166 10 142 122 72
56939 - 46 46 46 18 18 18 6 6 6 0 0 0
56940 - 0 0 0 0 0 0 0 0 0 0 0 0
56941 - 0 0 0 0 0 0 0 0 0 0 0 0
56942 - 0 0 0 0 0 0 6 6 6 18 18 18
56943 - 50 50 50 109 106 95 192 133 9 224 166 10
56944 -242 186 14 246 190 14 246 190 14 246 190 14
56945 -246 190 14 246 190 14 246 190 14 246 190 14
56946 -246 190 14 246 190 14 246 190 14 246 190 14
56947 -246 190 14 246 190 14 246 190 14 246 190 14
56948 -242 186 14 226 184 13 210 162 10 142 110 46
56949 -226 226 226 253 253 253 253 253 253 253 253 253
56950 -253 253 253 253 253 253 253 253 253 253 253 253
56951 -253 253 253 253 253 253 253 253 253 253 253 253
56952 -198 198 198 66 66 66 2 2 6 2 2 6
56953 - 2 2 6 2 2 6 50 34 6 156 107 11
56954 -219 162 10 239 182 13 246 186 14 246 190 14
56955 -246 190 14 246 190 14 246 190 14 246 190 14
56956 -246 190 14 246 190 14 246 190 14 246 190 14
56957 -246 190 14 246 190 14 246 190 14 242 186 14
56958 -234 174 13 213 154 11 154 122 46 66 66 66
56959 - 30 30 30 10 10 10 0 0 0 0 0 0
56960 - 0 0 0 0 0 0 0 0 0 0 0 0
56961 - 0 0 0 0 0 0 0 0 0 0 0 0
56962 - 0 0 0 0 0 0 6 6 6 22 22 22
56963 - 58 58 58 154 121 60 206 145 10 234 174 13
56964 -242 186 14 246 186 14 246 190 14 246 190 14
56965 -246 190 14 246 190 14 246 190 14 246 190 14
56966 -246 190 14 246 190 14 246 190 14 246 190 14
56967 -246 190 14 246 190 14 246 190 14 246 190 14
56968 -246 186 14 236 178 12 210 162 10 163 110 8
56969 - 61 42 6 138 138 138 218 218 218 250 250 250
56970 -253 253 253 253 253 253 253 253 253 250 250 250
56971 -242 242 242 210 210 210 144 144 144 66 66 66
56972 - 6 6 6 2 2 6 2 2 6 2 2 6
56973 - 2 2 6 2 2 6 61 42 6 163 110 8
56974 -216 158 10 236 178 12 246 190 14 246 190 14
56975 -246 190 14 246 190 14 246 190 14 246 190 14
56976 -246 190 14 246 190 14 246 190 14 246 190 14
56977 -246 190 14 239 182 13 230 174 11 216 158 10
56978 -190 142 34 124 112 88 70 70 70 38 38 38
56979 - 18 18 18 6 6 6 0 0 0 0 0 0
56980 - 0 0 0 0 0 0 0 0 0 0 0 0
56981 - 0 0 0 0 0 0 0 0 0 0 0 0
56982 - 0 0 0 0 0 0 6 6 6 22 22 22
56983 - 62 62 62 168 124 44 206 145 10 224 166 10
56984 -236 178 12 239 182 13 242 186 14 242 186 14
56985 -246 186 14 246 190 14 246 190 14 246 190 14
56986 -246 190 14 246 190 14 246 190 14 246 190 14
56987 -246 190 14 246 190 14 246 190 14 246 190 14
56988 -246 190 14 236 178 12 216 158 10 175 118 6
56989 - 80 54 7 2 2 6 6 6 6 30 30 30
56990 - 54 54 54 62 62 62 50 50 50 38 38 38
56991 - 14 14 14 2 2 6 2 2 6 2 2 6
56992 - 2 2 6 2 2 6 2 2 6 2 2 6
56993 - 2 2 6 6 6 6 80 54 7 167 114 7
56994 -213 154 11 236 178 12 246 190 14 246 190 14
56995 -246 190 14 246 190 14 246 190 14 246 190 14
56996 -246 190 14 242 186 14 239 182 13 239 182 13
56997 -230 174 11 210 150 10 174 135 50 124 112 88
56998 - 82 82 82 54 54 54 34 34 34 18 18 18
56999 - 6 6 6 0 0 0 0 0 0 0 0 0
57000 - 0 0 0 0 0 0 0 0 0 0 0 0
57001 - 0 0 0 0 0 0 0 0 0 0 0 0
57002 - 0 0 0 0 0 0 6 6 6 18 18 18
57003 - 50 50 50 158 118 36 192 133 9 200 144 11
57004 -216 158 10 219 162 10 224 166 10 226 170 11
57005 -230 174 11 236 178 12 239 182 13 239 182 13
57006 -242 186 14 246 186 14 246 190 14 246 190 14
57007 -246 190 14 246 190 14 246 190 14 246 190 14
57008 -246 186 14 230 174 11 210 150 10 163 110 8
57009 -104 69 6 10 10 10 2 2 6 2 2 6
57010 - 2 2 6 2 2 6 2 2 6 2 2 6
57011 - 2 2 6 2 2 6 2 2 6 2 2 6
57012 - 2 2 6 2 2 6 2 2 6 2 2 6
57013 - 2 2 6 6 6 6 91 60 6 167 114 7
57014 -206 145 10 230 174 11 242 186 14 246 190 14
57015 -246 190 14 246 190 14 246 186 14 242 186 14
57016 -239 182 13 230 174 11 224 166 10 213 154 11
57017 -180 133 36 124 112 88 86 86 86 58 58 58
57018 - 38 38 38 22 22 22 10 10 10 6 6 6
57019 - 0 0 0 0 0 0 0 0 0 0 0 0
57020 - 0 0 0 0 0 0 0 0 0 0 0 0
57021 - 0 0 0 0 0 0 0 0 0 0 0 0
57022 - 0 0 0 0 0 0 0 0 0 14 14 14
57023 - 34 34 34 70 70 70 138 110 50 158 118 36
57024 -167 114 7 180 123 7 192 133 9 197 138 11
57025 -200 144 11 206 145 10 213 154 11 219 162 10
57026 -224 166 10 230 174 11 239 182 13 242 186 14
57027 -246 186 14 246 186 14 246 186 14 246 186 14
57028 -239 182 13 216 158 10 185 133 11 152 99 6
57029 -104 69 6 18 14 6 2 2 6 2 2 6
57030 - 2 2 6 2 2 6 2 2 6 2 2 6
57031 - 2 2 6 2 2 6 2 2 6 2 2 6
57032 - 2 2 6 2 2 6 2 2 6 2 2 6
57033 - 2 2 6 6 6 6 80 54 7 152 99 6
57034 -192 133 9 219 162 10 236 178 12 239 182 13
57035 -246 186 14 242 186 14 239 182 13 236 178 12
57036 -224 166 10 206 145 10 192 133 9 154 121 60
57037 - 94 94 94 62 62 62 42 42 42 22 22 22
57038 - 14 14 14 6 6 6 0 0 0 0 0 0
57039 - 0 0 0 0 0 0 0 0 0 0 0 0
57040 - 0 0 0 0 0 0 0 0 0 0 0 0
57041 - 0 0 0 0 0 0 0 0 0 0 0 0
57042 - 0 0 0 0 0 0 0 0 0 6 6 6
57043 - 18 18 18 34 34 34 58 58 58 78 78 78
57044 -101 98 89 124 112 88 142 110 46 156 107 11
57045 -163 110 8 167 114 7 175 118 6 180 123 7
57046 -185 133 11 197 138 11 210 150 10 219 162 10
57047 -226 170 11 236 178 12 236 178 12 234 174 13
57048 -219 162 10 197 138 11 163 110 8 130 83 6
57049 - 91 60 6 10 10 10 2 2 6 2 2 6
57050 - 18 18 18 38 38 38 38 38 38 38 38 38
57051 - 38 38 38 38 38 38 38 38 38 38 38 38
57052 - 38 38 38 38 38 38 26 26 26 2 2 6
57053 - 2 2 6 6 6 6 70 47 6 137 92 6
57054 -175 118 6 200 144 11 219 162 10 230 174 11
57055 -234 174 13 230 174 11 219 162 10 210 150 10
57056 -192 133 9 163 110 8 124 112 88 82 82 82
57057 - 50 50 50 30 30 30 14 14 14 6 6 6
57058 - 0 0 0 0 0 0 0 0 0 0 0 0
57059 - 0 0 0 0 0 0 0 0 0 0 0 0
57060 - 0 0 0 0 0 0 0 0 0 0 0 0
57061 - 0 0 0 0 0 0 0 0 0 0 0 0
57062 - 0 0 0 0 0 0 0 0 0 0 0 0
57063 - 6 6 6 14 14 14 22 22 22 34 34 34
57064 - 42 42 42 58 58 58 74 74 74 86 86 86
57065 -101 98 89 122 102 70 130 98 46 121 87 25
57066 -137 92 6 152 99 6 163 110 8 180 123 7
57067 -185 133 11 197 138 11 206 145 10 200 144 11
57068 -180 123 7 156 107 11 130 83 6 104 69 6
57069 - 50 34 6 54 54 54 110 110 110 101 98 89
57070 - 86 86 86 82 82 82 78 78 78 78 78 78
57071 - 78 78 78 78 78 78 78 78 78 78 78 78
57072 - 78 78 78 82 82 82 86 86 86 94 94 94
57073 -106 106 106 101 101 101 86 66 34 124 80 6
57074 -156 107 11 180 123 7 192 133 9 200 144 11
57075 -206 145 10 200 144 11 192 133 9 175 118 6
57076 -139 102 15 109 106 95 70 70 70 42 42 42
57077 - 22 22 22 10 10 10 0 0 0 0 0 0
57078 - 0 0 0 0 0 0 0 0 0 0 0 0
57079 - 0 0 0 0 0 0 0 0 0 0 0 0
57080 - 0 0 0 0 0 0 0 0 0 0 0 0
57081 - 0 0 0 0 0 0 0 0 0 0 0 0
57082 - 0 0 0 0 0 0 0 0 0 0 0 0
57083 - 0 0 0 0 0 0 6 6 6 10 10 10
57084 - 14 14 14 22 22 22 30 30 30 38 38 38
57085 - 50 50 50 62 62 62 74 74 74 90 90 90
57086 -101 98 89 112 100 78 121 87 25 124 80 6
57087 -137 92 6 152 99 6 152 99 6 152 99 6
57088 -138 86 6 124 80 6 98 70 6 86 66 30
57089 -101 98 89 82 82 82 58 58 58 46 46 46
57090 - 38 38 38 34 34 34 34 34 34 34 34 34
57091 - 34 34 34 34 34 34 34 34 34 34 34 34
57092 - 34 34 34 34 34 34 38 38 38 42 42 42
57093 - 54 54 54 82 82 82 94 86 76 91 60 6
57094 -134 86 6 156 107 11 167 114 7 175 118 6
57095 -175 118 6 167 114 7 152 99 6 121 87 25
57096 -101 98 89 62 62 62 34 34 34 18 18 18
57097 - 6 6 6 0 0 0 0 0 0 0 0 0
57098 - 0 0 0 0 0 0 0 0 0 0 0 0
57099 - 0 0 0 0 0 0 0 0 0 0 0 0
57100 - 0 0 0 0 0 0 0 0 0 0 0 0
57101 - 0 0 0 0 0 0 0 0 0 0 0 0
57102 - 0 0 0 0 0 0 0 0 0 0 0 0
57103 - 0 0 0 0 0 0 0 0 0 0 0 0
57104 - 0 0 0 6 6 6 6 6 6 10 10 10
57105 - 18 18 18 22 22 22 30 30 30 42 42 42
57106 - 50 50 50 66 66 66 86 86 86 101 98 89
57107 -106 86 58 98 70 6 104 69 6 104 69 6
57108 -104 69 6 91 60 6 82 62 34 90 90 90
57109 - 62 62 62 38 38 38 22 22 22 14 14 14
57110 - 10 10 10 10 10 10 10 10 10 10 10 10
57111 - 10 10 10 10 10 10 6 6 6 10 10 10
57112 - 10 10 10 10 10 10 10 10 10 14 14 14
57113 - 22 22 22 42 42 42 70 70 70 89 81 66
57114 - 80 54 7 104 69 6 124 80 6 137 92 6
57115 -134 86 6 116 81 8 100 82 52 86 86 86
57116 - 58 58 58 30 30 30 14 14 14 6 6 6
57117 - 0 0 0 0 0 0 0 0 0 0 0 0
57118 - 0 0 0 0 0 0 0 0 0 0 0 0
57119 - 0 0 0 0 0 0 0 0 0 0 0 0
57120 - 0 0 0 0 0 0 0 0 0 0 0 0
57121 - 0 0 0 0 0 0 0 0 0 0 0 0
57122 - 0 0 0 0 0 0 0 0 0 0 0 0
57123 - 0 0 0 0 0 0 0 0 0 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 6 6 6 10 10 10 14 14 14
57126 - 18 18 18 26 26 26 38 38 38 54 54 54
57127 - 70 70 70 86 86 86 94 86 76 89 81 66
57128 - 89 81 66 86 86 86 74 74 74 50 50 50
57129 - 30 30 30 14 14 14 6 6 6 0 0 0
57130 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 34 34 34 58 58 58
57134 - 82 82 82 89 81 66 89 81 66 89 81 66
57135 - 94 86 66 94 86 76 74 74 74 50 50 50
57136 - 26 26 26 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
57141 - 0 0 0 0 0 0 0 0 0 0 0 0
57142 - 0 0 0 0 0 0 0 0 0 0 0 0
57143 - 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
57147 - 30 30 30 38 38 38 46 46 46 54 54 54
57148 - 50 50 50 42 42 42 30 30 30 18 18 18
57149 - 10 10 10 0 0 0 0 0 0 0 0 0
57150 - 0 0 0 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 6 6 6 14 14 14 26 26 26
57154 - 38 38 38 50 50 50 58 58 58 58 58 58
57155 - 54 54 54 42 42 42 30 30 30 18 18 18
57156 - 10 10 10 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 0 0 0
57161 - 0 0 0 0 0 0 0 0 0 0 0 0
57162 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
57167 - 6 6 6 10 10 10 14 14 14 18 18 18
57168 - 18 18 18 14 14 14 10 10 10 6 6 6
57169 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
57174 - 14 14 14 18 18 18 22 22 22 22 22 22
57175 - 18 18 18 14 14 14 10 10 10 6 6 6
57176 - 0 0 0 0 0 0 0 0 0 0 0 0
57177 - 0 0 0 0 0 0 0 0 0 0 0 0
57178 - 0 0 0 0 0 0 0 0 0 0 0 0
57179 - 0 0 0 0 0 0 0 0 0 0 0 0
57180 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
57237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57248 +4 4 4 4 4 4 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
57251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57264 +4 4 4 4 4 4
57265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57269 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57270 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57274 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57275 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57276 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57278 +4 4 4 4 4 4
57279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57283 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57284 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57285 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57288 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57289 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57290 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57291 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57292 +4 4 4 4 4 4
57293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57297 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57298 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57299 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57302 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57303 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57304 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57305 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57306 +4 4 4 4 4 4
57307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57310 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57311 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57312 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57313 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57315 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57316 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57317 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57318 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57319 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57320 +4 4 4 4 4 4
57321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57324 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57325 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57326 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57327 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57328 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57329 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57330 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57331 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57332 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57333 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57334 +4 4 4 4 4 4
57335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57338 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57339 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57340 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57341 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57342 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57343 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57344 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57345 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57346 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57347 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57348 +4 4 4 4 4 4
57349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57351 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57352 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57353 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57354 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57355 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57356 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57357 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57358 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57359 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57360 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57361 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57362 +4 4 4 4 4 4
57363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57365 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57366 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57367 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57368 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57369 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57370 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57371 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57372 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57373 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57374 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57375 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57376 +4 4 4 4 4 4
57377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57379 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57380 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57381 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57382 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57383 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57384 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57385 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57386 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57387 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57388 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57389 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57390 +4 4 4 4 4 4
57391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57393 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57394 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57395 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57396 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57397 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57398 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57399 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57400 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57401 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57402 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57403 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57404 +4 4 4 4 4 4
57405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57406 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57407 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57408 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57409 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57410 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57411 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57412 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57413 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57414 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57415 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57416 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57417 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57418 +4 4 4 4 4 4
57419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57420 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57421 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57422 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57423 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57424 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57425 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57426 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57427 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57428 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57429 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57430 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57431 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57432 +0 0 0 4 4 4
57433 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57434 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57435 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57436 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57437 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57438 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57439 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57440 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57441 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57442 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57443 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57444 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57445 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57446 +2 0 0 0 0 0
57447 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57448 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57449 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57450 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57451 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57452 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57453 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57454 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57455 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57456 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57457 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57458 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57459 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57460 +37 38 37 0 0 0
57461 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57462 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57463 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57464 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57465 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57466 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57467 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57468 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57469 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57470 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57471 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57472 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57473 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57474 +85 115 134 4 0 0
57475 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57476 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57477 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57478 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57479 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57480 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57481 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57482 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57483 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57484 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57485 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57486 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57487 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57488 +60 73 81 4 0 0
57489 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57490 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57491 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57492 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57493 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57494 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57495 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57496 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57497 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57498 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57499 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57500 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57501 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57502 +16 19 21 4 0 0
57503 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57504 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57505 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57506 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57507 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57508 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57509 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57510 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57511 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57512 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57513 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57514 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57515 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57516 +4 0 0 4 3 3
57517 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57518 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57519 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57521 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57522 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57523 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57524 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57525 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57526 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57527 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57528 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57529 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57530 +3 2 2 4 4 4
57531 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57532 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57533 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57534 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57535 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57536 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57537 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57538 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57539 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57540 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57541 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57542 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57543 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57544 +4 4 4 4 4 4
57545 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57546 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57547 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57548 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57549 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57550 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57551 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57552 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57553 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57554 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57555 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57556 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57557 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57558 +4 4 4 4 4 4
57559 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57560 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57561 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57562 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57563 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57564 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57565 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57566 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57567 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57568 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57569 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57570 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57571 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57572 +5 5 5 5 5 5
57573 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57574 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57575 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57576 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57577 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57578 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57579 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57580 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57581 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57582 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57583 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57584 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57585 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57586 +5 5 5 4 4 4
57587 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57588 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57589 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57590 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57591 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57592 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57593 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57594 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57595 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57596 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57597 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57598 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57600 +4 4 4 4 4 4
57601 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57602 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57603 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57604 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57605 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57606 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57607 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57608 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57609 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57610 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57611 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57612 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57614 +4 4 4 4 4 4
57615 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57616 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57617 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57618 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57619 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57620 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57621 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57622 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57623 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57624 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57625 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57628 +4 4 4 4 4 4
57629 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57630 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57631 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57632 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57633 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57634 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57635 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57636 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57637 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57638 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57639 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57642 +4 4 4 4 4 4
57643 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57644 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57645 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57646 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57647 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57648 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57649 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57650 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57651 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57652 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57653 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57656 +4 4 4 4 4 4
57657 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57658 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57659 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57660 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57661 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57662 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57663 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57664 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57665 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57666 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57667 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57670 +4 4 4 4 4 4
57671 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57672 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57673 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57674 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57675 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57676 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57677 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57678 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57679 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57680 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57681 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57684 +4 4 4 4 4 4
57685 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57686 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57687 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57688 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57689 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57690 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57691 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57692 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57693 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57694 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57695 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57698 +4 4 4 4 4 4
57699 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57700 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57701 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57702 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57703 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57704 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57705 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57706 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57707 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57708 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57709 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57712 +4 4 4 4 4 4
57713 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57714 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57715 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57716 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57717 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57718 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57719 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57720 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57721 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57722 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57723 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57726 +4 4 4 4 4 4
57727 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57728 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57729 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57730 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57731 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57732 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57733 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57734 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57735 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57736 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57737 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57740 +4 4 4 4 4 4
57741 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57742 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57743 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57744 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57745 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57746 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57747 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57748 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57749 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57750 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57751 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57754 +4 4 4 4 4 4
57755 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57756 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57757 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57758 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57759 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57760 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57761 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57762 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57763 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57764 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57765 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57768 +4 4 4 4 4 4
57769 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57770 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57771 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57772 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57773 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57774 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57775 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57776 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57777 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57778 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57779 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57782 +4 4 4 4 4 4
57783 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57784 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57785 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57786 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57787 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57788 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57789 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57790 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57791 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57792 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57793 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57796 +4 4 4 4 4 4
57797 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57798 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57799 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57800 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57801 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57802 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57803 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57804 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57805 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57806 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57807 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57810 +4 4 4 4 4 4
57811 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57812 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57813 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57814 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57815 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57816 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57817 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57818 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57819 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57820 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57821 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57824 +4 4 4 4 4 4
57825 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57826 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57827 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57828 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57829 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57830 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57831 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57832 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57833 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57834 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57835 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57838 +4 4 4 4 4 4
57839 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57840 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57841 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57842 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57843 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57844 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57845 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57846 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57847 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57848 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57849 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57852 +4 4 4 4 4 4
57853 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57854 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57855 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57856 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57857 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57858 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57859 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57860 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57861 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57862 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57863 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57866 +4 4 4 4 4 4
57867 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57868 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57869 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57870 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57871 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57872 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57873 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57874 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57875 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57876 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57877 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57880 +4 4 4 4 4 4
57881 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57882 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57883 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57884 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57885 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57886 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57887 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57888 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57889 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57890 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57891 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57894 +4 4 4 4 4 4
57895 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57896 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57897 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57898 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57899 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57900 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57901 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57902 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57903 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57904 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57905 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57908 +4 4 4 4 4 4
57909 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57910 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57911 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57912 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57913 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57914 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57915 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57916 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57917 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57918 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57919 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57922 +4 4 4 4 4 4
57923 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57924 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57925 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57926 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57927 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57928 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57929 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57930 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57931 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57932 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57933 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57936 +4 4 4 4 4 4
57937 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57938 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57939 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57940 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57941 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57942 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57943 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57944 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57945 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57946 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57947 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57950 +4 4 4 4 4 4
57951 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57952 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57953 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57954 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57955 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57956 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57957 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57958 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57959 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57960 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57961 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57964 +4 4 4 4 4 4
57965 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57966 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57967 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57968 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57969 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57970 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57971 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57972 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57973 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57974 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57975 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57978 +4 4 4 4 4 4
57979 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57980 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57981 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57982 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57983 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57984 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57985 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57986 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57987 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57988 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57989 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57992 +4 4 4 4 4 4
57993 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57994 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57995 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57996 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57997 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57998 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57999 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58000 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58001 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58002 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58006 +4 4 4 4 4 4
58007 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58008 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58009 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58010 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58011 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58012 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58013 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58014 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58015 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58016 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58020 +4 4 4 4 4 4
58021 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58022 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58023 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58024 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58025 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58026 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58027 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58028 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58029 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58030 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58034 +4 4 4 4 4 4
58035 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58036 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58037 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58038 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58039 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58040 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58041 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58042 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58043 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58044 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58048 +4 4 4 4 4 4
58049 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58050 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58051 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58052 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58053 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58054 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58055 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58056 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58057 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58062 +4 4 4 4 4 4
58063 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58064 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58065 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58066 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58067 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58068 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58069 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58070 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58071 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58076 +4 4 4 4 4 4
58077 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58078 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58079 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58080 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58081 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58082 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58083 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58084 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58085 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58090 +4 4 4 4 4 4
58091 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58092 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58093 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58094 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58095 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58096 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58097 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58098 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58104 +4 4 4 4 4 4
58105 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58106 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58107 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58108 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58109 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58110 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58111 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58112 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58118 +4 4 4 4 4 4
58119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58120 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58121 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58122 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58123 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58124 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58125 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58126 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58132 +4 4 4 4 4 4
58133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58135 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58136 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58137 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58138 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58139 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58140 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58146 +4 4 4 4 4 4
58147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58149 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58150 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58151 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58152 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58153 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58154 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58160 +4 4 4 4 4 4
58161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58163 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58164 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58165 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58166 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58167 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58168 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58174 +4 4 4 4 4 4
58175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5
58178 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58179 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58180 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58181 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188 +4 4 4 4 4 4
58189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58193 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58194 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58195 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58202 +4 4 4 4 4 4
58203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
58207 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58208 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58209 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58216 +4 4 4 4 4 4
58217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
58221 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58222 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58223 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58230 +4 4 4 4 4 4
58231 +4 4 4 4 4 4 4 4 4 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 5 5 5
58235 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58236 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58237 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58244 +4 4 4 4 4 4
58245 +4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58250 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58251 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58258 +4 4 4 4 4 4
58259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260 +4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58264 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58265 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58272 +4 4 4 4 4 4
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 5 5 5 4 3 3 6 6 6
58278 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284 +4 4 4 4 4 4 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 4 4 4 4 4 4
58286 +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 5 5 5 4 3 3
58292 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58300 +4 4 4 4 4 4
58301 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58302 index fef20db..d28b1ab 100644
58303 --- a/drivers/xen/xenfs/xenstored.c
58304 +++ b/drivers/xen/xenfs/xenstored.c
58305 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58306 static int xsd_kva_open(struct inode *inode, struct file *file)
58307 {
58308 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58309 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58310 + NULL);
58311 +#else
58312 xen_store_interface);
58313 +#endif
58314 +
58315 if (!file->private_data)
58316 return -ENOMEM;
58317 return 0;
58318 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58319 index eb14e05..5156de7 100644
58320 --- a/fs/9p/vfs_addr.c
58321 +++ b/fs/9p/vfs_addr.c
58322 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58323
58324 retval = v9fs_file_write_internal(inode,
58325 v9inode->writeback_fid,
58326 - (__force const char __user *)buffer,
58327 + (const char __force_user *)buffer,
58328 len, &offset, 0);
58329 if (retval > 0)
58330 retval = 0;
58331 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58332 index 296482f..183ddc3 100644
58333 --- a/fs/9p/vfs_inode.c
58334 +++ b/fs/9p/vfs_inode.c
58335 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58336 void
58337 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58338 {
58339 - char *s = nd_get_link(nd);
58340 + const char *s = nd_get_link(nd);
58341
58342 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58343 dentry, IS_ERR(s) ? "<error>" : s);
58344 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58345 index 370b24c..ff0be7b 100644
58346 --- a/fs/Kconfig.binfmt
58347 +++ b/fs/Kconfig.binfmt
58348 @@ -103,7 +103,7 @@ config HAVE_AOUT
58349
58350 config BINFMT_AOUT
58351 tristate "Kernel support for a.out and ECOFF binaries"
58352 - depends on HAVE_AOUT
58353 + depends on HAVE_AOUT && BROKEN
58354 ---help---
58355 A.out (Assembler.OUTput) is a set of formats for libraries and
58356 executables used in the earliest versions of UNIX. Linux used
58357 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58358 index 2946712..f737435 100644
58359 --- a/fs/afs/inode.c
58360 +++ b/fs/afs/inode.c
58361 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58362 struct afs_vnode *vnode;
58363 struct super_block *sb;
58364 struct inode *inode;
58365 - static atomic_t afs_autocell_ino;
58366 + static atomic_unchecked_t afs_autocell_ino;
58367
58368 _enter("{%x:%u},%*.*s,",
58369 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58370 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58371 data.fid.unique = 0;
58372 data.fid.vnode = 0;
58373
58374 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58375 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58376 afs_iget5_autocell_test, afs_iget5_set,
58377 &data);
58378 if (!inode) {
58379 diff --git a/fs/aio.c b/fs/aio.c
58380 index 14b9315..365980f 100644
58381 --- a/fs/aio.c
58382 +++ b/fs/aio.c
58383 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58384 size += sizeof(struct io_event) * nr_events;
58385
58386 nr_pages = PFN_UP(size);
58387 - if (nr_pages < 0)
58388 + if (nr_pages <= 0)
58389 return -EINVAL;
58390
58391 file = aio_private_file(ctx, nr_pages);
58392 diff --git a/fs/attr.c b/fs/attr.c
58393 index 6530ced..4a827e2 100644
58394 --- a/fs/attr.c
58395 +++ b/fs/attr.c
58396 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58397 unsigned long limit;
58398
58399 limit = rlimit(RLIMIT_FSIZE);
58400 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58401 if (limit != RLIM_INFINITY && offset > limit)
58402 goto out_sig;
58403 if (offset > inode->i_sb->s_maxbytes)
58404 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58405 index 116fd38..c04182da 100644
58406 --- a/fs/autofs4/waitq.c
58407 +++ b/fs/autofs4/waitq.c
58408 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58409 {
58410 unsigned long sigpipe, flags;
58411 mm_segment_t fs;
58412 - const char *data = (const char *)addr;
58413 + const char __user *data = (const char __force_user *)addr;
58414 ssize_t wr = 0;
58415
58416 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58417 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58418 return 1;
58419 }
58420
58421 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58422 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58423 +#endif
58424 +
58425 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58426 enum autofs_notify notify)
58427 {
58428 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58429
58430 /* If this is a direct mount request create a dummy name */
58431 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58432 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58433 + /* this name does get written to userland via autofs4_write() */
58434 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58435 +#else
58436 qstr.len = sprintf(name, "%p", dentry);
58437 +#endif
58438 else {
58439 qstr.len = autofs4_getpath(sbi, dentry, &name);
58440 if (!qstr.len) {
58441 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58442 index 2722387..56059b5 100644
58443 --- a/fs/befs/endian.h
58444 +++ b/fs/befs/endian.h
58445 @@ -11,7 +11,7 @@
58446
58447 #include <asm/byteorder.h>
58448
58449 -static inline u64
58450 +static inline u64 __intentional_overflow(-1)
58451 fs64_to_cpu(const struct super_block *sb, fs64 n)
58452 {
58453 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58454 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58455 return (__force fs64)cpu_to_be64(n);
58456 }
58457
58458 -static inline u32
58459 +static inline u32 __intentional_overflow(-1)
58460 fs32_to_cpu(const struct super_block *sb, fs32 n)
58461 {
58462 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58463 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58464 return (__force fs32)cpu_to_be32(n);
58465 }
58466
58467 -static inline u16
58468 +static inline u16 __intentional_overflow(-1)
58469 fs16_to_cpu(const struct super_block *sb, fs16 n)
58470 {
58471 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58472 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58473 index 929dec0..84bd914 100644
58474 --- a/fs/binfmt_aout.c
58475 +++ b/fs/binfmt_aout.c
58476 @@ -16,6 +16,7 @@
58477 #include <linux/string.h>
58478 #include <linux/fs.h>
58479 #include <linux/file.h>
58480 +#include <linux/security.h>
58481 #include <linux/stat.h>
58482 #include <linux/fcntl.h>
58483 #include <linux/ptrace.h>
58484 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58485 #endif
58486 # define START_STACK(u) ((void __user *)u.start_stack)
58487
58488 + memset(&dump, 0, sizeof(dump));
58489 +
58490 fs = get_fs();
58491 set_fs(KERNEL_DS);
58492 has_dumped = 1;
58493 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58494
58495 /* If the size of the dump file exceeds the rlimit, then see what would happen
58496 if we wrote the stack, but not the data area. */
58497 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58498 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58499 dump.u_dsize = 0;
58500
58501 /* Make sure we have enough room to write the stack and data areas. */
58502 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58503 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58504 dump.u_ssize = 0;
58505
58506 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58507 rlim = rlimit(RLIMIT_DATA);
58508 if (rlim >= RLIM_INFINITY)
58509 rlim = ~0;
58510 +
58511 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58512 if (ex.a_data + ex.a_bss > rlim)
58513 return -ENOMEM;
58514
58515 @@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58516
58517 install_exec_creds(bprm);
58518
58519 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58520 + current->mm->pax_flags = 0UL;
58521 +#endif
58522 +
58523 +#ifdef CONFIG_PAX_PAGEEXEC
58524 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58525 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58526 +
58527 +#ifdef CONFIG_PAX_EMUTRAMP
58528 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58529 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58530 +#endif
58531 +
58532 +#ifdef CONFIG_PAX_MPROTECT
58533 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58534 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58535 +#endif
58536 +
58537 + }
58538 +#endif
58539 +
58540 if (N_MAGIC(ex) == OMAGIC) {
58541 unsigned long text_addr, map_size;
58542 loff_t pos;
58543 @@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58544 return error;
58545
58546 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58547 - PROT_READ | PROT_WRITE | PROT_EXEC,
58548 + PROT_READ | PROT_WRITE,
58549 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58550 fd_offset + ex.a_text);
58551 if (error != N_DATADDR(ex))
58552 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58553 index d8fc060..cbd44d5 100644
58554 --- a/fs/binfmt_elf.c
58555 +++ b/fs/binfmt_elf.c
58556 @@ -34,6 +34,7 @@
58557 #include <linux/utsname.h>
58558 #include <linux/coredump.h>
58559 #include <linux/sched.h>
58560 +#include <linux/xattr.h>
58561 #include <asm/uaccess.h>
58562 #include <asm/param.h>
58563 #include <asm/page.h>
58564 @@ -47,7 +48,7 @@
58565
58566 static int load_elf_binary(struct linux_binprm *bprm);
58567 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58568 - int, int, unsigned long);
58569 + int, int, unsigned long) __intentional_overflow(-1);
58570
58571 #ifdef CONFIG_USELIB
58572 static int load_elf_library(struct file *);
58573 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58574 #define elf_core_dump NULL
58575 #endif
58576
58577 +#ifdef CONFIG_PAX_MPROTECT
58578 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58579 +#endif
58580 +
58581 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58582 +static void elf_handle_mmap(struct file *file);
58583 +#endif
58584 +
58585 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58586 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58587 #else
58588 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58589 .load_binary = load_elf_binary,
58590 .load_shlib = load_elf_library,
58591 .core_dump = elf_core_dump,
58592 +
58593 +#ifdef CONFIG_PAX_MPROTECT
58594 + .handle_mprotect= elf_handle_mprotect,
58595 +#endif
58596 +
58597 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58598 + .handle_mmap = elf_handle_mmap,
58599 +#endif
58600 +
58601 .min_coredump = ELF_EXEC_PAGESIZE,
58602 };
58603
58604 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58605
58606 static int set_brk(unsigned long start, unsigned long end)
58607 {
58608 + unsigned long e = end;
58609 +
58610 start = ELF_PAGEALIGN(start);
58611 end = ELF_PAGEALIGN(end);
58612 if (end > start) {
58613 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58614 if (BAD_ADDR(addr))
58615 return addr;
58616 }
58617 - current->mm->start_brk = current->mm->brk = end;
58618 + current->mm->start_brk = current->mm->brk = e;
58619 return 0;
58620 }
58621
58622 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58623 elf_addr_t __user *u_rand_bytes;
58624 const char *k_platform = ELF_PLATFORM;
58625 const char *k_base_platform = ELF_BASE_PLATFORM;
58626 - unsigned char k_rand_bytes[16];
58627 + u32 k_rand_bytes[4];
58628 int items;
58629 elf_addr_t *elf_info;
58630 int ei_index = 0;
58631 const struct cred *cred = current_cred();
58632 struct vm_area_struct *vma;
58633 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58634
58635 /*
58636 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58637 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58638 * Generate 16 random bytes for userspace PRNG seeding.
58639 */
58640 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58641 - u_rand_bytes = (elf_addr_t __user *)
58642 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58643 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58644 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58645 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58646 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58647 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58648 + u_rand_bytes = (elf_addr_t __user *) p;
58649 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58650 return -EFAULT;
58651
58652 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58653 return -EFAULT;
58654 current->mm->env_end = p;
58655
58656 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58657 +
58658 /* Put the elf_info on the stack in the right place. */
58659 sp = (elf_addr_t __user *)envp + 1;
58660 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58661 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58662 return -EFAULT;
58663 return 0;
58664 }
58665 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58666 an ELF header */
58667
58668 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58669 - struct file *interpreter, unsigned long *interp_map_addr,
58670 - unsigned long no_base)
58671 + struct file *interpreter, unsigned long no_base)
58672 {
58673 struct elf_phdr *elf_phdata;
58674 struct elf_phdr *eppnt;
58675 - unsigned long load_addr = 0;
58676 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58677 int load_addr_set = 0;
58678 unsigned long last_bss = 0, elf_bss = 0;
58679 - unsigned long error = ~0UL;
58680 + unsigned long error = -EINVAL;
58681 unsigned long total_size;
58682 int retval, i, size;
58683
58684 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58685 goto out_close;
58686 }
58687
58688 +#ifdef CONFIG_PAX_SEGMEXEC
58689 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58690 + pax_task_size = SEGMEXEC_TASK_SIZE;
58691 +#endif
58692 +
58693 eppnt = elf_phdata;
58694 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58695 if (eppnt->p_type == PT_LOAD) {
58696 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58697 map_addr = elf_map(interpreter, load_addr + vaddr,
58698 eppnt, elf_prot, elf_type, total_size);
58699 total_size = 0;
58700 - if (!*interp_map_addr)
58701 - *interp_map_addr = map_addr;
58702 error = map_addr;
58703 if (BAD_ADDR(map_addr))
58704 goto out_close;
58705 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58706 k = load_addr + eppnt->p_vaddr;
58707 if (BAD_ADDR(k) ||
58708 eppnt->p_filesz > eppnt->p_memsz ||
58709 - eppnt->p_memsz > TASK_SIZE ||
58710 - TASK_SIZE - eppnt->p_memsz < k) {
58711 + eppnt->p_memsz > pax_task_size ||
58712 + pax_task_size - eppnt->p_memsz < k) {
58713 error = -ENOMEM;
58714 goto out_close;
58715 }
58716 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58717 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58718
58719 /* Map the last of the bss segment */
58720 - error = vm_brk(elf_bss, last_bss - elf_bss);
58721 - if (BAD_ADDR(error))
58722 - goto out_close;
58723 + if (last_bss > elf_bss) {
58724 + error = vm_brk(elf_bss, last_bss - elf_bss);
58725 + if (BAD_ADDR(error))
58726 + goto out_close;
58727 + }
58728 }
58729
58730 error = load_addr;
58731 @@ -543,6 +574,336 @@ out:
58732 return error;
58733 }
58734
58735 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58736 +#ifdef CONFIG_PAX_SOFTMODE
58737 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58738 +{
58739 + unsigned long pax_flags = 0UL;
58740 +
58741 +#ifdef CONFIG_PAX_PAGEEXEC
58742 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58743 + pax_flags |= MF_PAX_PAGEEXEC;
58744 +#endif
58745 +
58746 +#ifdef CONFIG_PAX_SEGMEXEC
58747 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58748 + pax_flags |= MF_PAX_SEGMEXEC;
58749 +#endif
58750 +
58751 +#ifdef CONFIG_PAX_EMUTRAMP
58752 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58753 + pax_flags |= MF_PAX_EMUTRAMP;
58754 +#endif
58755 +
58756 +#ifdef CONFIG_PAX_MPROTECT
58757 + if (elf_phdata->p_flags & PF_MPROTECT)
58758 + pax_flags |= MF_PAX_MPROTECT;
58759 +#endif
58760 +
58761 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58762 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58763 + pax_flags |= MF_PAX_RANDMMAP;
58764 +#endif
58765 +
58766 + return pax_flags;
58767 +}
58768 +#endif
58769 +
58770 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58771 +{
58772 + unsigned long pax_flags = 0UL;
58773 +
58774 +#ifdef CONFIG_PAX_PAGEEXEC
58775 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58776 + pax_flags |= MF_PAX_PAGEEXEC;
58777 +#endif
58778 +
58779 +#ifdef CONFIG_PAX_SEGMEXEC
58780 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58781 + pax_flags |= MF_PAX_SEGMEXEC;
58782 +#endif
58783 +
58784 +#ifdef CONFIG_PAX_EMUTRAMP
58785 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58786 + pax_flags |= MF_PAX_EMUTRAMP;
58787 +#endif
58788 +
58789 +#ifdef CONFIG_PAX_MPROTECT
58790 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58791 + pax_flags |= MF_PAX_MPROTECT;
58792 +#endif
58793 +
58794 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58795 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58796 + pax_flags |= MF_PAX_RANDMMAP;
58797 +#endif
58798 +
58799 + return pax_flags;
58800 +}
58801 +#endif
58802 +
58803 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58804 +#ifdef CONFIG_PAX_SOFTMODE
58805 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58806 +{
58807 + unsigned long pax_flags = 0UL;
58808 +
58809 +#ifdef CONFIG_PAX_PAGEEXEC
58810 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58811 + pax_flags |= MF_PAX_PAGEEXEC;
58812 +#endif
58813 +
58814 +#ifdef CONFIG_PAX_SEGMEXEC
58815 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58816 + pax_flags |= MF_PAX_SEGMEXEC;
58817 +#endif
58818 +
58819 +#ifdef CONFIG_PAX_EMUTRAMP
58820 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58821 + pax_flags |= MF_PAX_EMUTRAMP;
58822 +#endif
58823 +
58824 +#ifdef CONFIG_PAX_MPROTECT
58825 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58826 + pax_flags |= MF_PAX_MPROTECT;
58827 +#endif
58828 +
58829 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58830 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58831 + pax_flags |= MF_PAX_RANDMMAP;
58832 +#endif
58833 +
58834 + return pax_flags;
58835 +}
58836 +#endif
58837 +
58838 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58839 +{
58840 + unsigned long pax_flags = 0UL;
58841 +
58842 +#ifdef CONFIG_PAX_PAGEEXEC
58843 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58844 + pax_flags |= MF_PAX_PAGEEXEC;
58845 +#endif
58846 +
58847 +#ifdef CONFIG_PAX_SEGMEXEC
58848 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58849 + pax_flags |= MF_PAX_SEGMEXEC;
58850 +#endif
58851 +
58852 +#ifdef CONFIG_PAX_EMUTRAMP
58853 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58854 + pax_flags |= MF_PAX_EMUTRAMP;
58855 +#endif
58856 +
58857 +#ifdef CONFIG_PAX_MPROTECT
58858 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58859 + pax_flags |= MF_PAX_MPROTECT;
58860 +#endif
58861 +
58862 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58863 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58864 + pax_flags |= MF_PAX_RANDMMAP;
58865 +#endif
58866 +
58867 + return pax_flags;
58868 +}
58869 +#endif
58870 +
58871 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58872 +static unsigned long pax_parse_defaults(void)
58873 +{
58874 + unsigned long pax_flags = 0UL;
58875 +
58876 +#ifdef CONFIG_PAX_SOFTMODE
58877 + if (pax_softmode)
58878 + return pax_flags;
58879 +#endif
58880 +
58881 +#ifdef CONFIG_PAX_PAGEEXEC
58882 + pax_flags |= MF_PAX_PAGEEXEC;
58883 +#endif
58884 +
58885 +#ifdef CONFIG_PAX_SEGMEXEC
58886 + pax_flags |= MF_PAX_SEGMEXEC;
58887 +#endif
58888 +
58889 +#ifdef CONFIG_PAX_MPROTECT
58890 + pax_flags |= MF_PAX_MPROTECT;
58891 +#endif
58892 +
58893 +#ifdef CONFIG_PAX_RANDMMAP
58894 + if (randomize_va_space)
58895 + pax_flags |= MF_PAX_RANDMMAP;
58896 +#endif
58897 +
58898 + return pax_flags;
58899 +}
58900 +
58901 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58902 +{
58903 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58904 +
58905 +#ifdef CONFIG_PAX_EI_PAX
58906 +
58907 +#ifdef CONFIG_PAX_SOFTMODE
58908 + if (pax_softmode)
58909 + return pax_flags;
58910 +#endif
58911 +
58912 + pax_flags = 0UL;
58913 +
58914 +#ifdef CONFIG_PAX_PAGEEXEC
58915 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58916 + pax_flags |= MF_PAX_PAGEEXEC;
58917 +#endif
58918 +
58919 +#ifdef CONFIG_PAX_SEGMEXEC
58920 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58921 + pax_flags |= MF_PAX_SEGMEXEC;
58922 +#endif
58923 +
58924 +#ifdef CONFIG_PAX_EMUTRAMP
58925 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58926 + pax_flags |= MF_PAX_EMUTRAMP;
58927 +#endif
58928 +
58929 +#ifdef CONFIG_PAX_MPROTECT
58930 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58931 + pax_flags |= MF_PAX_MPROTECT;
58932 +#endif
58933 +
58934 +#ifdef CONFIG_PAX_ASLR
58935 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58936 + pax_flags |= MF_PAX_RANDMMAP;
58937 +#endif
58938 +
58939 +#endif
58940 +
58941 + return pax_flags;
58942 +
58943 +}
58944 +
58945 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58946 +{
58947 +
58948 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58949 + unsigned long i;
58950 +
58951 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58952 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58953 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58954 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58955 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58956 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58957 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58958 + return PAX_PARSE_FLAGS_FALLBACK;
58959 +
58960 +#ifdef CONFIG_PAX_SOFTMODE
58961 + if (pax_softmode)
58962 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58963 + else
58964 +#endif
58965 +
58966 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58967 + break;
58968 + }
58969 +#endif
58970 +
58971 + return PAX_PARSE_FLAGS_FALLBACK;
58972 +}
58973 +
58974 +static unsigned long pax_parse_xattr_pax(struct file * const file)
58975 +{
58976 +
58977 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58978 + ssize_t xattr_size, i;
58979 + unsigned char xattr_value[sizeof("pemrs") - 1];
58980 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58981 +
58982 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58983 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58984 + return PAX_PARSE_FLAGS_FALLBACK;
58985 +
58986 + for (i = 0; i < xattr_size; i++)
58987 + switch (xattr_value[i]) {
58988 + default:
58989 + return PAX_PARSE_FLAGS_FALLBACK;
58990 +
58991 +#define parse_flag(option1, option2, flag) \
58992 + case option1: \
58993 + if (pax_flags_hardmode & MF_PAX_##flag) \
58994 + return PAX_PARSE_FLAGS_FALLBACK;\
58995 + pax_flags_hardmode |= MF_PAX_##flag; \
58996 + break; \
58997 + case option2: \
58998 + if (pax_flags_softmode & MF_PAX_##flag) \
58999 + return PAX_PARSE_FLAGS_FALLBACK;\
59000 + pax_flags_softmode |= MF_PAX_##flag; \
59001 + break;
59002 +
59003 + parse_flag('p', 'P', PAGEEXEC);
59004 + parse_flag('e', 'E', EMUTRAMP);
59005 + parse_flag('m', 'M', MPROTECT);
59006 + parse_flag('r', 'R', RANDMMAP);
59007 + parse_flag('s', 'S', SEGMEXEC);
59008 +
59009 +#undef parse_flag
59010 + }
59011 +
59012 + if (pax_flags_hardmode & pax_flags_softmode)
59013 + return PAX_PARSE_FLAGS_FALLBACK;
59014 +
59015 +#ifdef CONFIG_PAX_SOFTMODE
59016 + if (pax_softmode)
59017 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59018 + else
59019 +#endif
59020 +
59021 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59022 +#else
59023 + return PAX_PARSE_FLAGS_FALLBACK;
59024 +#endif
59025 +
59026 +}
59027 +
59028 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59029 +{
59030 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59031 +
59032 + pax_flags = pax_parse_defaults();
59033 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59034 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59035 + xattr_pax_flags = pax_parse_xattr_pax(file);
59036 +
59037 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59038 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59039 + pt_pax_flags != xattr_pax_flags)
59040 + return -EINVAL;
59041 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59042 + pax_flags = xattr_pax_flags;
59043 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59044 + pax_flags = pt_pax_flags;
59045 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59046 + pax_flags = ei_pax_flags;
59047 +
59048 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59049 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59050 + if ((__supported_pte_mask & _PAGE_NX))
59051 + pax_flags &= ~MF_PAX_SEGMEXEC;
59052 + else
59053 + pax_flags &= ~MF_PAX_PAGEEXEC;
59054 + }
59055 +#endif
59056 +
59057 + if (0 > pax_check_flags(&pax_flags))
59058 + return -EINVAL;
59059 +
59060 + current->mm->pax_flags = pax_flags;
59061 + return 0;
59062 +}
59063 +#endif
59064 +
59065 /*
59066 * These are the functions used to load ELF style executables and shared
59067 * libraries. There is no binary dependent code anywhere else.
59068 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59069 {
59070 unsigned int random_variable = 0;
59071
59072 +#ifdef CONFIG_PAX_RANDUSTACK
59073 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59074 + return stack_top - current->mm->delta_stack;
59075 +#endif
59076 +
59077 if ((current->flags & PF_RANDOMIZE) &&
59078 !(current->personality & ADDR_NO_RANDOMIZE)) {
59079 random_variable = get_random_int() & STACK_RND_MASK;
59080 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59081 unsigned long load_addr = 0, load_bias = 0;
59082 int load_addr_set = 0;
59083 char * elf_interpreter = NULL;
59084 - unsigned long error;
59085 + unsigned long error = 0;
59086 struct elf_phdr *elf_ppnt, *elf_phdata;
59087 unsigned long elf_bss, elf_brk;
59088 int retval, i;
59089 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59090 struct elfhdr elf_ex;
59091 struct elfhdr interp_elf_ex;
59092 } *loc;
59093 + unsigned long pax_task_size;
59094
59095 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59096 if (!loc) {
59097 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59098 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59099 may depend on the personality. */
59100 SET_PERSONALITY(loc->elf_ex);
59101 +
59102 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59103 + current->mm->pax_flags = 0UL;
59104 +#endif
59105 +
59106 +#ifdef CONFIG_PAX_DLRESOLVE
59107 + current->mm->call_dl_resolve = 0UL;
59108 +#endif
59109 +
59110 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59111 + current->mm->call_syscall = 0UL;
59112 +#endif
59113 +
59114 +#ifdef CONFIG_PAX_ASLR
59115 + current->mm->delta_mmap = 0UL;
59116 + current->mm->delta_stack = 0UL;
59117 +#endif
59118 +
59119 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59120 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59121 + send_sig(SIGKILL, current, 0);
59122 + goto out_free_dentry;
59123 + }
59124 +#endif
59125 +
59126 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59127 + pax_set_initial_flags(bprm);
59128 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59129 + if (pax_set_initial_flags_func)
59130 + (pax_set_initial_flags_func)(bprm);
59131 +#endif
59132 +
59133 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59134 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59135 + current->mm->context.user_cs_limit = PAGE_SIZE;
59136 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59137 + }
59138 +#endif
59139 +
59140 +#ifdef CONFIG_PAX_SEGMEXEC
59141 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59142 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59143 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59144 + pax_task_size = SEGMEXEC_TASK_SIZE;
59145 + current->mm->def_flags |= VM_NOHUGEPAGE;
59146 + } else
59147 +#endif
59148 +
59149 + pax_task_size = TASK_SIZE;
59150 +
59151 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59152 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59153 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59154 + put_cpu();
59155 + }
59156 +#endif
59157 +
59158 +#ifdef CONFIG_PAX_ASLR
59159 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59160 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59161 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59162 + }
59163 +#endif
59164 +
59165 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59166 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59167 + executable_stack = EXSTACK_DISABLE_X;
59168 + current->personality &= ~READ_IMPLIES_EXEC;
59169 + } else
59170 +#endif
59171 +
59172 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59173 current->personality |= READ_IMPLIES_EXEC;
59174
59175 @@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59176 #else
59177 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59178 #endif
59179 +
59180 +#ifdef CONFIG_PAX_RANDMMAP
59181 + /* PaX: randomize base address at the default exe base if requested */
59182 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59183 +#ifdef CONFIG_SPARC64
59184 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59185 +#else
59186 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59187 +#endif
59188 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59189 + elf_flags |= MAP_FIXED;
59190 + }
59191 +#endif
59192 +
59193 }
59194
59195 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59196 @@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59197 * allowed task size. Note that p_filesz must always be
59198 * <= p_memsz so it is only necessary to check p_memsz.
59199 */
59200 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59201 - elf_ppnt->p_memsz > TASK_SIZE ||
59202 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59203 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59204 + elf_ppnt->p_memsz > pax_task_size ||
59205 + pax_task_size - elf_ppnt->p_memsz < k) {
59206 /* set_brk can never work. Avoid overflows. */
59207 retval = -EINVAL;
59208 goto out_free_dentry;
59209 @@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
59210 if (retval)
59211 goto out_free_dentry;
59212 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59213 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59214 - goto out_free_dentry;
59215 + /*
59216 + * This bss-zeroing can fail if the ELF
59217 + * file specifies odd protections. So
59218 + * we don't check the return value
59219 + */
59220 }
59221
59222 +#ifdef CONFIG_PAX_RANDMMAP
59223 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59224 + unsigned long start, size, flags;
59225 + vm_flags_t vm_flags;
59226 +
59227 + start = ELF_PAGEALIGN(elf_brk);
59228 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59229 + flags = MAP_FIXED | MAP_PRIVATE;
59230 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59231 +
59232 + down_write(&current->mm->mmap_sem);
59233 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59234 + retval = -ENOMEM;
59235 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59236 +// if (current->personality & ADDR_NO_RANDOMIZE)
59237 +// vm_flags |= VM_READ | VM_MAYREAD;
59238 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59239 + retval = IS_ERR_VALUE(start) ? start : 0;
59240 + }
59241 + up_write(&current->mm->mmap_sem);
59242 + if (retval == 0)
59243 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59244 + if (retval < 0)
59245 + goto out_free_dentry;
59246 + }
59247 +#endif
59248 +
59249 if (elf_interpreter) {
59250 - unsigned long interp_map_addr = 0;
59251 -
59252 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59253 interpreter,
59254 - &interp_map_addr,
59255 load_bias);
59256 if (!IS_ERR((void *)elf_entry)) {
59257 /*
59258 @@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59259 * Decide what to dump of a segment, part, all or none.
59260 */
59261 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59262 - unsigned long mm_flags)
59263 + unsigned long mm_flags, long signr)
59264 {
59265 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59266
59267 @@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59268 if (vma->vm_file == NULL)
59269 return 0;
59270
59271 - if (FILTER(MAPPED_PRIVATE))
59272 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59273 goto whole;
59274
59275 /*
59276 @@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59277 {
59278 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59279 int i = 0;
59280 - do
59281 + do {
59282 i += 2;
59283 - while (auxv[i - 2] != AT_NULL);
59284 + } while (auxv[i - 2] != AT_NULL);
59285 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59286 }
59287
59288 @@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59289 {
59290 mm_segment_t old_fs = get_fs();
59291 set_fs(KERNEL_DS);
59292 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59293 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59294 set_fs(old_fs);
59295 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59296 }
59297 @@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59298 }
59299
59300 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59301 - unsigned long mm_flags)
59302 + struct coredump_params *cprm)
59303 {
59304 struct vm_area_struct *vma;
59305 size_t size = 0;
59306
59307 for (vma = first_vma(current, gate_vma); vma != NULL;
59308 vma = next_vma(vma, gate_vma))
59309 - size += vma_dump_size(vma, mm_flags);
59310 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59311 return size;
59312 }
59313
59314 @@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59315
59316 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59317
59318 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59319 + offset += elf_core_vma_data_size(gate_vma, cprm);
59320 offset += elf_core_extra_data_size();
59321 e_shoff = offset;
59322
59323 @@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59324 phdr.p_offset = offset;
59325 phdr.p_vaddr = vma->vm_start;
59326 phdr.p_paddr = 0;
59327 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59328 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59329 phdr.p_memsz = vma->vm_end - vma->vm_start;
59330 offset += phdr.p_filesz;
59331 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59332 @@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59333 unsigned long addr;
59334 unsigned long end;
59335
59336 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59337 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59338
59339 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59340 struct page *page;
59341 @@ -2195,6 +2674,167 @@ out:
59342
59343 #endif /* CONFIG_ELF_CORE */
59344
59345 +#ifdef CONFIG_PAX_MPROTECT
59346 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59347 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59348 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59349 + *
59350 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59351 + * basis because we want to allow the common case and not the special ones.
59352 + */
59353 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59354 +{
59355 + struct elfhdr elf_h;
59356 + struct elf_phdr elf_p;
59357 + unsigned long i;
59358 + unsigned long oldflags;
59359 + bool is_textrel_rw, is_textrel_rx, is_relro;
59360 +
59361 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59362 + return;
59363 +
59364 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59365 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59366 +
59367 +#ifdef CONFIG_PAX_ELFRELOCS
59368 + /* possible TEXTREL */
59369 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59370 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59371 +#else
59372 + is_textrel_rw = false;
59373 + is_textrel_rx = false;
59374 +#endif
59375 +
59376 + /* possible RELRO */
59377 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59378 +
59379 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59380 + return;
59381 +
59382 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59383 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59384 +
59385 +#ifdef CONFIG_PAX_ETEXECRELOCS
59386 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59387 +#else
59388 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59389 +#endif
59390 +
59391 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59392 + !elf_check_arch(&elf_h) ||
59393 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59394 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59395 + return;
59396 +
59397 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59398 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59399 + return;
59400 + switch (elf_p.p_type) {
59401 + case PT_DYNAMIC:
59402 + if (!is_textrel_rw && !is_textrel_rx)
59403 + continue;
59404 + i = 0UL;
59405 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59406 + elf_dyn dyn;
59407 +
59408 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59409 + break;
59410 + if (dyn.d_tag == DT_NULL)
59411 + break;
59412 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59413 + gr_log_textrel(vma);
59414 + if (is_textrel_rw)
59415 + vma->vm_flags |= VM_MAYWRITE;
59416 + else
59417 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59418 + vma->vm_flags &= ~VM_MAYWRITE;
59419 + break;
59420 + }
59421 + i++;
59422 + }
59423 + is_textrel_rw = false;
59424 + is_textrel_rx = false;
59425 + continue;
59426 +
59427 + case PT_GNU_RELRO:
59428 + if (!is_relro)
59429 + continue;
59430 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59431 + vma->vm_flags &= ~VM_MAYWRITE;
59432 + is_relro = false;
59433 + continue;
59434 +
59435 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59436 + case PT_PAX_FLAGS: {
59437 + const char *msg_mprotect = "", *msg_emutramp = "";
59438 + char *buffer_lib, *buffer_exe;
59439 +
59440 + if (elf_p.p_flags & PF_NOMPROTECT)
59441 + msg_mprotect = "MPROTECT disabled";
59442 +
59443 +#ifdef CONFIG_PAX_EMUTRAMP
59444 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59445 + msg_emutramp = "EMUTRAMP enabled";
59446 +#endif
59447 +
59448 + if (!msg_mprotect[0] && !msg_emutramp[0])
59449 + continue;
59450 +
59451 + if (!printk_ratelimit())
59452 + continue;
59453 +
59454 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59455 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59456 + if (buffer_lib && buffer_exe) {
59457 + char *path_lib, *path_exe;
59458 +
59459 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59460 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59461 +
59462 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59463 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59464 +
59465 + }
59466 + free_page((unsigned long)buffer_exe);
59467 + free_page((unsigned long)buffer_lib);
59468 + continue;
59469 + }
59470 +#endif
59471 +
59472 + }
59473 + }
59474 +}
59475 +#endif
59476 +
59477 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59478 +
59479 +extern int grsec_enable_log_rwxmaps;
59480 +
59481 +static void elf_handle_mmap(struct file *file)
59482 +{
59483 + struct elfhdr elf_h;
59484 + struct elf_phdr elf_p;
59485 + unsigned long i;
59486 +
59487 + if (!grsec_enable_log_rwxmaps)
59488 + return;
59489 +
59490 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59491 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59492 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59493 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59494 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59495 + return;
59496 +
59497 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59498 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59499 + return;
59500 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59501 + gr_log_ptgnustack(file);
59502 + }
59503 +}
59504 +#endif
59505 +
59506 static int __init init_elf_binfmt(void)
59507 {
59508 register_binfmt(&elf_format);
59509 diff --git a/fs/block_dev.c b/fs/block_dev.c
59510 index 1d9c9f3..2905786 100644
59511 --- a/fs/block_dev.c
59512 +++ b/fs/block_dev.c
59513 @@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59514 else if (bdev->bd_contains == bdev)
59515 return true; /* is a whole device which isn't held */
59516
59517 - else if (whole->bd_holder == bd_may_claim)
59518 + else if (whole->bd_holder == (void *)bd_may_claim)
59519 return true; /* is a partition of a device that is being partitioned */
59520 else if (whole->bd_holder != NULL)
59521 return false; /* is a partition of a held device */
59522 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59523 index 150822e..75bb326 100644
59524 --- a/fs/btrfs/ctree.c
59525 +++ b/fs/btrfs/ctree.c
59526 @@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59527 free_extent_buffer(buf);
59528 add_root_to_dirty_list(root);
59529 } else {
59530 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59531 - parent_start = parent->start;
59532 - else
59533 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59534 + if (parent)
59535 + parent_start = parent->start;
59536 + else
59537 + parent_start = 0;
59538 + } else
59539 parent_start = 0;
59540
59541 WARN_ON(trans->transid != btrfs_header_generation(parent));
59542 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59543 index de4e70f..b41dc45 100644
59544 --- a/fs/btrfs/delayed-inode.c
59545 +++ b/fs/btrfs/delayed-inode.c
59546 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59547
59548 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59549 {
59550 - int seq = atomic_inc_return(&delayed_root->items_seq);
59551 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59552 if ((atomic_dec_return(&delayed_root->items) <
59553 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59554 waitqueue_active(&delayed_root->wait))
59555 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59556
59557 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59558 {
59559 - int val = atomic_read(&delayed_root->items_seq);
59560 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59561
59562 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59563 return 1;
59564 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59565 int seq;
59566 int ret;
59567
59568 - seq = atomic_read(&delayed_root->items_seq);
59569 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59570
59571 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59572 if (ret)
59573 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59574 index f70119f..ab5894d 100644
59575 --- a/fs/btrfs/delayed-inode.h
59576 +++ b/fs/btrfs/delayed-inode.h
59577 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59578 */
59579 struct list_head prepare_list;
59580 atomic_t items; /* for delayed items */
59581 - atomic_t items_seq; /* for delayed items */
59582 + atomic_unchecked_t items_seq; /* for delayed items */
59583 int nodes; /* for delayed nodes */
59584 wait_queue_head_t wait;
59585 };
59586 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59587 struct btrfs_delayed_root *delayed_root)
59588 {
59589 atomic_set(&delayed_root->items, 0);
59590 - atomic_set(&delayed_root->items_seq, 0);
59591 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59592 delayed_root->nodes = 0;
59593 spin_lock_init(&delayed_root->lock);
59594 init_waitqueue_head(&delayed_root->wait);
59595 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59596 index 4399f0c..a34d8b4 100644
59597 --- a/fs/btrfs/ioctl.c
59598 +++ b/fs/btrfs/ioctl.c
59599 @@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59600 for (i = 0; i < num_types; i++) {
59601 struct btrfs_space_info *tmp;
59602
59603 + /* Don't copy in more than we allocated */
59604 if (!slot_count)
59605 break;
59606
59607 + slot_count--;
59608 +
59609 info = NULL;
59610 rcu_read_lock();
59611 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59612 @@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59613 memcpy(dest, &space, sizeof(space));
59614 dest++;
59615 space_args.total_spaces++;
59616 - slot_count--;
59617 }
59618 - if (!slot_count)
59619 - break;
59620 }
59621 up_read(&info->groups_sem);
59622 }
59623 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59624 index cde9c03..ad4d4db 100644
59625 --- a/fs/btrfs/super.c
59626 +++ b/fs/btrfs/super.c
59627 @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59628 function, line, errstr);
59629 return;
59630 }
59631 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59632 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59633 /* Wake up anybody who may be waiting on this transaction */
59634 wake_up(&root->fs_info->transaction_wait);
59635 wake_up(&root->fs_info->transaction_blocked_wait);
59636 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59637 index b2e7bb4..3719201 100644
59638 --- a/fs/btrfs/sysfs.c
59639 +++ b/fs/btrfs/sysfs.c
59640 @@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59641 for (set = 0; set < FEAT_MAX; set++) {
59642 int i;
59643 struct attribute *attrs[2];
59644 - struct attribute_group agroup = {
59645 + attribute_group_no_const agroup = {
59646 .name = "features",
59647 .attrs = attrs,
59648 };
59649 diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59650 index 2299bfd..4098e72 100644
59651 --- a/fs/btrfs/tests/free-space-tests.c
59652 +++ b/fs/btrfs/tests/free-space-tests.c
59653 @@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59654 * extent entry.
59655 */
59656 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59657 - cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59658 + pax_open_kernel();
59659 + *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59660 + pax_close_kernel();
59661
59662 /*
59663 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59664 @@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59665 if (ret)
59666 return ret;
59667
59668 - cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59669 + pax_open_kernel();
59670 + *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59671 + pax_close_kernel();
59672 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59673
59674 return 0;
59675 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59676 index 154990c..d0cf699 100644
59677 --- a/fs/btrfs/tree-log.h
59678 +++ b/fs/btrfs/tree-log.h
59679 @@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59680 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59681 struct btrfs_trans_handle *trans)
59682 {
59683 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59684 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59685 }
59686
59687 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59688 diff --git a/fs/buffer.c b/fs/buffer.c
59689 index 20805db..2e8fc69 100644
59690 --- a/fs/buffer.c
59691 +++ b/fs/buffer.c
59692 @@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59693 bh_cachep = kmem_cache_create("buffer_head",
59694 sizeof(struct buffer_head), 0,
59695 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59696 - SLAB_MEM_SPREAD),
59697 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59698 NULL);
59699
59700 /*
59701 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59702 index fbb08e9..0fda764 100644
59703 --- a/fs/cachefiles/bind.c
59704 +++ b/fs/cachefiles/bind.c
59705 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59706 args);
59707
59708 /* start by checking things over */
59709 - ASSERT(cache->fstop_percent >= 0 &&
59710 - cache->fstop_percent < cache->fcull_percent &&
59711 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59712 cache->fcull_percent < cache->frun_percent &&
59713 cache->frun_percent < 100);
59714
59715 - ASSERT(cache->bstop_percent >= 0 &&
59716 - cache->bstop_percent < cache->bcull_percent &&
59717 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59718 cache->bcull_percent < cache->brun_percent &&
59719 cache->brun_percent < 100);
59720
59721 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59722 index ce1b115..4a6852c 100644
59723 --- a/fs/cachefiles/daemon.c
59724 +++ b/fs/cachefiles/daemon.c
59725 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59726 if (n > buflen)
59727 return -EMSGSIZE;
59728
59729 - if (copy_to_user(_buffer, buffer, n) != 0)
59730 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59731 return -EFAULT;
59732
59733 return n;
59734 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59735 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59736 return -EIO;
59737
59738 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59739 + if (datalen > PAGE_SIZE - 1)
59740 return -EOPNOTSUPP;
59741
59742 /* drag the command string into the kernel so we can parse it */
59743 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59744 if (args[0] != '%' || args[1] != '\0')
59745 return -EINVAL;
59746
59747 - if (fstop < 0 || fstop >= cache->fcull_percent)
59748 + if (fstop >= cache->fcull_percent)
59749 return cachefiles_daemon_range_error(cache, args);
59750
59751 cache->fstop_percent = fstop;
59752 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59753 if (args[0] != '%' || args[1] != '\0')
59754 return -EINVAL;
59755
59756 - if (bstop < 0 || bstop >= cache->bcull_percent)
59757 + if (bstop >= cache->bcull_percent)
59758 return cachefiles_daemon_range_error(cache, args);
59759
59760 cache->bstop_percent = bstop;
59761 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59762 index 8c52472..c4e3a69 100644
59763 --- a/fs/cachefiles/internal.h
59764 +++ b/fs/cachefiles/internal.h
59765 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59766 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59767 struct rb_root active_nodes; /* active nodes (can't be culled) */
59768 rwlock_t active_lock; /* lock for active_nodes */
59769 - atomic_t gravecounter; /* graveyard uniquifier */
59770 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59771 unsigned frun_percent; /* when to stop culling (% files) */
59772 unsigned fcull_percent; /* when to start culling (% files) */
59773 unsigned fstop_percent; /* when to stop allocating (% files) */
59774 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59775 * proc.c
59776 */
59777 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59778 -extern atomic_t cachefiles_lookup_histogram[HZ];
59779 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59780 -extern atomic_t cachefiles_create_histogram[HZ];
59781 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59782 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59783 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59784
59785 extern int __init cachefiles_proc_init(void);
59786 extern void cachefiles_proc_cleanup(void);
59787 static inline
59788 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59789 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59790 {
59791 unsigned long jif = jiffies - start_jif;
59792 if (jif >= HZ)
59793 jif = HZ - 1;
59794 - atomic_inc(&histogram[jif]);
59795 + atomic_inc_unchecked(&histogram[jif]);
59796 }
59797
59798 #else
59799 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59800 index e12f189..ed17244 100644
59801 --- a/fs/cachefiles/namei.c
59802 +++ b/fs/cachefiles/namei.c
59803 @@ -312,7 +312,7 @@ try_again:
59804 /* first step is to make up a grave dentry in the graveyard */
59805 sprintf(nbuffer, "%08x%08x",
59806 (uint32_t) get_seconds(),
59807 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59808 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59809
59810 /* do the multiway lock magic */
59811 trap = lock_rename(cache->graveyard, dir);
59812 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59813 index eccd339..4c1d995 100644
59814 --- a/fs/cachefiles/proc.c
59815 +++ b/fs/cachefiles/proc.c
59816 @@ -14,9 +14,9 @@
59817 #include <linux/seq_file.h>
59818 #include "internal.h"
59819
59820 -atomic_t cachefiles_lookup_histogram[HZ];
59821 -atomic_t cachefiles_mkdir_histogram[HZ];
59822 -atomic_t cachefiles_create_histogram[HZ];
59823 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59824 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59825 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59826
59827 /*
59828 * display the latency histogram
59829 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59830 return 0;
59831 default:
59832 index = (unsigned long) v - 3;
59833 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59834 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59835 - z = atomic_read(&cachefiles_create_histogram[index]);
59836 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59837 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59838 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59839 if (x == 0 && y == 0 && z == 0)
59840 return 0;
59841
59842 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59843 index 695e788..f4a9d4d 100644
59844 --- a/fs/ceph/dir.c
59845 +++ b/fs/ceph/dir.c
59846 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59847 struct dentry *dentry, *last;
59848 struct ceph_dentry_info *di;
59849 int err = 0;
59850 + char d_name[DNAME_INLINE_LEN];
59851 + const unsigned char *name;
59852
59853 /* claim ref on last dentry we returned */
59854 last = fi->dentry;
59855 @@ -192,7 +194,12 @@ more:
59856
59857 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59858 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59859 - if (!dir_emit(ctx, dentry->d_name.name,
59860 + name = dentry->d_name.name;
59861 + if (name == dentry->d_iname) {
59862 + memcpy(d_name, name, dentry->d_name.len);
59863 + name = d_name;
59864 + }
59865 + if (!dir_emit(ctx, name,
59866 dentry->d_name.len,
59867 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59868 dentry->d_inode->i_mode >> 12)) {
59869 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59870 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59871 struct ceph_mds_client *mdsc = fsc->mdsc;
59872 unsigned frag = fpos_frag(ctx->pos);
59873 - int off = fpos_off(ctx->pos);
59874 + unsigned int off = fpos_off(ctx->pos);
59875 int err;
59876 u32 ftype;
59877 struct ceph_mds_reply_info_parsed *rinfo;
59878 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59879 index f6e1237..796ffd1 100644
59880 --- a/fs/ceph/super.c
59881 +++ b/fs/ceph/super.c
59882 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59883 /*
59884 * construct our own bdi so we can control readahead, etc.
59885 */
59886 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59887 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59888
59889 static int ceph_register_bdi(struct super_block *sb,
59890 struct ceph_fs_client *fsc)
59891 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59892 default_backing_dev_info.ra_pages;
59893
59894 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59895 - atomic_long_inc_return(&bdi_seq));
59896 + atomic_long_inc_return_unchecked(&bdi_seq));
59897 if (!err)
59898 sb->s_bdi = &fsc->backing_dev_info;
59899 return err;
59900 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59901 index 44ec726..11a056f 100644
59902 --- a/fs/cifs/cifs_debug.c
59903 +++ b/fs/cifs/cifs_debug.c
59904 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59905
59906 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59907 #ifdef CONFIG_CIFS_STATS2
59908 - atomic_set(&totBufAllocCount, 0);
59909 - atomic_set(&totSmBufAllocCount, 0);
59910 + atomic_set_unchecked(&totBufAllocCount, 0);
59911 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59912 #endif /* CONFIG_CIFS_STATS2 */
59913 spin_lock(&cifs_tcp_ses_lock);
59914 list_for_each(tmp1, &cifs_tcp_ses_list) {
59915 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59916 tcon = list_entry(tmp3,
59917 struct cifs_tcon,
59918 tcon_list);
59919 - atomic_set(&tcon->num_smbs_sent, 0);
59920 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59921 if (server->ops->clear_stats)
59922 server->ops->clear_stats(tcon);
59923 }
59924 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59925 smBufAllocCount.counter, cifs_min_small);
59926 #ifdef CONFIG_CIFS_STATS2
59927 seq_printf(m, "Total Large %d Small %d Allocations\n",
59928 - atomic_read(&totBufAllocCount),
59929 - atomic_read(&totSmBufAllocCount));
59930 + atomic_read_unchecked(&totBufAllocCount),
59931 + atomic_read_unchecked(&totSmBufAllocCount));
59932 #endif /* CONFIG_CIFS_STATS2 */
59933
59934 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59935 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59936 if (tcon->need_reconnect)
59937 seq_puts(m, "\tDISCONNECTED ");
59938 seq_printf(m, "\nSMBs: %d",
59939 - atomic_read(&tcon->num_smbs_sent));
59940 + atomic_read_unchecked(&tcon->num_smbs_sent));
59941 if (server->ops->print_stats)
59942 server->ops->print_stats(m, tcon);
59943 }
59944 @@ -615,9 +615,11 @@ cifs_security_flags_handle_must_flags(unsigned int *flags)
59945 *flags = CIFSSEC_MUST_NTLMV2;
59946 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
59947 *flags = CIFSSEC_MUST_NTLM;
59948 - else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59949 + else if (CIFSSEC_MUST_LANMAN &&
59950 + (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59951 *flags = CIFSSEC_MUST_LANMAN;
59952 - else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59953 + else if (CIFSSEC_MUST_PLNTXT &&
59954 + (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59955 *flags = CIFSSEC_MUST_PLNTXT;
59956
59957 *flags |= signflags;
59958 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59959 index 9d7996e..35ad5cf4 100644
59960 --- a/fs/cifs/cifsfs.c
59961 +++ b/fs/cifs/cifsfs.c
59962 @@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59963 */
59964 cifs_req_cachep = kmem_cache_create("cifs_request",
59965 CIFSMaxBufSize + max_hdr_size, 0,
59966 - SLAB_HWCACHE_ALIGN, NULL);
59967 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59968 if (cifs_req_cachep == NULL)
59969 return -ENOMEM;
59970
59971 @@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59972 efficient to alloc 1 per page off the slab compared to 17K (5page)
59973 alloc of large cifs buffers even when page debugging is on */
59974 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59975 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59976 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59977 NULL);
59978 if (cifs_sm_req_cachep == NULL) {
59979 mempool_destroy(cifs_req_poolp);
59980 @@ -1205,8 +1205,8 @@ init_cifs(void)
59981 atomic_set(&bufAllocCount, 0);
59982 atomic_set(&smBufAllocCount, 0);
59983 #ifdef CONFIG_CIFS_STATS2
59984 - atomic_set(&totBufAllocCount, 0);
59985 - atomic_set(&totSmBufAllocCount, 0);
59986 + atomic_set_unchecked(&totBufAllocCount, 0);
59987 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59988 #endif /* CONFIG_CIFS_STATS2 */
59989
59990 atomic_set(&midCount, 0);
59991 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59992 index 02a33e5..3a28b5a 100644
59993 --- a/fs/cifs/cifsglob.h
59994 +++ b/fs/cifs/cifsglob.h
59995 @@ -823,35 +823,35 @@ struct cifs_tcon {
59996 __u16 Flags; /* optional support bits */
59997 enum statusEnum tidStatus;
59998 #ifdef CONFIG_CIFS_STATS
59999 - atomic_t num_smbs_sent;
60000 + atomic_unchecked_t num_smbs_sent;
60001 union {
60002 struct {
60003 - atomic_t num_writes;
60004 - atomic_t num_reads;
60005 - atomic_t num_flushes;
60006 - atomic_t num_oplock_brks;
60007 - atomic_t num_opens;
60008 - atomic_t num_closes;
60009 - atomic_t num_deletes;
60010 - atomic_t num_mkdirs;
60011 - atomic_t num_posixopens;
60012 - atomic_t num_posixmkdirs;
60013 - atomic_t num_rmdirs;
60014 - atomic_t num_renames;
60015 - atomic_t num_t2renames;
60016 - atomic_t num_ffirst;
60017 - atomic_t num_fnext;
60018 - atomic_t num_fclose;
60019 - atomic_t num_hardlinks;
60020 - atomic_t num_symlinks;
60021 - atomic_t num_locks;
60022 - atomic_t num_acl_get;
60023 - atomic_t num_acl_set;
60024 + atomic_unchecked_t num_writes;
60025 + atomic_unchecked_t num_reads;
60026 + atomic_unchecked_t num_flushes;
60027 + atomic_unchecked_t num_oplock_brks;
60028 + atomic_unchecked_t num_opens;
60029 + atomic_unchecked_t num_closes;
60030 + atomic_unchecked_t num_deletes;
60031 + atomic_unchecked_t num_mkdirs;
60032 + atomic_unchecked_t num_posixopens;
60033 + atomic_unchecked_t num_posixmkdirs;
60034 + atomic_unchecked_t num_rmdirs;
60035 + atomic_unchecked_t num_renames;
60036 + atomic_unchecked_t num_t2renames;
60037 + atomic_unchecked_t num_ffirst;
60038 + atomic_unchecked_t num_fnext;
60039 + atomic_unchecked_t num_fclose;
60040 + atomic_unchecked_t num_hardlinks;
60041 + atomic_unchecked_t num_symlinks;
60042 + atomic_unchecked_t num_locks;
60043 + atomic_unchecked_t num_acl_get;
60044 + atomic_unchecked_t num_acl_set;
60045 } cifs_stats;
60046 #ifdef CONFIG_CIFS_SMB2
60047 struct {
60048 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60049 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60050 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60051 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60052 } smb2_stats;
60053 #endif /* CONFIG_CIFS_SMB2 */
60054 } stats;
60055 @@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
60056 }
60057
60058 #ifdef CONFIG_CIFS_STATS
60059 -#define cifs_stats_inc atomic_inc
60060 +#define cifs_stats_inc atomic_inc_unchecked
60061
60062 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60063 unsigned int bytes)
60064 @@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60065 /* Various Debug counters */
60066 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60067 #ifdef CONFIG_CIFS_STATS2
60068 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60069 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60070 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60071 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60072 #endif
60073 GLOBAL_EXTERN atomic_t smBufAllocCount;
60074 GLOBAL_EXTERN atomic_t midCount;
60075 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60076 index 3e4d00a..4132187 100644
60077 --- a/fs/cifs/file.c
60078 +++ b/fs/cifs/file.c
60079 @@ -366,6 +366,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
60080 struct cifsLockInfo *li, *tmp;
60081 struct cifs_fid fid;
60082 struct cifs_pending_open open;
60083 + bool oplock_break_cancelled;
60084
60085 spin_lock(&cifs_file_list_lock);
60086 if (--cifs_file->count > 0) {
60087 @@ -397,7 +398,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
60088 }
60089 spin_unlock(&cifs_file_list_lock);
60090
60091 - cancel_work_sync(&cifs_file->oplock_break);
60092 + oplock_break_cancelled = cancel_work_sync(&cifs_file->oplock_break);
60093
60094 if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
60095 struct TCP_Server_Info *server = tcon->ses->server;
60096 @@ -409,6 +410,9 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
60097 _free_xid(xid);
60098 }
60099
60100 + if (oplock_break_cancelled)
60101 + cifs_done_oplock_break(cifsi);
60102 +
60103 cifs_del_pending_open(&open);
60104
60105 /*
60106 @@ -2056,10 +2060,14 @@ static int cifs_writepages(struct address_space *mapping,
60107 index = mapping->writeback_index; /* Start from prev offset */
60108 end = -1;
60109 } else {
60110 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60111 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60112 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60113 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60114 range_whole = true;
60115 + index = 0;
60116 + end = ULONG_MAX;
60117 + } else {
60118 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60119 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60120 + }
60121 scanned = true;
60122 }
60123 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60124 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60125 index b7415d5..3984ec0 100644
60126 --- a/fs/cifs/misc.c
60127 +++ b/fs/cifs/misc.c
60128 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60129 memset(ret_buf, 0, buf_size + 3);
60130 atomic_inc(&bufAllocCount);
60131 #ifdef CONFIG_CIFS_STATS2
60132 - atomic_inc(&totBufAllocCount);
60133 + atomic_inc_unchecked(&totBufAllocCount);
60134 #endif /* CONFIG_CIFS_STATS2 */
60135 }
60136
60137 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60138 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60139 atomic_inc(&smBufAllocCount);
60140 #ifdef CONFIG_CIFS_STATS2
60141 - atomic_inc(&totSmBufAllocCount);
60142 + atomic_inc_unchecked(&totSmBufAllocCount);
60143 #endif /* CONFIG_CIFS_STATS2 */
60144
60145 }
60146 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60147 index d297903..1cb7516 100644
60148 --- a/fs/cifs/smb1ops.c
60149 +++ b/fs/cifs/smb1ops.c
60150 @@ -622,27 +622,27 @@ static void
60151 cifs_clear_stats(struct cifs_tcon *tcon)
60152 {
60153 #ifdef CONFIG_CIFS_STATS
60154 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60155 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60156 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60157 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60158 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60159 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60160 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60161 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60162 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60163 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60164 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60165 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60166 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60167 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60168 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60169 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60170 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60171 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60172 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60173 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60174 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60175 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60176 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60177 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60178 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60179 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60180 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60181 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60182 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60183 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60184 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60185 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60186 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60187 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60188 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60189 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60190 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60191 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60192 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60193 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60194 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60195 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60196 #endif
60197 }
60198
60199 @@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60200 {
60201 #ifdef CONFIG_CIFS_STATS
60202 seq_printf(m, " Oplocks breaks: %d",
60203 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60204 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60205 seq_printf(m, "\nReads: %d Bytes: %llu",
60206 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60207 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60208 (long long)(tcon->bytes_read));
60209 seq_printf(m, "\nWrites: %d Bytes: %llu",
60210 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60211 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60212 (long long)(tcon->bytes_written));
60213 seq_printf(m, "\nFlushes: %d",
60214 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60215 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60216 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60217 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60218 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60219 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60220 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60221 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60222 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60223 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60224 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60225 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60226 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60227 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60228 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60229 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60230 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60231 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60232 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60233 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60234 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60235 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60236 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60237 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60238 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60239 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60240 seq_printf(m, "\nRenames: %d T2 Renames %d",
60241 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60242 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60243 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60244 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60245 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60246 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60247 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60248 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60249 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60250 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60251 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60252 #endif
60253 }
60254
60255 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60256 index c5f521b..1a40865 100644
60257 --- a/fs/cifs/smb2ops.c
60258 +++ b/fs/cifs/smb2ops.c
60259 @@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60260 #ifdef CONFIG_CIFS_STATS
60261 int i;
60262 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60263 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60264 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60265 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60266 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60267 }
60268 #endif
60269 }
60270 @@ -458,65 +458,65 @@ static void
60271 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60272 {
60273 #ifdef CONFIG_CIFS_STATS
60274 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60275 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60276 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60277 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60278 seq_printf(m, "\nNegotiates: %d sent %d failed",
60279 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60280 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60281 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60282 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60283 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60284 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60285 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60286 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60287 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60288 seq_printf(m, "\nLogoffs: %d sent %d failed",
60289 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60290 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60291 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60292 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60293 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60294 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60295 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60296 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60297 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60298 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60299 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60300 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60301 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60302 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60303 seq_printf(m, "\nCreates: %d sent %d failed",
60304 - atomic_read(&sent[SMB2_CREATE_HE]),
60305 - atomic_read(&failed[SMB2_CREATE_HE]));
60306 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60307 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60308 seq_printf(m, "\nCloses: %d sent %d failed",
60309 - atomic_read(&sent[SMB2_CLOSE_HE]),
60310 - atomic_read(&failed[SMB2_CLOSE_HE]));
60311 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60312 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60313 seq_printf(m, "\nFlushes: %d sent %d failed",
60314 - atomic_read(&sent[SMB2_FLUSH_HE]),
60315 - atomic_read(&failed[SMB2_FLUSH_HE]));
60316 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60317 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60318 seq_printf(m, "\nReads: %d sent %d failed",
60319 - atomic_read(&sent[SMB2_READ_HE]),
60320 - atomic_read(&failed[SMB2_READ_HE]));
60321 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60322 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60323 seq_printf(m, "\nWrites: %d sent %d failed",
60324 - atomic_read(&sent[SMB2_WRITE_HE]),
60325 - atomic_read(&failed[SMB2_WRITE_HE]));
60326 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60327 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60328 seq_printf(m, "\nLocks: %d sent %d failed",
60329 - atomic_read(&sent[SMB2_LOCK_HE]),
60330 - atomic_read(&failed[SMB2_LOCK_HE]));
60331 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60332 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60333 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60334 - atomic_read(&sent[SMB2_IOCTL_HE]),
60335 - atomic_read(&failed[SMB2_IOCTL_HE]));
60336 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60337 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60338 seq_printf(m, "\nCancels: %d sent %d failed",
60339 - atomic_read(&sent[SMB2_CANCEL_HE]),
60340 - atomic_read(&failed[SMB2_CANCEL_HE]));
60341 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60342 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60343 seq_printf(m, "\nEchos: %d sent %d failed",
60344 - atomic_read(&sent[SMB2_ECHO_HE]),
60345 - atomic_read(&failed[SMB2_ECHO_HE]));
60346 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60347 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60348 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60349 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60350 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60351 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60352 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60353 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60354 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60355 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60356 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60357 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60358 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60359 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60360 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60361 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60362 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60363 seq_printf(m, "\nSetInfos: %d sent %d failed",
60364 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60365 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60366 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60367 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60368 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60369 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60370 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60371 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60372 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60373 #endif
60374 }
60375
60376 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60377 index 8f1672b..af339c07 100644
60378 --- a/fs/cifs/smb2pdu.c
60379 +++ b/fs/cifs/smb2pdu.c
60380 @@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60381 default:
60382 cifs_dbg(VFS, "info level %u isn't supported\n",
60383 srch_inf->info_level);
60384 - rc = -EINVAL;
60385 - goto qdir_exit;
60386 + return -EINVAL;
60387 }
60388
60389 req->FileIndex = cpu_to_le32(index);
60390 diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
60391 index 6c15663..a4232ec 100644
60392 --- a/fs/cifs/smbencrypt.c
60393 +++ b/fs/cifs/smbencrypt.c
60394 @@ -221,7 +221,7 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16,
60395 }
60396
60397 rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__le16));
60398 - memset(wpwd, 0, 129 * sizeof(__le16));
60399 + memzero_explicit(wpwd, sizeof(wpwd));
60400
60401 return rc;
60402 }
60403 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60404 index 46ee6f2..89a9e7f 100644
60405 --- a/fs/coda/cache.c
60406 +++ b/fs/coda/cache.c
60407 @@ -24,7 +24,7 @@
60408 #include "coda_linux.h"
60409 #include "coda_cache.h"
60410
60411 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60412 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60413
60414 /* replace or extend an acl cache hit */
60415 void coda_cache_enter(struct inode *inode, int mask)
60416 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60417 struct coda_inode_info *cii = ITOC(inode);
60418
60419 spin_lock(&cii->c_lock);
60420 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60421 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60422 if (!uid_eq(cii->c_uid, current_fsuid())) {
60423 cii->c_uid = current_fsuid();
60424 cii->c_cached_perm = mask;
60425 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60426 {
60427 struct coda_inode_info *cii = ITOC(inode);
60428 spin_lock(&cii->c_lock);
60429 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60430 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60431 spin_unlock(&cii->c_lock);
60432 }
60433
60434 /* remove all acl caches */
60435 void coda_cache_clear_all(struct super_block *sb)
60436 {
60437 - atomic_inc(&permission_epoch);
60438 + atomic_inc_unchecked(&permission_epoch);
60439 }
60440
60441
60442 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60443 spin_lock(&cii->c_lock);
60444 hit = (mask & cii->c_cached_perm) == mask &&
60445 uid_eq(cii->c_uid, current_fsuid()) &&
60446 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60447 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60448 spin_unlock(&cii->c_lock);
60449
60450 return hit;
60451 diff --git a/fs/compat.c b/fs/compat.c
60452 index b13df99..6f6f4a3 100644
60453 --- a/fs/compat.c
60454 +++ b/fs/compat.c
60455 @@ -54,7 +54,7 @@
60456 #include <asm/ioctls.h>
60457 #include "internal.h"
60458
60459 -int compat_log = 1;
60460 +int compat_log = 0;
60461
60462 int compat_printk(const char *fmt, ...)
60463 {
60464 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60465
60466 set_fs(KERNEL_DS);
60467 /* The __user pointer cast is valid because of the set_fs() */
60468 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60469 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60470 set_fs(oldfs);
60471 /* truncating is ok because it's a user address */
60472 if (!ret)
60473 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60474 goto out;
60475
60476 ret = -EINVAL;
60477 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60478 + if (nr_segs > UIO_MAXIOV)
60479 goto out;
60480 if (nr_segs > fast_segs) {
60481 ret = -ENOMEM;
60482 @@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60483 struct compat_readdir_callback {
60484 struct dir_context ctx;
60485 struct compat_old_linux_dirent __user *dirent;
60486 + struct file * file;
60487 int result;
60488 };
60489
60490 @@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60491 buf->result = -EOVERFLOW;
60492 return -EOVERFLOW;
60493 }
60494 +
60495 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60496 + return 0;
60497 +
60498 buf->result++;
60499 dirent = buf->dirent;
60500 if (!access_ok(VERIFY_WRITE, dirent,
60501 @@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60502 if (!f.file)
60503 return -EBADF;
60504
60505 + buf.file = f.file;
60506 error = iterate_dir(f.file, &buf.ctx);
60507 if (buf.result)
60508 error = buf.result;
60509 @@ -911,6 +917,7 @@ struct compat_getdents_callback {
60510 struct dir_context ctx;
60511 struct compat_linux_dirent __user *current_dir;
60512 struct compat_linux_dirent __user *previous;
60513 + struct file * file;
60514 int count;
60515 int error;
60516 };
60517 @@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60518 buf->error = -EOVERFLOW;
60519 return -EOVERFLOW;
60520 }
60521 +
60522 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60523 + return 0;
60524 +
60525 dirent = buf->previous;
60526 if (dirent) {
60527 if (__put_user(offset, &dirent->d_off))
60528 @@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60529 if (!f.file)
60530 return -EBADF;
60531
60532 + buf.file = f.file;
60533 error = iterate_dir(f.file, &buf.ctx);
60534 if (error >= 0)
60535 error = buf.error;
60536 @@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60537 struct dir_context ctx;
60538 struct linux_dirent64 __user *current_dir;
60539 struct linux_dirent64 __user *previous;
60540 + struct file * file;
60541 int count;
60542 int error;
60543 };
60544 @@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60545 buf->error = -EINVAL; /* only used if we fail.. */
60546 if (reclen > buf->count)
60547 return -EINVAL;
60548 +
60549 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60550 + return 0;
60551 +
60552 dirent = buf->previous;
60553
60554 if (dirent) {
60555 @@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60556 if (!f.file)
60557 return -EBADF;
60558
60559 + buf.file = f.file;
60560 error = iterate_dir(f.file, &buf.ctx);
60561 if (error >= 0)
60562 error = buf.error;
60563 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60564 index 4d24d17..4f8c09e 100644
60565 --- a/fs/compat_binfmt_elf.c
60566 +++ b/fs/compat_binfmt_elf.c
60567 @@ -30,11 +30,13 @@
60568 #undef elf_phdr
60569 #undef elf_shdr
60570 #undef elf_note
60571 +#undef elf_dyn
60572 #undef elf_addr_t
60573 #define elfhdr elf32_hdr
60574 #define elf_phdr elf32_phdr
60575 #define elf_shdr elf32_shdr
60576 #define elf_note elf32_note
60577 +#define elf_dyn Elf32_Dyn
60578 #define elf_addr_t Elf32_Addr
60579
60580 /*
60581 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60582 index afec645..9c65620 100644
60583 --- a/fs/compat_ioctl.c
60584 +++ b/fs/compat_ioctl.c
60585 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60586 return -EFAULT;
60587 if (__get_user(udata, &ss32->iomem_base))
60588 return -EFAULT;
60589 - ss.iomem_base = compat_ptr(udata);
60590 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60591 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60592 __get_user(ss.port_high, &ss32->port_high))
60593 return -EFAULT;
60594 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60595 for (i = 0; i < nmsgs; i++) {
60596 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60597 return -EFAULT;
60598 - if (get_user(datap, &umsgs[i].buf) ||
60599 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60600 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60601 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60602 return -EFAULT;
60603 }
60604 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60605 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60606 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60607 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60608 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60609 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60610 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60611 return -EFAULT;
60612
60613 return ioctl_preallocate(file, p);
60614 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60615 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60616 {
60617 unsigned int a, b;
60618 - a = *(unsigned int *)p;
60619 - b = *(unsigned int *)q;
60620 + a = *(const unsigned int *)p;
60621 + b = *(const unsigned int *)q;
60622 if (a > b)
60623 return 1;
60624 if (a < b)
60625 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60626 index 668dcab..daebcd6 100644
60627 --- a/fs/configfs/dir.c
60628 +++ b/fs/configfs/dir.c
60629 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60630 }
60631 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60632 struct configfs_dirent *next;
60633 - const char *name;
60634 + const unsigned char * name;
60635 + char d_name[sizeof(next->s_dentry->d_iname)];
60636 int len;
60637 struct inode *inode = NULL;
60638
60639 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60640 continue;
60641
60642 name = configfs_get_name(next);
60643 - len = strlen(name);
60644 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60645 + len = next->s_dentry->d_name.len;
60646 + memcpy(d_name, name, len);
60647 + name = d_name;
60648 + } else
60649 + len = strlen(name);
60650
60651 /*
60652 * We'll have a dentry and an inode for
60653 diff --git a/fs/coredump.c b/fs/coredump.c
60654 index b5c86ff..0dac262 100644
60655 --- a/fs/coredump.c
60656 +++ b/fs/coredump.c
60657 @@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60658 struct pipe_inode_info *pipe = file->private_data;
60659
60660 pipe_lock(pipe);
60661 - pipe->readers++;
60662 - pipe->writers--;
60663 + atomic_inc(&pipe->readers);
60664 + atomic_dec(&pipe->writers);
60665 wake_up_interruptible_sync(&pipe->wait);
60666 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60667 pipe_unlock(pipe);
60668 @@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60669 * We actually want wait_event_freezable() but then we need
60670 * to clear TIF_SIGPENDING and improve dump_interrupted().
60671 */
60672 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60673 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60674
60675 pipe_lock(pipe);
60676 - pipe->readers--;
60677 - pipe->writers++;
60678 + atomic_dec(&pipe->readers);
60679 + atomic_inc(&pipe->writers);
60680 pipe_unlock(pipe);
60681 }
60682
60683 @@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60684 struct files_struct *displaced;
60685 bool need_nonrelative = false;
60686 bool core_dumped = false;
60687 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60688 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60689 + long signr = siginfo->si_signo;
60690 + int dumpable;
60691 struct coredump_params cprm = {
60692 .siginfo = siginfo,
60693 .regs = signal_pt_regs(),
60694 @@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60695 .mm_flags = mm->flags,
60696 };
60697
60698 - audit_core_dumps(siginfo->si_signo);
60699 + audit_core_dumps(signr);
60700 +
60701 + dumpable = __get_dumpable(cprm.mm_flags);
60702 +
60703 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60704 + gr_handle_brute_attach(dumpable);
60705
60706 binfmt = mm->binfmt;
60707 if (!binfmt || !binfmt->core_dump)
60708 goto fail;
60709 - if (!__get_dumpable(cprm.mm_flags))
60710 + if (!dumpable)
60711 goto fail;
60712
60713 cred = prepare_creds();
60714 @@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60715 need_nonrelative = true;
60716 }
60717
60718 - retval = coredump_wait(siginfo->si_signo, &core_state);
60719 + retval = coredump_wait(signr, &core_state);
60720 if (retval < 0)
60721 goto fail_creds;
60722
60723 @@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60724 }
60725 cprm.limit = RLIM_INFINITY;
60726
60727 - dump_count = atomic_inc_return(&core_dump_count);
60728 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60729 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60730 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60731 task_tgid_vnr(current), current->comm);
60732 @@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60733 } else {
60734 struct inode *inode;
60735
60736 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60737 +
60738 if (cprm.limit < binfmt->min_coredump)
60739 goto fail_unlock;
60740
60741 @@ -681,7 +690,7 @@ close_fail:
60742 filp_close(cprm.file, NULL);
60743 fail_dropcount:
60744 if (ispipe)
60745 - atomic_dec(&core_dump_count);
60746 + atomic_dec_unchecked(&core_dump_count);
60747 fail_unlock:
60748 kfree(cn.corename);
60749 coredump_finish(mm, core_dumped);
60750 @@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60751 struct file *file = cprm->file;
60752 loff_t pos = file->f_pos;
60753 ssize_t n;
60754 +
60755 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60756 if (cprm->written + nr > cprm->limit)
60757 return 0;
60758 while (nr) {
60759 diff --git a/fs/dcache.c b/fs/dcache.c
60760 index 03dca3c..15f326d 100644
60761 --- a/fs/dcache.c
60762 +++ b/fs/dcache.c
60763 @@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60764 * dentry_iput drops the locks, at which point nobody (except
60765 * transient RCU lookups) can reach this dentry.
60766 */
60767 - BUG_ON((int)dentry->d_lockref.count > 0);
60768 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60769 this_cpu_dec(nr_dentry);
60770 if (dentry->d_op && dentry->d_op->d_release)
60771 dentry->d_op->d_release(dentry);
60772 @@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60773 struct dentry *parent = dentry->d_parent;
60774 if (IS_ROOT(dentry))
60775 return NULL;
60776 - if (unlikely((int)dentry->d_lockref.count < 0))
60777 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60778 return NULL;
60779 if (likely(spin_trylock(&parent->d_lock)))
60780 return parent;
60781 @@ -638,7 +638,7 @@ repeat:
60782 dentry->d_flags |= DCACHE_REFERENCED;
60783 dentry_lru_add(dentry);
60784
60785 - dentry->d_lockref.count--;
60786 + __lockref_dec(&dentry->d_lockref);
60787 spin_unlock(&dentry->d_lock);
60788 return;
60789
60790 @@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60791 /* This must be called with d_lock held */
60792 static inline void __dget_dlock(struct dentry *dentry)
60793 {
60794 - dentry->d_lockref.count++;
60795 + __lockref_inc(&dentry->d_lockref);
60796 }
60797
60798 static inline void __dget(struct dentry *dentry)
60799 @@ -694,8 +694,8 @@ repeat:
60800 goto repeat;
60801 }
60802 rcu_read_unlock();
60803 - BUG_ON(!ret->d_lockref.count);
60804 - ret->d_lockref.count++;
60805 + BUG_ON(!__lockref_read(&ret->d_lockref));
60806 + __lockref_inc(&ret->d_lockref);
60807 spin_unlock(&ret->d_lock);
60808 return ret;
60809 }
60810 @@ -773,9 +773,9 @@ restart:
60811 spin_lock(&inode->i_lock);
60812 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60813 spin_lock(&dentry->d_lock);
60814 - if (!dentry->d_lockref.count) {
60815 + if (!__lockref_read(&dentry->d_lockref)) {
60816 struct dentry *parent = lock_parent(dentry);
60817 - if (likely(!dentry->d_lockref.count)) {
60818 + if (likely(!__lockref_read(&dentry->d_lockref))) {
60819 __dentry_kill(dentry);
60820 dput(parent);
60821 goto restart;
60822 @@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60823 * We found an inuse dentry which was not removed from
60824 * the LRU because of laziness during lookup. Do not free it.
60825 */
60826 - if ((int)dentry->d_lockref.count > 0) {
60827 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60828 spin_unlock(&dentry->d_lock);
60829 if (parent)
60830 spin_unlock(&parent->d_lock);
60831 @@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60832 dentry = parent;
60833 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60834 parent = lock_parent(dentry);
60835 - if (dentry->d_lockref.count != 1) {
60836 - dentry->d_lockref.count--;
60837 + if (__lockref_read(&dentry->d_lockref) != 1) {
60838 + __lockref_inc(&dentry->d_lockref);
60839 spin_unlock(&dentry->d_lock);
60840 if (parent)
60841 spin_unlock(&parent->d_lock);
60842 @@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60843 * counts, just remove them from the LRU. Otherwise give them
60844 * another pass through the LRU.
60845 */
60846 - if (dentry->d_lockref.count) {
60847 + if (__lockref_read(&dentry->d_lockref) > 0) {
60848 d_lru_isolate(dentry);
60849 spin_unlock(&dentry->d_lock);
60850 return LRU_REMOVED;
60851 @@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60852 } else {
60853 if (dentry->d_flags & DCACHE_LRU_LIST)
60854 d_lru_del(dentry);
60855 - if (!dentry->d_lockref.count) {
60856 + if (!__lockref_read(&dentry->d_lockref)) {
60857 d_shrink_add(dentry, &data->dispose);
60858 data->found++;
60859 }
60860 @@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60861 return D_WALK_CONTINUE;
60862
60863 /* root with refcount 1 is fine */
60864 - if (dentry == _data && dentry->d_lockref.count == 1)
60865 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60866 return D_WALK_CONTINUE;
60867
60868 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60869 @@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60870 dentry->d_inode ?
60871 dentry->d_inode->i_ino : 0UL,
60872 dentry,
60873 - dentry->d_lockref.count,
60874 + __lockref_read(&dentry->d_lockref),
60875 dentry->d_sb->s_type->name,
60876 dentry->d_sb->s_id);
60877 WARN_ON(1);
60878 @@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60879 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60880 if (name->len > DNAME_INLINE_LEN-1) {
60881 size_t size = offsetof(struct external_name, name[1]);
60882 - struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60883 + struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60884 if (!p) {
60885 kmem_cache_free(dentry_cache, dentry);
60886 return NULL;
60887 @@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60888 smp_wmb();
60889 dentry->d_name.name = dname;
60890
60891 - dentry->d_lockref.count = 1;
60892 + __lockref_set(&dentry->d_lockref, 1);
60893 dentry->d_flags = 0;
60894 spin_lock_init(&dentry->d_lock);
60895 seqcount_init(&dentry->d_seq);
60896 @@ -1452,6 +1452,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60897 dentry->d_sb = sb;
60898 dentry->d_op = NULL;
60899 dentry->d_fsdata = NULL;
60900 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
60901 + atomic_set(&dentry->chroot_refcnt, 0);
60902 +#endif
60903 INIT_HLIST_BL_NODE(&dentry->d_hash);
60904 INIT_LIST_HEAD(&dentry->d_lru);
60905 INIT_LIST_HEAD(&dentry->d_subdirs);
60906 @@ -2183,7 +2186,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60907 goto next;
60908 }
60909
60910 - dentry->d_lockref.count++;
60911 + __lockref_inc(&dentry->d_lockref);
60912 found = dentry;
60913 spin_unlock(&dentry->d_lock);
60914 break;
60915 @@ -2282,7 +2285,7 @@ again:
60916 spin_lock(&dentry->d_lock);
60917 inode = dentry->d_inode;
60918 isdir = S_ISDIR(inode->i_mode);
60919 - if (dentry->d_lockref.count == 1) {
60920 + if (__lockref_read(&dentry->d_lockref) == 1) {
60921 if (!spin_trylock(&inode->i_lock)) {
60922 spin_unlock(&dentry->d_lock);
60923 cpu_relax();
60924 @@ -3308,7 +3311,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60925
60926 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60927 dentry->d_flags |= DCACHE_GENOCIDE;
60928 - dentry->d_lockref.count--;
60929 + __lockref_dec(&dentry->d_lockref);
60930 }
60931 }
60932 return D_WALK_CONTINUE;
60933 @@ -3424,7 +3427,8 @@ void __init vfs_caches_init(unsigned long mempages)
60934 mempages -= reserve;
60935
60936 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60937 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60938 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60939 + SLAB_NO_SANITIZE, NULL);
60940
60941 dcache_init();
60942 inode_init();
60943 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60944 index 05f2960..b012481 100644
60945 --- a/fs/debugfs/inode.c
60946 +++ b/fs/debugfs/inode.c
60947 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60948 */
60949 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60950 {
60951 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60952 + return __create_file(name, S_IFDIR | S_IRWXU,
60953 +#else
60954 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60955 +#endif
60956 parent, NULL, NULL);
60957 }
60958 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60959 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60960 index 1686dc2..9611c50 100644
60961 --- a/fs/ecryptfs/inode.c
60962 +++ b/fs/ecryptfs/inode.c
60963 @@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60964 old_fs = get_fs();
60965 set_fs(get_ds());
60966 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60967 - (char __user *)lower_buf,
60968 + (char __force_user *)lower_buf,
60969 PATH_MAX);
60970 set_fs(old_fs);
60971 if (rc < 0)
60972 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60973 index e4141f2..d8263e8 100644
60974 --- a/fs/ecryptfs/miscdev.c
60975 +++ b/fs/ecryptfs/miscdev.c
60976 @@ -304,7 +304,7 @@ check_list:
60977 goto out_unlock_msg_ctx;
60978 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60979 if (msg_ctx->msg) {
60980 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
60981 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60982 goto out_unlock_msg_ctx;
60983 i += packet_length_size;
60984 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60985 diff --git a/fs/exec.c b/fs/exec.c
60986 index 7302b75..b917171 100644
60987 --- a/fs/exec.c
60988 +++ b/fs/exec.c
60989 @@ -56,8 +56,20 @@
60990 #include <linux/pipe_fs_i.h>
60991 #include <linux/oom.h>
60992 #include <linux/compat.h>
60993 +#include <linux/random.h>
60994 +#include <linux/seq_file.h>
60995 +#include <linux/coredump.h>
60996 +#include <linux/mman.h>
60997 +
60998 +#ifdef CONFIG_PAX_REFCOUNT
60999 +#include <linux/kallsyms.h>
61000 +#include <linux/kdebug.h>
61001 +#endif
61002 +
61003 +#include <trace/events/fs.h>
61004
61005 #include <asm/uaccess.h>
61006 +#include <asm/sections.h>
61007 #include <asm/mmu_context.h>
61008 #include <asm/tlb.h>
61009
61010 @@ -66,19 +78,34 @@
61011
61012 #include <trace/events/sched.h>
61013
61014 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61015 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61016 +{
61017 + 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");
61018 +}
61019 +#endif
61020 +
61021 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61022 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61023 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61024 +#endif
61025 +
61026 int suid_dumpable = 0;
61027
61028 static LIST_HEAD(formats);
61029 static DEFINE_RWLOCK(binfmt_lock);
61030
61031 +extern int gr_process_kernel_exec_ban(void);
61032 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61033 +
61034 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61035 {
61036 BUG_ON(!fmt);
61037 if (WARN_ON(!fmt->load_binary))
61038 return;
61039 write_lock(&binfmt_lock);
61040 - insert ? list_add(&fmt->lh, &formats) :
61041 - list_add_tail(&fmt->lh, &formats);
61042 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61043 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61044 write_unlock(&binfmt_lock);
61045 }
61046
61047 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61048 void unregister_binfmt(struct linux_binfmt * fmt)
61049 {
61050 write_lock(&binfmt_lock);
61051 - list_del(&fmt->lh);
61052 + pax_list_del((struct list_head *)&fmt->lh);
61053 write_unlock(&binfmt_lock);
61054 }
61055
61056 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61057 int write)
61058 {
61059 struct page *page;
61060 - int ret;
61061
61062 -#ifdef CONFIG_STACK_GROWSUP
61063 - if (write) {
61064 - ret = expand_downwards(bprm->vma, pos);
61065 - if (ret < 0)
61066 - return NULL;
61067 - }
61068 -#endif
61069 - ret = get_user_pages(current, bprm->mm, pos,
61070 - 1, write, 1, &page, NULL);
61071 - if (ret <= 0)
61072 + if (0 > expand_downwards(bprm->vma, pos))
61073 + return NULL;
61074 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61075 return NULL;
61076
61077 if (write) {
61078 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61079 if (size <= ARG_MAX)
61080 return page;
61081
61082 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61083 + // only allow 512KB for argv+env on suid/sgid binaries
61084 + // to prevent easy ASLR exhaustion
61085 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61086 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61087 + (size > (512 * 1024))) {
61088 + put_page(page);
61089 + return NULL;
61090 + }
61091 +#endif
61092 +
61093 /*
61094 * Limit to 1/4-th the stack size for the argv+env strings.
61095 * This ensures that:
61096 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61097 vma->vm_end = STACK_TOP_MAX;
61098 vma->vm_start = vma->vm_end - PAGE_SIZE;
61099 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61100 +
61101 +#ifdef CONFIG_PAX_SEGMEXEC
61102 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61103 +#endif
61104 +
61105 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61106 INIT_LIST_HEAD(&vma->anon_vma_chain);
61107
61108 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61109 mm->stack_vm = mm->total_vm = 1;
61110 up_write(&mm->mmap_sem);
61111 bprm->p = vma->vm_end - sizeof(void *);
61112 +
61113 +#ifdef CONFIG_PAX_RANDUSTACK
61114 + if (randomize_va_space)
61115 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61116 +#endif
61117 +
61118 return 0;
61119 err:
61120 up_write(&mm->mmap_sem);
61121 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61122 } ptr;
61123 };
61124
61125 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61126 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61127 {
61128 const char __user *native;
61129
61130 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61131 compat_uptr_t compat;
61132
61133 if (get_user(compat, argv.ptr.compat + nr))
61134 - return ERR_PTR(-EFAULT);
61135 + return (const char __force_user *)ERR_PTR(-EFAULT);
61136
61137 return compat_ptr(compat);
61138 }
61139 #endif
61140
61141 if (get_user(native, argv.ptr.native + nr))
61142 - return ERR_PTR(-EFAULT);
61143 + return (const char __force_user *)ERR_PTR(-EFAULT);
61144
61145 return native;
61146 }
61147 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61148 if (!p)
61149 break;
61150
61151 - if (IS_ERR(p))
61152 + if (IS_ERR((const char __force_kernel *)p))
61153 return -EFAULT;
61154
61155 if (i >= max)
61156 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61157
61158 ret = -EFAULT;
61159 str = get_user_arg_ptr(argv, argc);
61160 - if (IS_ERR(str))
61161 + if (IS_ERR((const char __force_kernel *)str))
61162 goto out;
61163
61164 len = strnlen_user(str, MAX_ARG_STRLEN);
61165 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61166 int r;
61167 mm_segment_t oldfs = get_fs();
61168 struct user_arg_ptr argv = {
61169 - .ptr.native = (const char __user *const __user *)__argv,
61170 + .ptr.native = (const char __user * const __force_user *)__argv,
61171 };
61172
61173 set_fs(KERNEL_DS);
61174 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61175 unsigned long new_end = old_end - shift;
61176 struct mmu_gather tlb;
61177
61178 - BUG_ON(new_start > new_end);
61179 + if (new_start >= new_end || new_start < mmap_min_addr)
61180 + return -ENOMEM;
61181
61182 /*
61183 * ensure there are no vmas between where we want to go
61184 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61185 if (vma != find_vma(mm, new_start))
61186 return -EFAULT;
61187
61188 +#ifdef CONFIG_PAX_SEGMEXEC
61189 + BUG_ON(pax_find_mirror_vma(vma));
61190 +#endif
61191 +
61192 /*
61193 * cover the whole range: [new_start, old_end)
61194 */
61195 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61196 stack_top = arch_align_stack(stack_top);
61197 stack_top = PAGE_ALIGN(stack_top);
61198
61199 - if (unlikely(stack_top < mmap_min_addr) ||
61200 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61201 - return -ENOMEM;
61202 -
61203 stack_shift = vma->vm_end - stack_top;
61204
61205 bprm->p -= stack_shift;
61206 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61207 bprm->exec -= stack_shift;
61208
61209 down_write(&mm->mmap_sem);
61210 +
61211 + /* Move stack pages down in memory. */
61212 + if (stack_shift) {
61213 + ret = shift_arg_pages(vma, stack_shift);
61214 + if (ret)
61215 + goto out_unlock;
61216 + }
61217 +
61218 vm_flags = VM_STACK_FLAGS;
61219
61220 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61221 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61222 + vm_flags &= ~VM_EXEC;
61223 +
61224 +#ifdef CONFIG_PAX_MPROTECT
61225 + if (mm->pax_flags & MF_PAX_MPROTECT)
61226 + vm_flags &= ~VM_MAYEXEC;
61227 +#endif
61228 +
61229 + }
61230 +#endif
61231 +
61232 /*
61233 * Adjust stack execute permissions; explicitly enable for
61234 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61235 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61236 goto out_unlock;
61237 BUG_ON(prev != vma);
61238
61239 - /* Move stack pages down in memory. */
61240 - if (stack_shift) {
61241 - ret = shift_arg_pages(vma, stack_shift);
61242 - if (ret)
61243 - goto out_unlock;
61244 - }
61245 -
61246 /* mprotect_fixup is overkill to remove the temporary stack flags */
61247 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61248
61249 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61250 #endif
61251 current->mm->start_stack = bprm->p;
61252 ret = expand_stack(vma, stack_base);
61253 +
61254 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61255 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61256 + unsigned long size;
61257 + vm_flags_t vm_flags;
61258 +
61259 + size = STACK_TOP - vma->vm_end;
61260 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61261 +
61262 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61263 +
61264 +#ifdef CONFIG_X86
61265 + if (!ret) {
61266 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61267 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61268 + }
61269 +#endif
61270 +
61271 + }
61272 +#endif
61273 +
61274 if (ret)
61275 ret = -EFAULT;
61276
61277 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61278
61279 fsnotify_open(file);
61280
61281 + trace_open_exec(name->name);
61282 +
61283 err = deny_write_access(file);
61284 if (err)
61285 goto exit;
61286 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61287 old_fs = get_fs();
61288 set_fs(get_ds());
61289 /* The cast to a user pointer is valid due to the set_fs() */
61290 - result = vfs_read(file, (void __user *)addr, count, &pos);
61291 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61292 set_fs(old_fs);
61293 return result;
61294 }
61295 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61296 tsk->mm = mm;
61297 tsk->active_mm = mm;
61298 activate_mm(active_mm, mm);
61299 + populate_stack();
61300 tsk->mm->vmacache_seqnum = 0;
61301 vmacache_flush(tsk);
61302 task_unlock(tsk);
61303 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61304 }
61305 rcu_read_unlock();
61306
61307 - if (p->fs->users > n_fs)
61308 + if (atomic_read(&p->fs->users) > n_fs)
61309 bprm->unsafe |= LSM_UNSAFE_SHARE;
61310 else
61311 p->fs->in_exec = 1;
61312 @@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61313 return ret;
61314 }
61315
61316 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61317 +static DEFINE_PER_CPU(u64, exec_counter);
61318 +static int __init init_exec_counters(void)
61319 +{
61320 + unsigned int cpu;
61321 +
61322 + for_each_possible_cpu(cpu) {
61323 + per_cpu(exec_counter, cpu) = (u64)cpu;
61324 + }
61325 +
61326 + return 0;
61327 +}
61328 +early_initcall(init_exec_counters);
61329 +static inline void increment_exec_counter(void)
61330 +{
61331 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61332 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61333 +}
61334 +#else
61335 +static inline void increment_exec_counter(void) {}
61336 +#endif
61337 +
61338 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61339 + struct user_arg_ptr argv);
61340 +
61341 /*
61342 * sys_execve() executes a new program.
61343 */
61344 @@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61345 struct user_arg_ptr argv,
61346 struct user_arg_ptr envp)
61347 {
61348 +#ifdef CONFIG_GRKERNSEC
61349 + struct file *old_exec_file;
61350 + struct acl_subject_label *old_acl;
61351 + struct rlimit old_rlim[RLIM_NLIMITS];
61352 +#endif
61353 struct linux_binprm *bprm;
61354 struct file *file;
61355 struct files_struct *displaced;
61356 @@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61357 if (IS_ERR(filename))
61358 return PTR_ERR(filename);
61359
61360 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61361 +
61362 /*
61363 * We move the actual failure in case of RLIMIT_NPROC excess from
61364 * set*uid() to execve() because too many poorly written programs
61365 @@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61366 if (IS_ERR(file))
61367 goto out_unmark;
61368
61369 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61370 + retval = -EPERM;
61371 + goto out_unmark;
61372 + }
61373 +
61374 sched_exec();
61375
61376 bprm->file = file;
61377 bprm->filename = bprm->interp = filename->name;
61378
61379 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61380 + retval = -EACCES;
61381 + goto out_unmark;
61382 + }
61383 +
61384 retval = bprm_mm_init(bprm);
61385 if (retval)
61386 goto out_unmark;
61387 @@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61388 if (retval < 0)
61389 goto out;
61390
61391 +#ifdef CONFIG_GRKERNSEC
61392 + old_acl = current->acl;
61393 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61394 + old_exec_file = current->exec_file;
61395 + get_file(file);
61396 + current->exec_file = file;
61397 +#endif
61398 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61399 + /* limit suid stack to 8MB
61400 + * we saved the old limits above and will restore them if this exec fails
61401 + */
61402 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61403 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61404 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61405 +#endif
61406 +
61407 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61408 + retval = -EPERM;
61409 + goto out_fail;
61410 + }
61411 +
61412 + if (!gr_tpe_allow(file)) {
61413 + retval = -EACCES;
61414 + goto out_fail;
61415 + }
61416 +
61417 + if (gr_check_crash_exec(file)) {
61418 + retval = -EACCES;
61419 + goto out_fail;
61420 + }
61421 +
61422 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61423 + bprm->unsafe);
61424 + if (retval < 0)
61425 + goto out_fail;
61426 +
61427 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61428 if (retval < 0)
61429 - goto out;
61430 + goto out_fail;
61431
61432 bprm->exec = bprm->p;
61433 retval = copy_strings(bprm->envc, envp, bprm);
61434 if (retval < 0)
61435 - goto out;
61436 + goto out_fail;
61437
61438 retval = copy_strings(bprm->argc, argv, bprm);
61439 if (retval < 0)
61440 - goto out;
61441 + goto out_fail;
61442 +
61443 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61444 +
61445 + gr_handle_exec_args(bprm, argv);
61446
61447 retval = exec_binprm(bprm);
61448 if (retval < 0)
61449 - goto out;
61450 + goto out_fail;
61451 +#ifdef CONFIG_GRKERNSEC
61452 + if (old_exec_file)
61453 + fput(old_exec_file);
61454 +#endif
61455
61456 /* execve succeeded */
61457 +
61458 + increment_exec_counter();
61459 current->fs->in_exec = 0;
61460 current->in_execve = 0;
61461 acct_update_integrals(current);
61462 @@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61463 put_files_struct(displaced);
61464 return retval;
61465
61466 +out_fail:
61467 +#ifdef CONFIG_GRKERNSEC
61468 + current->acl = old_acl;
61469 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61470 + fput(current->exec_file);
61471 + current->exec_file = old_exec_file;
61472 +#endif
61473 +
61474 out:
61475 if (bprm->mm) {
61476 acct_arg_size(bprm, 0);
61477 @@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61478 return compat_do_execve(getname(filename), argv, envp);
61479 }
61480 #endif
61481 +
61482 +int pax_check_flags(unsigned long *flags)
61483 +{
61484 + int retval = 0;
61485 +
61486 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61487 + if (*flags & MF_PAX_SEGMEXEC)
61488 + {
61489 + *flags &= ~MF_PAX_SEGMEXEC;
61490 + retval = -EINVAL;
61491 + }
61492 +#endif
61493 +
61494 + if ((*flags & MF_PAX_PAGEEXEC)
61495 +
61496 +#ifdef CONFIG_PAX_PAGEEXEC
61497 + && (*flags & MF_PAX_SEGMEXEC)
61498 +#endif
61499 +
61500 + )
61501 + {
61502 + *flags &= ~MF_PAX_PAGEEXEC;
61503 + retval = -EINVAL;
61504 + }
61505 +
61506 + if ((*flags & MF_PAX_MPROTECT)
61507 +
61508 +#ifdef CONFIG_PAX_MPROTECT
61509 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61510 +#endif
61511 +
61512 + )
61513 + {
61514 + *flags &= ~MF_PAX_MPROTECT;
61515 + retval = -EINVAL;
61516 + }
61517 +
61518 + if ((*flags & MF_PAX_EMUTRAMP)
61519 +
61520 +#ifdef CONFIG_PAX_EMUTRAMP
61521 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61522 +#endif
61523 +
61524 + )
61525 + {
61526 + *flags &= ~MF_PAX_EMUTRAMP;
61527 + retval = -EINVAL;
61528 + }
61529 +
61530 + return retval;
61531 +}
61532 +
61533 +EXPORT_SYMBOL(pax_check_flags);
61534 +
61535 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61536 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61537 +{
61538 + char *pathname = d_path(path, buf, buflen);
61539 +
61540 + if (IS_ERR(pathname))
61541 + goto toolong;
61542 +
61543 + pathname = mangle_path(buf, pathname, "\t\n\\");
61544 + if (!pathname)
61545 + goto toolong;
61546 +
61547 + *pathname = 0;
61548 + return buf;
61549 +
61550 +toolong:
61551 + return "<path too long>";
61552 +}
61553 +EXPORT_SYMBOL(pax_get_path);
61554 +
61555 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61556 +{
61557 + struct task_struct *tsk = current;
61558 + struct mm_struct *mm = current->mm;
61559 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61560 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61561 + char *path_exec = NULL;
61562 + char *path_fault = NULL;
61563 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61564 + siginfo_t info = { };
61565 +
61566 + if (buffer_exec && buffer_fault) {
61567 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61568 +
61569 + down_read(&mm->mmap_sem);
61570 + vma = mm->mmap;
61571 + while (vma && (!vma_exec || !vma_fault)) {
61572 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61573 + vma_exec = vma;
61574 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61575 + vma_fault = vma;
61576 + vma = vma->vm_next;
61577 + }
61578 + if (vma_exec)
61579 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61580 + if (vma_fault) {
61581 + start = vma_fault->vm_start;
61582 + end = vma_fault->vm_end;
61583 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61584 + if (vma_fault->vm_file)
61585 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61586 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61587 + path_fault = "<heap>";
61588 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61589 + path_fault = "<stack>";
61590 + else
61591 + path_fault = "<anonymous mapping>";
61592 + }
61593 + up_read(&mm->mmap_sem);
61594 + }
61595 + if (tsk->signal->curr_ip)
61596 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61597 + else
61598 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61599 + 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),
61600 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61601 + free_page((unsigned long)buffer_exec);
61602 + free_page((unsigned long)buffer_fault);
61603 + pax_report_insns(regs, pc, sp);
61604 + info.si_signo = SIGKILL;
61605 + info.si_errno = 0;
61606 + info.si_code = SI_KERNEL;
61607 + info.si_pid = 0;
61608 + info.si_uid = 0;
61609 + do_coredump(&info);
61610 +}
61611 +#endif
61612 +
61613 +#ifdef CONFIG_PAX_REFCOUNT
61614 +void pax_report_refcount_overflow(struct pt_regs *regs)
61615 +{
61616 + if (current->signal->curr_ip)
61617 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61618 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61619 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61620 + else
61621 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61622 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61623 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61624 + preempt_disable();
61625 + show_regs(regs);
61626 + preempt_enable();
61627 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61628 +}
61629 +#endif
61630 +
61631 +#ifdef CONFIG_PAX_USERCOPY
61632 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61633 +static noinline int check_stack_object(const void *obj, unsigned long len)
61634 +{
61635 + const void * const stack = task_stack_page(current);
61636 + const void * const stackend = stack + THREAD_SIZE;
61637 +
61638 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61639 + const void *frame = NULL;
61640 + const void *oldframe;
61641 +#endif
61642 +
61643 + if (obj + len < obj)
61644 + return -1;
61645 +
61646 + if (obj + len <= stack || stackend <= obj)
61647 + return 0;
61648 +
61649 + if (obj < stack || stackend < obj + len)
61650 + return -1;
61651 +
61652 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61653 + oldframe = __builtin_frame_address(1);
61654 + if (oldframe)
61655 + frame = __builtin_frame_address(2);
61656 + /*
61657 + low ----------------------------------------------> high
61658 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61659 + ^----------------^
61660 + allow copies only within here
61661 + */
61662 + while (stack <= frame && frame < stackend) {
61663 + /* if obj + len extends past the last frame, this
61664 + check won't pass and the next frame will be 0,
61665 + causing us to bail out and correctly report
61666 + the copy as invalid
61667 + */
61668 + if (obj + len <= frame)
61669 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61670 + oldframe = frame;
61671 + frame = *(const void * const *)frame;
61672 + }
61673 + return -1;
61674 +#else
61675 + return 1;
61676 +#endif
61677 +}
61678 +
61679 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61680 +{
61681 + if (current->signal->curr_ip)
61682 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61683 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61684 + else
61685 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61686 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61687 + dump_stack();
61688 + gr_handle_kernel_exploit();
61689 + do_group_exit(SIGKILL);
61690 +}
61691 +#endif
61692 +
61693 +#ifdef CONFIG_PAX_USERCOPY
61694 +
61695 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61696 +{
61697 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61698 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61699 +#ifdef CONFIG_MODULES
61700 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61701 +#else
61702 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61703 +#endif
61704 +
61705 +#else
61706 + unsigned long textlow = (unsigned long)_stext;
61707 + unsigned long texthigh = (unsigned long)_etext;
61708 +
61709 +#ifdef CONFIG_X86_64
61710 + /* check against linear mapping as well */
61711 + if (high > (unsigned long)__va(__pa(textlow)) &&
61712 + low < (unsigned long)__va(__pa(texthigh)))
61713 + return true;
61714 +#endif
61715 +
61716 +#endif
61717 +
61718 + if (high <= textlow || low >= texthigh)
61719 + return false;
61720 + else
61721 + return true;
61722 +}
61723 +#endif
61724 +
61725 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61726 +{
61727 +#ifdef CONFIG_PAX_USERCOPY
61728 + const char *type;
61729 +#endif
61730 +
61731 +#ifndef CONFIG_STACK_GROWSUP
61732 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61733 + unsigned long currentsp = (unsigned long)&stackstart;
61734 + if (unlikely((currentsp < stackstart + 512 ||
61735 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61736 + BUG();
61737 +#endif
61738 +
61739 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61740 + if (const_size)
61741 + return;
61742 +#endif
61743 +
61744 +#ifdef CONFIG_PAX_USERCOPY
61745 + if (!n)
61746 + return;
61747 +
61748 + type = check_heap_object(ptr, n);
61749 + if (!type) {
61750 + int ret = check_stack_object(ptr, n);
61751 + if (ret == 1 || ret == 2)
61752 + return;
61753 + if (ret == 0) {
61754 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61755 + type = "<kernel text>";
61756 + else
61757 + return;
61758 + } else
61759 + type = "<process stack>";
61760 + }
61761 +
61762 + pax_report_usercopy(ptr, n, to_user, type);
61763 +#endif
61764 +
61765 +}
61766 +EXPORT_SYMBOL(__check_object_size);
61767 +
61768 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61769 +void pax_track_stack(void)
61770 +{
61771 + unsigned long sp = (unsigned long)&sp;
61772 + if (sp < current_thread_info()->lowest_stack &&
61773 + sp >= (unsigned long)task_stack_page(current) + 2 * sizeof(unsigned long))
61774 + current_thread_info()->lowest_stack = sp;
61775 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61776 + BUG();
61777 +}
61778 +EXPORT_SYMBOL(pax_track_stack);
61779 +#endif
61780 +
61781 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61782 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61783 +{
61784 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61785 + dump_stack();
61786 + do_group_exit(SIGKILL);
61787 +}
61788 +EXPORT_SYMBOL(report_size_overflow);
61789 +#endif
61790 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61791 index 9f9992b..8b59411 100644
61792 --- a/fs/ext2/balloc.c
61793 +++ b/fs/ext2/balloc.c
61794 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61795
61796 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61797 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61798 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61799 + if (free_blocks < root_blocks + 1 &&
61800 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61801 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61802 - !in_group_p (sbi->s_resgid))) {
61803 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61804 return 0;
61805 }
61806 return 1;
61807 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61808 index 170dc41..62f6b18 100644
61809 --- a/fs/ext2/super.c
61810 +++ b/fs/ext2/super.c
61811 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61812 #ifdef CONFIG_EXT2_FS_XATTR
61813 if (test_opt(sb, XATTR_USER))
61814 seq_puts(seq, ",user_xattr");
61815 - if (!test_opt(sb, XATTR_USER) &&
61816 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61817 + if (!test_opt(sb, XATTR_USER))
61818 seq_puts(seq, ",nouser_xattr");
61819 - }
61820 #endif
61821
61822 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61823 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61824 if (def_mount_opts & EXT2_DEFM_UID16)
61825 set_opt(sbi->s_mount_opt, NO_UID32);
61826 #ifdef CONFIG_EXT2_FS_XATTR
61827 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61828 - set_opt(sbi->s_mount_opt, XATTR_USER);
61829 + /* always enable user xattrs */
61830 + set_opt(sbi->s_mount_opt, XATTR_USER);
61831 #endif
61832 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61833 if (def_mount_opts & EXT2_DEFM_ACL)
61834 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61835 index 9142614..97484fa 100644
61836 --- a/fs/ext2/xattr.c
61837 +++ b/fs/ext2/xattr.c
61838 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61839 struct buffer_head *bh = NULL;
61840 struct ext2_xattr_entry *entry;
61841 char *end;
61842 - size_t rest = buffer_size;
61843 + size_t rest = buffer_size, total_size = 0;
61844 int error;
61845
61846 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61847 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61848 buffer += size;
61849 }
61850 rest -= size;
61851 + total_size += size;
61852 }
61853 }
61854 - error = buffer_size - rest; /* total size */
61855 + error = total_size;
61856
61857 cleanup:
61858 brelse(bh);
61859 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61860 index 158b5d4..2432610 100644
61861 --- a/fs/ext3/balloc.c
61862 +++ b/fs/ext3/balloc.c
61863 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61864
61865 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61866 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61867 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61868 + if (free_blocks < root_blocks + 1 &&
61869 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61870 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61871 - !in_group_p (sbi->s_resgid))) {
61872 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61873 return 0;
61874 }
61875 return 1;
61876 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61877 index eb742d0..c19f705 100644
61878 --- a/fs/ext3/super.c
61879 +++ b/fs/ext3/super.c
61880 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61881 #ifdef CONFIG_EXT3_FS_XATTR
61882 if (test_opt(sb, XATTR_USER))
61883 seq_puts(seq, ",user_xattr");
61884 - if (!test_opt(sb, XATTR_USER) &&
61885 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61886 + if (!test_opt(sb, XATTR_USER))
61887 seq_puts(seq, ",nouser_xattr");
61888 - }
61889 #endif
61890 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61891 if (test_opt(sb, POSIX_ACL))
61892 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61893 if (def_mount_opts & EXT3_DEFM_UID16)
61894 set_opt(sbi->s_mount_opt, NO_UID32);
61895 #ifdef CONFIG_EXT3_FS_XATTR
61896 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61897 - set_opt(sbi->s_mount_opt, XATTR_USER);
61898 + /* always enable user xattrs */
61899 + set_opt(sbi->s_mount_opt, XATTR_USER);
61900 #endif
61901 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61902 if (def_mount_opts & EXT3_DEFM_ACL)
61903 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61904 index c6874be..f8a6ae8 100644
61905 --- a/fs/ext3/xattr.c
61906 +++ b/fs/ext3/xattr.c
61907 @@ -330,7 +330,7 @@ static int
61908 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61909 char *buffer, size_t buffer_size)
61910 {
61911 - size_t rest = buffer_size;
61912 + size_t rest = buffer_size, total_size = 0;
61913
61914 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61915 const struct xattr_handler *handler =
61916 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61917 buffer += size;
61918 }
61919 rest -= size;
61920 + total_size += size;
61921 }
61922 }
61923 - return buffer_size - rest;
61924 + return total_size;
61925 }
61926
61927 static int
61928 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61929 index 83a6f49..d4e4d03 100644
61930 --- a/fs/ext4/balloc.c
61931 +++ b/fs/ext4/balloc.c
61932 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61933 /* Hm, nope. Are (enough) root reserved clusters available? */
61934 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61935 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61936 - capable(CAP_SYS_RESOURCE) ||
61937 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61938 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61939 + capable_nolog(CAP_SYS_RESOURCE)) {
61940
61941 if (free_clusters >= (nclusters + dirty_clusters +
61942 resv_clusters))
61943 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61944 index c55a1fa..9904ebb 100644
61945 --- a/fs/ext4/ext4.h
61946 +++ b/fs/ext4/ext4.h
61947 @@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61948 unsigned long s_mb_last_start;
61949
61950 /* stats for buddy allocator */
61951 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61952 - atomic_t s_bal_success; /* we found long enough chunks */
61953 - atomic_t s_bal_allocated; /* in blocks */
61954 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61955 - atomic_t s_bal_goals; /* goal hits */
61956 - atomic_t s_bal_breaks; /* too long searches */
61957 - atomic_t s_bal_2orders; /* 2^order hits */
61958 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61959 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61960 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61961 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61962 + atomic_unchecked_t s_bal_goals; /* goal hits */
61963 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61964 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61965 spinlock_t s_bal_lock;
61966 unsigned long s_mb_buddies_generated;
61967 unsigned long long s_mb_generation_time;
61968 - atomic_t s_mb_lost_chunks;
61969 - atomic_t s_mb_preallocated;
61970 - atomic_t s_mb_discarded;
61971 + atomic_unchecked_t s_mb_lost_chunks;
61972 + atomic_unchecked_t s_mb_preallocated;
61973 + atomic_unchecked_t s_mb_discarded;
61974 atomic_t s_lock_busy;
61975
61976 /* locality groups */
61977 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61978 index dbfe15c..9a6ee8d 100644
61979 --- a/fs/ext4/mballoc.c
61980 +++ b/fs/ext4/mballoc.c
61981 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61982 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61983
61984 if (EXT4_SB(sb)->s_mb_stats)
61985 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61986 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61987
61988 break;
61989 }
61990 @@ -2211,7 +2211,7 @@ repeat:
61991 ac->ac_status = AC_STATUS_CONTINUE;
61992 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61993 cr = 3;
61994 - atomic_inc(&sbi->s_mb_lost_chunks);
61995 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61996 goto repeat;
61997 }
61998 }
61999 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62000 if (sbi->s_mb_stats) {
62001 ext4_msg(sb, KERN_INFO,
62002 "mballoc: %u blocks %u reqs (%u success)",
62003 - atomic_read(&sbi->s_bal_allocated),
62004 - atomic_read(&sbi->s_bal_reqs),
62005 - atomic_read(&sbi->s_bal_success));
62006 + atomic_read_unchecked(&sbi->s_bal_allocated),
62007 + atomic_read_unchecked(&sbi->s_bal_reqs),
62008 + atomic_read_unchecked(&sbi->s_bal_success));
62009 ext4_msg(sb, KERN_INFO,
62010 "mballoc: %u extents scanned, %u goal hits, "
62011 "%u 2^N hits, %u breaks, %u lost",
62012 - atomic_read(&sbi->s_bal_ex_scanned),
62013 - atomic_read(&sbi->s_bal_goals),
62014 - atomic_read(&sbi->s_bal_2orders),
62015 - atomic_read(&sbi->s_bal_breaks),
62016 - atomic_read(&sbi->s_mb_lost_chunks));
62017 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62018 + atomic_read_unchecked(&sbi->s_bal_goals),
62019 + atomic_read_unchecked(&sbi->s_bal_2orders),
62020 + atomic_read_unchecked(&sbi->s_bal_breaks),
62021 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62022 ext4_msg(sb, KERN_INFO,
62023 "mballoc: %lu generated and it took %Lu",
62024 sbi->s_mb_buddies_generated,
62025 sbi->s_mb_generation_time);
62026 ext4_msg(sb, KERN_INFO,
62027 "mballoc: %u preallocated, %u discarded",
62028 - atomic_read(&sbi->s_mb_preallocated),
62029 - atomic_read(&sbi->s_mb_discarded));
62030 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62031 + atomic_read_unchecked(&sbi->s_mb_discarded));
62032 }
62033
62034 free_percpu(sbi->s_locality_groups);
62035 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62036 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62037
62038 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62039 - atomic_inc(&sbi->s_bal_reqs);
62040 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62041 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62042 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62043 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62044 - atomic_inc(&sbi->s_bal_success);
62045 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62046 + atomic_inc_unchecked(&sbi->s_bal_success);
62047 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62048 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62049 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62050 - atomic_inc(&sbi->s_bal_goals);
62051 + atomic_inc_unchecked(&sbi->s_bal_goals);
62052 if (ac->ac_found > sbi->s_mb_max_to_scan)
62053 - atomic_inc(&sbi->s_bal_breaks);
62054 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62055 }
62056
62057 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62058 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62059 trace_ext4_mb_new_inode_pa(ac, pa);
62060
62061 ext4_mb_use_inode_pa(ac, pa);
62062 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62063 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62064
62065 ei = EXT4_I(ac->ac_inode);
62066 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62067 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62068 trace_ext4_mb_new_group_pa(ac, pa);
62069
62070 ext4_mb_use_group_pa(ac, pa);
62071 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62072 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62073
62074 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62075 lg = ac->ac_lg;
62076 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62077 * from the bitmap and continue.
62078 */
62079 }
62080 - atomic_add(free, &sbi->s_mb_discarded);
62081 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62082
62083 return err;
62084 }
62085 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62086 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62087 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62088 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62089 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62090 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62091 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62092
62093 return 0;
62094 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62095 index 8313ca3..8a37d08 100644
62096 --- a/fs/ext4/mmp.c
62097 +++ b/fs/ext4/mmp.c
62098 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62099 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62100 const char *function, unsigned int line, const char *msg)
62101 {
62102 - __ext4_warning(sb, function, line, msg);
62103 + __ext4_warning(sb, function, line, "%s", msg);
62104 __ext4_warning(sb, function, line,
62105 "MMP failure info: last update time: %llu, last update "
62106 "node: %s, last update device: %s\n",
62107 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62108 index 2c9e686..6a40edc 100644
62109 --- a/fs/ext4/super.c
62110 +++ b/fs/ext4/super.c
62111 @@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62112 }
62113
62114 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62115 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62116 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62117 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62118
62119 #ifdef CONFIG_QUOTA
62120 @@ -2434,7 +2434,7 @@ struct ext4_attr {
62121 int offset;
62122 int deprecated_val;
62123 } u;
62124 -};
62125 +} __do_const;
62126
62127 static int parse_strtoull(const char *buf,
62128 unsigned long long max, unsigned long long *value)
62129 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62130 index 1e09fc7..0400dd4 100644
62131 --- a/fs/ext4/xattr.c
62132 +++ b/fs/ext4/xattr.c
62133 @@ -399,7 +399,7 @@ static int
62134 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62135 char *buffer, size_t buffer_size)
62136 {
62137 - size_t rest = buffer_size;
62138 + size_t rest = buffer_size, total_size = 0;
62139
62140 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62141 const struct xattr_handler *handler =
62142 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62143 buffer += size;
62144 }
62145 rest -= size;
62146 + total_size += size;
62147 }
62148 }
62149 - return buffer_size - rest;
62150 + return total_size;
62151 }
62152
62153 static int
62154 diff --git a/fs/fcntl.c b/fs/fcntl.c
62155 index 99d440a..eb979d1 100644
62156 --- a/fs/fcntl.c
62157 +++ b/fs/fcntl.c
62158 @@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62159 int force)
62160 {
62161 security_file_set_fowner(filp);
62162 + if (gr_handle_chroot_fowner(pid, type))
62163 + return;
62164 + if (gr_check_protected_task_fowner(pid, type))
62165 + return;
62166 f_modown(filp, pid, type, force);
62167 }
62168 EXPORT_SYMBOL(__f_setown);
62169 diff --git a/fs/fhandle.c b/fs/fhandle.c
62170 index 999ff5c..2281df9 100644
62171 --- a/fs/fhandle.c
62172 +++ b/fs/fhandle.c
62173 @@ -8,6 +8,7 @@
62174 #include <linux/fs_struct.h>
62175 #include <linux/fsnotify.h>
62176 #include <linux/personality.h>
62177 +#include <linux/grsecurity.h>
62178 #include <asm/uaccess.h>
62179 #include "internal.h"
62180 #include "mount.h"
62181 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62182 } else
62183 retval = 0;
62184 /* copy the mount id */
62185 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62186 - sizeof(*mnt_id)) ||
62187 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62188 copy_to_user(ufh, handle,
62189 sizeof(struct file_handle) + handle_bytes))
62190 retval = -EFAULT;
62191 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62192 * the directory. Ideally we would like CAP_DAC_SEARCH.
62193 * But we don't have that
62194 */
62195 - if (!capable(CAP_DAC_READ_SEARCH)) {
62196 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62197 retval = -EPERM;
62198 goto out_err;
62199 }
62200 @@ -195,8 +195,9 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62201 goto out_err;
62202 }
62203 /* copy the full handle */
62204 - if (copy_from_user(handle, ufh,
62205 - sizeof(struct file_handle) +
62206 + *handle = f_handle;
62207 + if (copy_from_user(&handle->f_handle,
62208 + &ufh->f_handle,
62209 f_handle.handle_bytes)) {
62210 retval = -EFAULT;
62211 goto out_handle;
62212 diff --git a/fs/file.c b/fs/file.c
62213 index ab3eb6a..8de2392 100644
62214 --- a/fs/file.c
62215 +++ b/fs/file.c
62216 @@ -16,6 +16,7 @@
62217 #include <linux/slab.h>
62218 #include <linux/vmalloc.h>
62219 #include <linux/file.h>
62220 +#include <linux/security.h>
62221 #include <linux/fdtable.h>
62222 #include <linux/bitops.h>
62223 #include <linux/interrupt.h>
62224 @@ -139,7 +140,7 @@ out:
62225 * Return <0 error code on error; 1 on successful completion.
62226 * The files->file_lock should be held on entry, and will be held on exit.
62227 */
62228 -static int expand_fdtable(struct files_struct *files, int nr)
62229 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62230 __releases(files->file_lock)
62231 __acquires(files->file_lock)
62232 {
62233 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62234 * expanded and execution may have blocked.
62235 * The files->file_lock should be held on entry, and will be held on exit.
62236 */
62237 -static int expand_files(struct files_struct *files, int nr)
62238 +static int expand_files(struct files_struct *files, unsigned int nr)
62239 {
62240 struct fdtable *fdt;
62241
62242 @@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62243 if (!file)
62244 return __close_fd(files, fd);
62245
62246 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62247 if (fd >= rlimit(RLIMIT_NOFILE))
62248 return -EBADF;
62249
62250 @@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62251 if (unlikely(oldfd == newfd))
62252 return -EINVAL;
62253
62254 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62255 if (newfd >= rlimit(RLIMIT_NOFILE))
62256 return -EBADF;
62257
62258 @@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62259 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62260 {
62261 int err;
62262 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62263 if (from >= rlimit(RLIMIT_NOFILE))
62264 return -EINVAL;
62265 err = alloc_fd(from, flags);
62266 diff --git a/fs/filesystems.c b/fs/filesystems.c
62267 index 5797d45..7d7d79a 100644
62268 --- a/fs/filesystems.c
62269 +++ b/fs/filesystems.c
62270 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62271 int len = dot ? dot - name : strlen(name);
62272
62273 fs = __get_fs_type(name, len);
62274 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62275 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62276 +#else
62277 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62278 +#endif
62279 fs = __get_fs_type(name, len);
62280
62281 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62282 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62283 index 7dca743..f5e007d 100644
62284 --- a/fs/fs_struct.c
62285 +++ b/fs/fs_struct.c
62286 @@ -4,6 +4,7 @@
62287 #include <linux/path.h>
62288 #include <linux/slab.h>
62289 #include <linux/fs_struct.h>
62290 +#include <linux/grsecurity.h>
62291 #include "internal.h"
62292
62293 /*
62294 @@ -15,14 +16,18 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62295 struct path old_root;
62296
62297 path_get(path);
62298 + gr_inc_chroot_refcnts(path->dentry, path->mnt);
62299 spin_lock(&fs->lock);
62300 write_seqcount_begin(&fs->seq);
62301 old_root = fs->root;
62302 fs->root = *path;
62303 + gr_set_chroot_entries(current, path);
62304 write_seqcount_end(&fs->seq);
62305 spin_unlock(&fs->lock);
62306 - if (old_root.dentry)
62307 + if (old_root.dentry) {
62308 + gr_inc_chroot_refcnts(old_root.dentry, old_root.mnt);
62309 path_put(&old_root);
62310 + }
62311 }
62312
62313 /*
62314 @@ -67,6 +72,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62315 int hits = 0;
62316 spin_lock(&fs->lock);
62317 write_seqcount_begin(&fs->seq);
62318 + /* this root replacement is only done by pivot_root,
62319 + leave grsec's chroot tagging alone for this task
62320 + so that a pivoted root isn't treated as a chroot
62321 + */
62322 hits += replace_path(&fs->root, old_root, new_root);
62323 hits += replace_path(&fs->pwd, old_root, new_root);
62324 write_seqcount_end(&fs->seq);
62325 @@ -85,6 +94,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62326
62327 void free_fs_struct(struct fs_struct *fs)
62328 {
62329 + gr_dec_chroot_refcnts(fs->root.dentry, fs->root.mnt);
62330 path_put(&fs->root);
62331 path_put(&fs->pwd);
62332 kmem_cache_free(fs_cachep, fs);
62333 @@ -99,7 +109,8 @@ void exit_fs(struct task_struct *tsk)
62334 task_lock(tsk);
62335 spin_lock(&fs->lock);
62336 tsk->fs = NULL;
62337 - kill = !--fs->users;
62338 + gr_clear_chroot_entries(tsk);
62339 + kill = !atomic_dec_return(&fs->users);
62340 spin_unlock(&fs->lock);
62341 task_unlock(tsk);
62342 if (kill)
62343 @@ -112,7 +123,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62344 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62345 /* We don't need to lock fs - think why ;-) */
62346 if (fs) {
62347 - fs->users = 1;
62348 + atomic_set(&fs->users, 1);
62349 fs->in_exec = 0;
62350 spin_lock_init(&fs->lock);
62351 seqcount_init(&fs->seq);
62352 @@ -121,6 +132,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62353 spin_lock(&old->lock);
62354 fs->root = old->root;
62355 path_get(&fs->root);
62356 + /* instead of calling gr_set_chroot_entries here,
62357 + we call it from every caller of this function
62358 + */
62359 fs->pwd = old->pwd;
62360 path_get(&fs->pwd);
62361 spin_unlock(&old->lock);
62362 @@ -139,8 +153,9 @@ int unshare_fs_struct(void)
62363
62364 task_lock(current);
62365 spin_lock(&fs->lock);
62366 - kill = !--fs->users;
62367 + kill = !atomic_dec_return(&fs->users);
62368 current->fs = new_fs;
62369 + gr_set_chroot_entries(current, &new_fs->root);
62370 spin_unlock(&fs->lock);
62371 task_unlock(current);
62372
62373 @@ -153,13 +168,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62374
62375 int current_umask(void)
62376 {
62377 - return current->fs->umask;
62378 + return current->fs->umask | gr_acl_umask();
62379 }
62380 EXPORT_SYMBOL(current_umask);
62381
62382 /* to be mentioned only in INIT_TASK */
62383 struct fs_struct init_fs = {
62384 - .users = 1,
62385 + .users = ATOMIC_INIT(1),
62386 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62387 .seq = SEQCNT_ZERO(init_fs.seq),
62388 .umask = 0022,
62389 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62390 index 89acec7..a575262 100644
62391 --- a/fs/fscache/cookie.c
62392 +++ b/fs/fscache/cookie.c
62393 @@ -19,7 +19,7 @@
62394
62395 struct kmem_cache *fscache_cookie_jar;
62396
62397 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62398 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62399
62400 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62401 static int fscache_alloc_object(struct fscache_cache *cache,
62402 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62403 parent ? (char *) parent->def->name : "<no-parent>",
62404 def->name, netfs_data, enable);
62405
62406 - fscache_stat(&fscache_n_acquires);
62407 + fscache_stat_unchecked(&fscache_n_acquires);
62408
62409 /* if there's no parent cookie, then we don't create one here either */
62410 if (!parent) {
62411 - fscache_stat(&fscache_n_acquires_null);
62412 + fscache_stat_unchecked(&fscache_n_acquires_null);
62413 _leave(" [no parent]");
62414 return NULL;
62415 }
62416 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62417 /* allocate and initialise a cookie */
62418 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62419 if (!cookie) {
62420 - fscache_stat(&fscache_n_acquires_oom);
62421 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62422 _leave(" [ENOMEM]");
62423 return NULL;
62424 }
62425 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62426
62427 switch (cookie->def->type) {
62428 case FSCACHE_COOKIE_TYPE_INDEX:
62429 - fscache_stat(&fscache_n_cookie_index);
62430 + fscache_stat_unchecked(&fscache_n_cookie_index);
62431 break;
62432 case FSCACHE_COOKIE_TYPE_DATAFILE:
62433 - fscache_stat(&fscache_n_cookie_data);
62434 + fscache_stat_unchecked(&fscache_n_cookie_data);
62435 break;
62436 default:
62437 - fscache_stat(&fscache_n_cookie_special);
62438 + fscache_stat_unchecked(&fscache_n_cookie_special);
62439 break;
62440 }
62441
62442 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62443 } else {
62444 atomic_dec(&parent->n_children);
62445 __fscache_cookie_put(cookie);
62446 - fscache_stat(&fscache_n_acquires_nobufs);
62447 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62448 _leave(" = NULL");
62449 return NULL;
62450 }
62451 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62452 }
62453 }
62454
62455 - fscache_stat(&fscache_n_acquires_ok);
62456 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62457 _leave(" = %p", cookie);
62458 return cookie;
62459 }
62460 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62461 cache = fscache_select_cache_for_object(cookie->parent);
62462 if (!cache) {
62463 up_read(&fscache_addremove_sem);
62464 - fscache_stat(&fscache_n_acquires_no_cache);
62465 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62466 _leave(" = -ENOMEDIUM [no cache]");
62467 return -ENOMEDIUM;
62468 }
62469 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62470 object = cache->ops->alloc_object(cache, cookie);
62471 fscache_stat_d(&fscache_n_cop_alloc_object);
62472 if (IS_ERR(object)) {
62473 - fscache_stat(&fscache_n_object_no_alloc);
62474 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62475 ret = PTR_ERR(object);
62476 goto error;
62477 }
62478
62479 - fscache_stat(&fscache_n_object_alloc);
62480 + fscache_stat_unchecked(&fscache_n_object_alloc);
62481
62482 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62483 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62484
62485 _debug("ALLOC OBJ%x: %s {%lx}",
62486 object->debug_id, cookie->def->name, object->events);
62487 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62488
62489 _enter("{%s}", cookie->def->name);
62490
62491 - fscache_stat(&fscache_n_invalidates);
62492 + fscache_stat_unchecked(&fscache_n_invalidates);
62493
62494 /* Only permit invalidation of data files. Invalidating an index will
62495 * require the caller to release all its attachments to the tree rooted
62496 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62497 {
62498 struct fscache_object *object;
62499
62500 - fscache_stat(&fscache_n_updates);
62501 + fscache_stat_unchecked(&fscache_n_updates);
62502
62503 if (!cookie) {
62504 - fscache_stat(&fscache_n_updates_null);
62505 + fscache_stat_unchecked(&fscache_n_updates_null);
62506 _leave(" [no cookie]");
62507 return;
62508 }
62509 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62510 */
62511 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62512 {
62513 - fscache_stat(&fscache_n_relinquishes);
62514 + fscache_stat_unchecked(&fscache_n_relinquishes);
62515 if (retire)
62516 - fscache_stat(&fscache_n_relinquishes_retire);
62517 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62518
62519 if (!cookie) {
62520 - fscache_stat(&fscache_n_relinquishes_null);
62521 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62522 _leave(" [no cookie]");
62523 return;
62524 }
62525 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62526 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62527 goto inconsistent;
62528
62529 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62530 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62531
62532 __fscache_use_cookie(cookie);
62533 if (fscache_submit_op(object, op) < 0)
62534 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62535 index 7872a62..d91b19f 100644
62536 --- a/fs/fscache/internal.h
62537 +++ b/fs/fscache/internal.h
62538 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62539 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62540 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62541 struct fscache_operation *,
62542 - atomic_t *,
62543 - atomic_t *,
62544 + atomic_unchecked_t *,
62545 + atomic_unchecked_t *,
62546 void (*)(struct fscache_operation *));
62547 extern void fscache_invalidate_writes(struct fscache_cookie *);
62548
62549 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62550 * stats.c
62551 */
62552 #ifdef CONFIG_FSCACHE_STATS
62553 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62554 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62555 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62556 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62557
62558 -extern atomic_t fscache_n_op_pend;
62559 -extern atomic_t fscache_n_op_run;
62560 -extern atomic_t fscache_n_op_enqueue;
62561 -extern atomic_t fscache_n_op_deferred_release;
62562 -extern atomic_t fscache_n_op_release;
62563 -extern atomic_t fscache_n_op_gc;
62564 -extern atomic_t fscache_n_op_cancelled;
62565 -extern atomic_t fscache_n_op_rejected;
62566 +extern atomic_unchecked_t fscache_n_op_pend;
62567 +extern atomic_unchecked_t fscache_n_op_run;
62568 +extern atomic_unchecked_t fscache_n_op_enqueue;
62569 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62570 +extern atomic_unchecked_t fscache_n_op_release;
62571 +extern atomic_unchecked_t fscache_n_op_gc;
62572 +extern atomic_unchecked_t fscache_n_op_cancelled;
62573 +extern atomic_unchecked_t fscache_n_op_rejected;
62574
62575 -extern atomic_t fscache_n_attr_changed;
62576 -extern atomic_t fscache_n_attr_changed_ok;
62577 -extern atomic_t fscache_n_attr_changed_nobufs;
62578 -extern atomic_t fscache_n_attr_changed_nomem;
62579 -extern atomic_t fscache_n_attr_changed_calls;
62580 +extern atomic_unchecked_t fscache_n_attr_changed;
62581 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62582 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62583 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62584 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62585
62586 -extern atomic_t fscache_n_allocs;
62587 -extern atomic_t fscache_n_allocs_ok;
62588 -extern atomic_t fscache_n_allocs_wait;
62589 -extern atomic_t fscache_n_allocs_nobufs;
62590 -extern atomic_t fscache_n_allocs_intr;
62591 -extern atomic_t fscache_n_allocs_object_dead;
62592 -extern atomic_t fscache_n_alloc_ops;
62593 -extern atomic_t fscache_n_alloc_op_waits;
62594 +extern atomic_unchecked_t fscache_n_allocs;
62595 +extern atomic_unchecked_t fscache_n_allocs_ok;
62596 +extern atomic_unchecked_t fscache_n_allocs_wait;
62597 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62598 +extern atomic_unchecked_t fscache_n_allocs_intr;
62599 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62600 +extern atomic_unchecked_t fscache_n_alloc_ops;
62601 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62602
62603 -extern atomic_t fscache_n_retrievals;
62604 -extern atomic_t fscache_n_retrievals_ok;
62605 -extern atomic_t fscache_n_retrievals_wait;
62606 -extern atomic_t fscache_n_retrievals_nodata;
62607 -extern atomic_t fscache_n_retrievals_nobufs;
62608 -extern atomic_t fscache_n_retrievals_intr;
62609 -extern atomic_t fscache_n_retrievals_nomem;
62610 -extern atomic_t fscache_n_retrievals_object_dead;
62611 -extern atomic_t fscache_n_retrieval_ops;
62612 -extern atomic_t fscache_n_retrieval_op_waits;
62613 +extern atomic_unchecked_t fscache_n_retrievals;
62614 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62615 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62616 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62617 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62618 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62619 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62620 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62621 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62622 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62623
62624 -extern atomic_t fscache_n_stores;
62625 -extern atomic_t fscache_n_stores_ok;
62626 -extern atomic_t fscache_n_stores_again;
62627 -extern atomic_t fscache_n_stores_nobufs;
62628 -extern atomic_t fscache_n_stores_oom;
62629 -extern atomic_t fscache_n_store_ops;
62630 -extern atomic_t fscache_n_store_calls;
62631 -extern atomic_t fscache_n_store_pages;
62632 -extern atomic_t fscache_n_store_radix_deletes;
62633 -extern atomic_t fscache_n_store_pages_over_limit;
62634 +extern atomic_unchecked_t fscache_n_stores;
62635 +extern atomic_unchecked_t fscache_n_stores_ok;
62636 +extern atomic_unchecked_t fscache_n_stores_again;
62637 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62638 +extern atomic_unchecked_t fscache_n_stores_oom;
62639 +extern atomic_unchecked_t fscache_n_store_ops;
62640 +extern atomic_unchecked_t fscache_n_store_calls;
62641 +extern atomic_unchecked_t fscache_n_store_pages;
62642 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62643 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62644
62645 -extern atomic_t fscache_n_store_vmscan_not_storing;
62646 -extern atomic_t fscache_n_store_vmscan_gone;
62647 -extern atomic_t fscache_n_store_vmscan_busy;
62648 -extern atomic_t fscache_n_store_vmscan_cancelled;
62649 -extern atomic_t fscache_n_store_vmscan_wait;
62650 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62651 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62652 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62653 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62654 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62655
62656 -extern atomic_t fscache_n_marks;
62657 -extern atomic_t fscache_n_uncaches;
62658 +extern atomic_unchecked_t fscache_n_marks;
62659 +extern atomic_unchecked_t fscache_n_uncaches;
62660
62661 -extern atomic_t fscache_n_acquires;
62662 -extern atomic_t fscache_n_acquires_null;
62663 -extern atomic_t fscache_n_acquires_no_cache;
62664 -extern atomic_t fscache_n_acquires_ok;
62665 -extern atomic_t fscache_n_acquires_nobufs;
62666 -extern atomic_t fscache_n_acquires_oom;
62667 +extern atomic_unchecked_t fscache_n_acquires;
62668 +extern atomic_unchecked_t fscache_n_acquires_null;
62669 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62670 +extern atomic_unchecked_t fscache_n_acquires_ok;
62671 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62672 +extern atomic_unchecked_t fscache_n_acquires_oom;
62673
62674 -extern atomic_t fscache_n_invalidates;
62675 -extern atomic_t fscache_n_invalidates_run;
62676 +extern atomic_unchecked_t fscache_n_invalidates;
62677 +extern atomic_unchecked_t fscache_n_invalidates_run;
62678
62679 -extern atomic_t fscache_n_updates;
62680 -extern atomic_t fscache_n_updates_null;
62681 -extern atomic_t fscache_n_updates_run;
62682 +extern atomic_unchecked_t fscache_n_updates;
62683 +extern atomic_unchecked_t fscache_n_updates_null;
62684 +extern atomic_unchecked_t fscache_n_updates_run;
62685
62686 -extern atomic_t fscache_n_relinquishes;
62687 -extern atomic_t fscache_n_relinquishes_null;
62688 -extern atomic_t fscache_n_relinquishes_waitcrt;
62689 -extern atomic_t fscache_n_relinquishes_retire;
62690 +extern atomic_unchecked_t fscache_n_relinquishes;
62691 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62692 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62693 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62694
62695 -extern atomic_t fscache_n_cookie_index;
62696 -extern atomic_t fscache_n_cookie_data;
62697 -extern atomic_t fscache_n_cookie_special;
62698 +extern atomic_unchecked_t fscache_n_cookie_index;
62699 +extern atomic_unchecked_t fscache_n_cookie_data;
62700 +extern atomic_unchecked_t fscache_n_cookie_special;
62701
62702 -extern atomic_t fscache_n_object_alloc;
62703 -extern atomic_t fscache_n_object_no_alloc;
62704 -extern atomic_t fscache_n_object_lookups;
62705 -extern atomic_t fscache_n_object_lookups_negative;
62706 -extern atomic_t fscache_n_object_lookups_positive;
62707 -extern atomic_t fscache_n_object_lookups_timed_out;
62708 -extern atomic_t fscache_n_object_created;
62709 -extern atomic_t fscache_n_object_avail;
62710 -extern atomic_t fscache_n_object_dead;
62711 +extern atomic_unchecked_t fscache_n_object_alloc;
62712 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62713 +extern atomic_unchecked_t fscache_n_object_lookups;
62714 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62715 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62716 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62717 +extern atomic_unchecked_t fscache_n_object_created;
62718 +extern atomic_unchecked_t fscache_n_object_avail;
62719 +extern atomic_unchecked_t fscache_n_object_dead;
62720
62721 -extern atomic_t fscache_n_checkaux_none;
62722 -extern atomic_t fscache_n_checkaux_okay;
62723 -extern atomic_t fscache_n_checkaux_update;
62724 -extern atomic_t fscache_n_checkaux_obsolete;
62725 +extern atomic_unchecked_t fscache_n_checkaux_none;
62726 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62727 +extern atomic_unchecked_t fscache_n_checkaux_update;
62728 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62729
62730 extern atomic_t fscache_n_cop_alloc_object;
62731 extern atomic_t fscache_n_cop_lookup_object;
62732 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62733 atomic_inc(stat);
62734 }
62735
62736 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62737 +{
62738 + atomic_inc_unchecked(stat);
62739 +}
62740 +
62741 static inline void fscache_stat_d(atomic_t *stat)
62742 {
62743 atomic_dec(stat);
62744 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62745
62746 #define __fscache_stat(stat) (NULL)
62747 #define fscache_stat(stat) do {} while (0)
62748 +#define fscache_stat_unchecked(stat) do {} while (0)
62749 #define fscache_stat_d(stat) do {} while (0)
62750 #endif
62751
62752 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62753 index da032da..0076ce7 100644
62754 --- a/fs/fscache/object.c
62755 +++ b/fs/fscache/object.c
62756 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62757 _debug("LOOKUP \"%s\" in \"%s\"",
62758 cookie->def->name, object->cache->tag->name);
62759
62760 - fscache_stat(&fscache_n_object_lookups);
62761 + fscache_stat_unchecked(&fscache_n_object_lookups);
62762 fscache_stat(&fscache_n_cop_lookup_object);
62763 ret = object->cache->ops->lookup_object(object);
62764 fscache_stat_d(&fscache_n_cop_lookup_object);
62765 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62766 if (ret == -ETIMEDOUT) {
62767 /* probably stuck behind another object, so move this one to
62768 * the back of the queue */
62769 - fscache_stat(&fscache_n_object_lookups_timed_out);
62770 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62771 _leave(" [timeout]");
62772 return NO_TRANSIT;
62773 }
62774 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62775 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62776
62777 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62778 - fscache_stat(&fscache_n_object_lookups_negative);
62779 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62780
62781 /* Allow write requests to begin stacking up and read requests to begin
62782 * returning ENODATA.
62783 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62784 /* if we were still looking up, then we must have a positive lookup
62785 * result, in which case there may be data available */
62786 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62787 - fscache_stat(&fscache_n_object_lookups_positive);
62788 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62789
62790 /* We do (presumably) have data */
62791 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62792 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62793 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62794 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62795 } else {
62796 - fscache_stat(&fscache_n_object_created);
62797 + fscache_stat_unchecked(&fscache_n_object_created);
62798 }
62799
62800 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62801 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62802 fscache_stat_d(&fscache_n_cop_lookup_complete);
62803
62804 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62805 - fscache_stat(&fscache_n_object_avail);
62806 + fscache_stat_unchecked(&fscache_n_object_avail);
62807
62808 _leave("");
62809 return transit_to(JUMPSTART_DEPS);
62810 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62811
62812 /* this just shifts the object release to the work processor */
62813 fscache_put_object(object);
62814 - fscache_stat(&fscache_n_object_dead);
62815 + fscache_stat_unchecked(&fscache_n_object_dead);
62816
62817 _leave("");
62818 return transit_to(OBJECT_DEAD);
62819 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62820 enum fscache_checkaux result;
62821
62822 if (!object->cookie->def->check_aux) {
62823 - fscache_stat(&fscache_n_checkaux_none);
62824 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62825 return FSCACHE_CHECKAUX_OKAY;
62826 }
62827
62828 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62829 switch (result) {
62830 /* entry okay as is */
62831 case FSCACHE_CHECKAUX_OKAY:
62832 - fscache_stat(&fscache_n_checkaux_okay);
62833 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62834 break;
62835
62836 /* entry requires update */
62837 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62838 - fscache_stat(&fscache_n_checkaux_update);
62839 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62840 break;
62841
62842 /* entry requires deletion */
62843 case FSCACHE_CHECKAUX_OBSOLETE:
62844 - fscache_stat(&fscache_n_checkaux_obsolete);
62845 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62846 break;
62847
62848 default:
62849 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62850 {
62851 const struct fscache_state *s;
62852
62853 - fscache_stat(&fscache_n_invalidates_run);
62854 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62855 fscache_stat(&fscache_n_cop_invalidate_object);
62856 s = _fscache_invalidate_object(object, event);
62857 fscache_stat_d(&fscache_n_cop_invalidate_object);
62858 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62859 {
62860 _enter("{OBJ%x},%d", object->debug_id, event);
62861
62862 - fscache_stat(&fscache_n_updates_run);
62863 + fscache_stat_unchecked(&fscache_n_updates_run);
62864 fscache_stat(&fscache_n_cop_update_object);
62865 object->cache->ops->update_object(object);
62866 fscache_stat_d(&fscache_n_cop_update_object);
62867 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62868 index e7b87a0..a85d47a 100644
62869 --- a/fs/fscache/operation.c
62870 +++ b/fs/fscache/operation.c
62871 @@ -17,7 +17,7 @@
62872 #include <linux/slab.h>
62873 #include "internal.h"
62874
62875 -atomic_t fscache_op_debug_id;
62876 +atomic_unchecked_t fscache_op_debug_id;
62877 EXPORT_SYMBOL(fscache_op_debug_id);
62878
62879 /**
62880 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62881 ASSERTCMP(atomic_read(&op->usage), >, 0);
62882 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62883
62884 - fscache_stat(&fscache_n_op_enqueue);
62885 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62886 switch (op->flags & FSCACHE_OP_TYPE) {
62887 case FSCACHE_OP_ASYNC:
62888 _debug("queue async");
62889 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62890 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62891 if (op->processor)
62892 fscache_enqueue_operation(op);
62893 - fscache_stat(&fscache_n_op_run);
62894 + fscache_stat_unchecked(&fscache_n_op_run);
62895 }
62896
62897 /*
62898 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62899 if (object->n_in_progress > 0) {
62900 atomic_inc(&op->usage);
62901 list_add_tail(&op->pend_link, &object->pending_ops);
62902 - fscache_stat(&fscache_n_op_pend);
62903 + fscache_stat_unchecked(&fscache_n_op_pend);
62904 } else if (!list_empty(&object->pending_ops)) {
62905 atomic_inc(&op->usage);
62906 list_add_tail(&op->pend_link, &object->pending_ops);
62907 - fscache_stat(&fscache_n_op_pend);
62908 + fscache_stat_unchecked(&fscache_n_op_pend);
62909 fscache_start_operations(object);
62910 } else {
62911 ASSERTCMP(object->n_in_progress, ==, 0);
62912 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62913 object->n_exclusive++; /* reads and writes must wait */
62914 atomic_inc(&op->usage);
62915 list_add_tail(&op->pend_link, &object->pending_ops);
62916 - fscache_stat(&fscache_n_op_pend);
62917 + fscache_stat_unchecked(&fscache_n_op_pend);
62918 ret = 0;
62919 } else {
62920 /* If we're in any other state, there must have been an I/O
62921 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62922 if (object->n_exclusive > 0) {
62923 atomic_inc(&op->usage);
62924 list_add_tail(&op->pend_link, &object->pending_ops);
62925 - fscache_stat(&fscache_n_op_pend);
62926 + fscache_stat_unchecked(&fscache_n_op_pend);
62927 } else if (!list_empty(&object->pending_ops)) {
62928 atomic_inc(&op->usage);
62929 list_add_tail(&op->pend_link, &object->pending_ops);
62930 - fscache_stat(&fscache_n_op_pend);
62931 + fscache_stat_unchecked(&fscache_n_op_pend);
62932 fscache_start_operations(object);
62933 } else {
62934 ASSERTCMP(object->n_exclusive, ==, 0);
62935 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62936 object->n_ops++;
62937 atomic_inc(&op->usage);
62938 list_add_tail(&op->pend_link, &object->pending_ops);
62939 - fscache_stat(&fscache_n_op_pend);
62940 + fscache_stat_unchecked(&fscache_n_op_pend);
62941 ret = 0;
62942 } else if (fscache_object_is_dying(object)) {
62943 - fscache_stat(&fscache_n_op_rejected);
62944 + fscache_stat_unchecked(&fscache_n_op_rejected);
62945 op->state = FSCACHE_OP_ST_CANCELLED;
62946 ret = -ENOBUFS;
62947 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62948 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62949 ret = -EBUSY;
62950 if (op->state == FSCACHE_OP_ST_PENDING) {
62951 ASSERT(!list_empty(&op->pend_link));
62952 - fscache_stat(&fscache_n_op_cancelled);
62953 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62954 list_del_init(&op->pend_link);
62955 if (do_cancel)
62956 do_cancel(op);
62957 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62958 while (!list_empty(&object->pending_ops)) {
62959 op = list_entry(object->pending_ops.next,
62960 struct fscache_operation, pend_link);
62961 - fscache_stat(&fscache_n_op_cancelled);
62962 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62963 list_del_init(&op->pend_link);
62964
62965 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62966 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62967 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62968 op->state = FSCACHE_OP_ST_DEAD;
62969
62970 - fscache_stat(&fscache_n_op_release);
62971 + fscache_stat_unchecked(&fscache_n_op_release);
62972
62973 if (op->release) {
62974 op->release(op);
62975 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62976 * lock, and defer it otherwise */
62977 if (!spin_trylock(&object->lock)) {
62978 _debug("defer put");
62979 - fscache_stat(&fscache_n_op_deferred_release);
62980 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
62981
62982 cache = object->cache;
62983 spin_lock(&cache->op_gc_list_lock);
62984 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62985
62986 _debug("GC DEFERRED REL OBJ%x OP%x",
62987 object->debug_id, op->debug_id);
62988 - fscache_stat(&fscache_n_op_gc);
62989 + fscache_stat_unchecked(&fscache_n_op_gc);
62990
62991 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62992 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62993 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62994 index de33b3f..8be4d29 100644
62995 --- a/fs/fscache/page.c
62996 +++ b/fs/fscache/page.c
62997 @@ -74,7 +74,7 @@ try_again:
62998 val = radix_tree_lookup(&cookie->stores, page->index);
62999 if (!val) {
63000 rcu_read_unlock();
63001 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63002 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63003 __fscache_uncache_page(cookie, page);
63004 return true;
63005 }
63006 @@ -104,11 +104,11 @@ try_again:
63007 spin_unlock(&cookie->stores_lock);
63008
63009 if (xpage) {
63010 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63011 - fscache_stat(&fscache_n_store_radix_deletes);
63012 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63013 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63014 ASSERTCMP(xpage, ==, page);
63015 } else {
63016 - fscache_stat(&fscache_n_store_vmscan_gone);
63017 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63018 }
63019
63020 wake_up_bit(&cookie->flags, 0);
63021 @@ -123,11 +123,11 @@ page_busy:
63022 * sleeping on memory allocation, so we may need to impose a timeout
63023 * too. */
63024 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63025 - fscache_stat(&fscache_n_store_vmscan_busy);
63026 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63027 return false;
63028 }
63029
63030 - fscache_stat(&fscache_n_store_vmscan_wait);
63031 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63032 if (!release_page_wait_timeout(cookie, page))
63033 _debug("fscache writeout timeout page: %p{%lx}",
63034 page, page->index);
63035 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63036 FSCACHE_COOKIE_STORING_TAG);
63037 if (!radix_tree_tag_get(&cookie->stores, page->index,
63038 FSCACHE_COOKIE_PENDING_TAG)) {
63039 - fscache_stat(&fscache_n_store_radix_deletes);
63040 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63041 xpage = radix_tree_delete(&cookie->stores, page->index);
63042 }
63043 spin_unlock(&cookie->stores_lock);
63044 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63045
63046 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63047
63048 - fscache_stat(&fscache_n_attr_changed_calls);
63049 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63050
63051 if (fscache_object_is_active(object)) {
63052 fscache_stat(&fscache_n_cop_attr_changed);
63053 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63054
63055 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63056
63057 - fscache_stat(&fscache_n_attr_changed);
63058 + fscache_stat_unchecked(&fscache_n_attr_changed);
63059
63060 op = kzalloc(sizeof(*op), GFP_KERNEL);
63061 if (!op) {
63062 - fscache_stat(&fscache_n_attr_changed_nomem);
63063 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63064 _leave(" = -ENOMEM");
63065 return -ENOMEM;
63066 }
63067 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63068 if (fscache_submit_exclusive_op(object, op) < 0)
63069 goto nobufs_dec;
63070 spin_unlock(&cookie->lock);
63071 - fscache_stat(&fscache_n_attr_changed_ok);
63072 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63073 fscache_put_operation(op);
63074 _leave(" = 0");
63075 return 0;
63076 @@ -242,7 +242,7 @@ nobufs:
63077 kfree(op);
63078 if (wake_cookie)
63079 __fscache_wake_unused_cookie(cookie);
63080 - fscache_stat(&fscache_n_attr_changed_nobufs);
63081 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63082 _leave(" = %d", -ENOBUFS);
63083 return -ENOBUFS;
63084 }
63085 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63086 /* allocate a retrieval operation and attempt to submit it */
63087 op = kzalloc(sizeof(*op), GFP_NOIO);
63088 if (!op) {
63089 - fscache_stat(&fscache_n_retrievals_nomem);
63090 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63091 return NULL;
63092 }
63093
63094 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63095 return 0;
63096 }
63097
63098 - fscache_stat(&fscache_n_retrievals_wait);
63099 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63100
63101 jif = jiffies;
63102 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63103 TASK_INTERRUPTIBLE) != 0) {
63104 - fscache_stat(&fscache_n_retrievals_intr);
63105 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63106 _leave(" = -ERESTARTSYS");
63107 return -ERESTARTSYS;
63108 }
63109 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63110 */
63111 int fscache_wait_for_operation_activation(struct fscache_object *object,
63112 struct fscache_operation *op,
63113 - atomic_t *stat_op_waits,
63114 - atomic_t *stat_object_dead,
63115 + atomic_unchecked_t *stat_op_waits,
63116 + atomic_unchecked_t *stat_object_dead,
63117 void (*do_cancel)(struct fscache_operation *))
63118 {
63119 int ret;
63120 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63121
63122 _debug(">>> WT");
63123 if (stat_op_waits)
63124 - fscache_stat(stat_op_waits);
63125 + fscache_stat_unchecked(stat_op_waits);
63126 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63127 TASK_INTERRUPTIBLE) != 0) {
63128 ret = fscache_cancel_op(op, do_cancel);
63129 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63130 check_if_dead:
63131 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63132 if (stat_object_dead)
63133 - fscache_stat(stat_object_dead);
63134 + fscache_stat_unchecked(stat_object_dead);
63135 _leave(" = -ENOBUFS [cancelled]");
63136 return -ENOBUFS;
63137 }
63138 @@ -381,7 +381,7 @@ check_if_dead:
63139 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63140 fscache_cancel_op(op, do_cancel);
63141 if (stat_object_dead)
63142 - fscache_stat(stat_object_dead);
63143 + fscache_stat_unchecked(stat_object_dead);
63144 return -ENOBUFS;
63145 }
63146 return 0;
63147 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63148
63149 _enter("%p,%p,,,", cookie, page);
63150
63151 - fscache_stat(&fscache_n_retrievals);
63152 + fscache_stat_unchecked(&fscache_n_retrievals);
63153
63154 if (hlist_empty(&cookie->backing_objects))
63155 goto nobufs;
63156 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63157 goto nobufs_unlock_dec;
63158 spin_unlock(&cookie->lock);
63159
63160 - fscache_stat(&fscache_n_retrieval_ops);
63161 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63162
63163 /* pin the netfs read context in case we need to do the actual netfs
63164 * read because we've encountered a cache read failure */
63165 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63166
63167 error:
63168 if (ret == -ENOMEM)
63169 - fscache_stat(&fscache_n_retrievals_nomem);
63170 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63171 else if (ret == -ERESTARTSYS)
63172 - fscache_stat(&fscache_n_retrievals_intr);
63173 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63174 else if (ret == -ENODATA)
63175 - fscache_stat(&fscache_n_retrievals_nodata);
63176 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63177 else if (ret < 0)
63178 - fscache_stat(&fscache_n_retrievals_nobufs);
63179 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63180 else
63181 - fscache_stat(&fscache_n_retrievals_ok);
63182 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63183
63184 fscache_put_retrieval(op);
63185 _leave(" = %d", ret);
63186 @@ -505,7 +505,7 @@ nobufs_unlock:
63187 __fscache_wake_unused_cookie(cookie);
63188 kfree(op);
63189 nobufs:
63190 - fscache_stat(&fscache_n_retrievals_nobufs);
63191 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63192 _leave(" = -ENOBUFS");
63193 return -ENOBUFS;
63194 }
63195 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63196
63197 _enter("%p,,%d,,,", cookie, *nr_pages);
63198
63199 - fscache_stat(&fscache_n_retrievals);
63200 + fscache_stat_unchecked(&fscache_n_retrievals);
63201
63202 if (hlist_empty(&cookie->backing_objects))
63203 goto nobufs;
63204 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63205 goto nobufs_unlock_dec;
63206 spin_unlock(&cookie->lock);
63207
63208 - fscache_stat(&fscache_n_retrieval_ops);
63209 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63210
63211 /* pin the netfs read context in case we need to do the actual netfs
63212 * read because we've encountered a cache read failure */
63213 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63214
63215 error:
63216 if (ret == -ENOMEM)
63217 - fscache_stat(&fscache_n_retrievals_nomem);
63218 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63219 else if (ret == -ERESTARTSYS)
63220 - fscache_stat(&fscache_n_retrievals_intr);
63221 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63222 else if (ret == -ENODATA)
63223 - fscache_stat(&fscache_n_retrievals_nodata);
63224 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63225 else if (ret < 0)
63226 - fscache_stat(&fscache_n_retrievals_nobufs);
63227 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63228 else
63229 - fscache_stat(&fscache_n_retrievals_ok);
63230 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63231
63232 fscache_put_retrieval(op);
63233 _leave(" = %d", ret);
63234 @@ -636,7 +636,7 @@ nobufs_unlock:
63235 if (wake_cookie)
63236 __fscache_wake_unused_cookie(cookie);
63237 nobufs:
63238 - fscache_stat(&fscache_n_retrievals_nobufs);
63239 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63240 _leave(" = -ENOBUFS");
63241 return -ENOBUFS;
63242 }
63243 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63244
63245 _enter("%p,%p,,,", cookie, page);
63246
63247 - fscache_stat(&fscache_n_allocs);
63248 + fscache_stat_unchecked(&fscache_n_allocs);
63249
63250 if (hlist_empty(&cookie->backing_objects))
63251 goto nobufs;
63252 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63253 goto nobufs_unlock_dec;
63254 spin_unlock(&cookie->lock);
63255
63256 - fscache_stat(&fscache_n_alloc_ops);
63257 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63258
63259 ret = fscache_wait_for_operation_activation(
63260 object, &op->op,
63261 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63262
63263 error:
63264 if (ret == -ERESTARTSYS)
63265 - fscache_stat(&fscache_n_allocs_intr);
63266 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63267 else if (ret < 0)
63268 - fscache_stat(&fscache_n_allocs_nobufs);
63269 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63270 else
63271 - fscache_stat(&fscache_n_allocs_ok);
63272 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63273
63274 fscache_put_retrieval(op);
63275 _leave(" = %d", ret);
63276 @@ -730,7 +730,7 @@ nobufs_unlock:
63277 if (wake_cookie)
63278 __fscache_wake_unused_cookie(cookie);
63279 nobufs:
63280 - fscache_stat(&fscache_n_allocs_nobufs);
63281 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63282 _leave(" = -ENOBUFS");
63283 return -ENOBUFS;
63284 }
63285 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63286
63287 spin_lock(&cookie->stores_lock);
63288
63289 - fscache_stat(&fscache_n_store_calls);
63290 + fscache_stat_unchecked(&fscache_n_store_calls);
63291
63292 /* find a page to store */
63293 page = NULL;
63294 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63295 page = results[0];
63296 _debug("gang %d [%lx]", n, page->index);
63297 if (page->index > op->store_limit) {
63298 - fscache_stat(&fscache_n_store_pages_over_limit);
63299 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63300 goto superseded;
63301 }
63302
63303 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63304 spin_unlock(&cookie->stores_lock);
63305 spin_unlock(&object->lock);
63306
63307 - fscache_stat(&fscache_n_store_pages);
63308 + fscache_stat_unchecked(&fscache_n_store_pages);
63309 fscache_stat(&fscache_n_cop_write_page);
63310 ret = object->cache->ops->write_page(op, page);
63311 fscache_stat_d(&fscache_n_cop_write_page);
63312 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63313 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63314 ASSERT(PageFsCache(page));
63315
63316 - fscache_stat(&fscache_n_stores);
63317 + fscache_stat_unchecked(&fscache_n_stores);
63318
63319 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63320 _leave(" = -ENOBUFS [invalidating]");
63321 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63322 spin_unlock(&cookie->stores_lock);
63323 spin_unlock(&object->lock);
63324
63325 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63326 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63327 op->store_limit = object->store_limit;
63328
63329 __fscache_use_cookie(cookie);
63330 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63331
63332 spin_unlock(&cookie->lock);
63333 radix_tree_preload_end();
63334 - fscache_stat(&fscache_n_store_ops);
63335 - fscache_stat(&fscache_n_stores_ok);
63336 + fscache_stat_unchecked(&fscache_n_store_ops);
63337 + fscache_stat_unchecked(&fscache_n_stores_ok);
63338
63339 /* the work queue now carries its own ref on the object */
63340 fscache_put_operation(&op->op);
63341 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63342 return 0;
63343
63344 already_queued:
63345 - fscache_stat(&fscache_n_stores_again);
63346 + fscache_stat_unchecked(&fscache_n_stores_again);
63347 already_pending:
63348 spin_unlock(&cookie->stores_lock);
63349 spin_unlock(&object->lock);
63350 spin_unlock(&cookie->lock);
63351 radix_tree_preload_end();
63352 kfree(op);
63353 - fscache_stat(&fscache_n_stores_ok);
63354 + fscache_stat_unchecked(&fscache_n_stores_ok);
63355 _leave(" = 0");
63356 return 0;
63357
63358 @@ -1039,14 +1039,14 @@ nobufs:
63359 kfree(op);
63360 if (wake_cookie)
63361 __fscache_wake_unused_cookie(cookie);
63362 - fscache_stat(&fscache_n_stores_nobufs);
63363 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63364 _leave(" = -ENOBUFS");
63365 return -ENOBUFS;
63366
63367 nomem_free:
63368 kfree(op);
63369 nomem:
63370 - fscache_stat(&fscache_n_stores_oom);
63371 + fscache_stat_unchecked(&fscache_n_stores_oom);
63372 _leave(" = -ENOMEM");
63373 return -ENOMEM;
63374 }
63375 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63376 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63377 ASSERTCMP(page, !=, NULL);
63378
63379 - fscache_stat(&fscache_n_uncaches);
63380 + fscache_stat_unchecked(&fscache_n_uncaches);
63381
63382 /* cache withdrawal may beat us to it */
63383 if (!PageFsCache(page))
63384 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63385 struct fscache_cookie *cookie = op->op.object->cookie;
63386
63387 #ifdef CONFIG_FSCACHE_STATS
63388 - atomic_inc(&fscache_n_marks);
63389 + atomic_inc_unchecked(&fscache_n_marks);
63390 #endif
63391
63392 _debug("- mark %p{%lx}", page, page->index);
63393 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63394 index 40d13c7..ddf52b9 100644
63395 --- a/fs/fscache/stats.c
63396 +++ b/fs/fscache/stats.c
63397 @@ -18,99 +18,99 @@
63398 /*
63399 * operation counters
63400 */
63401 -atomic_t fscache_n_op_pend;
63402 -atomic_t fscache_n_op_run;
63403 -atomic_t fscache_n_op_enqueue;
63404 -atomic_t fscache_n_op_requeue;
63405 -atomic_t fscache_n_op_deferred_release;
63406 -atomic_t fscache_n_op_release;
63407 -atomic_t fscache_n_op_gc;
63408 -atomic_t fscache_n_op_cancelled;
63409 -atomic_t fscache_n_op_rejected;
63410 +atomic_unchecked_t fscache_n_op_pend;
63411 +atomic_unchecked_t fscache_n_op_run;
63412 +atomic_unchecked_t fscache_n_op_enqueue;
63413 +atomic_unchecked_t fscache_n_op_requeue;
63414 +atomic_unchecked_t fscache_n_op_deferred_release;
63415 +atomic_unchecked_t fscache_n_op_release;
63416 +atomic_unchecked_t fscache_n_op_gc;
63417 +atomic_unchecked_t fscache_n_op_cancelled;
63418 +atomic_unchecked_t fscache_n_op_rejected;
63419
63420 -atomic_t fscache_n_attr_changed;
63421 -atomic_t fscache_n_attr_changed_ok;
63422 -atomic_t fscache_n_attr_changed_nobufs;
63423 -atomic_t fscache_n_attr_changed_nomem;
63424 -atomic_t fscache_n_attr_changed_calls;
63425 +atomic_unchecked_t fscache_n_attr_changed;
63426 +atomic_unchecked_t fscache_n_attr_changed_ok;
63427 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63428 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63429 +atomic_unchecked_t fscache_n_attr_changed_calls;
63430
63431 -atomic_t fscache_n_allocs;
63432 -atomic_t fscache_n_allocs_ok;
63433 -atomic_t fscache_n_allocs_wait;
63434 -atomic_t fscache_n_allocs_nobufs;
63435 -atomic_t fscache_n_allocs_intr;
63436 -atomic_t fscache_n_allocs_object_dead;
63437 -atomic_t fscache_n_alloc_ops;
63438 -atomic_t fscache_n_alloc_op_waits;
63439 +atomic_unchecked_t fscache_n_allocs;
63440 +atomic_unchecked_t fscache_n_allocs_ok;
63441 +atomic_unchecked_t fscache_n_allocs_wait;
63442 +atomic_unchecked_t fscache_n_allocs_nobufs;
63443 +atomic_unchecked_t fscache_n_allocs_intr;
63444 +atomic_unchecked_t fscache_n_allocs_object_dead;
63445 +atomic_unchecked_t fscache_n_alloc_ops;
63446 +atomic_unchecked_t fscache_n_alloc_op_waits;
63447
63448 -atomic_t fscache_n_retrievals;
63449 -atomic_t fscache_n_retrievals_ok;
63450 -atomic_t fscache_n_retrievals_wait;
63451 -atomic_t fscache_n_retrievals_nodata;
63452 -atomic_t fscache_n_retrievals_nobufs;
63453 -atomic_t fscache_n_retrievals_intr;
63454 -atomic_t fscache_n_retrievals_nomem;
63455 -atomic_t fscache_n_retrievals_object_dead;
63456 -atomic_t fscache_n_retrieval_ops;
63457 -atomic_t fscache_n_retrieval_op_waits;
63458 +atomic_unchecked_t fscache_n_retrievals;
63459 +atomic_unchecked_t fscache_n_retrievals_ok;
63460 +atomic_unchecked_t fscache_n_retrievals_wait;
63461 +atomic_unchecked_t fscache_n_retrievals_nodata;
63462 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63463 +atomic_unchecked_t fscache_n_retrievals_intr;
63464 +atomic_unchecked_t fscache_n_retrievals_nomem;
63465 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63466 +atomic_unchecked_t fscache_n_retrieval_ops;
63467 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63468
63469 -atomic_t fscache_n_stores;
63470 -atomic_t fscache_n_stores_ok;
63471 -atomic_t fscache_n_stores_again;
63472 -atomic_t fscache_n_stores_nobufs;
63473 -atomic_t fscache_n_stores_oom;
63474 -atomic_t fscache_n_store_ops;
63475 -atomic_t fscache_n_store_calls;
63476 -atomic_t fscache_n_store_pages;
63477 -atomic_t fscache_n_store_radix_deletes;
63478 -atomic_t fscache_n_store_pages_over_limit;
63479 +atomic_unchecked_t fscache_n_stores;
63480 +atomic_unchecked_t fscache_n_stores_ok;
63481 +atomic_unchecked_t fscache_n_stores_again;
63482 +atomic_unchecked_t fscache_n_stores_nobufs;
63483 +atomic_unchecked_t fscache_n_stores_oom;
63484 +atomic_unchecked_t fscache_n_store_ops;
63485 +atomic_unchecked_t fscache_n_store_calls;
63486 +atomic_unchecked_t fscache_n_store_pages;
63487 +atomic_unchecked_t fscache_n_store_radix_deletes;
63488 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63489
63490 -atomic_t fscache_n_store_vmscan_not_storing;
63491 -atomic_t fscache_n_store_vmscan_gone;
63492 -atomic_t fscache_n_store_vmscan_busy;
63493 -atomic_t fscache_n_store_vmscan_cancelled;
63494 -atomic_t fscache_n_store_vmscan_wait;
63495 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63496 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63497 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63498 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63499 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63500
63501 -atomic_t fscache_n_marks;
63502 -atomic_t fscache_n_uncaches;
63503 +atomic_unchecked_t fscache_n_marks;
63504 +atomic_unchecked_t fscache_n_uncaches;
63505
63506 -atomic_t fscache_n_acquires;
63507 -atomic_t fscache_n_acquires_null;
63508 -atomic_t fscache_n_acquires_no_cache;
63509 -atomic_t fscache_n_acquires_ok;
63510 -atomic_t fscache_n_acquires_nobufs;
63511 -atomic_t fscache_n_acquires_oom;
63512 +atomic_unchecked_t fscache_n_acquires;
63513 +atomic_unchecked_t fscache_n_acquires_null;
63514 +atomic_unchecked_t fscache_n_acquires_no_cache;
63515 +atomic_unchecked_t fscache_n_acquires_ok;
63516 +atomic_unchecked_t fscache_n_acquires_nobufs;
63517 +atomic_unchecked_t fscache_n_acquires_oom;
63518
63519 -atomic_t fscache_n_invalidates;
63520 -atomic_t fscache_n_invalidates_run;
63521 +atomic_unchecked_t fscache_n_invalidates;
63522 +atomic_unchecked_t fscache_n_invalidates_run;
63523
63524 -atomic_t fscache_n_updates;
63525 -atomic_t fscache_n_updates_null;
63526 -atomic_t fscache_n_updates_run;
63527 +atomic_unchecked_t fscache_n_updates;
63528 +atomic_unchecked_t fscache_n_updates_null;
63529 +atomic_unchecked_t fscache_n_updates_run;
63530
63531 -atomic_t fscache_n_relinquishes;
63532 -atomic_t fscache_n_relinquishes_null;
63533 -atomic_t fscache_n_relinquishes_waitcrt;
63534 -atomic_t fscache_n_relinquishes_retire;
63535 +atomic_unchecked_t fscache_n_relinquishes;
63536 +atomic_unchecked_t fscache_n_relinquishes_null;
63537 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63538 +atomic_unchecked_t fscache_n_relinquishes_retire;
63539
63540 -atomic_t fscache_n_cookie_index;
63541 -atomic_t fscache_n_cookie_data;
63542 -atomic_t fscache_n_cookie_special;
63543 +atomic_unchecked_t fscache_n_cookie_index;
63544 +atomic_unchecked_t fscache_n_cookie_data;
63545 +atomic_unchecked_t fscache_n_cookie_special;
63546
63547 -atomic_t fscache_n_object_alloc;
63548 -atomic_t fscache_n_object_no_alloc;
63549 -atomic_t fscache_n_object_lookups;
63550 -atomic_t fscache_n_object_lookups_negative;
63551 -atomic_t fscache_n_object_lookups_positive;
63552 -atomic_t fscache_n_object_lookups_timed_out;
63553 -atomic_t fscache_n_object_created;
63554 -atomic_t fscache_n_object_avail;
63555 -atomic_t fscache_n_object_dead;
63556 +atomic_unchecked_t fscache_n_object_alloc;
63557 +atomic_unchecked_t fscache_n_object_no_alloc;
63558 +atomic_unchecked_t fscache_n_object_lookups;
63559 +atomic_unchecked_t fscache_n_object_lookups_negative;
63560 +atomic_unchecked_t fscache_n_object_lookups_positive;
63561 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63562 +atomic_unchecked_t fscache_n_object_created;
63563 +atomic_unchecked_t fscache_n_object_avail;
63564 +atomic_unchecked_t fscache_n_object_dead;
63565
63566 -atomic_t fscache_n_checkaux_none;
63567 -atomic_t fscache_n_checkaux_okay;
63568 -atomic_t fscache_n_checkaux_update;
63569 -atomic_t fscache_n_checkaux_obsolete;
63570 +atomic_unchecked_t fscache_n_checkaux_none;
63571 +atomic_unchecked_t fscache_n_checkaux_okay;
63572 +atomic_unchecked_t fscache_n_checkaux_update;
63573 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63574
63575 atomic_t fscache_n_cop_alloc_object;
63576 atomic_t fscache_n_cop_lookup_object;
63577 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63578 seq_puts(m, "FS-Cache statistics\n");
63579
63580 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63581 - atomic_read(&fscache_n_cookie_index),
63582 - atomic_read(&fscache_n_cookie_data),
63583 - atomic_read(&fscache_n_cookie_special));
63584 + atomic_read_unchecked(&fscache_n_cookie_index),
63585 + atomic_read_unchecked(&fscache_n_cookie_data),
63586 + atomic_read_unchecked(&fscache_n_cookie_special));
63587
63588 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63589 - atomic_read(&fscache_n_object_alloc),
63590 - atomic_read(&fscache_n_object_no_alloc),
63591 - atomic_read(&fscache_n_object_avail),
63592 - atomic_read(&fscache_n_object_dead));
63593 + atomic_read_unchecked(&fscache_n_object_alloc),
63594 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63595 + atomic_read_unchecked(&fscache_n_object_avail),
63596 + atomic_read_unchecked(&fscache_n_object_dead));
63597 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63598 - atomic_read(&fscache_n_checkaux_none),
63599 - atomic_read(&fscache_n_checkaux_okay),
63600 - atomic_read(&fscache_n_checkaux_update),
63601 - atomic_read(&fscache_n_checkaux_obsolete));
63602 + atomic_read_unchecked(&fscache_n_checkaux_none),
63603 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63604 + atomic_read_unchecked(&fscache_n_checkaux_update),
63605 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63606
63607 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63608 - atomic_read(&fscache_n_marks),
63609 - atomic_read(&fscache_n_uncaches));
63610 + atomic_read_unchecked(&fscache_n_marks),
63611 + atomic_read_unchecked(&fscache_n_uncaches));
63612
63613 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63614 " oom=%u\n",
63615 - atomic_read(&fscache_n_acquires),
63616 - atomic_read(&fscache_n_acquires_null),
63617 - atomic_read(&fscache_n_acquires_no_cache),
63618 - atomic_read(&fscache_n_acquires_ok),
63619 - atomic_read(&fscache_n_acquires_nobufs),
63620 - atomic_read(&fscache_n_acquires_oom));
63621 + atomic_read_unchecked(&fscache_n_acquires),
63622 + atomic_read_unchecked(&fscache_n_acquires_null),
63623 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63624 + atomic_read_unchecked(&fscache_n_acquires_ok),
63625 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63626 + atomic_read_unchecked(&fscache_n_acquires_oom));
63627
63628 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63629 - atomic_read(&fscache_n_object_lookups),
63630 - atomic_read(&fscache_n_object_lookups_negative),
63631 - atomic_read(&fscache_n_object_lookups_positive),
63632 - atomic_read(&fscache_n_object_created),
63633 - atomic_read(&fscache_n_object_lookups_timed_out));
63634 + atomic_read_unchecked(&fscache_n_object_lookups),
63635 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63636 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63637 + atomic_read_unchecked(&fscache_n_object_created),
63638 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63639
63640 seq_printf(m, "Invals : n=%u run=%u\n",
63641 - atomic_read(&fscache_n_invalidates),
63642 - atomic_read(&fscache_n_invalidates_run));
63643 + atomic_read_unchecked(&fscache_n_invalidates),
63644 + atomic_read_unchecked(&fscache_n_invalidates_run));
63645
63646 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63647 - atomic_read(&fscache_n_updates),
63648 - atomic_read(&fscache_n_updates_null),
63649 - atomic_read(&fscache_n_updates_run));
63650 + atomic_read_unchecked(&fscache_n_updates),
63651 + atomic_read_unchecked(&fscache_n_updates_null),
63652 + atomic_read_unchecked(&fscache_n_updates_run));
63653
63654 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63655 - atomic_read(&fscache_n_relinquishes),
63656 - atomic_read(&fscache_n_relinquishes_null),
63657 - atomic_read(&fscache_n_relinquishes_waitcrt),
63658 - atomic_read(&fscache_n_relinquishes_retire));
63659 + atomic_read_unchecked(&fscache_n_relinquishes),
63660 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63661 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63662 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63663
63664 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63665 - atomic_read(&fscache_n_attr_changed),
63666 - atomic_read(&fscache_n_attr_changed_ok),
63667 - atomic_read(&fscache_n_attr_changed_nobufs),
63668 - atomic_read(&fscache_n_attr_changed_nomem),
63669 - atomic_read(&fscache_n_attr_changed_calls));
63670 + atomic_read_unchecked(&fscache_n_attr_changed),
63671 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63672 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63673 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63674 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63675
63676 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63677 - atomic_read(&fscache_n_allocs),
63678 - atomic_read(&fscache_n_allocs_ok),
63679 - atomic_read(&fscache_n_allocs_wait),
63680 - atomic_read(&fscache_n_allocs_nobufs),
63681 - atomic_read(&fscache_n_allocs_intr));
63682 + atomic_read_unchecked(&fscache_n_allocs),
63683 + atomic_read_unchecked(&fscache_n_allocs_ok),
63684 + atomic_read_unchecked(&fscache_n_allocs_wait),
63685 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63686 + atomic_read_unchecked(&fscache_n_allocs_intr));
63687 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63688 - atomic_read(&fscache_n_alloc_ops),
63689 - atomic_read(&fscache_n_alloc_op_waits),
63690 - atomic_read(&fscache_n_allocs_object_dead));
63691 + atomic_read_unchecked(&fscache_n_alloc_ops),
63692 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63693 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63694
63695 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63696 " int=%u oom=%u\n",
63697 - atomic_read(&fscache_n_retrievals),
63698 - atomic_read(&fscache_n_retrievals_ok),
63699 - atomic_read(&fscache_n_retrievals_wait),
63700 - atomic_read(&fscache_n_retrievals_nodata),
63701 - atomic_read(&fscache_n_retrievals_nobufs),
63702 - atomic_read(&fscache_n_retrievals_intr),
63703 - atomic_read(&fscache_n_retrievals_nomem));
63704 + atomic_read_unchecked(&fscache_n_retrievals),
63705 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63706 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63707 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63708 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63709 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63710 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63711 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63712 - atomic_read(&fscache_n_retrieval_ops),
63713 - atomic_read(&fscache_n_retrieval_op_waits),
63714 - atomic_read(&fscache_n_retrievals_object_dead));
63715 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63716 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63717 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63718
63719 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63720 - atomic_read(&fscache_n_stores),
63721 - atomic_read(&fscache_n_stores_ok),
63722 - atomic_read(&fscache_n_stores_again),
63723 - atomic_read(&fscache_n_stores_nobufs),
63724 - atomic_read(&fscache_n_stores_oom));
63725 + atomic_read_unchecked(&fscache_n_stores),
63726 + atomic_read_unchecked(&fscache_n_stores_ok),
63727 + atomic_read_unchecked(&fscache_n_stores_again),
63728 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63729 + atomic_read_unchecked(&fscache_n_stores_oom));
63730 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63731 - atomic_read(&fscache_n_store_ops),
63732 - atomic_read(&fscache_n_store_calls),
63733 - atomic_read(&fscache_n_store_pages),
63734 - atomic_read(&fscache_n_store_radix_deletes),
63735 - atomic_read(&fscache_n_store_pages_over_limit));
63736 + atomic_read_unchecked(&fscache_n_store_ops),
63737 + atomic_read_unchecked(&fscache_n_store_calls),
63738 + atomic_read_unchecked(&fscache_n_store_pages),
63739 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63740 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63741
63742 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63743 - atomic_read(&fscache_n_store_vmscan_not_storing),
63744 - atomic_read(&fscache_n_store_vmscan_gone),
63745 - atomic_read(&fscache_n_store_vmscan_busy),
63746 - atomic_read(&fscache_n_store_vmscan_cancelled),
63747 - atomic_read(&fscache_n_store_vmscan_wait));
63748 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63749 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63750 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63751 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63752 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63753
63754 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63755 - atomic_read(&fscache_n_op_pend),
63756 - atomic_read(&fscache_n_op_run),
63757 - atomic_read(&fscache_n_op_enqueue),
63758 - atomic_read(&fscache_n_op_cancelled),
63759 - atomic_read(&fscache_n_op_rejected));
63760 + atomic_read_unchecked(&fscache_n_op_pend),
63761 + atomic_read_unchecked(&fscache_n_op_run),
63762 + atomic_read_unchecked(&fscache_n_op_enqueue),
63763 + atomic_read_unchecked(&fscache_n_op_cancelled),
63764 + atomic_read_unchecked(&fscache_n_op_rejected));
63765 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63766 - atomic_read(&fscache_n_op_deferred_release),
63767 - atomic_read(&fscache_n_op_release),
63768 - atomic_read(&fscache_n_op_gc));
63769 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63770 + atomic_read_unchecked(&fscache_n_op_release),
63771 + atomic_read_unchecked(&fscache_n_op_gc));
63772
63773 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63774 atomic_read(&fscache_n_cop_alloc_object),
63775 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63776 index 966ace8..030a03a 100644
63777 --- a/fs/fuse/cuse.c
63778 +++ b/fs/fuse/cuse.c
63779 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63780 INIT_LIST_HEAD(&cuse_conntbl[i]);
63781
63782 /* inherit and extend fuse_dev_operations */
63783 - cuse_channel_fops = fuse_dev_operations;
63784 - cuse_channel_fops.owner = THIS_MODULE;
63785 - cuse_channel_fops.open = cuse_channel_open;
63786 - cuse_channel_fops.release = cuse_channel_release;
63787 + pax_open_kernel();
63788 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63789 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63790 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63791 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63792 + pax_close_kernel();
63793
63794 cuse_class = class_create(THIS_MODULE, "cuse");
63795 if (IS_ERR(cuse_class))
63796 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63797 index ca88731..8e9c55d 100644
63798 --- a/fs/fuse/dev.c
63799 +++ b/fs/fuse/dev.c
63800 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63801 ret = 0;
63802 pipe_lock(pipe);
63803
63804 - if (!pipe->readers) {
63805 + if (!atomic_read(&pipe->readers)) {
63806 send_sig(SIGPIPE, current, 0);
63807 if (!ret)
63808 ret = -EPIPE;
63809 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63810 page_nr++;
63811 ret += buf->len;
63812
63813 - if (pipe->files)
63814 + if (atomic_read(&pipe->files))
63815 do_wakeup = 1;
63816 }
63817
63818 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63819 index dbab798..fefa22b 100644
63820 --- a/fs/fuse/dir.c
63821 +++ b/fs/fuse/dir.c
63822 @@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63823 return link;
63824 }
63825
63826 -static void free_link(char *link)
63827 +static void free_link(const char *link)
63828 {
63829 if (!IS_ERR(link))
63830 free_page((unsigned long) link);
63831 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63832 index fd62cae..3494dfa 100644
63833 --- a/fs/hostfs/hostfs_kern.c
63834 +++ b/fs/hostfs/hostfs_kern.c
63835 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63836
63837 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63838 {
63839 - char *s = nd_get_link(nd);
63840 + const char *s = nd_get_link(nd);
63841 if (!IS_ERR(s))
63842 __putname(s);
63843 }
63844 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63845 index 1e2872b..7aea000 100644
63846 --- a/fs/hugetlbfs/inode.c
63847 +++ b/fs/hugetlbfs/inode.c
63848 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63849 struct mm_struct *mm = current->mm;
63850 struct vm_area_struct *vma;
63851 struct hstate *h = hstate_file(file);
63852 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63853 struct vm_unmapped_area_info info;
63854
63855 if (len & ~huge_page_mask(h))
63856 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63857 return addr;
63858 }
63859
63860 +#ifdef CONFIG_PAX_RANDMMAP
63861 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63862 +#endif
63863 +
63864 if (addr) {
63865 addr = ALIGN(addr, huge_page_size(h));
63866 vma = find_vma(mm, addr);
63867 - if (TASK_SIZE - len >= addr &&
63868 - (!vma || addr + len <= vma->vm_start))
63869 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63870 return addr;
63871 }
63872
63873 info.flags = 0;
63874 info.length = len;
63875 info.low_limit = TASK_UNMAPPED_BASE;
63876 +
63877 +#ifdef CONFIG_PAX_RANDMMAP
63878 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63879 + info.low_limit += mm->delta_mmap;
63880 +#endif
63881 +
63882 info.high_limit = TASK_SIZE;
63883 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63884 info.align_offset = 0;
63885 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63886 };
63887 MODULE_ALIAS_FS("hugetlbfs");
63888
63889 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63890 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63891
63892 static int can_do_hugetlb_shm(void)
63893 {
63894 diff --git a/fs/inode.c b/fs/inode.c
63895 index 26753ba..d19eb34 100644
63896 --- a/fs/inode.c
63897 +++ b/fs/inode.c
63898 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63899 unsigned int *p = &get_cpu_var(last_ino);
63900 unsigned int res = *p;
63901
63902 +start:
63903 +
63904 #ifdef CONFIG_SMP
63905 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63906 - static atomic_t shared_last_ino;
63907 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63908 + static atomic_unchecked_t shared_last_ino;
63909 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63910
63911 res = next - LAST_INO_BATCH;
63912 }
63913 #endif
63914
63915 - *p = ++res;
63916 + if (unlikely(!++res))
63917 + goto start; /* never zero */
63918 + *p = res;
63919 put_cpu_var(last_ino);
63920 return res;
63921 }
63922 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63923 index 4a6cf28..d3a29d3 100644
63924 --- a/fs/jffs2/erase.c
63925 +++ b/fs/jffs2/erase.c
63926 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63927 struct jffs2_unknown_node marker = {
63928 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63929 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63930 - .totlen = cpu_to_je32(c->cleanmarker_size)
63931 + .totlen = cpu_to_je32(c->cleanmarker_size),
63932 + .hdr_crc = cpu_to_je32(0)
63933 };
63934
63935 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63936 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63937 index 09ed551..45684f8 100644
63938 --- a/fs/jffs2/wbuf.c
63939 +++ b/fs/jffs2/wbuf.c
63940 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63941 {
63942 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63943 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63944 - .totlen = constant_cpu_to_je32(8)
63945 + .totlen = constant_cpu_to_je32(8),
63946 + .hdr_crc = constant_cpu_to_je32(0)
63947 };
63948
63949 /*
63950 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63951 index 93e897e..a863de4 100644
63952 --- a/fs/jfs/super.c
63953 +++ b/fs/jfs/super.c
63954 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63955
63956 jfs_inode_cachep =
63957 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63958 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63959 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63960 init_once);
63961 if (jfs_inode_cachep == NULL)
63962 return -ENOMEM;
63963 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63964 index 1c77193..ba73e66 100644
63965 --- a/fs/kernfs/dir.c
63966 +++ b/fs/kernfs/dir.c
63967 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63968 *
63969 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63970 */
63971 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63972 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63973 {
63974 unsigned long hash = init_name_hash();
63975 unsigned int len = strlen(name);
63976 @@ -829,6 +829,12 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
63977 ret = scops->mkdir(parent, dentry->d_name.name, mode);
63978
63979 kernfs_put_active(parent);
63980 +
63981 + if (!ret) {
63982 + struct dentry *dentry_ret = kernfs_iop_lookup(dir, dentry, 0);
63983 + ret = PTR_ERR_OR_ZERO(dentry_ret);
63984 + }
63985 +
63986 return ret;
63987 }
63988
63989 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63990 index 4429d6d..9831f52 100644
63991 --- a/fs/kernfs/file.c
63992 +++ b/fs/kernfs/file.c
63993 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63994
63995 struct kernfs_open_node {
63996 atomic_t refcnt;
63997 - atomic_t event;
63998 + atomic_unchecked_t event;
63999 wait_queue_head_t poll;
64000 struct list_head files; /* goes through kernfs_open_file.list */
64001 };
64002 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64003 {
64004 struct kernfs_open_file *of = sf->private;
64005
64006 - of->event = atomic_read(&of->kn->attr.open->event);
64007 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64008
64009 return of->kn->attr.ops->seq_show(sf, v);
64010 }
64011 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64012 return ret;
64013 }
64014
64015 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64016 - void *buf, int len, int write)
64017 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64018 + void *buf, size_t len, int write)
64019 {
64020 struct file *file = vma->vm_file;
64021 struct kernfs_open_file *of = kernfs_of(file);
64022 - int ret;
64023 + ssize_t ret;
64024
64025 if (!of->vm_ops)
64026 return -EINVAL;
64027 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64028 return -ENOMEM;
64029
64030 atomic_set(&new_on->refcnt, 0);
64031 - atomic_set(&new_on->event, 1);
64032 + atomic_set_unchecked(&new_on->event, 1);
64033 init_waitqueue_head(&new_on->poll);
64034 INIT_LIST_HEAD(&new_on->files);
64035 goto retry;
64036 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64037
64038 kernfs_put_active(kn);
64039
64040 - if (of->event != atomic_read(&on->event))
64041 + if (of->event != atomic_read_unchecked(&on->event))
64042 goto trigger;
64043
64044 return DEFAULT_POLLMASK;
64045 @@ -818,7 +818,7 @@ repeat:
64046
64047 on = kn->attr.open;
64048 if (on) {
64049 - atomic_inc(&on->event);
64050 + atomic_inc_unchecked(&on->event);
64051 wake_up_interruptible(&on->poll);
64052 }
64053
64054 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64055 index 8a19889..4c3069a 100644
64056 --- a/fs/kernfs/symlink.c
64057 +++ b/fs/kernfs/symlink.c
64058 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64059 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64060 void *cookie)
64061 {
64062 - char *page = nd_get_link(nd);
64063 + const char *page = nd_get_link(nd);
64064 if (!IS_ERR(page))
64065 free_page((unsigned long)page);
64066 }
64067 diff --git a/fs/libfs.c b/fs/libfs.c
64068 index 005843c..06c4191 100644
64069 --- a/fs/libfs.c
64070 +++ b/fs/libfs.c
64071 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64072
64073 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64074 struct dentry *next = list_entry(p, struct dentry, d_child);
64075 + char d_name[sizeof(next->d_iname)];
64076 + const unsigned char *name;
64077 +
64078 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64079 if (!simple_positive(next)) {
64080 spin_unlock(&next->d_lock);
64081 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64082
64083 spin_unlock(&next->d_lock);
64084 spin_unlock(&dentry->d_lock);
64085 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64086 + name = next->d_name.name;
64087 + if (name == next->d_iname) {
64088 + memcpy(d_name, name, next->d_name.len);
64089 + name = d_name;
64090 + }
64091 + if (!dir_emit(ctx, name, next->d_name.len,
64092 next->d_inode->i_ino, dt_type(next->d_inode)))
64093 return 0;
64094 spin_lock(&dentry->d_lock);
64095 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64096 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64097 void *cookie)
64098 {
64099 - char *s = nd_get_link(nd);
64100 + const char *s = nd_get_link(nd);
64101 if (!IS_ERR(s))
64102 kfree(s);
64103 }
64104 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64105 index acd3947..1f896e2 100644
64106 --- a/fs/lockd/clntproc.c
64107 +++ b/fs/lockd/clntproc.c
64108 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64109 /*
64110 * Cookie counter for NLM requests
64111 */
64112 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64113 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64114
64115 void nlmclnt_next_cookie(struct nlm_cookie *c)
64116 {
64117 - u32 cookie = atomic_inc_return(&nlm_cookie);
64118 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64119
64120 memcpy(c->data, &cookie, 4);
64121 c->len=4;
64122 diff --git a/fs/locks.c b/fs/locks.c
64123 index 59e2f90..bd69071 100644
64124 --- a/fs/locks.c
64125 +++ b/fs/locks.c
64126 @@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
64127 locks_remove_posix(filp, filp);
64128
64129 if (filp->f_op->flock) {
64130 - struct file_lock fl = {
64131 + struct file_lock flock = {
64132 .fl_owner = filp,
64133 .fl_pid = current->tgid,
64134 .fl_file = filp,
64135 @@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
64136 .fl_type = F_UNLCK,
64137 .fl_end = OFFSET_MAX,
64138 };
64139 - filp->f_op->flock(filp, F_SETLKW, &fl);
64140 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64141 - fl.fl_ops->fl_release_private(&fl);
64142 + filp->f_op->flock(filp, F_SETLKW, &flock);
64143 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64144 + flock.fl_ops->fl_release_private(&flock);
64145 }
64146
64147 spin_lock(&inode->i_lock);
64148 diff --git a/fs/mount.h b/fs/mount.h
64149 index f82c628..9492b99 100644
64150 --- a/fs/mount.h
64151 +++ b/fs/mount.h
64152 @@ -11,7 +11,7 @@ struct mnt_namespace {
64153 u64 seq; /* Sequence number to prevent loops */
64154 wait_queue_head_t poll;
64155 u64 event;
64156 -};
64157 +} __randomize_layout;
64158
64159 struct mnt_pcp {
64160 int mnt_count;
64161 @@ -62,7 +62,7 @@ struct mount {
64162 int mnt_expiry_mark; /* true if marked for expiry */
64163 struct hlist_head mnt_pins;
64164 struct path mnt_ex_mountpoint;
64165 -};
64166 +} __randomize_layout;
64167
64168 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64169
64170 diff --git a/fs/namei.c b/fs/namei.c
64171 index db5fe86..ac769e4 100644
64172 --- a/fs/namei.c
64173 +++ b/fs/namei.c
64174 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64175 if (ret != -EACCES)
64176 return ret;
64177
64178 +#ifdef CONFIG_GRKERNSEC
64179 + /* we'll block if we have to log due to a denied capability use */
64180 + if (mask & MAY_NOT_BLOCK)
64181 + return -ECHILD;
64182 +#endif
64183 +
64184 if (S_ISDIR(inode->i_mode)) {
64185 /* DACs are overridable for directories */
64186 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64187 - return 0;
64188 if (!(mask & MAY_WRITE))
64189 - if (capable_wrt_inode_uidgid(inode,
64190 - CAP_DAC_READ_SEARCH))
64191 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64192 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64193 return 0;
64194 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64195 + return 0;
64196 return -EACCES;
64197 }
64198 /*
64199 + * Searching includes executable on directories, else just read.
64200 + */
64201 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64202 + if (mask == MAY_READ)
64203 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64204 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64205 + return 0;
64206 +
64207 + /*
64208 * Read/write DACs are always overridable.
64209 * Executable DACs are overridable when there is
64210 * at least one exec bit set.
64211 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64212 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64213 return 0;
64214
64215 - /*
64216 - * Searching includes executable on directories, else just read.
64217 - */
64218 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64219 - if (mask == MAY_READ)
64220 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64221 - return 0;
64222 -
64223 return -EACCES;
64224 }
64225 EXPORT_SYMBOL(generic_permission);
64226 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64227 {
64228 struct dentry *dentry = link->dentry;
64229 int error;
64230 - char *s;
64231 + const char *s;
64232
64233 BUG_ON(nd->flags & LOOKUP_RCU);
64234
64235 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64236 if (error)
64237 goto out_put_nd_path;
64238
64239 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64240 + dentry->d_inode, dentry, nd->path.mnt)) {
64241 + error = -EACCES;
64242 + goto out_put_nd_path;
64243 + }
64244 +
64245 nd->last_type = LAST_BIND;
64246 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64247 error = PTR_ERR(*p);
64248 @@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64249 if (res)
64250 break;
64251 res = walk_component(nd, path, LOOKUP_FOLLOW);
64252 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64253 + res = -EACCES;
64254 put_link(nd, &link, cookie);
64255 } while (res > 0);
64256
64257 @@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
64258 static inline u64 hash_name(const char *name)
64259 {
64260 unsigned long a, b, adata, bdata, mask, hash, len;
64261 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64262 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64263
64264 hash = a = 0;
64265 len = -sizeof(unsigned long);
64266 @@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
64267 if (err)
64268 break;
64269 err = lookup_last(nd, &path);
64270 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64271 + err = -EACCES;
64272 put_link(nd, &link, cookie);
64273 }
64274 }
64275 @@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
64276 if (!err)
64277 err = complete_walk(nd);
64278
64279 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64280 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64281 + path_put(&nd->path);
64282 + err = -ENOENT;
64283 + }
64284 + }
64285 +
64286 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64287 if (!d_can_lookup(nd->path.dentry)) {
64288 path_put(&nd->path);
64289 @@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
64290 retval = path_lookupat(dfd, name->name,
64291 flags | LOOKUP_REVAL, nd);
64292
64293 - if (likely(!retval))
64294 + if (likely(!retval)) {
64295 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64296 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64297 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64298 + path_put(&nd->path);
64299 + return -ENOENT;
64300 + }
64301 + }
64302 + }
64303 return retval;
64304 }
64305
64306 @@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64307 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64308 return -EPERM;
64309
64310 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64311 + return -EPERM;
64312 + if (gr_handle_rawio(inode))
64313 + return -EPERM;
64314 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64315 + return -EACCES;
64316 +
64317 return 0;
64318 }
64319
64320 @@ -2813,7 +2851,7 @@ looked_up:
64321 * cleared otherwise prior to returning.
64322 */
64323 static int lookup_open(struct nameidata *nd, struct path *path,
64324 - struct file *file,
64325 + struct path *link, struct file *file,
64326 const struct open_flags *op,
64327 bool got_write, int *opened)
64328 {
64329 @@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64330 /* Negative dentry, just create the file */
64331 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64332 umode_t mode = op->mode;
64333 +
64334 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64335 + error = -EACCES;
64336 + goto out_dput;
64337 + }
64338 +
64339 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64340 + error = -EACCES;
64341 + goto out_dput;
64342 + }
64343 +
64344 if (!IS_POSIXACL(dir->d_inode))
64345 mode &= ~current_umask();
64346 /*
64347 @@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64348 nd->flags & LOOKUP_EXCL);
64349 if (error)
64350 goto out_dput;
64351 + else
64352 + gr_handle_create(dentry, nd->path.mnt);
64353 }
64354 out_no_open:
64355 path->dentry = dentry;
64356 @@ -2883,7 +2934,7 @@ out_dput:
64357 /*
64358 * Handle the last step of open()
64359 */
64360 -static int do_last(struct nameidata *nd, struct path *path,
64361 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64362 struct file *file, const struct open_flags *op,
64363 int *opened, struct filename *name)
64364 {
64365 @@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64366 if (error)
64367 return error;
64368
64369 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64370 + error = -ENOENT;
64371 + goto out;
64372 + }
64373 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64374 + error = -EACCES;
64375 + goto out;
64376 + }
64377 +
64378 audit_inode(name, dir, LOOKUP_PARENT);
64379 error = -EISDIR;
64380 /* trailing slashes? */
64381 @@ -2952,7 +3012,7 @@ retry_lookup:
64382 */
64383 }
64384 mutex_lock(&dir->d_inode->i_mutex);
64385 - error = lookup_open(nd, path, file, op, got_write, opened);
64386 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64387 mutex_unlock(&dir->d_inode->i_mutex);
64388
64389 if (error <= 0) {
64390 @@ -2976,11 +3036,28 @@ retry_lookup:
64391 goto finish_open_created;
64392 }
64393
64394 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64395 + error = -ENOENT;
64396 + goto exit_dput;
64397 + }
64398 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64399 + error = -EACCES;
64400 + goto exit_dput;
64401 + }
64402 +
64403 /*
64404 * create/update audit record if it already exists.
64405 */
64406 - if (d_is_positive(path->dentry))
64407 + if (d_is_positive(path->dentry)) {
64408 + /* only check if O_CREAT is specified, all other checks need to go
64409 + into may_open */
64410 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64411 + error = -EACCES;
64412 + goto exit_dput;
64413 + }
64414 +
64415 audit_inode(name, path->dentry, 0);
64416 + }
64417
64418 /*
64419 * If atomic_open() acquired write access it is dropped now due to
64420 @@ -3021,6 +3098,11 @@ finish_lookup:
64421 }
64422 }
64423 BUG_ON(inode != path->dentry->d_inode);
64424 + /* if we're resolving a symlink to another symlink */
64425 + if (link && gr_handle_symlink_owner(link, inode)) {
64426 + error = -EACCES;
64427 + goto out;
64428 + }
64429 return 1;
64430 }
64431
64432 @@ -3040,7 +3122,18 @@ finish_open:
64433 path_put(&save_parent);
64434 return error;
64435 }
64436 +
64437 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64438 + error = -ENOENT;
64439 + goto out;
64440 + }
64441 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64442 + error = -EACCES;
64443 + goto out;
64444 + }
64445 +
64446 audit_inode(name, nd->path.dentry, 0);
64447 +
64448 error = -EISDIR;
64449 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64450 goto out;
64451 @@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64452 if (unlikely(error))
64453 goto out;
64454
64455 - error = do_last(nd, &path, file, op, &opened, pathname);
64456 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64457 while (unlikely(error > 0)) { /* trailing symlink */
64458 struct path link = path;
64459 void *cookie;
64460 @@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64461 error = follow_link(&link, nd, &cookie);
64462 if (unlikely(error))
64463 break;
64464 - error = do_last(nd, &path, file, op, &opened, pathname);
64465 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64466 put_link(nd, &link, cookie);
64467 }
64468 out:
64469 @@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64470 goto unlock;
64471
64472 error = -EEXIST;
64473 - if (d_is_positive(dentry))
64474 + if (d_is_positive(dentry)) {
64475 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64476 + error = -ENOENT;
64477 goto fail;
64478 -
64479 + }
64480 /*
64481 * Special case - lookup gave negative, but... we had foo/bar/
64482 * From the vfs_mknod() POV we just have a negative dentry -
64483 @@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64484 }
64485 EXPORT_SYMBOL(user_path_create);
64486
64487 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64488 +{
64489 + struct filename *tmp = getname(pathname);
64490 + struct dentry *res;
64491 + if (IS_ERR(tmp))
64492 + return ERR_CAST(tmp);
64493 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64494 + if (IS_ERR(res))
64495 + putname(tmp);
64496 + else
64497 + *to = tmp;
64498 + return res;
64499 +}
64500 +
64501 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64502 {
64503 int error = may_create(dir, dentry);
64504 @@ -3442,6 +3551,17 @@ retry:
64505
64506 if (!IS_POSIXACL(path.dentry->d_inode))
64507 mode &= ~current_umask();
64508 +
64509 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64510 + error = -EPERM;
64511 + goto out;
64512 + }
64513 +
64514 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64515 + error = -EACCES;
64516 + goto out;
64517 + }
64518 +
64519 error = security_path_mknod(&path, dentry, mode, dev);
64520 if (error)
64521 goto out;
64522 @@ -3457,6 +3577,8 @@ retry:
64523 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64524 break;
64525 }
64526 + if (!error)
64527 + gr_handle_create(dentry, path.mnt);
64528 out:
64529 done_path_create(&path, dentry);
64530 if (retry_estale(error, lookup_flags)) {
64531 @@ -3511,9 +3633,16 @@ retry:
64532
64533 if (!IS_POSIXACL(path.dentry->d_inode))
64534 mode &= ~current_umask();
64535 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64536 + error = -EACCES;
64537 + goto out;
64538 + }
64539 error = security_path_mkdir(&path, dentry, mode);
64540 if (!error)
64541 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64542 + if (!error)
64543 + gr_handle_create(dentry, path.mnt);
64544 +out:
64545 done_path_create(&path, dentry);
64546 if (retry_estale(error, lookup_flags)) {
64547 lookup_flags |= LOOKUP_REVAL;
64548 @@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64549 struct filename *name;
64550 struct dentry *dentry;
64551 struct nameidata nd;
64552 + ino_t saved_ino = 0;
64553 + dev_t saved_dev = 0;
64554 unsigned int lookup_flags = 0;
64555 retry:
64556 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64557 @@ -3629,10 +3760,21 @@ retry:
64558 error = -ENOENT;
64559 goto exit3;
64560 }
64561 +
64562 + saved_ino = dentry->d_inode->i_ino;
64563 + saved_dev = gr_get_dev_from_dentry(dentry);
64564 +
64565 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64566 + error = -EACCES;
64567 + goto exit3;
64568 + }
64569 +
64570 error = security_path_rmdir(&nd.path, dentry);
64571 if (error)
64572 goto exit3;
64573 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64574 + if (!error && (saved_dev || saved_ino))
64575 + gr_handle_delete(saved_ino, saved_dev);
64576 exit3:
64577 dput(dentry);
64578 exit2:
64579 @@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64580 struct nameidata nd;
64581 struct inode *inode = NULL;
64582 struct inode *delegated_inode = NULL;
64583 + ino_t saved_ino = 0;
64584 + dev_t saved_dev = 0;
64585 unsigned int lookup_flags = 0;
64586 retry:
64587 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64588 @@ -3751,10 +3895,22 @@ retry_deleg:
64589 if (d_is_negative(dentry))
64590 goto slashes;
64591 ihold(inode);
64592 +
64593 + if (inode->i_nlink <= 1) {
64594 + saved_ino = inode->i_ino;
64595 + saved_dev = gr_get_dev_from_dentry(dentry);
64596 + }
64597 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64598 + error = -EACCES;
64599 + goto exit2;
64600 + }
64601 +
64602 error = security_path_unlink(&nd.path, dentry);
64603 if (error)
64604 goto exit2;
64605 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64606 + if (!error && (saved_ino || saved_dev))
64607 + gr_handle_delete(saved_ino, saved_dev);
64608 exit2:
64609 dput(dentry);
64610 }
64611 @@ -3843,9 +3999,17 @@ retry:
64612 if (IS_ERR(dentry))
64613 goto out_putname;
64614
64615 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64616 + error = -EACCES;
64617 + goto out;
64618 + }
64619 +
64620 error = security_path_symlink(&path, dentry, from->name);
64621 if (!error)
64622 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64623 + if (!error)
64624 + gr_handle_create(dentry, path.mnt);
64625 +out:
64626 done_path_create(&path, dentry);
64627 if (retry_estale(error, lookup_flags)) {
64628 lookup_flags |= LOOKUP_REVAL;
64629 @@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64630 struct dentry *new_dentry;
64631 struct path old_path, new_path;
64632 struct inode *delegated_inode = NULL;
64633 + struct filename *to = NULL;
64634 int how = 0;
64635 int error;
64636
64637 @@ -3972,7 +4137,7 @@ retry:
64638 if (error)
64639 return error;
64640
64641 - new_dentry = user_path_create(newdfd, newname, &new_path,
64642 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64643 (how & LOOKUP_REVAL));
64644 error = PTR_ERR(new_dentry);
64645 if (IS_ERR(new_dentry))
64646 @@ -3984,11 +4149,28 @@ retry:
64647 error = may_linkat(&old_path);
64648 if (unlikely(error))
64649 goto out_dput;
64650 +
64651 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64652 + old_path.dentry->d_inode,
64653 + old_path.dentry->d_inode->i_mode, to)) {
64654 + error = -EACCES;
64655 + goto out_dput;
64656 + }
64657 +
64658 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64659 + old_path.dentry, old_path.mnt, to)) {
64660 + error = -EACCES;
64661 + goto out_dput;
64662 + }
64663 +
64664 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64665 if (error)
64666 goto out_dput;
64667 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64668 + if (!error)
64669 + gr_handle_create(new_dentry, new_path.mnt);
64670 out_dput:
64671 + putname(to);
64672 done_path_create(&new_path, new_dentry);
64673 if (delegated_inode) {
64674 error = break_deleg_wait(&delegated_inode);
64675 @@ -4304,6 +4486,20 @@ retry_deleg:
64676 if (new_dentry == trap)
64677 goto exit5;
64678
64679 + if (gr_bad_chroot_rename(old_dentry, oldnd.path.mnt, new_dentry, newnd.path.mnt)) {
64680 + /* use EXDEV error to cause 'mv' to switch to an alternative
64681 + * method for usability
64682 + */
64683 + error = -EXDEV;
64684 + goto exit5;
64685 + }
64686 +
64687 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64688 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64689 + to, flags);
64690 + if (error)
64691 + goto exit5;
64692 +
64693 error = security_path_rename(&oldnd.path, old_dentry,
64694 &newnd.path, new_dentry, flags);
64695 if (error)
64696 @@ -4311,6 +4507,9 @@ retry_deleg:
64697 error = vfs_rename(old_dir->d_inode, old_dentry,
64698 new_dir->d_inode, new_dentry,
64699 &delegated_inode, flags);
64700 + if (!error)
64701 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64702 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64703 exit5:
64704 dput(new_dentry);
64705 exit4:
64706 @@ -4367,14 +4566,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64707
64708 int readlink_copy(char __user *buffer, int buflen, const char *link)
64709 {
64710 + char tmpbuf[64];
64711 + const char *newlink;
64712 int len = PTR_ERR(link);
64713 +
64714 if (IS_ERR(link))
64715 goto out;
64716
64717 len = strlen(link);
64718 if (len > (unsigned) buflen)
64719 len = buflen;
64720 - if (copy_to_user(buffer, link, len))
64721 +
64722 + if (len < sizeof(tmpbuf)) {
64723 + memcpy(tmpbuf, link, len);
64724 + newlink = tmpbuf;
64725 + } else
64726 + newlink = link;
64727 +
64728 + if (copy_to_user(buffer, newlink, len))
64729 len = -EFAULT;
64730 out:
64731 return len;
64732 diff --git a/fs/namespace.c b/fs/namespace.c
64733 index bbde147..f4deeba 100644
64734 --- a/fs/namespace.c
64735 +++ b/fs/namespace.c
64736 @@ -1447,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64737 if (!(sb->s_flags & MS_RDONLY))
64738 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64739 up_write(&sb->s_umount);
64740 +
64741 + gr_log_remount(mnt->mnt_devname, retval);
64742 +
64743 return retval;
64744 }
64745
64746 @@ -1469,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64747 }
64748 unlock_mount_hash();
64749 namespace_unlock();
64750 +
64751 + gr_log_unmount(mnt->mnt_devname, retval);
64752 +
64753 return retval;
64754 }
64755
64756 @@ -1519,7 +1525,7 @@ static inline bool may_mount(void)
64757 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64758 */
64759
64760 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64761 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64762 {
64763 struct path path;
64764 struct mount *mnt;
64765 @@ -1564,7 +1570,7 @@ out:
64766 /*
64767 * The 2.0 compatible umount. No flags.
64768 */
64769 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64770 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64771 {
64772 return sys_umount(name, 0);
64773 }
64774 @@ -2632,6 +2638,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64775 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64776 MS_STRICTATIME);
64777
64778 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64779 + retval = -EPERM;
64780 + goto dput_out;
64781 + }
64782 +
64783 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64784 + retval = -EPERM;
64785 + goto dput_out;
64786 + }
64787 +
64788 if (flags & MS_REMOUNT)
64789 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64790 data_page);
64791 @@ -2645,7 +2661,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64792 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64793 dev_name, data_page);
64794 dput_out:
64795 + gr_log_mount(dev_name, &path, retval);
64796 +
64797 path_put(&path);
64798 +
64799 return retval;
64800 }
64801
64802 @@ -2663,7 +2682,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64803 * number incrementing at 10Ghz will take 12,427 years to wrap which
64804 * is effectively never, so we can ignore the possibility.
64805 */
64806 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64807 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64808
64809 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64810 {
64811 @@ -2678,7 +2697,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64812 kfree(new_ns);
64813 return ERR_PTR(ret);
64814 }
64815 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64816 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64817 atomic_set(&new_ns->count, 1);
64818 new_ns->root = NULL;
64819 INIT_LIST_HEAD(&new_ns->list);
64820 @@ -2688,7 +2707,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64821 return new_ns;
64822 }
64823
64824 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64825 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64826 struct user_namespace *user_ns, struct fs_struct *new_fs)
64827 {
64828 struct mnt_namespace *new_ns;
64829 @@ -2809,8 +2828,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64830 }
64831 EXPORT_SYMBOL(mount_subtree);
64832
64833 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64834 - char __user *, type, unsigned long, flags, void __user *, data)
64835 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64836 + const char __user *, type, unsigned long, flags, void __user *, data)
64837 {
64838 int ret;
64839 char *kernel_type;
64840 @@ -2916,6 +2935,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64841 if (error)
64842 goto out2;
64843
64844 + if (gr_handle_chroot_pivot()) {
64845 + error = -EPERM;
64846 + goto out2;
64847 + }
64848 +
64849 get_fs_root(current->fs, &root);
64850 old_mp = lock_mount(&old);
64851 error = PTR_ERR(old_mp);
64852 @@ -3187,7 +3211,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64853 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64854 return -EPERM;
64855
64856 - if (fs->users != 1)
64857 + if (atomic_read(&fs->users) != 1)
64858 return -EINVAL;
64859
64860 get_mnt_ns(mnt_ns);
64861 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64862 index f4ccfe6..a5cf064 100644
64863 --- a/fs/nfs/callback_xdr.c
64864 +++ b/fs/nfs/callback_xdr.c
64865 @@ -51,7 +51,7 @@ struct callback_op {
64866 callback_decode_arg_t decode_args;
64867 callback_encode_res_t encode_res;
64868 long res_maxsize;
64869 -};
64870 +} __do_const;
64871
64872 static struct callback_op callback_ops[];
64873
64874 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64875 index 00689a8..b162632 100644
64876 --- a/fs/nfs/inode.c
64877 +++ b/fs/nfs/inode.c
64878 @@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64879 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64880 }
64881
64882 -static atomic_long_t nfs_attr_generation_counter;
64883 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64884
64885 static unsigned long nfs_read_attr_generation_counter(void)
64886 {
64887 - return atomic_long_read(&nfs_attr_generation_counter);
64888 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64889 }
64890
64891 unsigned long nfs_inc_attr_generation_counter(void)
64892 {
64893 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64894 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64895 }
64896
64897 void nfs_fattr_init(struct nfs_fattr *fattr)
64898 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64899 index 0beb023..3f685ec 100644
64900 --- a/fs/nfsd/nfs4proc.c
64901 +++ b/fs/nfsd/nfs4proc.c
64902 @@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64903 nfsd4op_rsize op_rsize_bop;
64904 stateid_getter op_get_currentstateid;
64905 stateid_setter op_set_currentstateid;
64906 -};
64907 +} __do_const;
64908
64909 static struct nfsd4_operation nfsd4_ops[];
64910
64911 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64912 index 2a77603..68e0e37 100644
64913 --- a/fs/nfsd/nfs4xdr.c
64914 +++ b/fs/nfsd/nfs4xdr.c
64915 @@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64916
64917 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64918
64919 -static nfsd4_dec nfsd4_dec_ops[] = {
64920 +static const nfsd4_dec nfsd4_dec_ops[] = {
64921 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64922 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64923 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64924 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64925 index 122f691..a00e2e0 100644
64926 --- a/fs/nfsd/nfscache.c
64927 +++ b/fs/nfsd/nfscache.c
64928 @@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64929 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64930 u32 hash;
64931 struct nfsd_drc_bucket *b;
64932 - int len;
64933 + long len;
64934 size_t bufsize = 0;
64935
64936 if (!rp)
64937 @@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64938 hash = nfsd_cache_hash(rp->c_xid);
64939 b = &drc_hashtbl[hash];
64940
64941 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64942 - len >>= 2;
64943 + if (statp) {
64944 + len = (char*)statp - (char*)resv->iov_base;
64945 + len = resv->iov_len - len;
64946 + len >>= 2;
64947 + }
64948
64949 /* Don't cache excessive amounts of data and XDR failures */
64950 - if (!statp || len > (256 >> 2)) {
64951 + if (!statp || len > (256 >> 2) || len < 0) {
64952 nfsd_reply_cache_free(b, rp);
64953 return;
64954 }
64955 @@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64956 switch (cachetype) {
64957 case RC_REPLSTAT:
64958 if (len != 1)
64959 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64960 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64961 rp->c_replstat = *statp;
64962 break;
64963 case RC_REPLBUFF:
64964 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64965 index 989129e..42e019e 100644
64966 --- a/fs/nfsd/vfs.c
64967 +++ b/fs/nfsd/vfs.c
64968 @@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64969
64970 oldfs = get_fs();
64971 set_fs(KERNEL_DS);
64972 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64973 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64974 set_fs(oldfs);
64975 return nfsd_finish_read(file, count, host_err);
64976 }
64977 @@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64978
64979 /* Write the data. */
64980 oldfs = get_fs(); set_fs(KERNEL_DS);
64981 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64982 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64983 set_fs(oldfs);
64984 if (host_err < 0)
64985 goto out_nfserr;
64986 @@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64987 */
64988
64989 oldfs = get_fs(); set_fs(KERNEL_DS);
64990 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64991 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64992 set_fs(oldfs);
64993
64994 if (host_err < 0)
64995 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64996 index 52ccd34..7a6b202 100644
64997 --- a/fs/nls/nls_base.c
64998 +++ b/fs/nls/nls_base.c
64999 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65000
65001 int __register_nls(struct nls_table *nls, struct module *owner)
65002 {
65003 - struct nls_table ** tmp = &tables;
65004 + struct nls_table *tmp = tables;
65005
65006 if (nls->next)
65007 return -EBUSY;
65008
65009 - nls->owner = owner;
65010 + pax_open_kernel();
65011 + *(void **)&nls->owner = owner;
65012 + pax_close_kernel();
65013 spin_lock(&nls_lock);
65014 - while (*tmp) {
65015 - if (nls == *tmp) {
65016 + while (tmp) {
65017 + if (nls == tmp) {
65018 spin_unlock(&nls_lock);
65019 return -EBUSY;
65020 }
65021 - tmp = &(*tmp)->next;
65022 + tmp = tmp->next;
65023 }
65024 - nls->next = tables;
65025 + pax_open_kernel();
65026 + *(struct nls_table **)&nls->next = tables;
65027 + pax_close_kernel();
65028 tables = nls;
65029 spin_unlock(&nls_lock);
65030 return 0;
65031 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65032
65033 int unregister_nls(struct nls_table * nls)
65034 {
65035 - struct nls_table ** tmp = &tables;
65036 + struct nls_table * const * tmp = &tables;
65037
65038 spin_lock(&nls_lock);
65039 while (*tmp) {
65040 if (nls == *tmp) {
65041 - *tmp = nls->next;
65042 + pax_open_kernel();
65043 + *(struct nls_table **)tmp = nls->next;
65044 + pax_close_kernel();
65045 spin_unlock(&nls_lock);
65046 return 0;
65047 }
65048 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65049 return -EINVAL;
65050 }
65051
65052 -static struct nls_table *find_nls(char *charset)
65053 +static struct nls_table *find_nls(const char *charset)
65054 {
65055 struct nls_table *nls;
65056 spin_lock(&nls_lock);
65057 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65058 return nls;
65059 }
65060
65061 -struct nls_table *load_nls(char *charset)
65062 +struct nls_table *load_nls(const char *charset)
65063 {
65064 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65065 }
65066 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65067 index 162b3f1..6076a7c 100644
65068 --- a/fs/nls/nls_euc-jp.c
65069 +++ b/fs/nls/nls_euc-jp.c
65070 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65071 p_nls = load_nls("cp932");
65072
65073 if (p_nls) {
65074 - table.charset2upper = p_nls->charset2upper;
65075 - table.charset2lower = p_nls->charset2lower;
65076 + pax_open_kernel();
65077 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65078 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65079 + pax_close_kernel();
65080 return register_nls(&table);
65081 }
65082
65083 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65084 index a80a741..7b96e1b 100644
65085 --- a/fs/nls/nls_koi8-ru.c
65086 +++ b/fs/nls/nls_koi8-ru.c
65087 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65088 p_nls = load_nls("koi8-u");
65089
65090 if (p_nls) {
65091 - table.charset2upper = p_nls->charset2upper;
65092 - table.charset2lower = p_nls->charset2lower;
65093 + pax_open_kernel();
65094 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65095 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65096 + pax_close_kernel();
65097 return register_nls(&table);
65098 }
65099
65100 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65101 index c991616..5ae51af 100644
65102 --- a/fs/notify/fanotify/fanotify_user.c
65103 +++ b/fs/notify/fanotify/fanotify_user.c
65104 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65105
65106 fd = fanotify_event_metadata.fd;
65107 ret = -EFAULT;
65108 - if (copy_to_user(buf, &fanotify_event_metadata,
65109 - fanotify_event_metadata.event_len))
65110 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65111 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65112 goto out_close_fd;
65113
65114 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65115 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65116 index a95d8e0..a91a5fd 100644
65117 --- a/fs/notify/notification.c
65118 +++ b/fs/notify/notification.c
65119 @@ -48,7 +48,7 @@
65120 #include <linux/fsnotify_backend.h>
65121 #include "fsnotify.h"
65122
65123 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65124 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65125
65126 /**
65127 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65128 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65129 */
65130 u32 fsnotify_get_cookie(void)
65131 {
65132 - return atomic_inc_return(&fsnotify_sync_cookie);
65133 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65134 }
65135 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65136
65137 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65138 index 9e38daf..5727cae 100644
65139 --- a/fs/ntfs/dir.c
65140 +++ b/fs/ntfs/dir.c
65141 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65142 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65143 ~(s64)(ndir->itype.index.block_size - 1)));
65144 /* Bounds checks. */
65145 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65146 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65147 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65148 "inode 0x%lx or driver bug.", vdir->i_ino);
65149 goto err_out;
65150 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65151 index 643faa4..ef9027e 100644
65152 --- a/fs/ntfs/file.c
65153 +++ b/fs/ntfs/file.c
65154 @@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65155 char *addr;
65156 size_t total = 0;
65157 unsigned len;
65158 - int left;
65159 + unsigned left;
65160
65161 do {
65162 len = PAGE_CACHE_SIZE - ofs;
65163 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65164 index 9e1e112..241a52a 100644
65165 --- a/fs/ntfs/super.c
65166 +++ b/fs/ntfs/super.c
65167 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65168 if (!silent)
65169 ntfs_error(sb, "Primary boot sector is invalid.");
65170 } else if (!silent)
65171 - ntfs_error(sb, read_err_str, "primary");
65172 + ntfs_error(sb, read_err_str, "%s", "primary");
65173 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65174 if (bh_primary)
65175 brelse(bh_primary);
65176 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65177 goto hotfix_primary_boot_sector;
65178 brelse(bh_backup);
65179 } else if (!silent)
65180 - ntfs_error(sb, read_err_str, "backup");
65181 + ntfs_error(sb, read_err_str, "%s", "backup");
65182 /* Try to read NT3.51- backup boot sector. */
65183 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65184 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65185 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65186 "sector.");
65187 brelse(bh_backup);
65188 } else if (!silent)
65189 - ntfs_error(sb, read_err_str, "backup");
65190 + ntfs_error(sb, read_err_str, "%s", "backup");
65191 /* We failed. Cleanup and return. */
65192 if (bh_primary)
65193 brelse(bh_primary);
65194 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65195 index 0440134..d52c93a 100644
65196 --- a/fs/ocfs2/localalloc.c
65197 +++ b/fs/ocfs2/localalloc.c
65198 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65199 goto bail;
65200 }
65201
65202 - atomic_inc(&osb->alloc_stats.moves);
65203 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65204
65205 bail:
65206 if (handle)
65207 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65208 index bbec539..7b266d5 100644
65209 --- a/fs/ocfs2/ocfs2.h
65210 +++ b/fs/ocfs2/ocfs2.h
65211 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65212
65213 struct ocfs2_alloc_stats
65214 {
65215 - atomic_t moves;
65216 - atomic_t local_data;
65217 - atomic_t bitmap_data;
65218 - atomic_t bg_allocs;
65219 - atomic_t bg_extends;
65220 + atomic_unchecked_t moves;
65221 + atomic_unchecked_t local_data;
65222 + atomic_unchecked_t bitmap_data;
65223 + atomic_unchecked_t bg_allocs;
65224 + atomic_unchecked_t bg_extends;
65225 };
65226
65227 enum ocfs2_local_alloc_state
65228 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65229 index 0cb889a..6a26b24 100644
65230 --- a/fs/ocfs2/suballoc.c
65231 +++ b/fs/ocfs2/suballoc.c
65232 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65233 mlog_errno(status);
65234 goto bail;
65235 }
65236 - atomic_inc(&osb->alloc_stats.bg_extends);
65237 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65238
65239 /* You should never ask for this much metadata */
65240 BUG_ON(bits_wanted >
65241 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65242 mlog_errno(status);
65243 goto bail;
65244 }
65245 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65246 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65247
65248 *suballoc_loc = res.sr_bg_blkno;
65249 *suballoc_bit_start = res.sr_bit_offset;
65250 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65251 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65252 res->sr_bits);
65253
65254 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65255 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65256
65257 BUG_ON(res->sr_bits != 1);
65258
65259 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65260 mlog_errno(status);
65261 goto bail;
65262 }
65263 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65264 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65265
65266 BUG_ON(res.sr_bits != 1);
65267
65268 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65269 cluster_start,
65270 num_clusters);
65271 if (!status)
65272 - atomic_inc(&osb->alloc_stats.local_data);
65273 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65274 } else {
65275 if (min_clusters > (osb->bitmap_cpg - 1)) {
65276 /* The only paths asking for contiguousness
65277 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65278 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65279 res.sr_bg_blkno,
65280 res.sr_bit_offset);
65281 - atomic_inc(&osb->alloc_stats.bitmap_data);
65282 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65283 *num_clusters = res.sr_bits;
65284 }
65285 }
65286 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65287 index 93c85bc..02f68a4 100644
65288 --- a/fs/ocfs2/super.c
65289 +++ b/fs/ocfs2/super.c
65290 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65291 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65292 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65293 "Stats",
65294 - atomic_read(&osb->alloc_stats.bitmap_data),
65295 - atomic_read(&osb->alloc_stats.local_data),
65296 - atomic_read(&osb->alloc_stats.bg_allocs),
65297 - atomic_read(&osb->alloc_stats.moves),
65298 - atomic_read(&osb->alloc_stats.bg_extends));
65299 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65300 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65301 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65302 + atomic_read_unchecked(&osb->alloc_stats.moves),
65303 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65304
65305 out += snprintf(buf + out, len - out,
65306 "%10s => State: %u Descriptor: %llu Size: %u bits "
65307 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65308
65309 mutex_init(&osb->system_file_mutex);
65310
65311 - atomic_set(&osb->alloc_stats.moves, 0);
65312 - atomic_set(&osb->alloc_stats.local_data, 0);
65313 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65314 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65315 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65316 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65317 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65318 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65319 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65320 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65321
65322 /* Copy the blockcheck stats from the superblock probe */
65323 osb->osb_ecc_stats = *stats;
65324 diff --git a/fs/open.c b/fs/open.c
65325 index de92c13..52d2a6c 100644
65326 --- a/fs/open.c
65327 +++ b/fs/open.c
65328 @@ -32,6 +32,8 @@
65329 #include <linux/dnotify.h>
65330 #include <linux/compat.h>
65331
65332 +#define CREATE_TRACE_POINTS
65333 +#include <trace/events/fs.h>
65334 #include "internal.h"
65335
65336 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65337 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65338 error = locks_verify_truncate(inode, NULL, length);
65339 if (!error)
65340 error = security_path_truncate(path);
65341 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65342 + error = -EACCES;
65343 if (!error)
65344 error = do_truncate(path->dentry, length, 0, NULL);
65345
65346 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65347 error = locks_verify_truncate(inode, f.file, length);
65348 if (!error)
65349 error = security_path_truncate(&f.file->f_path);
65350 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65351 + error = -EACCES;
65352 if (!error)
65353 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65354 sb_end_write(inode->i_sb);
65355 @@ -380,6 +386,9 @@ retry:
65356 if (__mnt_is_readonly(path.mnt))
65357 res = -EROFS;
65358
65359 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65360 + res = -EACCES;
65361 +
65362 out_path_release:
65363 path_put(&path);
65364 if (retry_estale(res, lookup_flags)) {
65365 @@ -411,6 +420,8 @@ retry:
65366 if (error)
65367 goto dput_and_out;
65368
65369 + gr_log_chdir(path.dentry, path.mnt);
65370 +
65371 set_fs_pwd(current->fs, &path);
65372
65373 dput_and_out:
65374 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65375 goto out_putf;
65376
65377 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65378 +
65379 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65380 + error = -EPERM;
65381 +
65382 + if (!error)
65383 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65384 +
65385 if (!error)
65386 set_fs_pwd(current->fs, &f.file->f_path);
65387 out_putf:
65388 @@ -469,7 +487,13 @@ retry:
65389 if (error)
65390 goto dput_and_out;
65391
65392 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65393 + goto dput_and_out;
65394 +
65395 set_fs_root(current->fs, &path);
65396 +
65397 + gr_handle_chroot_chdir(&path);
65398 +
65399 error = 0;
65400 dput_and_out:
65401 path_put(&path);
65402 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65403 return error;
65404 retry_deleg:
65405 mutex_lock(&inode->i_mutex);
65406 +
65407 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65408 + error = -EACCES;
65409 + goto out_unlock;
65410 + }
65411 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65412 + error = -EACCES;
65413 + goto out_unlock;
65414 + }
65415 +
65416 error = security_path_chmod(path, mode);
65417 if (error)
65418 goto out_unlock;
65419 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65420 uid = make_kuid(current_user_ns(), user);
65421 gid = make_kgid(current_user_ns(), group);
65422
65423 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65424 + return -EACCES;
65425 +
65426 newattrs.ia_valid = ATTR_CTIME;
65427 if (user != (uid_t) -1) {
65428 if (!uid_valid(uid))
65429 @@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65430 } else {
65431 fsnotify_open(f);
65432 fd_install(fd, f);
65433 + trace_do_sys_open(tmp->name, flags, mode);
65434 }
65435 }
65436 putname(tmp);
65437 diff --git a/fs/pipe.c b/fs/pipe.c
65438 index 21981e5..3d5f55c 100644
65439 --- a/fs/pipe.c
65440 +++ b/fs/pipe.c
65441 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65442
65443 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65444 {
65445 - if (pipe->files)
65446 + if (atomic_read(&pipe->files))
65447 mutex_lock_nested(&pipe->mutex, subclass);
65448 }
65449
65450 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65451
65452 void pipe_unlock(struct pipe_inode_info *pipe)
65453 {
65454 - if (pipe->files)
65455 + if (atomic_read(&pipe->files))
65456 mutex_unlock(&pipe->mutex);
65457 }
65458 EXPORT_SYMBOL(pipe_unlock);
65459 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65460 }
65461 if (bufs) /* More to do? */
65462 continue;
65463 - if (!pipe->writers)
65464 + if (!atomic_read(&pipe->writers))
65465 break;
65466 - if (!pipe->waiting_writers) {
65467 + if (!atomic_read(&pipe->waiting_writers)) {
65468 /* syscall merging: Usually we must not sleep
65469 * if O_NONBLOCK is set, or if we got some data.
65470 * But if a writer sleeps in kernel space, then
65471 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65472
65473 __pipe_lock(pipe);
65474
65475 - if (!pipe->readers) {
65476 + if (!atomic_read(&pipe->readers)) {
65477 send_sig(SIGPIPE, current, 0);
65478 ret = -EPIPE;
65479 goto out;
65480 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65481 for (;;) {
65482 int bufs;
65483
65484 - if (!pipe->readers) {
65485 + if (!atomic_read(&pipe->readers)) {
65486 send_sig(SIGPIPE, current, 0);
65487 if (!ret)
65488 ret = -EPIPE;
65489 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65490 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65491 do_wakeup = 0;
65492 }
65493 - pipe->waiting_writers++;
65494 + atomic_inc(&pipe->waiting_writers);
65495 pipe_wait(pipe);
65496 - pipe->waiting_writers--;
65497 + atomic_dec(&pipe->waiting_writers);
65498 }
65499 out:
65500 __pipe_unlock(pipe);
65501 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65502 mask = 0;
65503 if (filp->f_mode & FMODE_READ) {
65504 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65505 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65506 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65507 mask |= POLLHUP;
65508 }
65509
65510 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65511 * Most Unices do not set POLLERR for FIFOs but on Linux they
65512 * behave exactly like pipes for poll().
65513 */
65514 - if (!pipe->readers)
65515 + if (!atomic_read(&pipe->readers))
65516 mask |= POLLERR;
65517 }
65518
65519 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65520 int kill = 0;
65521
65522 spin_lock(&inode->i_lock);
65523 - if (!--pipe->files) {
65524 + if (atomic_dec_and_test(&pipe->files)) {
65525 inode->i_pipe = NULL;
65526 kill = 1;
65527 }
65528 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65529
65530 __pipe_lock(pipe);
65531 if (file->f_mode & FMODE_READ)
65532 - pipe->readers--;
65533 + atomic_dec(&pipe->readers);
65534 if (file->f_mode & FMODE_WRITE)
65535 - pipe->writers--;
65536 + atomic_dec(&pipe->writers);
65537
65538 - if (pipe->readers || pipe->writers) {
65539 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65540 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65541 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65542 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65543 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65544 kfree(pipe);
65545 }
65546
65547 -static struct vfsmount *pipe_mnt __read_mostly;
65548 +struct vfsmount *pipe_mnt __read_mostly;
65549
65550 /*
65551 * pipefs_dname() is called from d_path().
65552 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65553 goto fail_iput;
65554
65555 inode->i_pipe = pipe;
65556 - pipe->files = 2;
65557 - pipe->readers = pipe->writers = 1;
65558 + atomic_set(&pipe->files, 2);
65559 + atomic_set(&pipe->readers, 1);
65560 + atomic_set(&pipe->writers, 1);
65561 inode->i_fop = &pipefifo_fops;
65562
65563 /*
65564 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65565 spin_lock(&inode->i_lock);
65566 if (inode->i_pipe) {
65567 pipe = inode->i_pipe;
65568 - pipe->files++;
65569 + atomic_inc(&pipe->files);
65570 spin_unlock(&inode->i_lock);
65571 } else {
65572 spin_unlock(&inode->i_lock);
65573 pipe = alloc_pipe_info();
65574 if (!pipe)
65575 return -ENOMEM;
65576 - pipe->files = 1;
65577 + atomic_set(&pipe->files, 1);
65578 spin_lock(&inode->i_lock);
65579 if (unlikely(inode->i_pipe)) {
65580 - inode->i_pipe->files++;
65581 + atomic_inc(&inode->i_pipe->files);
65582 spin_unlock(&inode->i_lock);
65583 free_pipe_info(pipe);
65584 pipe = inode->i_pipe;
65585 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65586 * opened, even when there is no process writing the FIFO.
65587 */
65588 pipe->r_counter++;
65589 - if (pipe->readers++ == 0)
65590 + if (atomic_inc_return(&pipe->readers) == 1)
65591 wake_up_partner(pipe);
65592
65593 - if (!is_pipe && !pipe->writers) {
65594 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65595 if ((filp->f_flags & O_NONBLOCK)) {
65596 /* suppress POLLHUP until we have
65597 * seen a writer */
65598 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65599 * errno=ENXIO when there is no process reading the FIFO.
65600 */
65601 ret = -ENXIO;
65602 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65603 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65604 goto err;
65605
65606 pipe->w_counter++;
65607 - if (!pipe->writers++)
65608 + if (atomic_inc_return(&pipe->writers) == 1)
65609 wake_up_partner(pipe);
65610
65611 - if (!is_pipe && !pipe->readers) {
65612 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65613 if (wait_for_partner(pipe, &pipe->r_counter))
65614 goto err_wr;
65615 }
65616 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65617 * the process can at least talk to itself.
65618 */
65619
65620 - pipe->readers++;
65621 - pipe->writers++;
65622 + atomic_inc(&pipe->readers);
65623 + atomic_inc(&pipe->writers);
65624 pipe->r_counter++;
65625 pipe->w_counter++;
65626 - if (pipe->readers == 1 || pipe->writers == 1)
65627 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65628 wake_up_partner(pipe);
65629 break;
65630
65631 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65632 return 0;
65633
65634 err_rd:
65635 - if (!--pipe->readers)
65636 + if (atomic_dec_and_test(&pipe->readers))
65637 wake_up_interruptible(&pipe->wait);
65638 ret = -ERESTARTSYS;
65639 goto err;
65640
65641 err_wr:
65642 - if (!--pipe->writers)
65643 + if (atomic_dec_and_test(&pipe->writers))
65644 wake_up_interruptible(&pipe->wait);
65645 ret = -ERESTARTSYS;
65646 goto err;
65647 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65648 index 0855f77..6787d50 100644
65649 --- a/fs/posix_acl.c
65650 +++ b/fs/posix_acl.c
65651 @@ -20,6 +20,7 @@
65652 #include <linux/xattr.h>
65653 #include <linux/export.h>
65654 #include <linux/user_namespace.h>
65655 +#include <linux/grsecurity.h>
65656
65657 struct posix_acl **acl_by_type(struct inode *inode, int type)
65658 {
65659 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65660 }
65661 }
65662 if (mode_p)
65663 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65664 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65665 return not_equiv;
65666 }
65667 EXPORT_SYMBOL(posix_acl_equiv_mode);
65668 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65669 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65670 }
65671
65672 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65673 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65674 return not_equiv;
65675 }
65676
65677 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65678 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65679 int err = -ENOMEM;
65680 if (clone) {
65681 + *mode_p &= ~gr_acl_umask();
65682 +
65683 err = posix_acl_create_masq(clone, mode_p);
65684 if (err < 0) {
65685 posix_acl_release(clone);
65686 @@ -659,11 +662,12 @@ struct posix_acl *
65687 posix_acl_from_xattr(struct user_namespace *user_ns,
65688 const void *value, size_t size)
65689 {
65690 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65691 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65692 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65693 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65694 int count;
65695 struct posix_acl *acl;
65696 struct posix_acl_entry *acl_e;
65697 + umode_t umask = gr_acl_umask();
65698
65699 if (!value)
65700 return NULL;
65701 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65702
65703 switch(acl_e->e_tag) {
65704 case ACL_USER_OBJ:
65705 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65706 + break;
65707 case ACL_GROUP_OBJ:
65708 case ACL_MASK:
65709 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65710 + break;
65711 case ACL_OTHER:
65712 + acl_e->e_perm &= ~(umask & S_IRWXO);
65713 break;
65714
65715 case ACL_USER:
65716 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65717 acl_e->e_uid =
65718 make_kuid(user_ns,
65719 le32_to_cpu(entry->e_id));
65720 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65721 goto fail;
65722 break;
65723 case ACL_GROUP:
65724 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65725 acl_e->e_gid =
65726 make_kgid(user_ns,
65727 le32_to_cpu(entry->e_id));
65728 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65729 index 2183fcf..3c32a98 100644
65730 --- a/fs/proc/Kconfig
65731 +++ b/fs/proc/Kconfig
65732 @@ -30,7 +30,7 @@ config PROC_FS
65733
65734 config PROC_KCORE
65735 bool "/proc/kcore support" if !ARM
65736 - depends on PROC_FS && MMU
65737 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65738 help
65739 Provides a virtual ELF core file of the live kernel. This can
65740 be read with gdb and other ELF tools. No modifications can be
65741 @@ -38,8 +38,8 @@ config PROC_KCORE
65742
65743 config PROC_VMCORE
65744 bool "/proc/vmcore support"
65745 - depends on PROC_FS && CRASH_DUMP
65746 - default y
65747 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65748 + default n
65749 help
65750 Exports the dump image of crashed kernel in ELF format.
65751
65752 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65753 limited in memory.
65754
65755 config PROC_PAGE_MONITOR
65756 - default y
65757 - depends on PROC_FS && MMU
65758 + default n
65759 + depends on PROC_FS && MMU && !GRKERNSEC
65760 bool "Enable /proc page monitoring" if EXPERT
65761 help
65762 Various /proc files exist to monitor process memory utilization:
65763 diff --git a/fs/proc/array.c b/fs/proc/array.c
65764 index cd3653e..9b9b79a 100644
65765 --- a/fs/proc/array.c
65766 +++ b/fs/proc/array.c
65767 @@ -60,6 +60,7 @@
65768 #include <linux/tty.h>
65769 #include <linux/string.h>
65770 #include <linux/mman.h>
65771 +#include <linux/grsecurity.h>
65772 #include <linux/proc_fs.h>
65773 #include <linux/ioport.h>
65774 #include <linux/uaccess.h>
65775 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65776 seq_putc(m, '\n');
65777 }
65778
65779 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65780 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65781 +{
65782 + if (p->mm)
65783 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65784 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65785 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65786 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65787 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65788 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65789 + else
65790 + seq_printf(m, "PaX:\t-----\n");
65791 +}
65792 +#endif
65793 +
65794 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65795 struct pid *pid, struct task_struct *task)
65796 {
65797 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65798 task_cpus_allowed(m, task);
65799 cpuset_task_status_allowed(m, task);
65800 task_context_switch_counts(m, task);
65801 +
65802 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65803 + task_pax(m, task);
65804 +#endif
65805 +
65806 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65807 + task_grsec_rbac(m, task);
65808 +#endif
65809 +
65810 return 0;
65811 }
65812
65813 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65814 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65815 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65816 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65817 +#endif
65818 +
65819 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65820 struct pid *pid, struct task_struct *task, int whole)
65821 {
65822 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65823 char tcomm[sizeof(task->comm)];
65824 unsigned long flags;
65825
65826 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65827 + if (current->exec_id != m->exec_id) {
65828 + gr_log_badprocpid("stat");
65829 + return 0;
65830 + }
65831 +#endif
65832 +
65833 state = *get_task_state(task);
65834 vsize = eip = esp = 0;
65835 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65836 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65837 gtime = task_gtime(task);
65838 }
65839
65840 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65841 + if (PAX_RAND_FLAGS(mm)) {
65842 + eip = 0;
65843 + esp = 0;
65844 + wchan = 0;
65845 + }
65846 +#endif
65847 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65848 + wchan = 0;
65849 + eip =0;
65850 + esp =0;
65851 +#endif
65852 +
65853 /* scale priority and nice values from timeslices to -20..20 */
65854 /* to make it look like a "normal" Unix priority/nice value */
65855 priority = task_prio(task);
65856 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65857 seq_put_decimal_ull(m, ' ', vsize);
65858 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65859 seq_put_decimal_ull(m, ' ', rsslim);
65860 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65861 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65862 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65863 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65864 +#else
65865 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65866 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65867 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65868 +#endif
65869 seq_put_decimal_ull(m, ' ', esp);
65870 seq_put_decimal_ull(m, ' ', eip);
65871 /* The signal information here is obsolete.
65872 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65873 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65874 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65875
65876 - if (mm && permitted) {
65877 + if (mm && permitted
65878 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65879 + && !PAX_RAND_FLAGS(mm)
65880 +#endif
65881 + ) {
65882 seq_put_decimal_ull(m, ' ', mm->start_data);
65883 seq_put_decimal_ull(m, ' ', mm->end_data);
65884 seq_put_decimal_ull(m, ' ', mm->start_brk);
65885 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65886 struct pid *pid, struct task_struct *task)
65887 {
65888 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65889 - struct mm_struct *mm = get_task_mm(task);
65890 + struct mm_struct *mm;
65891
65892 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65893 + if (current->exec_id != m->exec_id) {
65894 + gr_log_badprocpid("statm");
65895 + return 0;
65896 + }
65897 +#endif
65898 + mm = get_task_mm(task);
65899 if (mm) {
65900 size = task_statm(mm, &shared, &text, &data, &resident);
65901 mmput(mm);
65902 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65903 return 0;
65904 }
65905
65906 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65907 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65908 +{
65909 + unsigned long flags;
65910 + u32 curr_ip = 0;
65911 +
65912 + if (lock_task_sighand(task, &flags)) {
65913 + curr_ip = task->signal->curr_ip;
65914 + unlock_task_sighand(task, &flags);
65915 + }
65916 + return seq_printf(m, "%pI4\n", &curr_ip);
65917 +}
65918 +#endif
65919 +
65920 #ifdef CONFIG_CHECKPOINT_RESTORE
65921 static struct pid *
65922 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65923 diff --git a/fs/proc/base.c b/fs/proc/base.c
65924 index 7dc3ea8..a08077e 100644
65925 --- a/fs/proc/base.c
65926 +++ b/fs/proc/base.c
65927 @@ -113,6 +113,14 @@ struct pid_entry {
65928 union proc_op op;
65929 };
65930
65931 +struct getdents_callback {
65932 + struct linux_dirent __user * current_dir;
65933 + struct linux_dirent __user * previous;
65934 + struct file * file;
65935 + int count;
65936 + int error;
65937 +};
65938 +
65939 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65940 .name = (NAME), \
65941 .len = sizeof(NAME) - 1, \
65942 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65943 return 0;
65944 }
65945
65946 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65947 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65948 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65949 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65950 +#endif
65951 +
65952 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65953 struct pid *pid, struct task_struct *task)
65954 {
65955 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65956 if (mm && !IS_ERR(mm)) {
65957 unsigned int nwords = 0;
65958 +
65959 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65960 + /* allow if we're currently ptracing this task */
65961 + if (PAX_RAND_FLAGS(mm) &&
65962 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65963 + mmput(mm);
65964 + return 0;
65965 + }
65966 +#endif
65967 +
65968 do {
65969 nwords += 2;
65970 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65971 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65972 }
65973
65974
65975 -#ifdef CONFIG_KALLSYMS
65976 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65977 /*
65978 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65979 * Returns the resolved symbol. If that fails, simply return the address.
65980 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65981 mutex_unlock(&task->signal->cred_guard_mutex);
65982 }
65983
65984 -#ifdef CONFIG_STACKTRACE
65985 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65986
65987 #define MAX_STACK_TRACE_DEPTH 64
65988
65989 @@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65990 return 0;
65991 }
65992
65993 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65994 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65995 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65996 struct pid *pid, struct task_struct *task)
65997 {
65998 @@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65999 /************************************************************************/
66000
66001 /* permission checks */
66002 -static int proc_fd_access_allowed(struct inode *inode)
66003 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66004 {
66005 struct task_struct *task;
66006 int allowed = 0;
66007 @@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66008 */
66009 task = get_proc_task(inode);
66010 if (task) {
66011 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66012 + if (log)
66013 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66014 + else
66015 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66016 put_task_struct(task);
66017 }
66018 return allowed;
66019 @@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66020 struct task_struct *task,
66021 int hide_pid_min)
66022 {
66023 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66024 + return false;
66025 +
66026 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66027 + rcu_read_lock();
66028 + {
66029 + const struct cred *tmpcred = current_cred();
66030 + const struct cred *cred = __task_cred(task);
66031 +
66032 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66033 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66034 + || in_group_p(grsec_proc_gid)
66035 +#endif
66036 + ) {
66037 + rcu_read_unlock();
66038 + return true;
66039 + }
66040 + }
66041 + rcu_read_unlock();
66042 +
66043 + if (!pid->hide_pid)
66044 + return false;
66045 +#endif
66046 +
66047 if (pid->hide_pid < hide_pid_min)
66048 return true;
66049 if (in_group_p(pid->pid_gid))
66050 return true;
66051 +
66052 return ptrace_may_access(task, PTRACE_MODE_READ);
66053 }
66054
66055 @@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66056 put_task_struct(task);
66057
66058 if (!has_perms) {
66059 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66060 + {
66061 +#else
66062 if (pid->hide_pid == 2) {
66063 +#endif
66064 /*
66065 * Let's make getdents(), stat(), and open()
66066 * consistent with each other. If a process
66067 @@ -609,6 +665,10 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
66068
66069 if (task) {
66070 mm = mm_access(task, mode);
66071 + if (!IS_ERR_OR_NULL(mm) && gr_acl_handle_procpidmem(task)) {
66072 + mmput(mm);
66073 + mm = ERR_PTR(-EPERM);
66074 + }
66075 put_task_struct(task);
66076
66077 if (!IS_ERR_OR_NULL(mm)) {
66078 @@ -630,6 +690,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66079 return PTR_ERR(mm);
66080
66081 file->private_data = mm;
66082 +
66083 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66084 + file->f_version = current->exec_id;
66085 +#endif
66086 +
66087 return 0;
66088 }
66089
66090 @@ -651,6 +716,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66091 ssize_t copied;
66092 char *page;
66093
66094 +#ifdef CONFIG_GRKERNSEC
66095 + if (write)
66096 + return -EPERM;
66097 +#endif
66098 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66099 + if (file->f_version != current->exec_id) {
66100 + gr_log_badprocpid("mem");
66101 + return 0;
66102 + }
66103 +#endif
66104 +
66105 if (!mm)
66106 return 0;
66107
66108 @@ -663,7 +739,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66109 goto free;
66110
66111 while (count > 0) {
66112 - int this_len = min_t(int, count, PAGE_SIZE);
66113 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66114
66115 if (write && copy_from_user(page, buf, this_len)) {
66116 copied = -EFAULT;
66117 @@ -755,6 +831,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66118 if (!mm)
66119 return 0;
66120
66121 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66122 + if (file->f_version != current->exec_id) {
66123 + gr_log_badprocpid("environ");
66124 + return 0;
66125 + }
66126 +#endif
66127 +
66128 page = (char *)__get_free_page(GFP_TEMPORARY);
66129 if (!page)
66130 return -ENOMEM;
66131 @@ -764,7 +847,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66132 goto free;
66133 while (count > 0) {
66134 size_t this_len, max_len;
66135 - int retval;
66136 + ssize_t retval;
66137
66138 if (src >= (mm->env_end - mm->env_start))
66139 break;
66140 @@ -1378,7 +1461,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66141 int error = -EACCES;
66142
66143 /* Are we allowed to snoop on the tasks file descriptors? */
66144 - if (!proc_fd_access_allowed(inode))
66145 + if (!proc_fd_access_allowed(inode, 0))
66146 goto out;
66147
66148 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66149 @@ -1422,8 +1505,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66150 struct path path;
66151
66152 /* Are we allowed to snoop on the tasks file descriptors? */
66153 - if (!proc_fd_access_allowed(inode))
66154 - goto out;
66155 + /* logging this is needed for learning on chromium to work properly,
66156 + but we don't want to flood the logs from 'ps' which does a readlink
66157 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66158 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66159 + */
66160 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66161 + if (!proc_fd_access_allowed(inode,0))
66162 + goto out;
66163 + } else {
66164 + if (!proc_fd_access_allowed(inode,1))
66165 + goto out;
66166 + }
66167
66168 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66169 if (error)
66170 @@ -1473,7 +1566,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66171 rcu_read_lock();
66172 cred = __task_cred(task);
66173 inode->i_uid = cred->euid;
66174 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66175 + inode->i_gid = grsec_proc_gid;
66176 +#else
66177 inode->i_gid = cred->egid;
66178 +#endif
66179 rcu_read_unlock();
66180 }
66181 security_task_to_inode(task, inode);
66182 @@ -1509,10 +1606,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66183 return -ENOENT;
66184 }
66185 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66186 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66187 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66188 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66189 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66190 +#endif
66191 task_dumpable(task)) {
66192 cred = __task_cred(task);
66193 stat->uid = cred->euid;
66194 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66195 + stat->gid = grsec_proc_gid;
66196 +#else
66197 stat->gid = cred->egid;
66198 +#endif
66199 }
66200 }
66201 rcu_read_unlock();
66202 @@ -1550,11 +1656,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66203
66204 if (task) {
66205 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66206 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66207 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66208 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66209 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66210 +#endif
66211 task_dumpable(task)) {
66212 rcu_read_lock();
66213 cred = __task_cred(task);
66214 inode->i_uid = cred->euid;
66215 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66216 + inode->i_gid = grsec_proc_gid;
66217 +#else
66218 inode->i_gid = cred->egid;
66219 +#endif
66220 rcu_read_unlock();
66221 } else {
66222 inode->i_uid = GLOBAL_ROOT_UID;
66223 @@ -2085,6 +2200,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66224 if (!task)
66225 goto out_no_task;
66226
66227 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66228 + goto out;
66229 +
66230 /*
66231 * Yes, it does not scale. And it should not. Don't add
66232 * new entries into /proc/<tgid>/ without very good reasons.
66233 @@ -2115,6 +2233,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66234 if (!task)
66235 return -ENOENT;
66236
66237 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66238 + goto out;
66239 +
66240 if (!dir_emit_dots(file, ctx))
66241 goto out;
66242
66243 @@ -2557,7 +2678,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66244 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66245 #endif
66246 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66247 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66248 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66249 ONE("syscall", S_IRUSR, proc_pid_syscall),
66250 #endif
66251 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66252 @@ -2582,10 +2703,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66253 #ifdef CONFIG_SECURITY
66254 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66255 #endif
66256 -#ifdef CONFIG_KALLSYMS
66257 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66258 ONE("wchan", S_IRUGO, proc_pid_wchan),
66259 #endif
66260 -#ifdef CONFIG_STACKTRACE
66261 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66262 ONE("stack", S_IRUSR, proc_pid_stack),
66263 #endif
66264 #ifdef CONFIG_SCHEDSTATS
66265 @@ -2619,6 +2740,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66266 #ifdef CONFIG_HARDWALL
66267 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66268 #endif
66269 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66270 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66271 +#endif
66272 #ifdef CONFIG_USER_NS
66273 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66274 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66275 @@ -2748,7 +2872,14 @@ static int proc_pid_instantiate(struct inode *dir,
66276 if (!inode)
66277 goto out;
66278
66279 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66280 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66281 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66282 + inode->i_gid = grsec_proc_gid;
66283 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66284 +#else
66285 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66286 +#endif
66287 inode->i_op = &proc_tgid_base_inode_operations;
66288 inode->i_fop = &proc_tgid_base_operations;
66289 inode->i_flags|=S_IMMUTABLE;
66290 @@ -2786,7 +2917,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66291 if (!task)
66292 goto out;
66293
66294 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66295 + goto out_put_task;
66296 +
66297 result = proc_pid_instantiate(dir, dentry, task, NULL);
66298 +out_put_task:
66299 put_task_struct(task);
66300 out:
66301 return ERR_PTR(result);
66302 @@ -2900,7 +3035,7 @@ static const struct pid_entry tid_base_stuff[] = {
66303 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66304 #endif
66305 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66306 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66307 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66308 ONE("syscall", S_IRUSR, proc_pid_syscall),
66309 #endif
66310 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66311 @@ -2927,10 +3062,10 @@ static const struct pid_entry tid_base_stuff[] = {
66312 #ifdef CONFIG_SECURITY
66313 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66314 #endif
66315 -#ifdef CONFIG_KALLSYMS
66316 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66317 ONE("wchan", S_IRUGO, proc_pid_wchan),
66318 #endif
66319 -#ifdef CONFIG_STACKTRACE
66320 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66321 ONE("stack", S_IRUSR, proc_pid_stack),
66322 #endif
66323 #ifdef CONFIG_SCHEDSTATS
66324 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66325 index cbd82df..c0407d2 100644
66326 --- a/fs/proc/cmdline.c
66327 +++ b/fs/proc/cmdline.c
66328 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66329
66330 static int __init proc_cmdline_init(void)
66331 {
66332 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66333 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66334 +#else
66335 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66336 +#endif
66337 return 0;
66338 }
66339 fs_initcall(proc_cmdline_init);
66340 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66341 index 50493ed..248166b 100644
66342 --- a/fs/proc/devices.c
66343 +++ b/fs/proc/devices.c
66344 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66345
66346 static int __init proc_devices_init(void)
66347 {
66348 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66349 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66350 +#else
66351 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66352 +#endif
66353 return 0;
66354 }
66355 fs_initcall(proc_devices_init);
66356 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66357 index e11d7c5..9128ce06 100644
66358 --- a/fs/proc/fd.c
66359 +++ b/fs/proc/fd.c
66360 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66361 if (!task)
66362 return -ENOENT;
66363
66364 - files = get_files_struct(task);
66365 + if (!gr_acl_handle_procpidmem(task))
66366 + files = get_files_struct(task);
66367 put_task_struct(task);
66368
66369 if (files) {
66370 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66371 */
66372 int proc_fd_permission(struct inode *inode, int mask)
66373 {
66374 + struct task_struct *task;
66375 int rv = generic_permission(inode, mask);
66376 - if (rv == 0)
66377 - return 0;
66378 +
66379 if (task_tgid(current) == proc_pid(inode))
66380 rv = 0;
66381 +
66382 + task = get_proc_task(inode);
66383 + if (task == NULL)
66384 + return rv;
66385 +
66386 + if (gr_acl_handle_procpidmem(task))
66387 + rv = -EACCES;
66388 +
66389 + put_task_struct(task);
66390 +
66391 return rv;
66392 }
66393
66394 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66395 index 317b726..e329aed 100644
66396 --- a/fs/proc/generic.c
66397 +++ b/fs/proc/generic.c
66398 @@ -23,6 +23,7 @@
66399 #include <linux/bitops.h>
66400 #include <linux/spinlock.h>
66401 #include <linux/completion.h>
66402 +#include <linux/grsecurity.h>
66403 #include <asm/uaccess.h>
66404
66405 #include "internal.h"
66406 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66407 return proc_lookup_de(PDE(dir), dir, dentry);
66408 }
66409
66410 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66411 + unsigned int flags)
66412 +{
66413 + if (gr_proc_is_restricted())
66414 + return ERR_PTR(-EACCES);
66415 +
66416 + return proc_lookup_de(PDE(dir), dir, dentry);
66417 +}
66418 +
66419 /*
66420 * This returns non-zero if at EOF, so that the /proc
66421 * root directory can use this and check if it should
66422 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66423 return proc_readdir_de(PDE(inode), file, ctx);
66424 }
66425
66426 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66427 +{
66428 + struct inode *inode = file_inode(file);
66429 +
66430 + if (gr_proc_is_restricted())
66431 + return -EACCES;
66432 +
66433 + return proc_readdir_de(PDE(inode), file, ctx);
66434 +}
66435 +
66436 /*
66437 * These are the generic /proc directory operations. They
66438 * use the in-memory "struct proc_dir_entry" tree to parse
66439 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66440 .iterate = proc_readdir,
66441 };
66442
66443 +static const struct file_operations proc_dir_restricted_operations = {
66444 + .llseek = generic_file_llseek,
66445 + .read = generic_read_dir,
66446 + .iterate = proc_readdir_restrict,
66447 +};
66448 +
66449 /*
66450 * proc directories can do almost nothing..
66451 */
66452 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66453 .setattr = proc_notify_change,
66454 };
66455
66456 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66457 + .lookup = proc_lookup_restrict,
66458 + .getattr = proc_getattr,
66459 + .setattr = proc_notify_change,
66460 +};
66461 +
66462 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66463 {
66464 struct proc_dir_entry *tmp;
66465 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66466 return ret;
66467
66468 if (S_ISDIR(dp->mode)) {
66469 - dp->proc_fops = &proc_dir_operations;
66470 - dp->proc_iops = &proc_dir_inode_operations;
66471 + if (dp->restricted) {
66472 + dp->proc_fops = &proc_dir_restricted_operations;
66473 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66474 + } else {
66475 + dp->proc_fops = &proc_dir_operations;
66476 + dp->proc_iops = &proc_dir_inode_operations;
66477 + }
66478 dir->nlink++;
66479 } else if (S_ISLNK(dp->mode)) {
66480 dp->proc_iops = &proc_link_inode_operations;
66481 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66482 }
66483 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66484
66485 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66486 + struct proc_dir_entry *parent, void *data)
66487 +{
66488 + struct proc_dir_entry *ent;
66489 +
66490 + if (mode == 0)
66491 + mode = S_IRUGO | S_IXUGO;
66492 +
66493 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66494 + if (ent) {
66495 + ent->data = data;
66496 + ent->restricted = 1;
66497 + if (proc_register(parent, ent) < 0) {
66498 + kfree(ent);
66499 + ent = NULL;
66500 + }
66501 + }
66502 + return ent;
66503 +}
66504 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66505 +
66506 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66507 struct proc_dir_entry *parent)
66508 {
66509 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66510 }
66511 EXPORT_SYMBOL(proc_mkdir);
66512
66513 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66514 + struct proc_dir_entry *parent)
66515 +{
66516 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66517 +}
66518 +EXPORT_SYMBOL(proc_mkdir_restrict);
66519 +
66520 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66521 struct proc_dir_entry *parent,
66522 const struct file_operations *proc_fops,
66523 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66524 index 333080d..0a35ec4 100644
66525 --- a/fs/proc/inode.c
66526 +++ b/fs/proc/inode.c
66527 @@ -23,11 +23,17 @@
66528 #include <linux/slab.h>
66529 #include <linux/mount.h>
66530 #include <linux/magic.h>
66531 +#include <linux/grsecurity.h>
66532
66533 #include <asm/uaccess.h>
66534
66535 #include "internal.h"
66536
66537 +#ifdef CONFIG_PROC_SYSCTL
66538 +extern const struct inode_operations proc_sys_inode_operations;
66539 +extern const struct inode_operations proc_sys_dir_operations;
66540 +#endif
66541 +
66542 static void proc_evict_inode(struct inode *inode)
66543 {
66544 struct proc_dir_entry *de;
66545 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66546 ns = PROC_I(inode)->ns.ns;
66547 if (ns_ops && ns)
66548 ns_ops->put(ns);
66549 +
66550 +#ifdef CONFIG_PROC_SYSCTL
66551 + if (inode->i_op == &proc_sys_inode_operations ||
66552 + inode->i_op == &proc_sys_dir_operations)
66553 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66554 +#endif
66555 +
66556 }
66557
66558 static struct kmem_cache * proc_inode_cachep;
66559 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66560 if (de->mode) {
66561 inode->i_mode = de->mode;
66562 inode->i_uid = de->uid;
66563 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66564 + inode->i_gid = grsec_proc_gid;
66565 +#else
66566 inode->i_gid = de->gid;
66567 +#endif
66568 }
66569 if (de->size)
66570 inode->i_size = de->size;
66571 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66572 index aa7a0ee..f2318df 100644
66573 --- a/fs/proc/internal.h
66574 +++ b/fs/proc/internal.h
66575 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66576 struct completion *pde_unload_completion;
66577 struct list_head pde_openers; /* who did ->open, but not ->release */
66578 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66579 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66580 u8 namelen;
66581 char name[];
66582 -};
66583 +} __randomize_layout;
66584
66585 union proc_op {
66586 int (*proc_get_link)(struct dentry *, struct path *);
66587 @@ -66,7 +67,7 @@ struct proc_inode {
66588 struct ctl_table *sysctl_entry;
66589 struct proc_ns ns;
66590 struct inode vfs_inode;
66591 -};
66592 +} __randomize_layout;
66593
66594 /*
66595 * General functions
66596 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66597 struct pid *, struct task_struct *);
66598 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66599 struct pid *, struct task_struct *);
66600 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66601 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66602 + struct pid *, struct task_struct *);
66603 +#endif
66604
66605 /*
66606 * base.c
66607 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66608 * generic.c
66609 */
66610 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66611 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66612 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66613 struct dentry *);
66614 extern int proc_readdir(struct file *, struct dir_context *);
66615 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66616 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66617
66618 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66619 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66620 index a352d57..cb94a5c 100644
66621 --- a/fs/proc/interrupts.c
66622 +++ b/fs/proc/interrupts.c
66623 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66624
66625 static int __init proc_interrupts_init(void)
66626 {
66627 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66628 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66629 +#else
66630 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66631 +#endif
66632 return 0;
66633 }
66634 fs_initcall(proc_interrupts_init);
66635 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66636 index 91a4e64..cb007c0 100644
66637 --- a/fs/proc/kcore.c
66638 +++ b/fs/proc/kcore.c
66639 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66640 * the addresses in the elf_phdr on our list.
66641 */
66642 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66643 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66644 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66645 + if (tsz > buflen)
66646 tsz = buflen;
66647 -
66648 +
66649 while (buflen) {
66650 struct kcore_list *m;
66651
66652 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66653 kfree(elf_buf);
66654 } else {
66655 if (kern_addr_valid(start)) {
66656 - unsigned long n;
66657 + char *elf_buf;
66658 + mm_segment_t oldfs;
66659
66660 - n = copy_to_user(buffer, (char *)start, tsz);
66661 - /*
66662 - * We cannot distinguish between fault on source
66663 - * and fault on destination. When this happens
66664 - * we clear too and hope it will trigger the
66665 - * EFAULT again.
66666 - */
66667 - if (n) {
66668 - if (clear_user(buffer + tsz - n,
66669 - n))
66670 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66671 + if (!elf_buf)
66672 + return -ENOMEM;
66673 + oldfs = get_fs();
66674 + set_fs(KERNEL_DS);
66675 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66676 + set_fs(oldfs);
66677 + if (copy_to_user(buffer, elf_buf, tsz)) {
66678 + kfree(elf_buf);
66679 return -EFAULT;
66680 + }
66681 }
66682 + set_fs(oldfs);
66683 + kfree(elf_buf);
66684 } else {
66685 if (clear_user(buffer, tsz))
66686 return -EFAULT;
66687 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66688
66689 static int open_kcore(struct inode *inode, struct file *filp)
66690 {
66691 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66692 + return -EPERM;
66693 +#endif
66694 if (!capable(CAP_SYS_RAWIO))
66695 return -EPERM;
66696 if (kcore_need_update)
66697 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66698 index aa1eee0..03dda72 100644
66699 --- a/fs/proc/meminfo.c
66700 +++ b/fs/proc/meminfo.c
66701 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66702 vmi.used >> 10,
66703 vmi.largest_chunk >> 10
66704 #ifdef CONFIG_MEMORY_FAILURE
66705 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66706 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66707 #endif
66708 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66709 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66710 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66711 index d4a3574..b421ce9 100644
66712 --- a/fs/proc/nommu.c
66713 +++ b/fs/proc/nommu.c
66714 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66715
66716 if (file) {
66717 seq_pad(m, ' ');
66718 - seq_path(m, &file->f_path, "");
66719 + seq_path(m, &file->f_path, "\n\\");
66720 }
66721
66722 seq_putc(m, '\n');
66723 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66724 index a63af3e..b4f262a 100644
66725 --- a/fs/proc/proc_net.c
66726 +++ b/fs/proc/proc_net.c
66727 @@ -23,9 +23,27 @@
66728 #include <linux/nsproxy.h>
66729 #include <net/net_namespace.h>
66730 #include <linux/seq_file.h>
66731 +#include <linux/grsecurity.h>
66732
66733 #include "internal.h"
66734
66735 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66736 +static struct seq_operations *ipv6_seq_ops_addr;
66737 +
66738 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66739 +{
66740 + ipv6_seq_ops_addr = addr;
66741 +}
66742 +
66743 +void unregister_ipv6_seq_ops_addr(void)
66744 +{
66745 + ipv6_seq_ops_addr = NULL;
66746 +}
66747 +
66748 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66749 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66750 +#endif
66751 +
66752 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66753 {
66754 return pde->parent->data;
66755 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66756 return maybe_get_net(PDE_NET(PDE(inode)));
66757 }
66758
66759 +extern const struct seq_operations dev_seq_ops;
66760 +
66761 int seq_open_net(struct inode *ino, struct file *f,
66762 const struct seq_operations *ops, int size)
66763 {
66764 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66765
66766 BUG_ON(size < sizeof(*p));
66767
66768 + /* only permit access to /proc/net/dev */
66769 + if (
66770 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66771 + ops != ipv6_seq_ops_addr &&
66772 +#endif
66773 + ops != &dev_seq_ops && gr_proc_is_restricted())
66774 + return -EACCES;
66775 +
66776 net = get_proc_net(ino);
66777 if (net == NULL)
66778 return -ENXIO;
66779 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66780 int err;
66781 struct net *net;
66782
66783 + if (gr_proc_is_restricted())
66784 + return -EACCES;
66785 +
66786 err = -ENXIO;
66787 net = get_proc_net(inode);
66788 if (net == NULL)
66789 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66790 index f92d5dd..26398ac 100644
66791 --- a/fs/proc/proc_sysctl.c
66792 +++ b/fs/proc/proc_sysctl.c
66793 @@ -11,13 +11,21 @@
66794 #include <linux/namei.h>
66795 #include <linux/mm.h>
66796 #include <linux/module.h>
66797 +#include <linux/nsproxy.h>
66798 +#ifdef CONFIG_GRKERNSEC
66799 +#include <net/net_namespace.h>
66800 +#endif
66801 #include "internal.h"
66802
66803 +extern int gr_handle_chroot_sysctl(const int op);
66804 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66805 + const int op);
66806 +
66807 static const struct dentry_operations proc_sys_dentry_operations;
66808 static const struct file_operations proc_sys_file_operations;
66809 -static const struct inode_operations proc_sys_inode_operations;
66810 +const struct inode_operations proc_sys_inode_operations;
66811 static const struct file_operations proc_sys_dir_file_operations;
66812 -static const struct inode_operations proc_sys_dir_operations;
66813 +const struct inode_operations proc_sys_dir_operations;
66814
66815 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66816 {
66817 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66818
66819 err = NULL;
66820 d_set_d_op(dentry, &proc_sys_dentry_operations);
66821 +
66822 + gr_handle_proc_create(dentry, inode);
66823 +
66824 d_add(dentry, inode);
66825
66826 out:
66827 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66828 struct inode *inode = file_inode(filp);
66829 struct ctl_table_header *head = grab_header(inode);
66830 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66831 + int op = write ? MAY_WRITE : MAY_READ;
66832 ssize_t error;
66833 size_t res;
66834
66835 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66836 * and won't be until we finish.
66837 */
66838 error = -EPERM;
66839 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66840 + if (sysctl_perm(head, table, op))
66841 goto out;
66842
66843 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66844 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66845 if (!table->proc_handler)
66846 goto out;
66847
66848 +#ifdef CONFIG_GRKERNSEC
66849 + error = -EPERM;
66850 + if (gr_handle_chroot_sysctl(op))
66851 + goto out;
66852 + dget(filp->f_path.dentry);
66853 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66854 + dput(filp->f_path.dentry);
66855 + goto out;
66856 + }
66857 + dput(filp->f_path.dentry);
66858 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66859 + goto out;
66860 + if (write) {
66861 + if (current->nsproxy->net_ns != table->extra2) {
66862 + if (!capable(CAP_SYS_ADMIN))
66863 + goto out;
66864 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66865 + goto out;
66866 + }
66867 +#endif
66868 +
66869 /* careful: calling conventions are nasty here */
66870 res = count;
66871 error = table->proc_handler(table, write, buf, &res, ppos);
66872 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66873 return false;
66874 } else {
66875 d_set_d_op(child, &proc_sys_dentry_operations);
66876 +
66877 + gr_handle_proc_create(child, inode);
66878 +
66879 d_add(child, inode);
66880 }
66881 } else {
66882 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66883 if ((*pos)++ < ctx->pos)
66884 return true;
66885
66886 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66887 + return 0;
66888 +
66889 if (unlikely(S_ISLNK(table->mode)))
66890 res = proc_sys_link_fill_cache(file, ctx, head, table);
66891 else
66892 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66893 if (IS_ERR(head))
66894 return PTR_ERR(head);
66895
66896 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66897 + return -ENOENT;
66898 +
66899 generic_fillattr(inode, stat);
66900 if (table)
66901 stat->mode = (stat->mode & S_IFMT) | table->mode;
66902 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66903 .llseek = generic_file_llseek,
66904 };
66905
66906 -static const struct inode_operations proc_sys_inode_operations = {
66907 +const struct inode_operations proc_sys_inode_operations = {
66908 .permission = proc_sys_permission,
66909 .setattr = proc_sys_setattr,
66910 .getattr = proc_sys_getattr,
66911 };
66912
66913 -static const struct inode_operations proc_sys_dir_operations = {
66914 +const struct inode_operations proc_sys_dir_operations = {
66915 .lookup = proc_sys_lookup,
66916 .permission = proc_sys_permission,
66917 .setattr = proc_sys_setattr,
66918 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66919 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66920 const char *name, int namelen)
66921 {
66922 - struct ctl_table *table;
66923 + ctl_table_no_const *table;
66924 struct ctl_dir *new;
66925 struct ctl_node *node;
66926 char *new_name;
66927 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66928 return NULL;
66929
66930 node = (struct ctl_node *)(new + 1);
66931 - table = (struct ctl_table *)(node + 1);
66932 + table = (ctl_table_no_const *)(node + 1);
66933 new_name = (char *)(table + 2);
66934 memcpy(new_name, name, namelen);
66935 new_name[namelen] = '\0';
66936 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66937 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66938 struct ctl_table_root *link_root)
66939 {
66940 - struct ctl_table *link_table, *entry, *link;
66941 + ctl_table_no_const *link_table, *link;
66942 + struct ctl_table *entry;
66943 struct ctl_table_header *links;
66944 struct ctl_node *node;
66945 char *link_name;
66946 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66947 return NULL;
66948
66949 node = (struct ctl_node *)(links + 1);
66950 - link_table = (struct ctl_table *)(node + nr_entries);
66951 + link_table = (ctl_table_no_const *)(node + nr_entries);
66952 link_name = (char *)&link_table[nr_entries + 1];
66953
66954 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66955 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66956 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66957 struct ctl_table *table)
66958 {
66959 - struct ctl_table *ctl_table_arg = NULL;
66960 - struct ctl_table *entry, *files;
66961 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66962 + struct ctl_table *entry;
66963 int nr_files = 0;
66964 int nr_dirs = 0;
66965 int err = -ENOMEM;
66966 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66967 nr_files++;
66968 }
66969
66970 - files = table;
66971 /* If there are mixed files and directories we need a new table */
66972 if (nr_dirs && nr_files) {
66973 - struct ctl_table *new;
66974 + ctl_table_no_const *new;
66975 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66976 GFP_KERNEL);
66977 if (!files)
66978 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66979 /* Register everything except a directory full of subdirectories */
66980 if (nr_files || !nr_dirs) {
66981 struct ctl_table_header *header;
66982 - header = __register_sysctl_table(set, path, files);
66983 + header = __register_sysctl_table(set, path, files ? files : table);
66984 if (!header) {
66985 kfree(ctl_table_arg);
66986 goto out;
66987 diff --git a/fs/proc/root.c b/fs/proc/root.c
66988 index 094e44d..085a877 100644
66989 --- a/fs/proc/root.c
66990 +++ b/fs/proc/root.c
66991 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
66992 proc_mkdir("openprom", NULL);
66993 #endif
66994 proc_tty_init();
66995 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66996 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66997 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66998 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66999 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67000 +#endif
67001 +#else
67002 proc_mkdir("bus", NULL);
67003 +#endif
67004 proc_sys_init();
67005 }
67006
67007 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67008 index 510413eb..34d9a8c 100644
67009 --- a/fs/proc/stat.c
67010 +++ b/fs/proc/stat.c
67011 @@ -11,6 +11,7 @@
67012 #include <linux/irqnr.h>
67013 #include <linux/cputime.h>
67014 #include <linux/tick.h>
67015 +#include <linux/grsecurity.h>
67016
67017 #ifndef arch_irq_stat_cpu
67018 #define arch_irq_stat_cpu(cpu) 0
67019 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67020 u64 sum_softirq = 0;
67021 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67022 struct timespec boottime;
67023 + int unrestricted = 1;
67024 +
67025 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67026 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67027 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67028 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67029 + && !in_group_p(grsec_proc_gid)
67030 +#endif
67031 + )
67032 + unrestricted = 0;
67033 +#endif
67034 +#endif
67035
67036 user = nice = system = idle = iowait =
67037 irq = softirq = steal = 0;
67038 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67039 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67040 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67041 idle += get_idle_time(i);
67042 - iowait += get_iowait_time(i);
67043 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67044 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67045 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67046 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67047 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67048 - sum += kstat_cpu_irqs_sum(i);
67049 - sum += arch_irq_stat_cpu(i);
67050 + if (unrestricted) {
67051 + iowait += get_iowait_time(i);
67052 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67053 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67054 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67055 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67056 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67057 + sum += kstat_cpu_irqs_sum(i);
67058 + sum += arch_irq_stat_cpu(i);
67059 + for (j = 0; j < NR_SOFTIRQS; j++) {
67060 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67061
67062 - for (j = 0; j < NR_SOFTIRQS; j++) {
67063 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67064 -
67065 - per_softirq_sums[j] += softirq_stat;
67066 - sum_softirq += softirq_stat;
67067 + per_softirq_sums[j] += softirq_stat;
67068 + sum_softirq += softirq_stat;
67069 + }
67070 }
67071 }
67072 - sum += arch_irq_stat();
67073 + if (unrestricted)
67074 + sum += arch_irq_stat();
67075
67076 seq_puts(p, "cpu ");
67077 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67078 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67079 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67080 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67081 idle = get_idle_time(i);
67082 - iowait = get_iowait_time(i);
67083 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67084 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67085 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67086 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67087 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67088 + if (unrestricted) {
67089 + iowait = get_iowait_time(i);
67090 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67091 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67092 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67093 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67094 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67095 + }
67096 seq_printf(p, "cpu%d", i);
67097 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67098 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67099 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67100
67101 /* sum again ? it could be updated? */
67102 for_each_irq_nr(j)
67103 - seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j));
67104 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs_usr(j) : 0ULL);
67105
67106 seq_printf(p,
67107 "\nctxt %llu\n"
67108 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67109 "processes %lu\n"
67110 "procs_running %lu\n"
67111 "procs_blocked %lu\n",
67112 - nr_context_switches(),
67113 + unrestricted ? nr_context_switches() : 0ULL,
67114 (unsigned long)jif,
67115 - total_forks,
67116 - nr_running(),
67117 - nr_iowait());
67118 + unrestricted ? total_forks : 0UL,
67119 + unrestricted ? nr_running() : 0UL,
67120 + unrestricted ? nr_iowait() : 0UL);
67121
67122 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67123
67124 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67125 index 4e0388c..fc6a0e1 100644
67126 --- a/fs/proc/task_mmu.c
67127 +++ b/fs/proc/task_mmu.c
67128 @@ -13,12 +13,19 @@
67129 #include <linux/swap.h>
67130 #include <linux/swapops.h>
67131 #include <linux/mmu_notifier.h>
67132 +#include <linux/grsecurity.h>
67133
67134 #include <asm/elf.h>
67135 #include <asm/uaccess.h>
67136 #include <asm/tlbflush.h>
67137 #include "internal.h"
67138
67139 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67140 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67141 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67142 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67143 +#endif
67144 +
67145 void task_mem(struct seq_file *m, struct mm_struct *mm)
67146 {
67147 unsigned long data, text, lib, swap;
67148 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67149 "VmExe:\t%8lu kB\n"
67150 "VmLib:\t%8lu kB\n"
67151 "VmPTE:\t%8lu kB\n"
67152 - "VmSwap:\t%8lu kB\n",
67153 - hiwater_vm << (PAGE_SHIFT-10),
67154 + "VmSwap:\t%8lu kB\n"
67155 +
67156 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67157 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67158 +#endif
67159 +
67160 + ,hiwater_vm << (PAGE_SHIFT-10),
67161 total_vm << (PAGE_SHIFT-10),
67162 mm->locked_vm << (PAGE_SHIFT-10),
67163 mm->pinned_vm << (PAGE_SHIFT-10),
67164 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67165 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67166 (PTRS_PER_PTE * sizeof(pte_t) *
67167 atomic_long_read(&mm->nr_ptes)) >> 10,
67168 - swap << (PAGE_SHIFT-10));
67169 + swap << (PAGE_SHIFT-10)
67170 +
67171 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67172 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67173 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67174 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67175 +#else
67176 + , mm->context.user_cs_base
67177 + , mm->context.user_cs_limit
67178 +#endif
67179 +#endif
67180 +
67181 + );
67182 }
67183
67184 unsigned long task_vsize(struct mm_struct *mm)
67185 @@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67186 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67187 }
67188
67189 - /* We don't show the stack guard page in /proc/maps */
67190 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67191 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67192 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67193 +#else
67194 start = vma->vm_start;
67195 - if (stack_guard_page_start(vma, start))
67196 - start += PAGE_SIZE;
67197 end = vma->vm_end;
67198 - if (stack_guard_page_end(vma, end))
67199 - end -= PAGE_SIZE;
67200 +#endif
67201
67202 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67203 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67204 @@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67205 flags & VM_WRITE ? 'w' : '-',
67206 flags & VM_EXEC ? 'x' : '-',
67207 flags & VM_MAYSHARE ? 's' : 'p',
67208 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67209 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67210 +#else
67211 pgoff,
67212 +#endif
67213 MAJOR(dev), MINOR(dev), ino);
67214
67215 /*
67216 @@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67217 */
67218 if (file) {
67219 seq_pad(m, ' ');
67220 - seq_path(m, &file->f_path, "\n");
67221 + seq_path(m, &file->f_path, "\n\\");
67222 goto done;
67223 }
67224
67225 @@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67226 * Thread stack in /proc/PID/task/TID/maps or
67227 * the main process stack.
67228 */
67229 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67230 - vma->vm_end >= mm->start_stack)) {
67231 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67232 + (vma->vm_start <= mm->start_stack &&
67233 + vma->vm_end >= mm->start_stack)) {
67234 name = "[stack]";
67235 } else {
67236 /* Thread stack in /proc/PID/maps */
67237 @@ -359,6 +388,12 @@ done:
67238
67239 static int show_map(struct seq_file *m, void *v, int is_pid)
67240 {
67241 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67242 + if (current->exec_id != m->exec_id) {
67243 + gr_log_badprocpid("maps");
67244 + return 0;
67245 + }
67246 +#endif
67247 show_map_vma(m, v, is_pid);
67248 m_cache_vma(m, v);
67249 return 0;
67250 @@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67251 .private = &mss,
67252 };
67253
67254 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67255 + if (current->exec_id != m->exec_id) {
67256 + gr_log_badprocpid("smaps");
67257 + return 0;
67258 + }
67259 +#endif
67260 memset(&mss, 0, sizeof mss);
67261 - mss.vma = vma;
67262 - /* mmap_sem is held in m_start */
67263 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67264 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67265 -
67266 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67267 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67268 +#endif
67269 + mss.vma = vma;
67270 + /* mmap_sem is held in m_start */
67271 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67272 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67273 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67274 + }
67275 +#endif
67276 show_map_vma(m, vma, is_pid);
67277
67278 seq_printf(m,
67279 @@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67280 "KernelPageSize: %8lu kB\n"
67281 "MMUPageSize: %8lu kB\n"
67282 "Locked: %8lu kB\n",
67283 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67284 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67285 +#else
67286 (vma->vm_end - vma->vm_start) >> 10,
67287 +#endif
67288 mss.resident >> 10,
67289 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67290 mss.shared_clean >> 10,
67291 @@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67292 char buffer[64];
67293 int nid;
67294
67295 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67296 + if (current->exec_id != m->exec_id) {
67297 + gr_log_badprocpid("numa_maps");
67298 + return 0;
67299 + }
67300 +#endif
67301 +
67302 if (!mm)
67303 return 0;
67304
67305 @@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67306 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
67307 }
67308
67309 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67310 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67311 +#else
67312 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67313 +#endif
67314
67315 if (file) {
67316 seq_puts(m, " file=");
67317 - seq_path(m, &file->f_path, "\n\t= ");
67318 + seq_path(m, &file->f_path, "\n\t\\= ");
67319 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67320 seq_puts(m, " heap");
67321 } else {
67322 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67323 index 599ec2e..f1413ae 100644
67324 --- a/fs/proc/task_nommu.c
67325 +++ b/fs/proc/task_nommu.c
67326 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67327 else
67328 bytes += kobjsize(mm);
67329
67330 - if (current->fs && current->fs->users > 1)
67331 + if (current->fs && atomic_read(&current->fs->users) > 1)
67332 sbytes += kobjsize(current->fs);
67333 else
67334 bytes += kobjsize(current->fs);
67335 @@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67336
67337 if (file) {
67338 seq_pad(m, ' ');
67339 - seq_path(m, &file->f_path, "");
67340 + seq_path(m, &file->f_path, "\n\\");
67341 } else if (mm) {
67342 pid_t tid = pid_of_stack(priv, vma, is_pid);
67343
67344 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67345 index a90d6d35..d08047c 100644
67346 --- a/fs/proc/vmcore.c
67347 +++ b/fs/proc/vmcore.c
67348 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67349 nr_bytes = count;
67350
67351 /* If pfn is not ram, return zeros for sparse dump files */
67352 - if (pfn_is_ram(pfn) == 0)
67353 - memset(buf, 0, nr_bytes);
67354 - else {
67355 + if (pfn_is_ram(pfn) == 0) {
67356 + if (userbuf) {
67357 + if (clear_user((char __force_user *)buf, nr_bytes))
67358 + return -EFAULT;
67359 + } else
67360 + memset(buf, 0, nr_bytes);
67361 + } else {
67362 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67363 offset, userbuf);
67364 if (tmp < 0)
67365 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67366 static int copy_to(void *target, void *src, size_t size, int userbuf)
67367 {
67368 if (userbuf) {
67369 - if (copy_to_user((char __user *) target, src, size))
67370 + if (copy_to_user((char __force_user *) target, src, size))
67371 return -EFAULT;
67372 } else {
67373 memcpy(target, src, size);
67374 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67375 if (*fpos < m->offset + m->size) {
67376 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67377 start = m->paddr + *fpos - m->offset;
67378 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67379 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67380 if (tmp < 0)
67381 return tmp;
67382 buflen -= tsz;
67383 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67384 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67385 size_t buflen, loff_t *fpos)
67386 {
67387 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67388 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67389 }
67390
67391 /*
67392 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67393 index d3fb2b6..43a8140 100644
67394 --- a/fs/qnx6/qnx6.h
67395 +++ b/fs/qnx6/qnx6.h
67396 @@ -74,7 +74,7 @@ enum {
67397 BYTESEX_BE,
67398 };
67399
67400 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67401 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67402 {
67403 if (sbi->s_bytesex == BYTESEX_LE)
67404 return le64_to_cpu((__force __le64)n);
67405 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67406 return (__force __fs64)cpu_to_be64(n);
67407 }
67408
67409 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67410 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67411 {
67412 if (sbi->s_bytesex == BYTESEX_LE)
67413 return le32_to_cpu((__force __le32)n);
67414 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67415 index bb2869f..d34ada8 100644
67416 --- a/fs/quota/netlink.c
67417 +++ b/fs/quota/netlink.c
67418 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67419 void quota_send_warning(struct kqid qid, dev_t dev,
67420 const char warntype)
67421 {
67422 - static atomic_t seq;
67423 + static atomic_unchecked_t seq;
67424 struct sk_buff *skb;
67425 void *msg_head;
67426 int ret;
67427 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67428 "VFS: Not enough memory to send quota warning.\n");
67429 return;
67430 }
67431 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67432 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67433 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67434 if (!msg_head) {
67435 printk(KERN_ERR
67436 diff --git a/fs/read_write.c b/fs/read_write.c
67437 index 7d9318c..51b336f 100644
67438 --- a/fs/read_write.c
67439 +++ b/fs/read_write.c
67440 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67441
67442 old_fs = get_fs();
67443 set_fs(get_ds());
67444 - p = (__force const char __user *)buf;
67445 + p = (const char __force_user *)buf;
67446 if (count > MAX_RW_COUNT)
67447 count = MAX_RW_COUNT;
67448 if (file->f_op->write)
67449 diff --git a/fs/readdir.c b/fs/readdir.c
67450 index 33fd922..e0d6094 100644
67451 --- a/fs/readdir.c
67452 +++ b/fs/readdir.c
67453 @@ -18,6 +18,7 @@
67454 #include <linux/security.h>
67455 #include <linux/syscalls.h>
67456 #include <linux/unistd.h>
67457 +#include <linux/namei.h>
67458
67459 #include <asm/uaccess.h>
67460
67461 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67462 struct readdir_callback {
67463 struct dir_context ctx;
67464 struct old_linux_dirent __user * dirent;
67465 + struct file * file;
67466 int result;
67467 };
67468
67469 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67470 buf->result = -EOVERFLOW;
67471 return -EOVERFLOW;
67472 }
67473 +
67474 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67475 + return 0;
67476 +
67477 buf->result++;
67478 dirent = buf->dirent;
67479 if (!access_ok(VERIFY_WRITE, dirent,
67480 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67481 if (!f.file)
67482 return -EBADF;
67483
67484 + buf.file = f.file;
67485 error = iterate_dir(f.file, &buf.ctx);
67486 if (buf.result)
67487 error = buf.result;
67488 @@ -144,6 +151,7 @@ struct getdents_callback {
67489 struct dir_context ctx;
67490 struct linux_dirent __user * current_dir;
67491 struct linux_dirent __user * previous;
67492 + struct file * file;
67493 int count;
67494 int error;
67495 };
67496 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67497 buf->error = -EOVERFLOW;
67498 return -EOVERFLOW;
67499 }
67500 +
67501 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67502 + return 0;
67503 +
67504 dirent = buf->previous;
67505 if (dirent) {
67506 if (__put_user(offset, &dirent->d_off))
67507 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67508 if (!f.file)
67509 return -EBADF;
67510
67511 + buf.file = f.file;
67512 error = iterate_dir(f.file, &buf.ctx);
67513 if (error >= 0)
67514 error = buf.error;
67515 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67516 struct dir_context ctx;
67517 struct linux_dirent64 __user * current_dir;
67518 struct linux_dirent64 __user * previous;
67519 + struct file *file;
67520 int count;
67521 int error;
67522 };
67523 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67524 buf->error = -EINVAL; /* only used if we fail.. */
67525 if (reclen > buf->count)
67526 return -EINVAL;
67527 +
67528 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67529 + return 0;
67530 +
67531 dirent = buf->previous;
67532 if (dirent) {
67533 if (__put_user(offset, &dirent->d_off))
67534 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67535 if (!f.file)
67536 return -EBADF;
67537
67538 + buf.file = f.file;
67539 error = iterate_dir(f.file, &buf.ctx);
67540 if (error >= 0)
67541 error = buf.error;
67542 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67543 index 9c02d96..6562c10 100644
67544 --- a/fs/reiserfs/do_balan.c
67545 +++ b/fs/reiserfs/do_balan.c
67546 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67547 return;
67548 }
67549
67550 - atomic_inc(&fs_generation(tb->tb_sb));
67551 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67552 do_balance_starts(tb);
67553
67554 /*
67555 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67556 index aca73dd..e3c558d 100644
67557 --- a/fs/reiserfs/item_ops.c
67558 +++ b/fs/reiserfs/item_ops.c
67559 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67560 }
67561
67562 static struct item_operations errcatch_ops = {
67563 - errcatch_bytes_number,
67564 - errcatch_decrement_key,
67565 - errcatch_is_left_mergeable,
67566 - errcatch_print_item,
67567 - errcatch_check_item,
67568 + .bytes_number = errcatch_bytes_number,
67569 + .decrement_key = errcatch_decrement_key,
67570 + .is_left_mergeable = errcatch_is_left_mergeable,
67571 + .print_item = errcatch_print_item,
67572 + .check_item = errcatch_check_item,
67573
67574 - errcatch_create_vi,
67575 - errcatch_check_left,
67576 - errcatch_check_right,
67577 - errcatch_part_size,
67578 - errcatch_unit_num,
67579 - errcatch_print_vi
67580 + .create_vi = errcatch_create_vi,
67581 + .check_left = errcatch_check_left,
67582 + .check_right = errcatch_check_right,
67583 + .part_size = errcatch_part_size,
67584 + .unit_num = errcatch_unit_num,
67585 + .print_vi = errcatch_print_vi
67586 };
67587
67588 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67589 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67590 index 621b9f3..af527fd 100644
67591 --- a/fs/reiserfs/procfs.c
67592 +++ b/fs/reiserfs/procfs.c
67593 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67594 "SMALL_TAILS " : "NO_TAILS ",
67595 replay_only(sb) ? "REPLAY_ONLY " : "",
67596 convert_reiserfs(sb) ? "CONV " : "",
67597 - atomic_read(&r->s_generation_counter),
67598 + atomic_read_unchecked(&r->s_generation_counter),
67599 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67600 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67601 SF(s_good_search_by_key_reada), SF(s_bmaps),
67602 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67603 index 1894d96..1dfd1c2 100644
67604 --- a/fs/reiserfs/reiserfs.h
67605 +++ b/fs/reiserfs/reiserfs.h
67606 @@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67607 /* Comment? -Hans */
67608 wait_queue_head_t s_wait;
67609 /* increased by one every time the tree gets re-balanced */
67610 - atomic_t s_generation_counter;
67611 + atomic_unchecked_t s_generation_counter;
67612
67613 /* File system properties. Currently holds on-disk FS format */
67614 unsigned long s_properties;
67615 @@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67616 #define REISERFS_USER_MEM 1 /* user memory mode */
67617
67618 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67619 -#define get_generation(s) atomic_read (&fs_generation(s))
67620 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67621 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67622 #define __fs_changed(gen,s) (gen != get_generation (s))
67623 #define fs_changed(gen,s) \
67624 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67625 index b27ef35..d9c6c18 100644
67626 --- a/fs/reiserfs/super.c
67627 +++ b/fs/reiserfs/super.c
67628 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67629 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67630 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67631 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67632 +#ifdef CONFIG_REISERFS_FS_XATTR
67633 + /* turn on user xattrs by default */
67634 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67635 +#endif
67636 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67637 sbi->s_alloc_options.preallocmin = 0;
67638 /* Preallocate by 16 blocks (17-1) at once */
67639 diff --git a/fs/select.c b/fs/select.c
67640 index 467bb1c..cf9d65a 100644
67641 --- a/fs/select.c
67642 +++ b/fs/select.c
67643 @@ -20,6 +20,7 @@
67644 #include <linux/export.h>
67645 #include <linux/slab.h>
67646 #include <linux/poll.h>
67647 +#include <linux/security.h>
67648 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67649 #include <linux/file.h>
67650 #include <linux/fdtable.h>
67651 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67652 struct poll_list *walk = head;
67653 unsigned long todo = nfds;
67654
67655 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67656 if (nfds > rlimit(RLIMIT_NOFILE))
67657 return -EINVAL;
67658
67659 diff --git a/fs/seq_file.c b/fs/seq_file.c
67660 index 3857b72..0b7281e 100644
67661 --- a/fs/seq_file.c
67662 +++ b/fs/seq_file.c
67663 @@ -12,6 +12,8 @@
67664 #include <linux/slab.h>
67665 #include <linux/cred.h>
67666 #include <linux/mm.h>
67667 +#include <linux/sched.h>
67668 +#include <linux/grsecurity.h>
67669
67670 #include <asm/uaccess.h>
67671 #include <asm/page.h>
67672 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67673
67674 static void *seq_buf_alloc(unsigned long size)
67675 {
67676 - void *buf;
67677 -
67678 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67679 - if (!buf && size > PAGE_SIZE)
67680 - buf = vmalloc(size);
67681 - return buf;
67682 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67683 }
67684
67685 /**
67686 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67687 #ifdef CONFIG_USER_NS
67688 p->user_ns = file->f_cred->user_ns;
67689 #endif
67690 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67691 + p->exec_id = current->exec_id;
67692 +#endif
67693
67694 /*
67695 * Wrappers around seq_open(e.g. swaps_open) need to be
67696 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67697 }
67698 EXPORT_SYMBOL(seq_open);
67699
67700 +
67701 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67702 +{
67703 + if (gr_proc_is_restricted())
67704 + return -EACCES;
67705 +
67706 + return seq_open(file, op);
67707 +}
67708 +EXPORT_SYMBOL(seq_open_restrict);
67709 +
67710 static int traverse(struct seq_file *m, loff_t offset)
67711 {
67712 loff_t pos = 0, index;
67713 @@ -165,7 +175,7 @@ Eoverflow:
67714 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67715 {
67716 struct seq_file *m = file->private_data;
67717 - size_t copied = 0;
67718 + ssize_t copied = 0;
67719 loff_t pos;
67720 size_t n;
67721 void *p;
67722 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67723 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67724 void *data)
67725 {
67726 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67727 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67728 int res = -ENOMEM;
67729
67730 if (op) {
67731 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67732 }
67733 EXPORT_SYMBOL(single_open_size);
67734
67735 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67736 + void *data)
67737 +{
67738 + if (gr_proc_is_restricted())
67739 + return -EACCES;
67740 +
67741 + return single_open(file, show, data);
67742 +}
67743 +EXPORT_SYMBOL(single_open_restrict);
67744 +
67745 +
67746 int single_release(struct inode *inode, struct file *file)
67747 {
67748 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67749 diff --git a/fs/splice.c b/fs/splice.c
67750 index 75c6058..770d40c 100644
67751 --- a/fs/splice.c
67752 +++ b/fs/splice.c
67753 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67754 pipe_lock(pipe);
67755
67756 for (;;) {
67757 - if (!pipe->readers) {
67758 + if (!atomic_read(&pipe->readers)) {
67759 send_sig(SIGPIPE, current, 0);
67760 if (!ret)
67761 ret = -EPIPE;
67762 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67763 page_nr++;
67764 ret += buf->len;
67765
67766 - if (pipe->files)
67767 + if (atomic_read(&pipe->files))
67768 do_wakeup = 1;
67769
67770 if (!--spd->nr_pages)
67771 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67772 do_wakeup = 0;
67773 }
67774
67775 - pipe->waiting_writers++;
67776 + atomic_inc(&pipe->waiting_writers);
67777 pipe_wait(pipe);
67778 - pipe->waiting_writers--;
67779 + atomic_dec(&pipe->waiting_writers);
67780 }
67781
67782 pipe_unlock(pipe);
67783 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67784 old_fs = get_fs();
67785 set_fs(get_ds());
67786 /* The cast to a user pointer is valid due to the set_fs() */
67787 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67788 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67789 set_fs(old_fs);
67790
67791 return res;
67792 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67793 old_fs = get_fs();
67794 set_fs(get_ds());
67795 /* The cast to a user pointer is valid due to the set_fs() */
67796 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67797 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67798 set_fs(old_fs);
67799
67800 return res;
67801 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67802 goto err;
67803
67804 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67805 - vec[i].iov_base = (void __user *) page_address(page);
67806 + vec[i].iov_base = (void __force_user *) page_address(page);
67807 vec[i].iov_len = this_len;
67808 spd.pages[i] = page;
67809 spd.nr_pages++;
67810 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67811 ops->release(pipe, buf);
67812 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67813 pipe->nrbufs--;
67814 - if (pipe->files)
67815 + if (atomic_read(&pipe->files))
67816 sd->need_wakeup = true;
67817 }
67818
67819 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67820 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67821 {
67822 while (!pipe->nrbufs) {
67823 - if (!pipe->writers)
67824 + if (!atomic_read(&pipe->writers))
67825 return 0;
67826
67827 - if (!pipe->waiting_writers && sd->num_spliced)
67828 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67829 return 0;
67830
67831 if (sd->flags & SPLICE_F_NONBLOCK)
67832 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67833 ops->release(pipe, buf);
67834 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67835 pipe->nrbufs--;
67836 - if (pipe->files)
67837 + if (atomic_read(&pipe->files))
67838 sd.need_wakeup = true;
67839 } else {
67840 buf->offset += ret;
67841 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67842 * out of the pipe right after the splice_to_pipe(). So set
67843 * PIPE_READERS appropriately.
67844 */
67845 - pipe->readers = 1;
67846 + atomic_set(&pipe->readers, 1);
67847
67848 current->splice_pipe = pipe;
67849 }
67850 @@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67851
67852 partial[buffers].offset = off;
67853 partial[buffers].len = plen;
67854 + partial[buffers].private = 0;
67855
67856 off = 0;
67857 len -= plen;
67858 @@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67859 ret = -ERESTARTSYS;
67860 break;
67861 }
67862 - if (!pipe->writers)
67863 + if (!atomic_read(&pipe->writers))
67864 break;
67865 - if (!pipe->waiting_writers) {
67866 + if (!atomic_read(&pipe->waiting_writers)) {
67867 if (flags & SPLICE_F_NONBLOCK) {
67868 ret = -EAGAIN;
67869 break;
67870 @@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67871 pipe_lock(pipe);
67872
67873 while (pipe->nrbufs >= pipe->buffers) {
67874 - if (!pipe->readers) {
67875 + if (!atomic_read(&pipe->readers)) {
67876 send_sig(SIGPIPE, current, 0);
67877 ret = -EPIPE;
67878 break;
67879 @@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67880 ret = -ERESTARTSYS;
67881 break;
67882 }
67883 - pipe->waiting_writers++;
67884 + atomic_inc(&pipe->waiting_writers);
67885 pipe_wait(pipe);
67886 - pipe->waiting_writers--;
67887 + atomic_dec(&pipe->waiting_writers);
67888 }
67889
67890 pipe_unlock(pipe);
67891 @@ -1818,14 +1819,14 @@ retry:
67892 pipe_double_lock(ipipe, opipe);
67893
67894 do {
67895 - if (!opipe->readers) {
67896 + if (!atomic_read(&opipe->readers)) {
67897 send_sig(SIGPIPE, current, 0);
67898 if (!ret)
67899 ret = -EPIPE;
67900 break;
67901 }
67902
67903 - if (!ipipe->nrbufs && !ipipe->writers)
67904 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67905 break;
67906
67907 /*
67908 @@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67909 pipe_double_lock(ipipe, opipe);
67910
67911 do {
67912 - if (!opipe->readers) {
67913 + if (!atomic_read(&opipe->readers)) {
67914 send_sig(SIGPIPE, current, 0);
67915 if (!ret)
67916 ret = -EPIPE;
67917 @@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67918 * return EAGAIN if we have the potential of some data in the
67919 * future, otherwise just return 0
67920 */
67921 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67922 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67923 ret = -EAGAIN;
67924
67925 pipe_unlock(ipipe);
67926 diff --git a/fs/stat.c b/fs/stat.c
67927 index ae0c3ce..9ee641c 100644
67928 --- a/fs/stat.c
67929 +++ b/fs/stat.c
67930 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67931 stat->gid = inode->i_gid;
67932 stat->rdev = inode->i_rdev;
67933 stat->size = i_size_read(inode);
67934 - stat->atime = inode->i_atime;
67935 - stat->mtime = inode->i_mtime;
67936 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67937 + stat->atime = inode->i_ctime;
67938 + stat->mtime = inode->i_ctime;
67939 + } else {
67940 + stat->atime = inode->i_atime;
67941 + stat->mtime = inode->i_mtime;
67942 + }
67943 stat->ctime = inode->i_ctime;
67944 stat->blksize = (1 << inode->i_blkbits);
67945 stat->blocks = inode->i_blocks;
67946 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67947 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67948 {
67949 struct inode *inode = path->dentry->d_inode;
67950 + int retval;
67951
67952 - if (inode->i_op->getattr)
67953 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67954 + if (inode->i_op->getattr) {
67955 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67956 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67957 + stat->atime = stat->ctime;
67958 + stat->mtime = stat->ctime;
67959 + }
67960 + return retval;
67961 + }
67962
67963 generic_fillattr(inode, stat);
67964 return 0;
67965 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67966 index 0b45ff4..847de5b 100644
67967 --- a/fs/sysfs/dir.c
67968 +++ b/fs/sysfs/dir.c
67969 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67970 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67971 {
67972 struct kernfs_node *parent, *kn;
67973 + const char *name;
67974 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67975 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67976 + const char *parent_name;
67977 +#endif
67978
67979 BUG_ON(!kobj);
67980
67981 + name = kobject_name(kobj);
67982 +
67983 if (kobj->parent)
67984 parent = kobj->parent->sd;
67985 else
67986 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67987 if (!parent)
67988 return -ENOENT;
67989
67990 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67991 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67992 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67993 + parent_name = parent->name;
67994 + mode = S_IRWXU;
67995 +
67996 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67997 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67998 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67999 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68000 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68001 +#endif
68002 +
68003 + kn = kernfs_create_dir_ns(parent, name,
68004 + mode, kobj, ns);
68005 if (IS_ERR(kn)) {
68006 if (PTR_ERR(kn) == -EEXIST)
68007 - sysfs_warn_dup(parent, kobject_name(kobj));
68008 + sysfs_warn_dup(parent, name);
68009 return PTR_ERR(kn);
68010 }
68011
68012 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68013 index 69d4889..a810bd4 100644
68014 --- a/fs/sysv/sysv.h
68015 +++ b/fs/sysv/sysv.h
68016 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68017 #endif
68018 }
68019
68020 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68021 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68022 {
68023 if (sbi->s_bytesex == BYTESEX_PDP)
68024 return PDP_swab((__force __u32)n);
68025 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68026 index fb08b0c..65fcc7e 100644
68027 --- a/fs/ubifs/io.c
68028 +++ b/fs/ubifs/io.c
68029 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68030 return err;
68031 }
68032
68033 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68034 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68035 {
68036 int err;
68037
68038 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68039 index c175b4d..8f36a16 100644
68040 --- a/fs/udf/misc.c
68041 +++ b/fs/udf/misc.c
68042 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68043
68044 u8 udf_tag_checksum(const struct tag *t)
68045 {
68046 - u8 *data = (u8 *)t;
68047 + const u8 *data = (const u8 *)t;
68048 u8 checksum = 0;
68049 int i;
68050 for (i = 0; i < sizeof(struct tag); ++i)
68051 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68052 index 8d974c4..b82f6ec 100644
68053 --- a/fs/ufs/swab.h
68054 +++ b/fs/ufs/swab.h
68055 @@ -22,7 +22,7 @@ enum {
68056 BYTESEX_BE
68057 };
68058
68059 -static inline u64
68060 +static inline u64 __intentional_overflow(-1)
68061 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68062 {
68063 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68064 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68065 return (__force __fs64)cpu_to_be64(n);
68066 }
68067
68068 -static inline u32
68069 +static inline u32 __intentional_overflow(-1)
68070 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68071 {
68072 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68073 diff --git a/fs/utimes.c b/fs/utimes.c
68074 index aa138d6..5f3a811 100644
68075 --- a/fs/utimes.c
68076 +++ b/fs/utimes.c
68077 @@ -1,6 +1,7 @@
68078 #include <linux/compiler.h>
68079 #include <linux/file.h>
68080 #include <linux/fs.h>
68081 +#include <linux/security.h>
68082 #include <linux/linkage.h>
68083 #include <linux/mount.h>
68084 #include <linux/namei.h>
68085 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68086 }
68087 }
68088 retry_deleg:
68089 +
68090 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68091 + error = -EACCES;
68092 + goto mnt_drop_write_and_out;
68093 + }
68094 +
68095 mutex_lock(&inode->i_mutex);
68096 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68097 mutex_unlock(&inode->i_mutex);
68098 diff --git a/fs/xattr.c b/fs/xattr.c
68099 index 64e83ef..b6be154 100644
68100 --- a/fs/xattr.c
68101 +++ b/fs/xattr.c
68102 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68103 return rc;
68104 }
68105
68106 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68107 +ssize_t
68108 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68109 +{
68110 + struct inode *inode = dentry->d_inode;
68111 + ssize_t error;
68112 +
68113 + error = inode_permission(inode, MAY_EXEC);
68114 + if (error)
68115 + return error;
68116 +
68117 + if (inode->i_op->getxattr)
68118 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68119 + else
68120 + error = -EOPNOTSUPP;
68121 +
68122 + return error;
68123 +}
68124 +EXPORT_SYMBOL(pax_getxattr);
68125 +#endif
68126 +
68127 ssize_t
68128 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68129 {
68130 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68131 * Extended attribute SET operations
68132 */
68133 static long
68134 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68135 +setxattr(struct path *path, const char __user *name, const void __user *value,
68136 size_t size, int flags)
68137 {
68138 int error;
68139 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68140 posix_acl_fix_xattr_from_user(kvalue, size);
68141 }
68142
68143 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68144 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68145 + error = -EACCES;
68146 + goto out;
68147 + }
68148 +
68149 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68150 out:
68151 if (vvalue)
68152 vfree(vvalue);
68153 @@ -376,7 +402,7 @@ retry:
68154 return error;
68155 error = mnt_want_write(path.mnt);
68156 if (!error) {
68157 - error = setxattr(path.dentry, name, value, size, flags);
68158 + error = setxattr(&path, name, value, size, flags);
68159 mnt_drop_write(path.mnt);
68160 }
68161 path_put(&path);
68162 @@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68163 const void __user *,value, size_t, size, int, flags)
68164 {
68165 struct fd f = fdget(fd);
68166 - struct dentry *dentry;
68167 int error = -EBADF;
68168
68169 if (!f.file)
68170 return error;
68171 - dentry = f.file->f_path.dentry;
68172 - audit_inode(NULL, dentry, 0);
68173 + audit_inode(NULL, f.file->f_path.dentry, 0);
68174 error = mnt_want_write_file(f.file);
68175 if (!error) {
68176 - error = setxattr(dentry, name, value, size, flags);
68177 + error = setxattr(&f.file->f_path, name, value, size, flags);
68178 mnt_drop_write_file(f.file);
68179 }
68180 fdput(f);
68181 @@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68182 * Extended attribute REMOVE operations
68183 */
68184 static long
68185 -removexattr(struct dentry *d, const char __user *name)
68186 +removexattr(struct path *path, const char __user *name)
68187 {
68188 int error;
68189 char kname[XATTR_NAME_MAX + 1];
68190 @@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68191 if (error < 0)
68192 return error;
68193
68194 - return vfs_removexattr(d, kname);
68195 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68196 + return -EACCES;
68197 +
68198 + return vfs_removexattr(path->dentry, kname);
68199 }
68200
68201 static int path_removexattr(const char __user *pathname,
68202 @@ -625,7 +652,7 @@ retry:
68203 return error;
68204 error = mnt_want_write(path.mnt);
68205 if (!error) {
68206 - error = removexattr(path.dentry, name);
68207 + error = removexattr(&path, name);
68208 mnt_drop_write(path.mnt);
68209 }
68210 path_put(&path);
68211 @@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68212 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68213 {
68214 struct fd f = fdget(fd);
68215 - struct dentry *dentry;
68216 + struct path *path;
68217 int error = -EBADF;
68218
68219 if (!f.file)
68220 return error;
68221 - dentry = f.file->f_path.dentry;
68222 - audit_inode(NULL, dentry, 0);
68223 + path = &f.file->f_path;
68224 + audit_inode(NULL, path->dentry, 0);
68225 error = mnt_want_write_file(f.file);
68226 if (!error) {
68227 - error = removexattr(dentry, name);
68228 + error = removexattr(path, name);
68229 mnt_drop_write_file(f.file);
68230 }
68231 fdput(f);
68232 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68233 index 79c9819..22226b4 100644
68234 --- a/fs/xfs/libxfs/xfs_bmap.c
68235 +++ b/fs/xfs/libxfs/xfs_bmap.c
68236 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68237
68238 #else
68239 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68240 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68241 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68242 #endif /* DEBUG */
68243
68244 /*
68245 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68246 index f1b69ed..3d0222f 100644
68247 --- a/fs/xfs/xfs_dir2_readdir.c
68248 +++ b/fs/xfs/xfs_dir2_readdir.c
68249 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68250 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68251 filetype = dp->d_ops->sf_get_ftype(sfep);
68252 ctx->pos = off & 0x7fffffff;
68253 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68254 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68255 + char name[sfep->namelen];
68256 + memcpy(name, sfep->name, sfep->namelen);
68257 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68258 + return 0;
68259 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68260 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68261 return 0;
68262 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68263 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68264 index 24c926b6..8726af88 100644
68265 --- a/fs/xfs/xfs_ioctl.c
68266 +++ b/fs/xfs/xfs_ioctl.c
68267 @@ -122,7 +122,7 @@ xfs_find_handle(
68268 }
68269
68270 error = -EFAULT;
68271 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68272 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68273 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68274 goto out_put;
68275
68276 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68277 index 6a51619..9592e1b 100644
68278 --- a/fs/xfs/xfs_linux.h
68279 +++ b/fs/xfs/xfs_linux.h
68280 @@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68281 * of the compiler which do not like us using do_div in the middle
68282 * of large functions.
68283 */
68284 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68285 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68286 {
68287 __u32 mod;
68288
68289 @@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68290 return 0;
68291 }
68292 #else
68293 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68294 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68295 {
68296 __u32 mod;
68297
68298 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68299 new file mode 100644
68300 index 0000000..31f8fe4
68301 --- /dev/null
68302 +++ b/grsecurity/Kconfig
68303 @@ -0,0 +1,1182 @@
68304 +#
68305 +# grecurity configuration
68306 +#
68307 +menu "Memory Protections"
68308 +depends on GRKERNSEC
68309 +
68310 +config GRKERNSEC_KMEM
68311 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68312 + default y if GRKERNSEC_CONFIG_AUTO
68313 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68314 + help
68315 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68316 + be written to or read from to modify or leak the contents of the running
68317 + kernel. /dev/port will also not be allowed to be opened, writing to
68318 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68319 + If you have module support disabled, enabling this will close up several
68320 + ways that are currently used to insert malicious code into the running
68321 + kernel.
68322 +
68323 + Even with this feature enabled, we still highly recommend that
68324 + you use the RBAC system, as it is still possible for an attacker to
68325 + modify the running kernel through other more obscure methods.
68326 +
68327 + It is highly recommended that you say Y here if you meet all the
68328 + conditions above.
68329 +
68330 +config GRKERNSEC_VM86
68331 + bool "Restrict VM86 mode"
68332 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68333 + depends on X86_32
68334 +
68335 + help
68336 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68337 + make use of a special execution mode on 32bit x86 processors called
68338 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68339 + video cards and will still work with this option enabled. The purpose
68340 + of the option is to prevent exploitation of emulation errors in
68341 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68342 + Nearly all users should be able to enable this option.
68343 +
68344 +config GRKERNSEC_IO
68345 + bool "Disable privileged I/O"
68346 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68347 + depends on X86
68348 + select RTC_CLASS
68349 + select RTC_INTF_DEV
68350 + select RTC_DRV_CMOS
68351 +
68352 + help
68353 + If you say Y here, all ioperm and iopl calls will return an error.
68354 + Ioperm and iopl can be used to modify the running kernel.
68355 + Unfortunately, some programs need this access to operate properly,
68356 + the most notable of which are XFree86 and hwclock. hwclock can be
68357 + remedied by having RTC support in the kernel, so real-time
68358 + clock support is enabled if this option is enabled, to ensure
68359 + that hwclock operates correctly. If hwclock still does not work,
68360 + either update udev or symlink /dev/rtc to /dev/rtc0.
68361 +
68362 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68363 + you may not be able to boot into a graphical environment with this
68364 + option enabled. In this case, you should use the RBAC system instead.
68365 +
68366 +config GRKERNSEC_BPF_HARDEN
68367 + bool "Harden BPF interpreter"
68368 + default y if GRKERNSEC_CONFIG_AUTO
68369 + help
68370 + Unlike previous versions of grsecurity that hardened both the BPF
68371 + interpreted code against corruption at rest as well as the JIT code
68372 + against JIT-spray attacks and attacker-controlled immediate values
68373 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68374 + and will ensure the interpreted code is read-only at rest. This feature
68375 + may be removed at a later time when eBPF stabilizes to entirely revert
68376 + back to the more secure pre-3.16 BPF interpreter/JIT.
68377 +
68378 + If you're using KERNEXEC, it's recommended that you enable this option
68379 + to supplement the hardening of the kernel.
68380 +
68381 +config GRKERNSEC_PERF_HARDEN
68382 + bool "Disable unprivileged PERF_EVENTS usage by default"
68383 + default y if GRKERNSEC_CONFIG_AUTO
68384 + depends on PERF_EVENTS
68385 + help
68386 + If you say Y here, the range of acceptable values for the
68387 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68388 + default to a new value: 3. When the sysctl is set to this value, no
68389 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68390 +
68391 + Though PERF_EVENTS can be used legitimately for performance monitoring
68392 + and low-level application profiling, it is forced on regardless of
68393 + configuration, has been at fault for several vulnerabilities, and
68394 + creates new opportunities for side channels and other information leaks.
68395 +
68396 + This feature puts PERF_EVENTS into a secure default state and permits
68397 + the administrator to change out of it temporarily if unprivileged
68398 + application profiling is needed.
68399 +
68400 +config GRKERNSEC_RAND_THREADSTACK
68401 + bool "Insert random gaps between thread stacks"
68402 + default y if GRKERNSEC_CONFIG_AUTO
68403 + depends on PAX_RANDMMAP && !PPC
68404 + help
68405 + If you say Y here, a random-sized gap will be enforced between allocated
68406 + thread stacks. Glibc's NPTL and other threading libraries that
68407 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68408 + The implementation currently provides 8 bits of entropy for the gap.
68409 +
68410 + Many distributions do not compile threaded remote services with the
68411 + -fstack-check argument to GCC, causing the variable-sized stack-based
68412 + allocator, alloca(), to not probe the stack on allocation. This
68413 + permits an unbounded alloca() to skip over any guard page and potentially
68414 + modify another thread's stack reliably. An enforced random gap
68415 + reduces the reliability of such an attack and increases the chance
68416 + that such a read/write to another thread's stack instead lands in
68417 + an unmapped area, causing a crash and triggering grsecurity's
68418 + anti-bruteforcing logic.
68419 +
68420 +config GRKERNSEC_PROC_MEMMAP
68421 + bool "Harden ASLR against information leaks and entropy reduction"
68422 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68423 + depends on PAX_NOEXEC || PAX_ASLR
68424 + help
68425 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68426 + give no information about the addresses of its mappings if
68427 + PaX features that rely on random addresses are enabled on the task.
68428 + In addition to sanitizing this information and disabling other
68429 + dangerous sources of information, this option causes reads of sensitive
68430 + /proc/<pid> entries where the file descriptor was opened in a different
68431 + task than the one performing the read. Such attempts are logged.
68432 + This option also limits argv/env strings for suid/sgid binaries
68433 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68434 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68435 + binaries to prevent alternative mmap layouts from being abused.
68436 +
68437 + If you use PaX it is essential that you say Y here as it closes up
68438 + several holes that make full ASLR useless locally.
68439 +
68440 +
68441 +config GRKERNSEC_KSTACKOVERFLOW
68442 + bool "Prevent kernel stack overflows"
68443 + default y if GRKERNSEC_CONFIG_AUTO
68444 + depends on !IA64 && 64BIT
68445 + help
68446 + If you say Y here, the kernel's process stacks will be allocated
68447 + with vmalloc instead of the kernel's default allocator. This
68448 + introduces guard pages that in combination with the alloca checking
68449 + of the STACKLEAK feature prevents all forms of kernel process stack
68450 + overflow abuse. Note that this is different from kernel stack
68451 + buffer overflows.
68452 +
68453 +config GRKERNSEC_BRUTE
68454 + bool "Deter exploit bruteforcing"
68455 + default y if GRKERNSEC_CONFIG_AUTO
68456 + help
68457 + If you say Y here, attempts to bruteforce exploits against forking
68458 + daemons such as apache or sshd, as well as against suid/sgid binaries
68459 + will be deterred. When a child of a forking daemon is killed by PaX
68460 + or crashes due to an illegal instruction or other suspicious signal,
68461 + the parent process will be delayed 30 seconds upon every subsequent
68462 + fork until the administrator is able to assess the situation and
68463 + restart the daemon.
68464 + In the suid/sgid case, the attempt is logged, the user has all their
68465 + existing instances of the suid/sgid binary terminated and will
68466 + be unable to execute any suid/sgid binaries for 15 minutes.
68467 +
68468 + It is recommended that you also enable signal logging in the auditing
68469 + section so that logs are generated when a process triggers a suspicious
68470 + signal.
68471 + If the sysctl option is enabled, a sysctl option with name
68472 + "deter_bruteforce" is created.
68473 +
68474 +config GRKERNSEC_MODHARDEN
68475 + bool "Harden module auto-loading"
68476 + default y if GRKERNSEC_CONFIG_AUTO
68477 + depends on MODULES
68478 + help
68479 + If you say Y here, module auto-loading in response to use of some
68480 + feature implemented by an unloaded module will be restricted to
68481 + root users. Enabling this option helps defend against attacks
68482 + by unprivileged users who abuse the auto-loading behavior to
68483 + cause a vulnerable module to load that is then exploited.
68484 +
68485 + If this option prevents a legitimate use of auto-loading for a
68486 + non-root user, the administrator can execute modprobe manually
68487 + with the exact name of the module mentioned in the alert log.
68488 + Alternatively, the administrator can add the module to the list
68489 + of modules loaded at boot by modifying init scripts.
68490 +
68491 + Modification of init scripts will most likely be needed on
68492 + Ubuntu servers with encrypted home directory support enabled,
68493 + as the first non-root user logging in will cause the ecb(aes),
68494 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68495 +
68496 +config GRKERNSEC_HIDESYM
68497 + bool "Hide kernel symbols"
68498 + default y if GRKERNSEC_CONFIG_AUTO
68499 + select PAX_USERCOPY_SLABS
68500 + help
68501 + If you say Y here, getting information on loaded modules, and
68502 + displaying all kernel symbols through a syscall will be restricted
68503 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68504 + /proc/kallsyms will be restricted to the root user. The RBAC
68505 + system can hide that entry even from root.
68506 +
68507 + This option also prevents leaking of kernel addresses through
68508 + several /proc entries.
68509 +
68510 + Note that this option is only effective provided the following
68511 + conditions are met:
68512 + 1) The kernel using grsecurity is not precompiled by some distribution
68513 + 2) You have also enabled GRKERNSEC_DMESG
68514 + 3) You are using the RBAC system and hiding other files such as your
68515 + kernel image and System.map. Alternatively, enabling this option
68516 + causes the permissions on /boot, /lib/modules, and the kernel
68517 + source directory to change at compile time to prevent
68518 + reading by non-root users.
68519 + If the above conditions are met, this option will aid in providing a
68520 + useful protection against local kernel exploitation of overflows
68521 + and arbitrary read/write vulnerabilities.
68522 +
68523 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68524 + in addition to this feature.
68525 +
68526 +config GRKERNSEC_RANDSTRUCT
68527 + bool "Randomize layout of sensitive kernel structures"
68528 + default y if GRKERNSEC_CONFIG_AUTO
68529 + select GRKERNSEC_HIDESYM
68530 + select MODVERSIONS if MODULES
68531 + help
68532 + If you say Y here, the layouts of a number of sensitive kernel
68533 + structures (task, fs, cred, etc) and all structures composed entirely
68534 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68535 + This can introduce the requirement of an additional infoleak
68536 + vulnerability for exploits targeting these structure types.
68537 +
68538 + Enabling this feature will introduce some performance impact, slightly
68539 + increase memory usage, and prevent the use of forensic tools like
68540 + Volatility against the system (unless the kernel source tree isn't
68541 + cleaned after kernel installation).
68542 +
68543 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68544 + It remains after a make clean to allow for external modules to be compiled
68545 + with the existing seed and will be removed by a make mrproper or
68546 + make distclean.
68547 +
68548 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68549 + to install the supporting headers explicitly in addition to the normal
68550 + gcc package.
68551 +
68552 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68553 + bool "Use cacheline-aware structure randomization"
68554 + depends on GRKERNSEC_RANDSTRUCT
68555 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68556 + help
68557 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68558 + at restricting randomization to cacheline-sized groups of elements. It
68559 + will further not randomize bitfields in structures. This reduces the
68560 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68561 +
68562 +config GRKERNSEC_KERN_LOCKOUT
68563 + bool "Active kernel exploit response"
68564 + default y if GRKERNSEC_CONFIG_AUTO
68565 + depends on X86 || ARM || PPC || SPARC
68566 + help
68567 + If you say Y here, when a PaX alert is triggered due to suspicious
68568 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68569 + or an OOPS occurs due to bad memory accesses, instead of just
68570 + terminating the offending process (and potentially allowing
68571 + a subsequent exploit from the same user), we will take one of two
68572 + actions:
68573 + If the user was root, we will panic the system
68574 + If the user was non-root, we will log the attempt, terminate
68575 + all processes owned by the user, then prevent them from creating
68576 + any new processes until the system is restarted
68577 + This deters repeated kernel exploitation/bruteforcing attempts
68578 + and is useful for later forensics.
68579 +
68580 +config GRKERNSEC_OLD_ARM_USERLAND
68581 + bool "Old ARM userland compatibility"
68582 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68583 + help
68584 + If you say Y here, stubs of executable code to perform such operations
68585 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68586 + table. This is unfortunately needed for old ARM userland meant to run
68587 + across a wide range of processors. Without this option enabled,
68588 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68589 + which is enough for Linaro userlands or other userlands designed for v6
68590 + and newer ARM CPUs. It's recommended that you try without this option enabled
68591 + first, and only enable it if your userland does not boot (it will likely fail
68592 + at init time).
68593 +
68594 +endmenu
68595 +menu "Role Based Access Control Options"
68596 +depends on GRKERNSEC
68597 +
68598 +config GRKERNSEC_RBAC_DEBUG
68599 + bool
68600 +
68601 +config GRKERNSEC_NO_RBAC
68602 + bool "Disable RBAC system"
68603 + help
68604 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68605 + preventing the RBAC system from being enabled. You should only say Y
68606 + here if you have no intention of using the RBAC system, so as to prevent
68607 + an attacker with root access from misusing the RBAC system to hide files
68608 + and processes when loadable module support and /dev/[k]mem have been
68609 + locked down.
68610 +
68611 +config GRKERNSEC_ACL_HIDEKERN
68612 + bool "Hide kernel processes"
68613 + help
68614 + If you say Y here, all kernel threads will be hidden to all
68615 + processes but those whose subject has the "view hidden processes"
68616 + flag.
68617 +
68618 +config GRKERNSEC_ACL_MAXTRIES
68619 + int "Maximum tries before password lockout"
68620 + default 3
68621 + help
68622 + This option enforces the maximum number of times a user can attempt
68623 + to authorize themselves with the grsecurity RBAC system before being
68624 + denied the ability to attempt authorization again for a specified time.
68625 + The lower the number, the harder it will be to brute-force a password.
68626 +
68627 +config GRKERNSEC_ACL_TIMEOUT
68628 + int "Time to wait after max password tries, in seconds"
68629 + default 30
68630 + help
68631 + This option specifies the time the user must wait after attempting to
68632 + authorize to the RBAC system with the maximum number of invalid
68633 + passwords. The higher the number, the harder it will be to brute-force
68634 + a password.
68635 +
68636 +endmenu
68637 +menu "Filesystem Protections"
68638 +depends on GRKERNSEC
68639 +
68640 +config GRKERNSEC_PROC
68641 + bool "Proc restrictions"
68642 + default y if GRKERNSEC_CONFIG_AUTO
68643 + help
68644 + If you say Y here, the permissions of the /proc filesystem
68645 + will be altered to enhance system security and privacy. You MUST
68646 + choose either a user only restriction or a user and group restriction.
68647 + Depending upon the option you choose, you can either restrict users to
68648 + see only the processes they themselves run, or choose a group that can
68649 + view all processes and files normally restricted to root if you choose
68650 + the "restrict to user only" option. NOTE: If you're running identd or
68651 + ntpd as a non-root user, you will have to run it as the group you
68652 + specify here.
68653 +
68654 +config GRKERNSEC_PROC_USER
68655 + bool "Restrict /proc to user only"
68656 + depends on GRKERNSEC_PROC
68657 + help
68658 + If you say Y here, non-root users will only be able to view their own
68659 + processes, and restricts them from viewing network-related information,
68660 + and viewing kernel symbol and module information.
68661 +
68662 +config GRKERNSEC_PROC_USERGROUP
68663 + bool "Allow special group"
68664 + default y if GRKERNSEC_CONFIG_AUTO
68665 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68666 + help
68667 + If you say Y here, you will be able to select a group that will be
68668 + able to view all processes and network-related information. If you've
68669 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68670 + remain hidden. This option is useful if you want to run identd as
68671 + a non-root user. The group you select may also be chosen at boot time
68672 + via "grsec_proc_gid=" on the kernel commandline.
68673 +
68674 +config GRKERNSEC_PROC_GID
68675 + int "GID for special group"
68676 + depends on GRKERNSEC_PROC_USERGROUP
68677 + default 1001
68678 +
68679 +config GRKERNSEC_PROC_ADD
68680 + bool "Additional restrictions"
68681 + default y if GRKERNSEC_CONFIG_AUTO
68682 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68683 + help
68684 + If you say Y here, additional restrictions will be placed on
68685 + /proc that keep normal users from viewing device information and
68686 + slabinfo information that could be useful for exploits.
68687 +
68688 +config GRKERNSEC_LINK
68689 + bool "Linking restrictions"
68690 + default y if GRKERNSEC_CONFIG_AUTO
68691 + help
68692 + If you say Y here, /tmp race exploits will be prevented, since users
68693 + will no longer be able to follow symlinks owned by other users in
68694 + world-writable +t directories (e.g. /tmp), unless the owner of the
68695 + symlink is the owner of the directory. users will also not be
68696 + able to hardlink to files they do not own. If the sysctl option is
68697 + enabled, a sysctl option with name "linking_restrictions" is created.
68698 +
68699 +config GRKERNSEC_SYMLINKOWN
68700 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68701 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68702 + help
68703 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68704 + that prevents it from being used as a security feature. As Apache
68705 + verifies the symlink by performing a stat() against the target of
68706 + the symlink before it is followed, an attacker can setup a symlink
68707 + to point to a same-owned file, then replace the symlink with one
68708 + that targets another user's file just after Apache "validates" the
68709 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68710 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68711 + will be in place for the group you specify. If the sysctl option
68712 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68713 + created.
68714 +
68715 +config GRKERNSEC_SYMLINKOWN_GID
68716 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68717 + depends on GRKERNSEC_SYMLINKOWN
68718 + default 1006
68719 + help
68720 + Setting this GID determines what group kernel-enforced
68721 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68722 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68723 +
68724 +config GRKERNSEC_FIFO
68725 + bool "FIFO restrictions"
68726 + default y if GRKERNSEC_CONFIG_AUTO
68727 + help
68728 + If you say Y here, users will not be able to write to FIFOs they don't
68729 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68730 + the FIFO is the same owner of the directory it's held in. If the sysctl
68731 + option is enabled, a sysctl option with name "fifo_restrictions" is
68732 + created.
68733 +
68734 +config GRKERNSEC_SYSFS_RESTRICT
68735 + bool "Sysfs/debugfs restriction"
68736 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68737 + depends on SYSFS
68738 + help
68739 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68740 + any filesystem normally mounted under it (e.g. debugfs) will be
68741 + mostly accessible only by root. These filesystems generally provide access
68742 + to hardware and debug information that isn't appropriate for unprivileged
68743 + users of the system. Sysfs and debugfs have also become a large source
68744 + of new vulnerabilities, ranging from infoleaks to local compromise.
68745 + There has been very little oversight with an eye toward security involved
68746 + in adding new exporters of information to these filesystems, so their
68747 + use is discouraged.
68748 + For reasons of compatibility, a few directories have been whitelisted
68749 + for access by non-root users:
68750 + /sys/fs/selinux
68751 + /sys/fs/fuse
68752 + /sys/devices/system/cpu
68753 +
68754 +config GRKERNSEC_ROFS
68755 + bool "Runtime read-only mount protection"
68756 + depends on SYSCTL
68757 + help
68758 + If you say Y here, a sysctl option with name "romount_protect" will
68759 + be created. By setting this option to 1 at runtime, filesystems
68760 + will be protected in the following ways:
68761 + * No new writable mounts will be allowed
68762 + * Existing read-only mounts won't be able to be remounted read/write
68763 + * Write operations will be denied on all block devices
68764 + This option acts independently of grsec_lock: once it is set to 1,
68765 + it cannot be turned off. Therefore, please be mindful of the resulting
68766 + behavior if this option is enabled in an init script on a read-only
68767 + filesystem.
68768 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68769 + and GRKERNSEC_IO should be enabled and module loading disabled via
68770 + config or at runtime.
68771 + This feature is mainly intended for secure embedded systems.
68772 +
68773 +
68774 +config GRKERNSEC_DEVICE_SIDECHANNEL
68775 + bool "Eliminate stat/notify-based device sidechannels"
68776 + default y if GRKERNSEC_CONFIG_AUTO
68777 + help
68778 + If you say Y here, timing analyses on block or character
68779 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68780 + will be thwarted for unprivileged users. If a process without
68781 + CAP_MKNOD stats such a device, the last access and last modify times
68782 + will match the device's create time. No access or modify events
68783 + will be triggered through inotify/dnotify/fanotify for such devices.
68784 + This feature will prevent attacks that may at a minimum
68785 + allow an attacker to determine the administrator's password length.
68786 +
68787 +config GRKERNSEC_CHROOT
68788 + bool "Chroot jail restrictions"
68789 + default y if GRKERNSEC_CONFIG_AUTO
68790 + help
68791 + If you say Y here, you will be able to choose several options that will
68792 + make breaking out of a chrooted jail much more difficult. If you
68793 + encounter no software incompatibilities with the following options, it
68794 + is recommended that you enable each one.
68795 +
68796 + Note that the chroot restrictions are not intended to apply to "chroots"
68797 + to directories that are simple bind mounts of the global root filesystem.
68798 + For several other reasons, a user shouldn't expect any significant
68799 + security by performing such a chroot.
68800 +
68801 +config GRKERNSEC_CHROOT_MOUNT
68802 + bool "Deny mounts"
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
68807 + mount or remount filesystems. If the sysctl option is enabled, a
68808 + sysctl option with name "chroot_deny_mount" is created.
68809 +
68810 +config GRKERNSEC_CHROOT_DOUBLE
68811 + bool "Deny double-chroots"
68812 + default y if GRKERNSEC_CONFIG_AUTO
68813 + depends on GRKERNSEC_CHROOT
68814 + help
68815 + If you say Y here, processes inside a chroot will not be able to chroot
68816 + again outside the chroot. This is a widely used method of breaking
68817 + out of a chroot jail and should not be allowed. If the sysctl
68818 + option is enabled, a sysctl option with name
68819 + "chroot_deny_chroot" is created.
68820 +
68821 +config GRKERNSEC_CHROOT_PIVOT
68822 + bool "Deny pivot_root in chroot"
68823 + default y if GRKERNSEC_CONFIG_AUTO
68824 + depends on GRKERNSEC_CHROOT
68825 + help
68826 + If you say Y here, processes inside a chroot will not be able to use
68827 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68828 + works similar to chroot in that it changes the root filesystem. This
68829 + function could be misused in a chrooted process to attempt to break out
68830 + of the chroot, and therefore should not be allowed. If the sysctl
68831 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68832 + created.
68833 +
68834 +config GRKERNSEC_CHROOT_CHDIR
68835 + bool "Enforce chdir(\"/\") on all chroots"
68836 + default y if GRKERNSEC_CONFIG_AUTO
68837 + depends on GRKERNSEC_CHROOT
68838 + help
68839 + If you say Y here, the current working directory of all newly-chrooted
68840 + applications will be set to the the root directory of the chroot.
68841 + The man page on chroot(2) states:
68842 + Note that this call does not change the current working
68843 + directory, so that `.' can be outside the tree rooted at
68844 + `/'. In particular, the super-user can escape from a
68845 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68846 +
68847 + It is recommended that you say Y here, since it's not known to break
68848 + any software. If the sysctl option is enabled, a sysctl option with
68849 + name "chroot_enforce_chdir" is created.
68850 +
68851 +config GRKERNSEC_CHROOT_CHMOD
68852 + bool "Deny (f)chmod +s"
68853 + default y if GRKERNSEC_CONFIG_AUTO
68854 + depends on GRKERNSEC_CHROOT
68855 + help
68856 + If you say Y here, processes inside a chroot will not be able to chmod
68857 + or fchmod files to make them have suid or sgid bits. This protects
68858 + against another published method of breaking a chroot. If the sysctl
68859 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68860 + created.
68861 +
68862 +config GRKERNSEC_CHROOT_FCHDIR
68863 + bool "Deny fchdir and fhandle out of chroot"
68864 + default y if GRKERNSEC_CONFIG_AUTO
68865 + depends on GRKERNSEC_CHROOT
68866 + help
68867 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68868 + to a file descriptor of the chrooting process that points to a directory
68869 + outside the filesystem will be stopped. Additionally, this option prevents
68870 + use of the recently-created syscall for opening files by a guessable "file
68871 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68872 + with name "chroot_deny_fchdir" is created.
68873 +
68874 +config GRKERNSEC_CHROOT_MKNOD
68875 + bool "Deny mknod"
68876 + default y if GRKERNSEC_CONFIG_AUTO
68877 + depends on GRKERNSEC_CHROOT
68878 + help
68879 + If you say Y here, processes inside a chroot will not be allowed to
68880 + mknod. The problem with using mknod inside a chroot is that it
68881 + would allow an attacker to create a device entry that is the same
68882 + as one on the physical root of your system, which could range from
68883 + anything from the console device to a device for your harddrive (which
68884 + they could then use to wipe the drive or steal data). It is recommended
68885 + that you say Y here, unless you run into software incompatibilities.
68886 + If the sysctl option is enabled, a sysctl option with name
68887 + "chroot_deny_mknod" is created.
68888 +
68889 +config GRKERNSEC_CHROOT_SHMAT
68890 + bool "Deny shmat() out of chroot"
68891 + default y if GRKERNSEC_CONFIG_AUTO
68892 + depends on GRKERNSEC_CHROOT
68893 + help
68894 + If you say Y here, processes inside a chroot will not be able to attach
68895 + to shared memory segments that were created outside of the chroot jail.
68896 + It is recommended that you say Y here. If the sysctl option is enabled,
68897 + a sysctl option with name "chroot_deny_shmat" is created.
68898 +
68899 +config GRKERNSEC_CHROOT_UNIX
68900 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68901 + default y if GRKERNSEC_CONFIG_AUTO
68902 + depends on GRKERNSEC_CHROOT
68903 + help
68904 + If you say Y here, processes inside a chroot will not be able to
68905 + connect to abstract (meaning not belonging to a filesystem) Unix
68906 + domain sockets that were bound outside of a chroot. It is recommended
68907 + that you say Y here. If the sysctl option is enabled, a sysctl option
68908 + with name "chroot_deny_unix" is created.
68909 +
68910 +config GRKERNSEC_CHROOT_FINDTASK
68911 + bool "Protect outside processes"
68912 + default y if GRKERNSEC_CONFIG_AUTO
68913 + depends on GRKERNSEC_CHROOT
68914 + help
68915 + If you say Y here, processes inside a chroot will not be able to
68916 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68917 + getsid, or view any process outside of the chroot. If the sysctl
68918 + option is enabled, a sysctl option with name "chroot_findtask" is
68919 + created.
68920 +
68921 +config GRKERNSEC_CHROOT_NICE
68922 + bool "Restrict priority changes"
68923 + default y if GRKERNSEC_CONFIG_AUTO
68924 + depends on GRKERNSEC_CHROOT
68925 + help
68926 + If you say Y here, processes inside a chroot will not be able to raise
68927 + the priority of processes in the chroot, or alter the priority of
68928 + processes outside the chroot. This provides more security than simply
68929 + removing CAP_SYS_NICE from the process' capability set. If the
68930 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68931 + is created.
68932 +
68933 +config GRKERNSEC_CHROOT_SYSCTL
68934 + bool "Deny sysctl writes"
68935 + default y if GRKERNSEC_CONFIG_AUTO
68936 + depends on GRKERNSEC_CHROOT
68937 + help
68938 + If you say Y here, an attacker in a chroot will not be able to
68939 + write to sysctl entries, either by sysctl(2) or through a /proc
68940 + interface. It is strongly recommended that you say Y here. If the
68941 + sysctl option is enabled, a sysctl option with name
68942 + "chroot_deny_sysctl" is created.
68943 +
68944 +config GRKERNSEC_CHROOT_RENAME
68945 + bool "Deny bad renames"
68946 + default y if GRKERNSEC_CONFIG_AUTO
68947 + depends on GRKERNSEC_CHROOT
68948 + help
68949 + If you say Y here, an attacker in a chroot will not be able to
68950 + abuse the ability to create double chroots to break out of the
68951 + chroot by exploiting a race condition between a rename of a directory
68952 + within a chroot against an open of a symlink with relative path
68953 + components. This feature will likewise prevent an accomplice outside
68954 + a chroot from enabling a user inside the chroot to break out and make
68955 + use of their credentials on the global filesystem. Enabling this
68956 + feature is essential to prevent root users from breaking out of a
68957 + chroot. If the sysctl option is enabled, a sysctl option with name
68958 + "chroot_deny_bad_rename" is created.
68959 +
68960 +config GRKERNSEC_CHROOT_CAPS
68961 + bool "Capability restrictions"
68962 + default y if GRKERNSEC_CONFIG_AUTO
68963 + depends on GRKERNSEC_CHROOT
68964 + help
68965 + If you say Y here, the capabilities on all processes within a
68966 + chroot jail will be lowered to stop module insertion, raw i/o,
68967 + system and net admin tasks, rebooting the system, modifying immutable
68968 + files, modifying IPC owned by another, and changing the system time.
68969 + This is left an option because it can break some apps. Disable this
68970 + if your chrooted apps are having problems performing those kinds of
68971 + tasks. If the sysctl option is enabled, a sysctl option with
68972 + name "chroot_caps" is created.
68973 +
68974 +config GRKERNSEC_CHROOT_INITRD
68975 + bool "Exempt initrd tasks from restrictions"
68976 + default y if GRKERNSEC_CONFIG_AUTO
68977 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68978 + help
68979 + If you say Y here, tasks started prior to init will be exempted from
68980 + grsecurity's chroot restrictions. This option is mainly meant to
68981 + resolve Plymouth's performing privileged operations unnecessarily
68982 + in a chroot.
68983 +
68984 +endmenu
68985 +menu "Kernel Auditing"
68986 +depends on GRKERNSEC
68987 +
68988 +config GRKERNSEC_AUDIT_GROUP
68989 + bool "Single group for auditing"
68990 + help
68991 + If you say Y here, the exec and chdir logging features will only operate
68992 + on a group you specify. This option is recommended if you only want to
68993 + watch certain users instead of having a large amount of logs from the
68994 + entire system. If the sysctl option is enabled, a sysctl option with
68995 + name "audit_group" is created.
68996 +
68997 +config GRKERNSEC_AUDIT_GID
68998 + int "GID for auditing"
68999 + depends on GRKERNSEC_AUDIT_GROUP
69000 + default 1007
69001 +
69002 +config GRKERNSEC_EXECLOG
69003 + bool "Exec logging"
69004 + help
69005 + If you say Y here, all execve() calls will be logged (since the
69006 + other exec*() calls are frontends to execve(), all execution
69007 + will be logged). Useful for shell-servers that like to keep track
69008 + of their users. If the sysctl option is enabled, a sysctl option with
69009 + name "exec_logging" is created.
69010 + WARNING: This option when enabled will produce a LOT of logs, especially
69011 + on an active system.
69012 +
69013 +config GRKERNSEC_RESLOG
69014 + bool "Resource logging"
69015 + default y if GRKERNSEC_CONFIG_AUTO
69016 + help
69017 + If you say Y here, all attempts to overstep resource limits will
69018 + be logged with the resource name, the requested size, and the current
69019 + limit. It is highly recommended that you say Y here. If the sysctl
69020 + option is enabled, a sysctl option with name "resource_logging" is
69021 + created. If the RBAC system is enabled, the sysctl value is ignored.
69022 +
69023 +config GRKERNSEC_CHROOT_EXECLOG
69024 + bool "Log execs within chroot"
69025 + help
69026 + If you say Y here, all executions inside a chroot jail will be logged
69027 + to syslog. This can cause a large amount of logs if certain
69028 + applications (eg. djb's daemontools) are installed on the system, and
69029 + is therefore left as an option. If the sysctl option is enabled, a
69030 + sysctl option with name "chroot_execlog" is created.
69031 +
69032 +config GRKERNSEC_AUDIT_PTRACE
69033 + bool "Ptrace logging"
69034 + help
69035 + If you say Y here, all attempts to attach to a process via ptrace
69036 + will be logged. If the sysctl option is enabled, a sysctl option
69037 + with name "audit_ptrace" is created.
69038 +
69039 +config GRKERNSEC_AUDIT_CHDIR
69040 + bool "Chdir logging"
69041 + help
69042 + If you say Y here, all chdir() calls will be logged. If the sysctl
69043 + option is enabled, a sysctl option with name "audit_chdir" is created.
69044 +
69045 +config GRKERNSEC_AUDIT_MOUNT
69046 + bool "(Un)Mount logging"
69047 + help
69048 + If you say Y here, all mounts and unmounts will be logged. If the
69049 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69050 + created.
69051 +
69052 +config GRKERNSEC_SIGNAL
69053 + bool "Signal logging"
69054 + default y if GRKERNSEC_CONFIG_AUTO
69055 + help
69056 + If you say Y here, certain important signals will be logged, such as
69057 + SIGSEGV, which will as a result inform you of when a error in a program
69058 + occurred, which in some cases could mean a possible exploit attempt.
69059 + If the sysctl option is enabled, a sysctl option with name
69060 + "signal_logging" is created.
69061 +
69062 +config GRKERNSEC_FORKFAIL
69063 + bool "Fork failure logging"
69064 + help
69065 + If you say Y here, all failed fork() attempts will be logged.
69066 + This could suggest a fork bomb, or someone attempting to overstep
69067 + their process limit. If the sysctl option is enabled, a sysctl option
69068 + with name "forkfail_logging" is created.
69069 +
69070 +config GRKERNSEC_TIME
69071 + bool "Time change logging"
69072 + default y if GRKERNSEC_CONFIG_AUTO
69073 + help
69074 + If you say Y here, any changes of the system clock will be logged.
69075 + If the sysctl option is enabled, a sysctl option with name
69076 + "timechange_logging" is created.
69077 +
69078 +config GRKERNSEC_PROC_IPADDR
69079 + bool "/proc/<pid>/ipaddr support"
69080 + default y if GRKERNSEC_CONFIG_AUTO
69081 + help
69082 + If you say Y here, a new entry will be added to each /proc/<pid>
69083 + directory that contains the IP address of the person using the task.
69084 + The IP is carried across local TCP and AF_UNIX stream sockets.
69085 + This information can be useful for IDS/IPSes to perform remote response
69086 + to a local attack. The entry is readable by only the owner of the
69087 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69088 + the RBAC system), and thus does not create privacy concerns.
69089 +
69090 +config GRKERNSEC_RWXMAP_LOG
69091 + bool 'Denied RWX mmap/mprotect logging'
69092 + default y if GRKERNSEC_CONFIG_AUTO
69093 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69094 + help
69095 + If you say Y here, calls to mmap() and mprotect() with explicit
69096 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69097 + denied by the PAX_MPROTECT feature. This feature will also
69098 + log other problematic scenarios that can occur when PAX_MPROTECT
69099 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69100 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69101 + is created.
69102 +
69103 +endmenu
69104 +
69105 +menu "Executable Protections"
69106 +depends on GRKERNSEC
69107 +
69108 +config GRKERNSEC_DMESG
69109 + bool "Dmesg(8) restriction"
69110 + default y if GRKERNSEC_CONFIG_AUTO
69111 + help
69112 + If you say Y here, non-root users will not be able to use dmesg(8)
69113 + to view the contents of the kernel's circular log buffer.
69114 + The kernel's log buffer often contains kernel addresses and other
69115 + identifying information useful to an attacker in fingerprinting a
69116 + system for a targeted exploit.
69117 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69118 + created.
69119 +
69120 +config GRKERNSEC_HARDEN_PTRACE
69121 + bool "Deter ptrace-based process snooping"
69122 + default y if GRKERNSEC_CONFIG_AUTO
69123 + help
69124 + If you say Y here, TTY sniffers and other malicious monitoring
69125 + programs implemented through ptrace will be defeated. If you
69126 + have been using the RBAC system, this option has already been
69127 + enabled for several years for all users, with the ability to make
69128 + fine-grained exceptions.
69129 +
69130 + This option only affects the ability of non-root users to ptrace
69131 + processes that are not a descendent of the ptracing process.
69132 + This means that strace ./binary and gdb ./binary will still work,
69133 + but attaching to arbitrary processes will not. If the sysctl
69134 + option is enabled, a sysctl option with name "harden_ptrace" is
69135 + created.
69136 +
69137 +config GRKERNSEC_PTRACE_READEXEC
69138 + bool "Require read access to ptrace sensitive binaries"
69139 + default y if GRKERNSEC_CONFIG_AUTO
69140 + help
69141 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69142 + binaries. This option is useful in environments that
69143 + remove the read bits (e.g. file mode 4711) from suid binaries to
69144 + prevent infoleaking of their contents. This option adds
69145 + consistency to the use of that file mode, as the binary could normally
69146 + be read out when run without privileges while ptracing.
69147 +
69148 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69149 + is created.
69150 +
69151 +config GRKERNSEC_SETXID
69152 + bool "Enforce consistent multithreaded privileges"
69153 + default y if GRKERNSEC_CONFIG_AUTO
69154 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69155 + help
69156 + If you say Y here, a change from a root uid to a non-root uid
69157 + in a multithreaded application will cause the resulting uids,
69158 + gids, supplementary groups, and capabilities in that thread
69159 + to be propagated to the other threads of the process. In most
69160 + cases this is unnecessary, as glibc will emulate this behavior
69161 + on behalf of the application. Other libcs do not act in the
69162 + same way, allowing the other threads of the process to continue
69163 + running with root privileges. If the sysctl option is enabled,
69164 + a sysctl option with name "consistent_setxid" is created.
69165 +
69166 +config GRKERNSEC_HARDEN_IPC
69167 + bool "Disallow access to overly-permissive IPC objects"
69168 + default y if GRKERNSEC_CONFIG_AUTO
69169 + depends on SYSVIPC
69170 + help
69171 + If you say Y here, access to overly-permissive IPC objects (shared
69172 + memory, message queues, and semaphores) will be denied for processes
69173 + given the following criteria beyond normal permission checks:
69174 + 1) If the IPC object is world-accessible and the euid doesn't match
69175 + that of the creator or current uid for the IPC object
69176 + 2) If the IPC object is group-accessible and the egid doesn't
69177 + match that of the creator or current gid for the IPC object
69178 + It's a common error to grant too much permission to these objects,
69179 + with impact ranging from denial of service and information leaking to
69180 + privilege escalation. This feature was developed in response to
69181 + research by Tim Brown:
69182 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69183 + who found hundreds of such insecure usages. Processes with
69184 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69185 + If the sysctl option is enabled, a sysctl option with name
69186 + "harden_ipc" is created.
69187 +
69188 +config GRKERNSEC_TPE
69189 + bool "Trusted Path Execution (TPE)"
69190 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69191 + help
69192 + If you say Y here, you will be able to choose a gid to add to the
69193 + supplementary groups of users you want to mark as "untrusted."
69194 + These users will not be able to execute any files that are not in
69195 + root-owned directories writable only by root. If the sysctl option
69196 + is enabled, a sysctl option with name "tpe" is created.
69197 +
69198 +config GRKERNSEC_TPE_ALL
69199 + bool "Partially restrict all non-root users"
69200 + depends on GRKERNSEC_TPE
69201 + help
69202 + If you say Y here, all non-root users will be covered under
69203 + a weaker TPE restriction. This is separate from, and in addition to,
69204 + the main TPE options that you have selected elsewhere. Thus, if a
69205 + "trusted" GID is chosen, this restriction applies to even that GID.
69206 + Under this restriction, all non-root users will only be allowed to
69207 + execute files in directories they own that are not group or
69208 + world-writable, or in directories owned by root and writable only by
69209 + root. If the sysctl option is enabled, a sysctl option with name
69210 + "tpe_restrict_all" is created.
69211 +
69212 +config GRKERNSEC_TPE_INVERT
69213 + bool "Invert GID option"
69214 + depends on GRKERNSEC_TPE
69215 + help
69216 + If you say Y here, the group you specify in the TPE configuration will
69217 + decide what group TPE restrictions will be *disabled* for. This
69218 + option is useful if you want TPE restrictions to be applied to most
69219 + users on the system. If the sysctl option is enabled, a sysctl option
69220 + with name "tpe_invert" is created. Unlike other sysctl options, this
69221 + entry will default to on for backward-compatibility.
69222 +
69223 +config GRKERNSEC_TPE_GID
69224 + int
69225 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69226 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69227 +
69228 +config GRKERNSEC_TPE_UNTRUSTED_GID
69229 + int "GID for TPE-untrusted users"
69230 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69231 + default 1005
69232 + help
69233 + Setting this GID determines what group TPE restrictions will be
69234 + *enabled* for. If the sysctl option is enabled, a sysctl option
69235 + with name "tpe_gid" is created.
69236 +
69237 +config GRKERNSEC_TPE_TRUSTED_GID
69238 + int "GID for TPE-trusted users"
69239 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69240 + default 1005
69241 + help
69242 + Setting this GID determines what group TPE restrictions will be
69243 + *disabled* for. If the sysctl option is enabled, a sysctl option
69244 + with name "tpe_gid" is created.
69245 +
69246 +endmenu
69247 +menu "Network Protections"
69248 +depends on GRKERNSEC
69249 +
69250 +config GRKERNSEC_BLACKHOLE
69251 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69252 + default y if GRKERNSEC_CONFIG_AUTO
69253 + depends on NET
69254 + help
69255 + If you say Y here, neither TCP resets nor ICMP
69256 + destination-unreachable packets will be sent in response to packets
69257 + sent to ports for which no associated listening process exists.
69258 + It will also prevent the sending of ICMP protocol unreachable packets
69259 + in response to packets with unknown protocols.
69260 + This feature supports both IPV4 and IPV6 and exempts the
69261 + loopback interface from blackholing. Enabling this feature
69262 + makes a host more resilient to DoS attacks and reduces network
69263 + visibility against scanners.
69264 +
69265 + The blackhole feature as-implemented is equivalent to the FreeBSD
69266 + blackhole feature, as it prevents RST responses to all packets, not
69267 + just SYNs. Under most application behavior this causes no
69268 + problems, but applications (like haproxy) may not close certain
69269 + connections in a way that cleanly terminates them on the remote
69270 + end, leaving the remote host in LAST_ACK state. Because of this
69271 + side-effect and to prevent intentional LAST_ACK DoSes, this
69272 + feature also adds automatic mitigation against such attacks.
69273 + The mitigation drastically reduces the amount of time a socket
69274 + can spend in LAST_ACK state. If you're using haproxy and not
69275 + all servers it connects to have this option enabled, consider
69276 + disabling this feature on the haproxy host.
69277 +
69278 + If the sysctl option is enabled, two sysctl options with names
69279 + "ip_blackhole" and "lastack_retries" will be created.
69280 + While "ip_blackhole" takes the standard zero/non-zero on/off
69281 + toggle, "lastack_retries" uses the same kinds of values as
69282 + "tcp_retries1" and "tcp_retries2". The default value of 4
69283 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69284 + state.
69285 +
69286 +config GRKERNSEC_NO_SIMULT_CONNECT
69287 + bool "Disable TCP Simultaneous Connect"
69288 + default y if GRKERNSEC_CONFIG_AUTO
69289 + depends on NET
69290 + help
69291 + If you say Y here, a feature by Willy Tarreau will be enabled that
69292 + removes a weakness in Linux's strict implementation of TCP that
69293 + allows two clients to connect to each other without either entering
69294 + a listening state. The weakness allows an attacker to easily prevent
69295 + a client from connecting to a known server provided the source port
69296 + for the connection is guessed correctly.
69297 +
69298 + As the weakness could be used to prevent an antivirus or IPS from
69299 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69300 + it should be eliminated by enabling this option. Though Linux is
69301 + one of few operating systems supporting simultaneous connect, it
69302 + has no legitimate use in practice and is rarely supported by firewalls.
69303 +
69304 +config GRKERNSEC_SOCKET
69305 + bool "Socket restrictions"
69306 + depends on NET
69307 + help
69308 + If you say Y here, you will be able to choose from several options.
69309 + If you assign a GID on your system and add it to the supplementary
69310 + groups of users you want to restrict socket access to, this patch
69311 + will perform up to three things, based on the option(s) you choose.
69312 +
69313 +config GRKERNSEC_SOCKET_ALL
69314 + bool "Deny any sockets to group"
69315 + depends on GRKERNSEC_SOCKET
69316 + help
69317 + If you say Y here, you will be able to choose a GID of whose users will
69318 + be unable to connect to other hosts from your machine or run server
69319 + applications from your machine. If the sysctl option is enabled, a
69320 + sysctl option with name "socket_all" is created.
69321 +
69322 +config GRKERNSEC_SOCKET_ALL_GID
69323 + int "GID to deny all sockets for"
69324 + depends on GRKERNSEC_SOCKET_ALL
69325 + default 1004
69326 + help
69327 + Here you can choose the GID to disable socket access for. Remember to
69328 + add the users you want socket access disabled for to the GID
69329 + specified here. If the sysctl option is enabled, a sysctl option
69330 + with name "socket_all_gid" is created.
69331 +
69332 +config GRKERNSEC_SOCKET_CLIENT
69333 + bool "Deny client sockets to group"
69334 + depends on GRKERNSEC_SOCKET
69335 + help
69336 + If you say Y here, you will be able to choose a GID of whose users will
69337 + be unable to connect to other hosts from your machine, but will be
69338 + able to run servers. If this option is enabled, all users in the group
69339 + you specify will have to use passive mode when initiating ftp transfers
69340 + from the shell on your machine. If the sysctl option is enabled, a
69341 + sysctl option with name "socket_client" is created.
69342 +
69343 +config GRKERNSEC_SOCKET_CLIENT_GID
69344 + int "GID to deny client sockets for"
69345 + depends on GRKERNSEC_SOCKET_CLIENT
69346 + default 1003
69347 + help
69348 + Here you can choose the GID to disable client socket access for.
69349 + Remember to add the users you want client socket access disabled for to
69350 + the GID specified here. If the sysctl option is enabled, a sysctl
69351 + option with name "socket_client_gid" is created.
69352 +
69353 +config GRKERNSEC_SOCKET_SERVER
69354 + bool "Deny server sockets to group"
69355 + depends on GRKERNSEC_SOCKET
69356 + help
69357 + If you say Y here, you will be able to choose a GID of whose users will
69358 + be unable to run server applications from your machine. If the sysctl
69359 + option is enabled, a sysctl option with name "socket_server" is created.
69360 +
69361 +config GRKERNSEC_SOCKET_SERVER_GID
69362 + int "GID to deny server sockets for"
69363 + depends on GRKERNSEC_SOCKET_SERVER
69364 + default 1002
69365 + help
69366 + Here you can choose the GID to disable server socket access for.
69367 + Remember to add the users you want server socket access disabled for to
69368 + the GID specified here. If the sysctl option is enabled, a sysctl
69369 + option with name "socket_server_gid" is created.
69370 +
69371 +endmenu
69372 +
69373 +menu "Physical Protections"
69374 +depends on GRKERNSEC
69375 +
69376 +config GRKERNSEC_DENYUSB
69377 + bool "Deny new USB connections after toggle"
69378 + default y if GRKERNSEC_CONFIG_AUTO
69379 + depends on SYSCTL && USB_SUPPORT
69380 + help
69381 + If you say Y here, a new sysctl option with name "deny_new_usb"
69382 + will be created. Setting its value to 1 will prevent any new
69383 + USB devices from being recognized by the OS. Any attempted USB
69384 + device insertion will be logged. This option is intended to be
69385 + used against custom USB devices designed to exploit vulnerabilities
69386 + in various USB device drivers.
69387 +
69388 + For greatest effectiveness, this sysctl should be set after any
69389 + relevant init scripts. This option is safe to enable in distros
69390 + as each user can choose whether or not to toggle the sysctl.
69391 +
69392 +config GRKERNSEC_DENYUSB_FORCE
69393 + bool "Reject all USB devices not connected at boot"
69394 + select USB
69395 + depends on GRKERNSEC_DENYUSB
69396 + help
69397 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69398 + that doesn't involve a sysctl entry. This option should only be
69399 + enabled if you're sure you want to deny all new USB connections
69400 + at runtime and don't want to modify init scripts. This should not
69401 + be enabled by distros. It forces the core USB code to be built
69402 + into the kernel image so that all devices connected at boot time
69403 + can be recognized and new USB device connections can be prevented
69404 + prior to init running.
69405 +
69406 +endmenu
69407 +
69408 +menu "Sysctl Support"
69409 +depends on GRKERNSEC && SYSCTL
69410 +
69411 +config GRKERNSEC_SYSCTL
69412 + bool "Sysctl support"
69413 + default y if GRKERNSEC_CONFIG_AUTO
69414 + help
69415 + If you say Y here, you will be able to change the options that
69416 + grsecurity runs with at bootup, without having to recompile your
69417 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69418 + to enable (1) or disable (0) various features. All the sysctl entries
69419 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69420 + All features enabled in the kernel configuration are disabled at boot
69421 + if you do not say Y to the "Turn on features by default" option.
69422 + All options should be set at startup, and the grsec_lock entry should
69423 + be set to a non-zero value after all the options are set.
69424 + *THIS IS EXTREMELY IMPORTANT*
69425 +
69426 +config GRKERNSEC_SYSCTL_DISTRO
69427 + bool "Extra sysctl support for distro makers (READ HELP)"
69428 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69429 + help
69430 + If you say Y here, additional sysctl options will be created
69431 + for features that affect processes running as root. Therefore,
69432 + it is critical when using this option that the grsec_lock entry be
69433 + enabled after boot. Only distros with prebuilt kernel packages
69434 + with this option enabled that can ensure grsec_lock is enabled
69435 + after boot should use this option.
69436 + *Failure to set grsec_lock after boot makes all grsec features
69437 + this option covers useless*
69438 +
69439 + Currently this option creates the following sysctl entries:
69440 + "Disable Privileged I/O": "disable_priv_io"
69441 +
69442 +config GRKERNSEC_SYSCTL_ON
69443 + bool "Turn on features by default"
69444 + default y if GRKERNSEC_CONFIG_AUTO
69445 + depends on GRKERNSEC_SYSCTL
69446 + help
69447 + If you say Y here, instead of having all features enabled in the
69448 + kernel configuration disabled at boot time, the features will be
69449 + enabled at boot time. It is recommended you say Y here unless
69450 + there is some reason you would want all sysctl-tunable features to
69451 + be disabled by default. As mentioned elsewhere, it is important
69452 + to enable the grsec_lock entry once you have finished modifying
69453 + the sysctl entries.
69454 +
69455 +endmenu
69456 +menu "Logging Options"
69457 +depends on GRKERNSEC
69458 +
69459 +config GRKERNSEC_FLOODTIME
69460 + int "Seconds in between log messages (minimum)"
69461 + default 10
69462 + help
69463 + This option allows you to enforce the number of seconds between
69464 + grsecurity log messages. The default should be suitable for most
69465 + people, however, if you choose to change it, choose a value small enough
69466 + to allow informative logs to be produced, but large enough to
69467 + prevent flooding.
69468 +
69469 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69470 + any rate limiting on grsecurity log messages.
69471 +
69472 +config GRKERNSEC_FLOODBURST
69473 + int "Number of messages in a burst (maximum)"
69474 + default 6
69475 + help
69476 + This option allows you to choose the maximum number of messages allowed
69477 + within the flood time interval you chose in a separate option. The
69478 + default should be suitable for most people, however if you find that
69479 + many of your logs are being interpreted as flooding, you may want to
69480 + raise this value.
69481 +
69482 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69483 + any rate limiting on grsecurity log messages.
69484 +
69485 +endmenu
69486 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69487 new file mode 100644
69488 index 0000000..30ababb
69489 --- /dev/null
69490 +++ b/grsecurity/Makefile
69491 @@ -0,0 +1,54 @@
69492 +# grsecurity – access control and security hardening for Linux
69493 +# All code in this directory and various hooks located throughout the Linux kernel are
69494 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69495 +# http://www.grsecurity.net spender@grsecurity.net
69496 +#
69497 +# This program is free software; you can redistribute it and/or
69498 +# modify it under the terms of the GNU General Public License version 2
69499 +# as published by the Free Software Foundation.
69500 +#
69501 +# This program is distributed in the hope that it will be useful,
69502 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69503 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69504 +# GNU General Public License for more details.
69505 +#
69506 +# You should have received a copy of the GNU General Public License
69507 +# along with this program; if not, write to the Free Software
69508 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69509 +
69510 +KBUILD_CFLAGS += -Werror
69511 +
69512 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69513 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69514 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69515 + grsec_usb.o grsec_ipc.o grsec_proc.o
69516 +
69517 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69518 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69519 + gracl_learn.o grsec_log.o gracl_policy.o
69520 +ifdef CONFIG_COMPAT
69521 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69522 +endif
69523 +
69524 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69525 +
69526 +ifdef CONFIG_NET
69527 +obj-y += grsec_sock.o
69528 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69529 +endif
69530 +
69531 +ifndef CONFIG_GRKERNSEC
69532 +obj-y += grsec_disabled.o
69533 +endif
69534 +
69535 +ifdef CONFIG_GRKERNSEC_HIDESYM
69536 +extra-y := grsec_hidesym.o
69537 +$(obj)/grsec_hidesym.o:
69538 + @-chmod -f 500 /boot
69539 + @-chmod -f 500 /lib/modules
69540 + @-chmod -f 500 /lib64/modules
69541 + @-chmod -f 500 /lib32/modules
69542 + @-chmod -f 700 .
69543 + @-chmod -f 700 $(objtree)
69544 + @echo ' grsec: protected kernel image paths'
69545 +endif
69546 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69547 new file mode 100644
69548 index 0000000..9c2d930
69549 --- /dev/null
69550 +++ b/grsecurity/gracl.c
69551 @@ -0,0 +1,2721 @@
69552 +#include <linux/kernel.h>
69553 +#include <linux/module.h>
69554 +#include <linux/sched.h>
69555 +#include <linux/mm.h>
69556 +#include <linux/file.h>
69557 +#include <linux/fs.h>
69558 +#include <linux/namei.h>
69559 +#include <linux/mount.h>
69560 +#include <linux/tty.h>
69561 +#include <linux/proc_fs.h>
69562 +#include <linux/lglock.h>
69563 +#include <linux/slab.h>
69564 +#include <linux/vmalloc.h>
69565 +#include <linux/types.h>
69566 +#include <linux/sysctl.h>
69567 +#include <linux/netdevice.h>
69568 +#include <linux/ptrace.h>
69569 +#include <linux/gracl.h>
69570 +#include <linux/gralloc.h>
69571 +#include <linux/security.h>
69572 +#include <linux/grinternal.h>
69573 +#include <linux/pid_namespace.h>
69574 +#include <linux/stop_machine.h>
69575 +#include <linux/fdtable.h>
69576 +#include <linux/percpu.h>
69577 +#include <linux/lglock.h>
69578 +#include <linux/hugetlb.h>
69579 +#include <linux/posix-timers.h>
69580 +#include <linux/prefetch.h>
69581 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69582 +#include <linux/magic.h>
69583 +#include <linux/pagemap.h>
69584 +#include "../fs/btrfs/async-thread.h"
69585 +#include "../fs/btrfs/ctree.h"
69586 +#include "../fs/btrfs/btrfs_inode.h"
69587 +#endif
69588 +#include "../fs/mount.h"
69589 +
69590 +#include <asm/uaccess.h>
69591 +#include <asm/errno.h>
69592 +#include <asm/mman.h>
69593 +
69594 +#define FOR_EACH_ROLE_START(role) \
69595 + role = running_polstate.role_list; \
69596 + while (role) {
69597 +
69598 +#define FOR_EACH_ROLE_END(role) \
69599 + role = role->prev; \
69600 + }
69601 +
69602 +extern struct path gr_real_root;
69603 +
69604 +static struct gr_policy_state running_polstate;
69605 +struct gr_policy_state *polstate = &running_polstate;
69606 +extern struct gr_alloc_state *current_alloc_state;
69607 +
69608 +extern char *gr_shared_page[4];
69609 +DEFINE_RWLOCK(gr_inode_lock);
69610 +
69611 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69612 +
69613 +#ifdef CONFIG_NET
69614 +extern struct vfsmount *sock_mnt;
69615 +#endif
69616 +
69617 +extern struct vfsmount *pipe_mnt;
69618 +extern struct vfsmount *shm_mnt;
69619 +
69620 +#ifdef CONFIG_HUGETLBFS
69621 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69622 +#endif
69623 +
69624 +extern u16 acl_sp_role_value;
69625 +extern struct acl_object_label *fakefs_obj_rw;
69626 +extern struct acl_object_label *fakefs_obj_rwx;
69627 +
69628 +int gr_acl_is_enabled(void)
69629 +{
69630 + return (gr_status & GR_READY);
69631 +}
69632 +
69633 +void gr_enable_rbac_system(void)
69634 +{
69635 + pax_open_kernel();
69636 + gr_status |= GR_READY;
69637 + pax_close_kernel();
69638 +}
69639 +
69640 +int gr_rbac_disable(void *unused)
69641 +{
69642 + pax_open_kernel();
69643 + gr_status &= ~GR_READY;
69644 + pax_close_kernel();
69645 +
69646 + return 0;
69647 +}
69648 +
69649 +static inline dev_t __get_dev(const struct dentry *dentry)
69650 +{
69651 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69652 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69653 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69654 + else
69655 +#endif
69656 + return dentry->d_sb->s_dev;
69657 +}
69658 +
69659 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69660 +{
69661 + return __get_dev(dentry);
69662 +}
69663 +
69664 +static char gr_task_roletype_to_char(struct task_struct *task)
69665 +{
69666 + switch (task->role->roletype &
69667 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69668 + GR_ROLE_SPECIAL)) {
69669 + case GR_ROLE_DEFAULT:
69670 + return 'D';
69671 + case GR_ROLE_USER:
69672 + return 'U';
69673 + case GR_ROLE_GROUP:
69674 + return 'G';
69675 + case GR_ROLE_SPECIAL:
69676 + return 'S';
69677 + }
69678 +
69679 + return 'X';
69680 +}
69681 +
69682 +char gr_roletype_to_char(void)
69683 +{
69684 + return gr_task_roletype_to_char(current);
69685 +}
69686 +
69687 +__inline__ int
69688 +gr_acl_tpe_check(void)
69689 +{
69690 + if (unlikely(!(gr_status & GR_READY)))
69691 + return 0;
69692 + if (current->role->roletype & GR_ROLE_TPE)
69693 + return 1;
69694 + else
69695 + return 0;
69696 +}
69697 +
69698 +int
69699 +gr_handle_rawio(const struct inode *inode)
69700 +{
69701 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69702 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69703 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69704 + !capable(CAP_SYS_RAWIO))
69705 + return 1;
69706 +#endif
69707 + return 0;
69708 +}
69709 +
69710 +int
69711 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69712 +{
69713 + if (likely(lena != lenb))
69714 + return 0;
69715 +
69716 + return !memcmp(a, b, lena);
69717 +}
69718 +
69719 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69720 +{
69721 + *buflen -= namelen;
69722 + if (*buflen < 0)
69723 + return -ENAMETOOLONG;
69724 + *buffer -= namelen;
69725 + memcpy(*buffer, str, namelen);
69726 + return 0;
69727 +}
69728 +
69729 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69730 +{
69731 + return prepend(buffer, buflen, name->name, name->len);
69732 +}
69733 +
69734 +static int prepend_path(const struct path *path, struct path *root,
69735 + char **buffer, int *buflen)
69736 +{
69737 + struct dentry *dentry = path->dentry;
69738 + struct vfsmount *vfsmnt = path->mnt;
69739 + struct mount *mnt = real_mount(vfsmnt);
69740 + bool slash = false;
69741 + int error = 0;
69742 +
69743 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69744 + struct dentry * parent;
69745 +
69746 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69747 + /* Global root? */
69748 + if (!mnt_has_parent(mnt)) {
69749 + goto out;
69750 + }
69751 + dentry = mnt->mnt_mountpoint;
69752 + mnt = mnt->mnt_parent;
69753 + vfsmnt = &mnt->mnt;
69754 + continue;
69755 + }
69756 + parent = dentry->d_parent;
69757 + prefetch(parent);
69758 + spin_lock(&dentry->d_lock);
69759 + error = prepend_name(buffer, buflen, &dentry->d_name);
69760 + spin_unlock(&dentry->d_lock);
69761 + if (!error)
69762 + error = prepend(buffer, buflen, "/", 1);
69763 + if (error)
69764 + break;
69765 +
69766 + slash = true;
69767 + dentry = parent;
69768 + }
69769 +
69770 +out:
69771 + if (!error && !slash)
69772 + error = prepend(buffer, buflen, "/", 1);
69773 +
69774 + return error;
69775 +}
69776 +
69777 +/* this must be called with mount_lock and rename_lock held */
69778 +
69779 +static char *__our_d_path(const struct path *path, struct path *root,
69780 + char *buf, int buflen)
69781 +{
69782 + char *res = buf + buflen;
69783 + int error;
69784 +
69785 + prepend(&res, &buflen, "\0", 1);
69786 + error = prepend_path(path, root, &res, &buflen);
69787 + if (error)
69788 + return ERR_PTR(error);
69789 +
69790 + return res;
69791 +}
69792 +
69793 +static char *
69794 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69795 +{
69796 + char *retval;
69797 +
69798 + retval = __our_d_path(path, root, buf, buflen);
69799 + if (unlikely(IS_ERR(retval)))
69800 + retval = strcpy(buf, "<path too long>");
69801 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69802 + retval[1] = '\0';
69803 +
69804 + return retval;
69805 +}
69806 +
69807 +static char *
69808 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69809 + char *buf, int buflen)
69810 +{
69811 + struct path path;
69812 + char *res;
69813 +
69814 + path.dentry = (struct dentry *)dentry;
69815 + path.mnt = (struct vfsmount *)vfsmnt;
69816 +
69817 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69818 + by the RBAC system */
69819 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69820 +
69821 + return res;
69822 +}
69823 +
69824 +static char *
69825 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69826 + char *buf, int buflen)
69827 +{
69828 + char *res;
69829 + struct path path;
69830 + struct path root;
69831 + struct task_struct *reaper = init_pid_ns.child_reaper;
69832 +
69833 + path.dentry = (struct dentry *)dentry;
69834 + path.mnt = (struct vfsmount *)vfsmnt;
69835 +
69836 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69837 + get_fs_root(reaper->fs, &root);
69838 +
69839 + read_seqlock_excl(&mount_lock);
69840 + write_seqlock(&rename_lock);
69841 + res = gen_full_path(&path, &root, buf, buflen);
69842 + write_sequnlock(&rename_lock);
69843 + read_sequnlock_excl(&mount_lock);
69844 +
69845 + path_put(&root);
69846 + return res;
69847 +}
69848 +
69849 +char *
69850 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69851 +{
69852 + char *ret;
69853 + read_seqlock_excl(&mount_lock);
69854 + write_seqlock(&rename_lock);
69855 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69856 + PAGE_SIZE);
69857 + write_sequnlock(&rename_lock);
69858 + read_sequnlock_excl(&mount_lock);
69859 + return ret;
69860 +}
69861 +
69862 +static char *
69863 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69864 +{
69865 + char *ret;
69866 + char *buf;
69867 + int buflen;
69868 +
69869 + read_seqlock_excl(&mount_lock);
69870 + write_seqlock(&rename_lock);
69871 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69872 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69873 + buflen = (int)(ret - buf);
69874 + if (buflen >= 5)
69875 + prepend(&ret, &buflen, "/proc", 5);
69876 + else
69877 + ret = strcpy(buf, "<path too long>");
69878 + write_sequnlock(&rename_lock);
69879 + read_sequnlock_excl(&mount_lock);
69880 + return ret;
69881 +}
69882 +
69883 +char *
69884 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69885 +{
69886 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69887 + PAGE_SIZE);
69888 +}
69889 +
69890 +char *
69891 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69892 +{
69893 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69894 + PAGE_SIZE);
69895 +}
69896 +
69897 +char *
69898 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69899 +{
69900 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69901 + PAGE_SIZE);
69902 +}
69903 +
69904 +char *
69905 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69906 +{
69907 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69908 + PAGE_SIZE);
69909 +}
69910 +
69911 +char *
69912 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69913 +{
69914 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69915 + PAGE_SIZE);
69916 +}
69917 +
69918 +__inline__ __u32
69919 +to_gr_audit(const __u32 reqmode)
69920 +{
69921 + /* masks off auditable permission flags, then shifts them to create
69922 + auditing flags, and adds the special case of append auditing if
69923 + we're requesting write */
69924 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69925 +}
69926 +
69927 +struct acl_role_label *
69928 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69929 + const gid_t gid)
69930 +{
69931 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69932 + struct acl_role_label *match;
69933 + struct role_allowed_ip *ipp;
69934 + unsigned int x;
69935 + u32 curr_ip = task->signal->saved_ip;
69936 +
69937 + match = state->acl_role_set.r_hash[index];
69938 +
69939 + while (match) {
69940 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69941 + for (x = 0; x < match->domain_child_num; x++) {
69942 + if (match->domain_children[x] == uid)
69943 + goto found;
69944 + }
69945 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69946 + break;
69947 + match = match->next;
69948 + }
69949 +found:
69950 + if (match == NULL) {
69951 + try_group:
69952 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69953 + match = state->acl_role_set.r_hash[index];
69954 +
69955 + while (match) {
69956 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69957 + for (x = 0; x < match->domain_child_num; x++) {
69958 + if (match->domain_children[x] == gid)
69959 + goto found2;
69960 + }
69961 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69962 + break;
69963 + match = match->next;
69964 + }
69965 +found2:
69966 + if (match == NULL)
69967 + match = state->default_role;
69968 + if (match->allowed_ips == NULL)
69969 + return match;
69970 + else {
69971 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69972 + if (likely
69973 + ((ntohl(curr_ip) & ipp->netmask) ==
69974 + (ntohl(ipp->addr) & ipp->netmask)))
69975 + return match;
69976 + }
69977 + match = state->default_role;
69978 + }
69979 + } else if (match->allowed_ips == NULL) {
69980 + return match;
69981 + } else {
69982 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69983 + if (likely
69984 + ((ntohl(curr_ip) & ipp->netmask) ==
69985 + (ntohl(ipp->addr) & ipp->netmask)))
69986 + return match;
69987 + }
69988 + goto try_group;
69989 + }
69990 +
69991 + return match;
69992 +}
69993 +
69994 +static struct acl_role_label *
69995 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69996 + const gid_t gid)
69997 +{
69998 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69999 +}
70000 +
70001 +struct acl_subject_label *
70002 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70003 + const struct acl_role_label *role)
70004 +{
70005 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70006 + struct acl_subject_label *match;
70007 +
70008 + match = role->subj_hash[index];
70009 +
70010 + while (match && (match->inode != ino || match->device != dev ||
70011 + (match->mode & GR_DELETED))) {
70012 + match = match->next;
70013 + }
70014 +
70015 + if (match && !(match->mode & GR_DELETED))
70016 + return match;
70017 + else
70018 + return NULL;
70019 +}
70020 +
70021 +struct acl_subject_label *
70022 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70023 + const struct acl_role_label *role)
70024 +{
70025 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70026 + struct acl_subject_label *match;
70027 +
70028 + match = role->subj_hash[index];
70029 +
70030 + while (match && (match->inode != ino || match->device != dev ||
70031 + !(match->mode & GR_DELETED))) {
70032 + match = match->next;
70033 + }
70034 +
70035 + if (match && (match->mode & GR_DELETED))
70036 + return match;
70037 + else
70038 + return NULL;
70039 +}
70040 +
70041 +static struct acl_object_label *
70042 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70043 + const struct acl_subject_label *subj)
70044 +{
70045 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70046 + struct acl_object_label *match;
70047 +
70048 + match = subj->obj_hash[index];
70049 +
70050 + while (match && (match->inode != ino || match->device != dev ||
70051 + (match->mode & GR_DELETED))) {
70052 + match = match->next;
70053 + }
70054 +
70055 + if (match && !(match->mode & GR_DELETED))
70056 + return match;
70057 + else
70058 + return NULL;
70059 +}
70060 +
70061 +static struct acl_object_label *
70062 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70063 + const struct acl_subject_label *subj)
70064 +{
70065 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70066 + struct acl_object_label *match;
70067 +
70068 + match = subj->obj_hash[index];
70069 +
70070 + while (match && (match->inode != ino || match->device != dev ||
70071 + !(match->mode & GR_DELETED))) {
70072 + match = match->next;
70073 + }
70074 +
70075 + if (match && (match->mode & GR_DELETED))
70076 + return match;
70077 +
70078 + match = subj->obj_hash[index];
70079 +
70080 + while (match && (match->inode != ino || match->device != dev ||
70081 + (match->mode & GR_DELETED))) {
70082 + match = match->next;
70083 + }
70084 +
70085 + if (match && !(match->mode & GR_DELETED))
70086 + return match;
70087 + else
70088 + return NULL;
70089 +}
70090 +
70091 +struct name_entry *
70092 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70093 +{
70094 + unsigned int len = strlen(name);
70095 + unsigned int key = full_name_hash(name, len);
70096 + unsigned int index = key % state->name_set.n_size;
70097 + struct name_entry *match;
70098 +
70099 + match = state->name_set.n_hash[index];
70100 +
70101 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70102 + match = match->next;
70103 +
70104 + return match;
70105 +}
70106 +
70107 +static struct name_entry *
70108 +lookup_name_entry(const char *name)
70109 +{
70110 + return __lookup_name_entry(&running_polstate, name);
70111 +}
70112 +
70113 +static struct name_entry *
70114 +lookup_name_entry_create(const char *name)
70115 +{
70116 + unsigned int len = strlen(name);
70117 + unsigned int key = full_name_hash(name, len);
70118 + unsigned int index = key % running_polstate.name_set.n_size;
70119 + struct name_entry *match;
70120 +
70121 + match = running_polstate.name_set.n_hash[index];
70122 +
70123 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70124 + !match->deleted))
70125 + match = match->next;
70126 +
70127 + if (match && match->deleted)
70128 + return match;
70129 +
70130 + match = running_polstate.name_set.n_hash[index];
70131 +
70132 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70133 + match->deleted))
70134 + match = match->next;
70135 +
70136 + if (match && !match->deleted)
70137 + return match;
70138 + else
70139 + return NULL;
70140 +}
70141 +
70142 +static struct inodev_entry *
70143 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70144 +{
70145 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70146 + struct inodev_entry *match;
70147 +
70148 + match = running_polstate.inodev_set.i_hash[index];
70149 +
70150 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70151 + match = match->next;
70152 +
70153 + return match;
70154 +}
70155 +
70156 +void
70157 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70158 +{
70159 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70160 + state->inodev_set.i_size);
70161 + struct inodev_entry **curr;
70162 +
70163 + entry->prev = NULL;
70164 +
70165 + curr = &state->inodev_set.i_hash[index];
70166 + if (*curr != NULL)
70167 + (*curr)->prev = entry;
70168 +
70169 + entry->next = *curr;
70170 + *curr = entry;
70171 +
70172 + return;
70173 +}
70174 +
70175 +static void
70176 +insert_inodev_entry(struct inodev_entry *entry)
70177 +{
70178 + __insert_inodev_entry(&running_polstate, entry);
70179 +}
70180 +
70181 +void
70182 +insert_acl_obj_label(struct acl_object_label *obj,
70183 + struct acl_subject_label *subj)
70184 +{
70185 + unsigned int index =
70186 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70187 + struct acl_object_label **curr;
70188 +
70189 + obj->prev = NULL;
70190 +
70191 + curr = &subj->obj_hash[index];
70192 + if (*curr != NULL)
70193 + (*curr)->prev = obj;
70194 +
70195 + obj->next = *curr;
70196 + *curr = obj;
70197 +
70198 + return;
70199 +}
70200 +
70201 +void
70202 +insert_acl_subj_label(struct acl_subject_label *obj,
70203 + struct acl_role_label *role)
70204 +{
70205 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70206 + struct acl_subject_label **curr;
70207 +
70208 + obj->prev = NULL;
70209 +
70210 + curr = &role->subj_hash[index];
70211 + if (*curr != NULL)
70212 + (*curr)->prev = obj;
70213 +
70214 + obj->next = *curr;
70215 + *curr = obj;
70216 +
70217 + return;
70218 +}
70219 +
70220 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70221 +
70222 +static int
70223 +glob_match(const char *p, const char *n)
70224 +{
70225 + char c;
70226 +
70227 + while ((c = *p++) != '\0') {
70228 + switch (c) {
70229 + case '?':
70230 + if (*n == '\0')
70231 + return 1;
70232 + else if (*n == '/')
70233 + return 1;
70234 + break;
70235 + case '\\':
70236 + if (*n != c)
70237 + return 1;
70238 + break;
70239 + case '*':
70240 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70241 + if (*n == '/')
70242 + return 1;
70243 + else if (c == '?') {
70244 + if (*n == '\0')
70245 + return 1;
70246 + else
70247 + ++n;
70248 + }
70249 + }
70250 + if (c == '\0') {
70251 + return 0;
70252 + } else {
70253 + const char *endp;
70254 +
70255 + if ((endp = strchr(n, '/')) == NULL)
70256 + endp = n + strlen(n);
70257 +
70258 + if (c == '[') {
70259 + for (--p; n < endp; ++n)
70260 + if (!glob_match(p, n))
70261 + return 0;
70262 + } else if (c == '/') {
70263 + while (*n != '\0' && *n != '/')
70264 + ++n;
70265 + if (*n == '/' && !glob_match(p, n + 1))
70266 + return 0;
70267 + } else {
70268 + for (--p; n < endp; ++n)
70269 + if (*n == c && !glob_match(p, n))
70270 + return 0;
70271 + }
70272 +
70273 + return 1;
70274 + }
70275 + case '[':
70276 + {
70277 + int not;
70278 + char cold;
70279 +
70280 + if (*n == '\0' || *n == '/')
70281 + return 1;
70282 +
70283 + not = (*p == '!' || *p == '^');
70284 + if (not)
70285 + ++p;
70286 +
70287 + c = *p++;
70288 + for (;;) {
70289 + unsigned char fn = (unsigned char)*n;
70290 +
70291 + if (c == '\0')
70292 + return 1;
70293 + else {
70294 + if (c == fn)
70295 + goto matched;
70296 + cold = c;
70297 + c = *p++;
70298 +
70299 + if (c == '-' && *p != ']') {
70300 + unsigned char cend = *p++;
70301 +
70302 + if (cend == '\0')
70303 + return 1;
70304 +
70305 + if (cold <= fn && fn <= cend)
70306 + goto matched;
70307 +
70308 + c = *p++;
70309 + }
70310 + }
70311 +
70312 + if (c == ']')
70313 + break;
70314 + }
70315 + if (!not)
70316 + return 1;
70317 + break;
70318 + matched:
70319 + while (c != ']') {
70320 + if (c == '\0')
70321 + return 1;
70322 +
70323 + c = *p++;
70324 + }
70325 + if (not)
70326 + return 1;
70327 + }
70328 + break;
70329 + default:
70330 + if (c != *n)
70331 + return 1;
70332 + }
70333 +
70334 + ++n;
70335 + }
70336 +
70337 + if (*n == '\0')
70338 + return 0;
70339 +
70340 + if (*n == '/')
70341 + return 0;
70342 +
70343 + return 1;
70344 +}
70345 +
70346 +static struct acl_object_label *
70347 +chk_glob_label(struct acl_object_label *globbed,
70348 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70349 +{
70350 + struct acl_object_label *tmp;
70351 +
70352 + if (*path == NULL)
70353 + *path = gr_to_filename_nolock(dentry, mnt);
70354 +
70355 + tmp = globbed;
70356 +
70357 + while (tmp) {
70358 + if (!glob_match(tmp->filename, *path))
70359 + return tmp;
70360 + tmp = tmp->next;
70361 + }
70362 +
70363 + return NULL;
70364 +}
70365 +
70366 +static struct acl_object_label *
70367 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70368 + const ino_t curr_ino, const dev_t curr_dev,
70369 + const struct acl_subject_label *subj, char **path, const int checkglob)
70370 +{
70371 + struct acl_subject_label *tmpsubj;
70372 + struct acl_object_label *retval;
70373 + struct acl_object_label *retval2;
70374 +
70375 + tmpsubj = (struct acl_subject_label *) subj;
70376 + read_lock(&gr_inode_lock);
70377 + do {
70378 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70379 + if (retval) {
70380 + if (checkglob && retval->globbed) {
70381 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70382 + if (retval2)
70383 + retval = retval2;
70384 + }
70385 + break;
70386 + }
70387 + } while ((tmpsubj = tmpsubj->parent_subject));
70388 + read_unlock(&gr_inode_lock);
70389 +
70390 + return retval;
70391 +}
70392 +
70393 +static __inline__ struct acl_object_label *
70394 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70395 + struct dentry *curr_dentry,
70396 + const struct acl_subject_label *subj, char **path, const int checkglob)
70397 +{
70398 + int newglob = checkglob;
70399 + ino_t inode;
70400 + dev_t device;
70401 +
70402 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70403 + as we don't want a / * rule to match instead of the / object
70404 + don't do this for create lookups that call this function though, since they're looking up
70405 + on the parent and thus need globbing checks on all paths
70406 + */
70407 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70408 + newglob = GR_NO_GLOB;
70409 +
70410 + spin_lock(&curr_dentry->d_lock);
70411 + inode = curr_dentry->d_inode->i_ino;
70412 + device = __get_dev(curr_dentry);
70413 + spin_unlock(&curr_dentry->d_lock);
70414 +
70415 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70416 +}
70417 +
70418 +#ifdef CONFIG_HUGETLBFS
70419 +static inline bool
70420 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70421 +{
70422 + int i;
70423 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70424 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70425 + return true;
70426 + }
70427 +
70428 + return false;
70429 +}
70430 +#endif
70431 +
70432 +static struct acl_object_label *
70433 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70434 + const struct acl_subject_label *subj, char *path, const int checkglob)
70435 +{
70436 + struct dentry *dentry = (struct dentry *) l_dentry;
70437 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70438 + struct mount *real_mnt = real_mount(mnt);
70439 + struct acl_object_label *retval;
70440 + struct dentry *parent;
70441 +
70442 + read_seqlock_excl(&mount_lock);
70443 + write_seqlock(&rename_lock);
70444 +
70445 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70446 +#ifdef CONFIG_NET
70447 + mnt == sock_mnt ||
70448 +#endif
70449 +#ifdef CONFIG_HUGETLBFS
70450 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70451 +#endif
70452 + /* ignore Eric Biederman */
70453 + IS_PRIVATE(l_dentry->d_inode))) {
70454 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70455 + goto out;
70456 + }
70457 +
70458 + for (;;) {
70459 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70460 + break;
70461 +
70462 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70463 + if (!mnt_has_parent(real_mnt))
70464 + break;
70465 +
70466 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70467 + if (retval != NULL)
70468 + goto out;
70469 +
70470 + dentry = real_mnt->mnt_mountpoint;
70471 + real_mnt = real_mnt->mnt_parent;
70472 + mnt = &real_mnt->mnt;
70473 + continue;
70474 + }
70475 +
70476 + parent = dentry->d_parent;
70477 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70478 + if (retval != NULL)
70479 + goto out;
70480 +
70481 + dentry = parent;
70482 + }
70483 +
70484 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70485 +
70486 + /* gr_real_root is pinned so we don't have to hold a reference */
70487 + if (retval == NULL)
70488 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70489 +out:
70490 + write_sequnlock(&rename_lock);
70491 + read_sequnlock_excl(&mount_lock);
70492 +
70493 + BUG_ON(retval == NULL);
70494 +
70495 + return retval;
70496 +}
70497 +
70498 +static __inline__ struct acl_object_label *
70499 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70500 + const struct acl_subject_label *subj)
70501 +{
70502 + char *path = NULL;
70503 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70504 +}
70505 +
70506 +static __inline__ struct acl_object_label *
70507 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70508 + const struct acl_subject_label *subj)
70509 +{
70510 + char *path = NULL;
70511 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70512 +}
70513 +
70514 +static __inline__ struct acl_object_label *
70515 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70516 + const struct acl_subject_label *subj, char *path)
70517 +{
70518 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70519 +}
70520 +
70521 +struct acl_subject_label *
70522 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70523 + const struct acl_role_label *role)
70524 +{
70525 + struct dentry *dentry = (struct dentry *) l_dentry;
70526 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70527 + struct mount *real_mnt = real_mount(mnt);
70528 + struct acl_subject_label *retval;
70529 + struct dentry *parent;
70530 +
70531 + read_seqlock_excl(&mount_lock);
70532 + write_seqlock(&rename_lock);
70533 +
70534 + for (;;) {
70535 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70536 + break;
70537 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70538 + if (!mnt_has_parent(real_mnt))
70539 + break;
70540 +
70541 + spin_lock(&dentry->d_lock);
70542 + read_lock(&gr_inode_lock);
70543 + retval =
70544 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70545 + __get_dev(dentry), role);
70546 + read_unlock(&gr_inode_lock);
70547 + spin_unlock(&dentry->d_lock);
70548 + if (retval != NULL)
70549 + goto out;
70550 +
70551 + dentry = real_mnt->mnt_mountpoint;
70552 + real_mnt = real_mnt->mnt_parent;
70553 + mnt = &real_mnt->mnt;
70554 + continue;
70555 + }
70556 +
70557 + spin_lock(&dentry->d_lock);
70558 + read_lock(&gr_inode_lock);
70559 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70560 + __get_dev(dentry), role);
70561 + read_unlock(&gr_inode_lock);
70562 + parent = dentry->d_parent;
70563 + spin_unlock(&dentry->d_lock);
70564 +
70565 + if (retval != NULL)
70566 + goto out;
70567 +
70568 + dentry = parent;
70569 + }
70570 +
70571 + spin_lock(&dentry->d_lock);
70572 + read_lock(&gr_inode_lock);
70573 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70574 + __get_dev(dentry), role);
70575 + read_unlock(&gr_inode_lock);
70576 + spin_unlock(&dentry->d_lock);
70577 +
70578 + if (unlikely(retval == NULL)) {
70579 + /* gr_real_root is pinned, we don't need to hold a reference */
70580 + read_lock(&gr_inode_lock);
70581 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70582 + __get_dev(gr_real_root.dentry), role);
70583 + read_unlock(&gr_inode_lock);
70584 + }
70585 +out:
70586 + write_sequnlock(&rename_lock);
70587 + read_sequnlock_excl(&mount_lock);
70588 +
70589 + BUG_ON(retval == NULL);
70590 +
70591 + return retval;
70592 +}
70593 +
70594 +void
70595 +assign_special_role(const char *rolename)
70596 +{
70597 + struct acl_object_label *obj;
70598 + struct acl_role_label *r;
70599 + struct acl_role_label *assigned = NULL;
70600 + struct task_struct *tsk;
70601 + struct file *filp;
70602 +
70603 + FOR_EACH_ROLE_START(r)
70604 + if (!strcmp(rolename, r->rolename) &&
70605 + (r->roletype & GR_ROLE_SPECIAL)) {
70606 + assigned = r;
70607 + break;
70608 + }
70609 + FOR_EACH_ROLE_END(r)
70610 +
70611 + if (!assigned)
70612 + return;
70613 +
70614 + read_lock(&tasklist_lock);
70615 + read_lock(&grsec_exec_file_lock);
70616 +
70617 + tsk = current->real_parent;
70618 + if (tsk == NULL)
70619 + goto out_unlock;
70620 +
70621 + filp = tsk->exec_file;
70622 + if (filp == NULL)
70623 + goto out_unlock;
70624 +
70625 + tsk->is_writable = 0;
70626 + tsk->inherited = 0;
70627 +
70628 + tsk->acl_sp_role = 1;
70629 + tsk->acl_role_id = ++acl_sp_role_value;
70630 + tsk->role = assigned;
70631 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70632 +
70633 + /* ignore additional mmap checks for processes that are writable
70634 + by the default ACL */
70635 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70636 + if (unlikely(obj->mode & GR_WRITE))
70637 + tsk->is_writable = 1;
70638 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70639 + if (unlikely(obj->mode & GR_WRITE))
70640 + tsk->is_writable = 1;
70641 +
70642 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70643 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70644 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70645 +#endif
70646 +
70647 +out_unlock:
70648 + read_unlock(&grsec_exec_file_lock);
70649 + read_unlock(&tasklist_lock);
70650 + return;
70651 +}
70652 +
70653 +
70654 +static void
70655 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70656 +{
70657 + struct task_struct *task = current;
70658 + const struct cred *cred = current_cred();
70659 +
70660 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70661 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70662 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70663 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70664 +
70665 + return;
70666 +}
70667 +
70668 +static void
70669 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70670 +{
70671 + struct task_struct *task = current;
70672 + const struct cred *cred = current_cred();
70673 +
70674 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70675 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70676 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70677 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70678 +
70679 + return;
70680 +}
70681 +
70682 +static void
70683 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70684 +{
70685 + struct task_struct *task = current;
70686 + const struct cred *cred = current_cred();
70687 +
70688 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70689 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70690 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70691 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70692 +
70693 + return;
70694 +}
70695 +
70696 +static void
70697 +gr_set_proc_res(struct task_struct *task)
70698 +{
70699 + struct acl_subject_label *proc;
70700 + unsigned short i;
70701 +
70702 + proc = task->acl;
70703 +
70704 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70705 + return;
70706 +
70707 + for (i = 0; i < RLIM_NLIMITS; i++) {
70708 + if (!(proc->resmask & (1U << i)))
70709 + continue;
70710 +
70711 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70712 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70713 +
70714 + if (i == RLIMIT_CPU)
70715 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70716 + }
70717 +
70718 + return;
70719 +}
70720 +
70721 +/* both of the below must be called with
70722 + rcu_read_lock();
70723 + read_lock(&tasklist_lock);
70724 + read_lock(&grsec_exec_file_lock);
70725 + except in the case of gr_set_role_label() (for __gr_get_subject_for_task)
70726 +*/
70727 +
70728 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback)
70729 +{
70730 + char *tmpname;
70731 + struct acl_subject_label *tmpsubj;
70732 + struct file *filp;
70733 + struct name_entry *nmatch;
70734 +
70735 + filp = task->exec_file;
70736 + if (filp == NULL)
70737 + return NULL;
70738 +
70739 + /* the following is to apply the correct subject
70740 + on binaries running when the RBAC system
70741 + is enabled, when the binaries have been
70742 + replaced or deleted since their execution
70743 + -----
70744 + when the RBAC system starts, the inode/dev
70745 + from exec_file will be one the RBAC system
70746 + is unaware of. It only knows the inode/dev
70747 + of the present file on disk, or the absence
70748 + of it.
70749 + */
70750 +
70751 + if (filename)
70752 + nmatch = __lookup_name_entry(state, filename);
70753 + else {
70754 + preempt_disable();
70755 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70756 +
70757 + nmatch = __lookup_name_entry(state, tmpname);
70758 + preempt_enable();
70759 + }
70760 + tmpsubj = NULL;
70761 + if (nmatch) {
70762 + if (nmatch->deleted)
70763 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70764 + else
70765 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70766 + }
70767 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70768 + then we fall back to a normal lookup based on the binary's ino/dev
70769 + */
70770 + if (tmpsubj == NULL && fallback)
70771 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70772 +
70773 + return tmpsubj;
70774 +}
70775 +
70776 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename, int fallback)
70777 +{
70778 + return __gr_get_subject_for_task(&running_polstate, task, filename, fallback);
70779 +}
70780 +
70781 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70782 +{
70783 + struct acl_object_label *obj;
70784 + struct file *filp;
70785 +
70786 + filp = task->exec_file;
70787 +
70788 + task->acl = subj;
70789 + task->is_writable = 0;
70790 + /* ignore additional mmap checks for processes that are writable
70791 + by the default ACL */
70792 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70793 + if (unlikely(obj->mode & GR_WRITE))
70794 + task->is_writable = 1;
70795 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70796 + if (unlikely(obj->mode & GR_WRITE))
70797 + task->is_writable = 1;
70798 +
70799 + gr_set_proc_res(task);
70800 +
70801 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70802 + 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);
70803 +#endif
70804 +}
70805 +
70806 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70807 +{
70808 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70809 +}
70810 +
70811 +__u32
70812 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70813 + const struct vfsmount * mnt)
70814 +{
70815 + __u32 retval = mode;
70816 + struct acl_subject_label *curracl;
70817 + struct acl_object_label *currobj;
70818 +
70819 + if (unlikely(!(gr_status & GR_READY)))
70820 + return (mode & ~GR_AUDITS);
70821 +
70822 + curracl = current->acl;
70823 +
70824 + currobj = chk_obj_label(dentry, mnt, curracl);
70825 + retval = currobj->mode & mode;
70826 +
70827 + /* if we're opening a specified transfer file for writing
70828 + (e.g. /dev/initctl), then transfer our role to init
70829 + */
70830 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70831 + current->role->roletype & GR_ROLE_PERSIST)) {
70832 + struct task_struct *task = init_pid_ns.child_reaper;
70833 +
70834 + if (task->role != current->role) {
70835 + struct acl_subject_label *subj;
70836 +
70837 + task->acl_sp_role = 0;
70838 + task->acl_role_id = current->acl_role_id;
70839 + task->role = current->role;
70840 + rcu_read_lock();
70841 + read_lock(&grsec_exec_file_lock);
70842 + subj = gr_get_subject_for_task(task, NULL, 1);
70843 + gr_apply_subject_to_task(task, subj);
70844 + read_unlock(&grsec_exec_file_lock);
70845 + rcu_read_unlock();
70846 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70847 + }
70848 + }
70849 +
70850 + if (unlikely
70851 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70852 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70853 + __u32 new_mode = mode;
70854 +
70855 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70856 +
70857 + retval = new_mode;
70858 +
70859 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70860 + new_mode |= GR_INHERIT;
70861 +
70862 + if (!(mode & GR_NOLEARN))
70863 + gr_log_learn(dentry, mnt, new_mode);
70864 + }
70865 +
70866 + return retval;
70867 +}
70868 +
70869 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70870 + const struct dentry *parent,
70871 + const struct vfsmount *mnt)
70872 +{
70873 + struct name_entry *match;
70874 + struct acl_object_label *matchpo;
70875 + struct acl_subject_label *curracl;
70876 + char *path;
70877 +
70878 + if (unlikely(!(gr_status & GR_READY)))
70879 + return NULL;
70880 +
70881 + preempt_disable();
70882 + path = gr_to_filename_rbac(new_dentry, mnt);
70883 + match = lookup_name_entry_create(path);
70884 +
70885 + curracl = current->acl;
70886 +
70887 + if (match) {
70888 + read_lock(&gr_inode_lock);
70889 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70890 + read_unlock(&gr_inode_lock);
70891 +
70892 + if (matchpo) {
70893 + preempt_enable();
70894 + return matchpo;
70895 + }
70896 + }
70897 +
70898 + // lookup parent
70899 +
70900 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70901 +
70902 + preempt_enable();
70903 + return matchpo;
70904 +}
70905 +
70906 +__u32
70907 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70908 + const struct vfsmount * mnt, const __u32 mode)
70909 +{
70910 + struct acl_object_label *matchpo;
70911 + __u32 retval;
70912 +
70913 + if (unlikely(!(gr_status & GR_READY)))
70914 + return (mode & ~GR_AUDITS);
70915 +
70916 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70917 +
70918 + retval = matchpo->mode & mode;
70919 +
70920 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70921 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70922 + __u32 new_mode = mode;
70923 +
70924 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70925 +
70926 + gr_log_learn(new_dentry, mnt, new_mode);
70927 + return new_mode;
70928 + }
70929 +
70930 + return retval;
70931 +}
70932 +
70933 +__u32
70934 +gr_check_link(const struct dentry * new_dentry,
70935 + const struct dentry * parent_dentry,
70936 + const struct vfsmount * parent_mnt,
70937 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70938 +{
70939 + struct acl_object_label *obj;
70940 + __u32 oldmode, newmode;
70941 + __u32 needmode;
70942 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70943 + GR_DELETE | GR_INHERIT;
70944 +
70945 + if (unlikely(!(gr_status & GR_READY)))
70946 + return (GR_CREATE | GR_LINK);
70947 +
70948 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70949 + oldmode = obj->mode;
70950 +
70951 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70952 + newmode = obj->mode;
70953 +
70954 + needmode = newmode & checkmodes;
70955 +
70956 + // old name for hardlink must have at least the permissions of the new name
70957 + if ((oldmode & needmode) != needmode)
70958 + goto bad;
70959 +
70960 + // if old name had restrictions/auditing, make sure the new name does as well
70961 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70962 +
70963 + // don't allow hardlinking of suid/sgid/fcapped files without permission
70964 + if (is_privileged_binary(old_dentry))
70965 + needmode |= GR_SETID;
70966 +
70967 + if ((newmode & needmode) != needmode)
70968 + goto bad;
70969 +
70970 + // enforce minimum permissions
70971 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70972 + return newmode;
70973 +bad:
70974 + needmode = oldmode;
70975 + if (is_privileged_binary(old_dentry))
70976 + needmode |= GR_SETID;
70977 +
70978 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70979 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70980 + return (GR_CREATE | GR_LINK);
70981 + } else if (newmode & GR_SUPPRESS)
70982 + return GR_SUPPRESS;
70983 + else
70984 + return 0;
70985 +}
70986 +
70987 +int
70988 +gr_check_hidden_task(const struct task_struct *task)
70989 +{
70990 + if (unlikely(!(gr_status & GR_READY)))
70991 + return 0;
70992 +
70993 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70994 + return 1;
70995 +
70996 + return 0;
70997 +}
70998 +
70999 +int
71000 +gr_check_protected_task(const struct task_struct *task)
71001 +{
71002 + if (unlikely(!(gr_status & GR_READY) || !task))
71003 + return 0;
71004 +
71005 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71006 + task->acl != current->acl)
71007 + return 1;
71008 +
71009 + return 0;
71010 +}
71011 +
71012 +int
71013 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71014 +{
71015 + struct task_struct *p;
71016 + int ret = 0;
71017 +
71018 + if (unlikely(!(gr_status & GR_READY) || !pid))
71019 + return ret;
71020 +
71021 + read_lock(&tasklist_lock);
71022 + do_each_pid_task(pid, type, p) {
71023 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71024 + p->acl != current->acl) {
71025 + ret = 1;
71026 + goto out;
71027 + }
71028 + } while_each_pid_task(pid, type, p);
71029 +out:
71030 + read_unlock(&tasklist_lock);
71031 +
71032 + return ret;
71033 +}
71034 +
71035 +void
71036 +gr_copy_label(struct task_struct *tsk)
71037 +{
71038 + struct task_struct *p = current;
71039 +
71040 + tsk->inherited = p->inherited;
71041 + tsk->acl_sp_role = 0;
71042 + tsk->acl_role_id = p->acl_role_id;
71043 + tsk->acl = p->acl;
71044 + tsk->role = p->role;
71045 + tsk->signal->used_accept = 0;
71046 + tsk->signal->curr_ip = p->signal->curr_ip;
71047 + tsk->signal->saved_ip = p->signal->saved_ip;
71048 + if (p->exec_file)
71049 + get_file(p->exec_file);
71050 + tsk->exec_file = p->exec_file;
71051 + tsk->is_writable = p->is_writable;
71052 + if (unlikely(p->signal->used_accept)) {
71053 + p->signal->curr_ip = 0;
71054 + p->signal->saved_ip = 0;
71055 + }
71056 +
71057 + return;
71058 +}
71059 +
71060 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71061 +
71062 +int
71063 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71064 +{
71065 + unsigned int i;
71066 + __u16 num;
71067 + uid_t *uidlist;
71068 + uid_t curuid;
71069 + int realok = 0;
71070 + int effectiveok = 0;
71071 + int fsok = 0;
71072 + uid_t globalreal, globaleffective, globalfs;
71073 +
71074 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71075 + struct user_struct *user;
71076 +
71077 + if (!uid_valid(real))
71078 + goto skipit;
71079 +
71080 + /* find user based on global namespace */
71081 +
71082 + globalreal = GR_GLOBAL_UID(real);
71083 +
71084 + user = find_user(make_kuid(&init_user_ns, globalreal));
71085 + if (user == NULL)
71086 + goto skipit;
71087 +
71088 + if (gr_process_kernel_setuid_ban(user)) {
71089 + /* for find_user */
71090 + free_uid(user);
71091 + return 1;
71092 + }
71093 +
71094 + /* for find_user */
71095 + free_uid(user);
71096 +
71097 +skipit:
71098 +#endif
71099 +
71100 + if (unlikely(!(gr_status & GR_READY)))
71101 + return 0;
71102 +
71103 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71104 + gr_log_learn_uid_change(real, effective, fs);
71105 +
71106 + num = current->acl->user_trans_num;
71107 + uidlist = current->acl->user_transitions;
71108 +
71109 + if (uidlist == NULL)
71110 + return 0;
71111 +
71112 + if (!uid_valid(real)) {
71113 + realok = 1;
71114 + globalreal = (uid_t)-1;
71115 + } else {
71116 + globalreal = GR_GLOBAL_UID(real);
71117 + }
71118 + if (!uid_valid(effective)) {
71119 + effectiveok = 1;
71120 + globaleffective = (uid_t)-1;
71121 + } else {
71122 + globaleffective = GR_GLOBAL_UID(effective);
71123 + }
71124 + if (!uid_valid(fs)) {
71125 + fsok = 1;
71126 + globalfs = (uid_t)-1;
71127 + } else {
71128 + globalfs = GR_GLOBAL_UID(fs);
71129 + }
71130 +
71131 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71132 + for (i = 0; i < num; i++) {
71133 + curuid = uidlist[i];
71134 + if (globalreal == curuid)
71135 + realok = 1;
71136 + if (globaleffective == curuid)
71137 + effectiveok = 1;
71138 + if (globalfs == curuid)
71139 + fsok = 1;
71140 + }
71141 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71142 + for (i = 0; i < num; i++) {
71143 + curuid = uidlist[i];
71144 + if (globalreal == curuid)
71145 + break;
71146 + if (globaleffective == curuid)
71147 + break;
71148 + if (globalfs == curuid)
71149 + break;
71150 + }
71151 + /* not in deny list */
71152 + if (i == num) {
71153 + realok = 1;
71154 + effectiveok = 1;
71155 + fsok = 1;
71156 + }
71157 + }
71158 +
71159 + if (realok && effectiveok && fsok)
71160 + return 0;
71161 + else {
71162 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71163 + return 1;
71164 + }
71165 +}
71166 +
71167 +int
71168 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71169 +{
71170 + unsigned int i;
71171 + __u16 num;
71172 + gid_t *gidlist;
71173 + gid_t curgid;
71174 + int realok = 0;
71175 + int effectiveok = 0;
71176 + int fsok = 0;
71177 + gid_t globalreal, globaleffective, globalfs;
71178 +
71179 + if (unlikely(!(gr_status & GR_READY)))
71180 + return 0;
71181 +
71182 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71183 + gr_log_learn_gid_change(real, effective, fs);
71184 +
71185 + num = current->acl->group_trans_num;
71186 + gidlist = current->acl->group_transitions;
71187 +
71188 + if (gidlist == NULL)
71189 + return 0;
71190 +
71191 + if (!gid_valid(real)) {
71192 + realok = 1;
71193 + globalreal = (gid_t)-1;
71194 + } else {
71195 + globalreal = GR_GLOBAL_GID(real);
71196 + }
71197 + if (!gid_valid(effective)) {
71198 + effectiveok = 1;
71199 + globaleffective = (gid_t)-1;
71200 + } else {
71201 + globaleffective = GR_GLOBAL_GID(effective);
71202 + }
71203 + if (!gid_valid(fs)) {
71204 + fsok = 1;
71205 + globalfs = (gid_t)-1;
71206 + } else {
71207 + globalfs = GR_GLOBAL_GID(fs);
71208 + }
71209 +
71210 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71211 + for (i = 0; i < num; i++) {
71212 + curgid = gidlist[i];
71213 + if (globalreal == curgid)
71214 + realok = 1;
71215 + if (globaleffective == curgid)
71216 + effectiveok = 1;
71217 + if (globalfs == curgid)
71218 + fsok = 1;
71219 + }
71220 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71221 + for (i = 0; i < num; i++) {
71222 + curgid = gidlist[i];
71223 + if (globalreal == curgid)
71224 + break;
71225 + if (globaleffective == curgid)
71226 + break;
71227 + if (globalfs == curgid)
71228 + break;
71229 + }
71230 + /* not in deny list */
71231 + if (i == num) {
71232 + realok = 1;
71233 + effectiveok = 1;
71234 + fsok = 1;
71235 + }
71236 + }
71237 +
71238 + if (realok && effectiveok && fsok)
71239 + return 0;
71240 + else {
71241 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71242 + return 1;
71243 + }
71244 +}
71245 +
71246 +extern int gr_acl_is_capable(const int cap);
71247 +
71248 +void
71249 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71250 +{
71251 + struct acl_role_label *role = task->role;
71252 + struct acl_role_label *origrole = role;
71253 + struct acl_subject_label *subj = NULL;
71254 + struct acl_object_label *obj;
71255 + struct file *filp;
71256 + uid_t uid;
71257 + gid_t gid;
71258 +
71259 + if (unlikely(!(gr_status & GR_READY)))
71260 + return;
71261 +
71262 + uid = GR_GLOBAL_UID(kuid);
71263 + gid = GR_GLOBAL_GID(kgid);
71264 +
71265 + filp = task->exec_file;
71266 +
71267 + /* kernel process, we'll give them the kernel role */
71268 + if (unlikely(!filp)) {
71269 + task->role = running_polstate.kernel_role;
71270 + task->acl = running_polstate.kernel_role->root_label;
71271 + return;
71272 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71273 + /* save the current ip at time of role lookup so that the proper
71274 + IP will be learned for role_allowed_ip */
71275 + task->signal->saved_ip = task->signal->curr_ip;
71276 + role = lookup_acl_role_label(task, uid, gid);
71277 + }
71278 +
71279 + /* don't change the role if we're not a privileged process */
71280 + if (role && task->role != role &&
71281 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71282 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71283 + return;
71284 +
71285 + task->role = role;
71286 +
71287 + if (task->inherited) {
71288 + /* if we reached our subject through inheritance, then first see
71289 + if there's a subject of the same name in the new role that has
71290 + an object that would result in the same inherited subject
71291 + */
71292 + subj = gr_get_subject_for_task(task, task->acl->filename, 0);
71293 + if (subj) {
71294 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, subj);
71295 + if (!(obj->mode & GR_INHERIT))
71296 + subj = NULL;
71297 + }
71298 +
71299 + }
71300 + if (subj == NULL) {
71301 + /* otherwise:
71302 + perform subject lookup in possibly new role
71303 + we can use this result below in the case where role == task->role
71304 + */
71305 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71306 + }
71307 +
71308 + /* if we changed uid/gid, but result in the same role
71309 + and are using inheritance, don't lose the inherited subject
71310 + if current subject is other than what normal lookup
71311 + would result in, we arrived via inheritance, don't
71312 + lose subject
71313 + */
71314 + if (role != origrole || (!(task->acl->mode & GR_INHERITLEARN) &&
71315 + (subj == task->acl)))
71316 + task->acl = subj;
71317 +
71318 + /* leave task->inherited unaffected */
71319 +
71320 + task->is_writable = 0;
71321 +
71322 + /* ignore additional mmap checks for processes that are writable
71323 + by the default ACL */
71324 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71325 + if (unlikely(obj->mode & GR_WRITE))
71326 + task->is_writable = 1;
71327 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71328 + if (unlikely(obj->mode & GR_WRITE))
71329 + task->is_writable = 1;
71330 +
71331 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71332 + 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);
71333 +#endif
71334 +
71335 + gr_set_proc_res(task);
71336 +
71337 + return;
71338 +}
71339 +
71340 +int
71341 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71342 + const int unsafe_flags)
71343 +{
71344 + struct task_struct *task = current;
71345 + struct acl_subject_label *newacl;
71346 + struct acl_object_label *obj;
71347 + __u32 retmode;
71348 +
71349 + if (unlikely(!(gr_status & GR_READY)))
71350 + return 0;
71351 +
71352 + newacl = chk_subj_label(dentry, mnt, task->role);
71353 +
71354 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71355 + did an exec
71356 + */
71357 + rcu_read_lock();
71358 + read_lock(&tasklist_lock);
71359 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71360 + (task->parent->acl->mode & GR_POVERRIDE))) {
71361 + read_unlock(&tasklist_lock);
71362 + rcu_read_unlock();
71363 + goto skip_check;
71364 + }
71365 + read_unlock(&tasklist_lock);
71366 + rcu_read_unlock();
71367 +
71368 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71369 + !(task->role->roletype & GR_ROLE_GOD) &&
71370 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71371 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71372 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71373 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71374 + else
71375 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71376 + return -EACCES;
71377 + }
71378 +
71379 +skip_check:
71380 +
71381 + obj = chk_obj_label(dentry, mnt, task->acl);
71382 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71383 +
71384 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71385 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71386 + if (obj->nested)
71387 + task->acl = obj->nested;
71388 + else
71389 + task->acl = newacl;
71390 + task->inherited = 0;
71391 + } else {
71392 + task->inherited = 1;
71393 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71394 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71395 + }
71396 +
71397 + task->is_writable = 0;
71398 +
71399 + /* ignore additional mmap checks for processes that are writable
71400 + by the default ACL */
71401 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71402 + if (unlikely(obj->mode & GR_WRITE))
71403 + task->is_writable = 1;
71404 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71405 + if (unlikely(obj->mode & GR_WRITE))
71406 + task->is_writable = 1;
71407 +
71408 + gr_set_proc_res(task);
71409 +
71410 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71411 + 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);
71412 +#endif
71413 + return 0;
71414 +}
71415 +
71416 +/* always called with valid inodev ptr */
71417 +static void
71418 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71419 +{
71420 + struct acl_object_label *matchpo;
71421 + struct acl_subject_label *matchps;
71422 + struct acl_subject_label *subj;
71423 + struct acl_role_label *role;
71424 + unsigned int x;
71425 +
71426 + FOR_EACH_ROLE_START(role)
71427 + FOR_EACH_SUBJECT_START(role, subj, x)
71428 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71429 + matchpo->mode |= GR_DELETED;
71430 + FOR_EACH_SUBJECT_END(subj,x)
71431 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71432 + /* nested subjects aren't in the role's subj_hash table */
71433 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71434 + matchpo->mode |= GR_DELETED;
71435 + FOR_EACH_NESTED_SUBJECT_END(subj)
71436 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71437 + matchps->mode |= GR_DELETED;
71438 + FOR_EACH_ROLE_END(role)
71439 +
71440 + inodev->nentry->deleted = 1;
71441 +
71442 + return;
71443 +}
71444 +
71445 +void
71446 +gr_handle_delete(const ino_t ino, const dev_t dev)
71447 +{
71448 + struct inodev_entry *inodev;
71449 +
71450 + if (unlikely(!(gr_status & GR_READY)))
71451 + return;
71452 +
71453 + write_lock(&gr_inode_lock);
71454 + inodev = lookup_inodev_entry(ino, dev);
71455 + if (inodev != NULL)
71456 + do_handle_delete(inodev, ino, dev);
71457 + write_unlock(&gr_inode_lock);
71458 +
71459 + return;
71460 +}
71461 +
71462 +static void
71463 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71464 + const ino_t newinode, const dev_t newdevice,
71465 + struct acl_subject_label *subj)
71466 +{
71467 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71468 + struct acl_object_label *match;
71469 +
71470 + match = subj->obj_hash[index];
71471 +
71472 + while (match && (match->inode != oldinode ||
71473 + match->device != olddevice ||
71474 + !(match->mode & GR_DELETED)))
71475 + match = match->next;
71476 +
71477 + if (match && (match->inode == oldinode)
71478 + && (match->device == olddevice)
71479 + && (match->mode & GR_DELETED)) {
71480 + if (match->prev == NULL) {
71481 + subj->obj_hash[index] = match->next;
71482 + if (match->next != NULL)
71483 + match->next->prev = NULL;
71484 + } else {
71485 + match->prev->next = match->next;
71486 + if (match->next != NULL)
71487 + match->next->prev = match->prev;
71488 + }
71489 + match->prev = NULL;
71490 + match->next = NULL;
71491 + match->inode = newinode;
71492 + match->device = newdevice;
71493 + match->mode &= ~GR_DELETED;
71494 +
71495 + insert_acl_obj_label(match, subj);
71496 + }
71497 +
71498 + return;
71499 +}
71500 +
71501 +static void
71502 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71503 + const ino_t newinode, const dev_t newdevice,
71504 + struct acl_role_label *role)
71505 +{
71506 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71507 + struct acl_subject_label *match;
71508 +
71509 + match = role->subj_hash[index];
71510 +
71511 + while (match && (match->inode != oldinode ||
71512 + match->device != olddevice ||
71513 + !(match->mode & GR_DELETED)))
71514 + match = match->next;
71515 +
71516 + if (match && (match->inode == oldinode)
71517 + && (match->device == olddevice)
71518 + && (match->mode & GR_DELETED)) {
71519 + if (match->prev == NULL) {
71520 + role->subj_hash[index] = match->next;
71521 + if (match->next != NULL)
71522 + match->next->prev = NULL;
71523 + } else {
71524 + match->prev->next = match->next;
71525 + if (match->next != NULL)
71526 + match->next->prev = match->prev;
71527 + }
71528 + match->prev = NULL;
71529 + match->next = NULL;
71530 + match->inode = newinode;
71531 + match->device = newdevice;
71532 + match->mode &= ~GR_DELETED;
71533 +
71534 + insert_acl_subj_label(match, role);
71535 + }
71536 +
71537 + return;
71538 +}
71539 +
71540 +static void
71541 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71542 + const ino_t newinode, const dev_t newdevice)
71543 +{
71544 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71545 + struct inodev_entry *match;
71546 +
71547 + match = running_polstate.inodev_set.i_hash[index];
71548 +
71549 + while (match && (match->nentry->inode != oldinode ||
71550 + match->nentry->device != olddevice || !match->nentry->deleted))
71551 + match = match->next;
71552 +
71553 + if (match && (match->nentry->inode == oldinode)
71554 + && (match->nentry->device == olddevice) &&
71555 + match->nentry->deleted) {
71556 + if (match->prev == NULL) {
71557 + running_polstate.inodev_set.i_hash[index] = match->next;
71558 + if (match->next != NULL)
71559 + match->next->prev = NULL;
71560 + } else {
71561 + match->prev->next = match->next;
71562 + if (match->next != NULL)
71563 + match->next->prev = match->prev;
71564 + }
71565 + match->prev = NULL;
71566 + match->next = NULL;
71567 + match->nentry->inode = newinode;
71568 + match->nentry->device = newdevice;
71569 + match->nentry->deleted = 0;
71570 +
71571 + insert_inodev_entry(match);
71572 + }
71573 +
71574 + return;
71575 +}
71576 +
71577 +static void
71578 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71579 +{
71580 + struct acl_subject_label *subj;
71581 + struct acl_role_label *role;
71582 + unsigned int x;
71583 +
71584 + FOR_EACH_ROLE_START(role)
71585 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71586 +
71587 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71588 + if ((subj->inode == ino) && (subj->device == dev)) {
71589 + subj->inode = ino;
71590 + subj->device = dev;
71591 + }
71592 + /* nested subjects aren't in the role's subj_hash table */
71593 + update_acl_obj_label(matchn->inode, matchn->device,
71594 + ino, dev, subj);
71595 + FOR_EACH_NESTED_SUBJECT_END(subj)
71596 + FOR_EACH_SUBJECT_START(role, subj, x)
71597 + update_acl_obj_label(matchn->inode, matchn->device,
71598 + ino, dev, subj);
71599 + FOR_EACH_SUBJECT_END(subj,x)
71600 + FOR_EACH_ROLE_END(role)
71601 +
71602 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71603 +
71604 + return;
71605 +}
71606 +
71607 +static void
71608 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71609 + const struct vfsmount *mnt)
71610 +{
71611 + ino_t ino = dentry->d_inode->i_ino;
71612 + dev_t dev = __get_dev(dentry);
71613 +
71614 + __do_handle_create(matchn, ino, dev);
71615 +
71616 + return;
71617 +}
71618 +
71619 +void
71620 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71621 +{
71622 + struct name_entry *matchn;
71623 +
71624 + if (unlikely(!(gr_status & GR_READY)))
71625 + return;
71626 +
71627 + preempt_disable();
71628 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71629 +
71630 + if (unlikely((unsigned long)matchn)) {
71631 + write_lock(&gr_inode_lock);
71632 + do_handle_create(matchn, dentry, mnt);
71633 + write_unlock(&gr_inode_lock);
71634 + }
71635 + preempt_enable();
71636 +
71637 + return;
71638 +}
71639 +
71640 +void
71641 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71642 +{
71643 + struct name_entry *matchn;
71644 +
71645 + if (unlikely(!(gr_status & GR_READY)))
71646 + return;
71647 +
71648 + preempt_disable();
71649 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71650 +
71651 + if (unlikely((unsigned long)matchn)) {
71652 + write_lock(&gr_inode_lock);
71653 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71654 + write_unlock(&gr_inode_lock);
71655 + }
71656 + preempt_enable();
71657 +
71658 + return;
71659 +}
71660 +
71661 +void
71662 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71663 + struct dentry *old_dentry,
71664 + struct dentry *new_dentry,
71665 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71666 +{
71667 + struct name_entry *matchn;
71668 + struct name_entry *matchn2 = NULL;
71669 + struct inodev_entry *inodev;
71670 + struct inode *inode = new_dentry->d_inode;
71671 + ino_t old_ino = old_dentry->d_inode->i_ino;
71672 + dev_t old_dev = __get_dev(old_dentry);
71673 + unsigned int exchange = flags & RENAME_EXCHANGE;
71674 +
71675 + /* vfs_rename swaps the name and parent link for old_dentry and
71676 + new_dentry
71677 + at this point, old_dentry has the new name, parent link, and inode
71678 + for the renamed file
71679 + if a file is being replaced by a rename, new_dentry has the inode
71680 + and name for the replaced file
71681 + */
71682 +
71683 + if (unlikely(!(gr_status & GR_READY)))
71684 + return;
71685 +
71686 + preempt_disable();
71687 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71688 +
71689 + /* exchange cases:
71690 + a filename exists for the source, but not dest
71691 + do a recreate on source
71692 + a filename exists for the dest, but not source
71693 + do a recreate on dest
71694 + a filename exists for both source and dest
71695 + delete source and dest, then create source and dest
71696 + a filename exists for neither source nor dest
71697 + no updates needed
71698 +
71699 + the name entry lookups get us the old inode/dev associated with
71700 + each name, so do the deletes first (if possible) so that when
71701 + we do the create, we pick up on the right entries
71702 + */
71703 +
71704 + if (exchange)
71705 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71706 +
71707 + /* we wouldn't have to check d_inode if it weren't for
71708 + NFS silly-renaming
71709 + */
71710 +
71711 + write_lock(&gr_inode_lock);
71712 + if (unlikely((replace || exchange) && inode)) {
71713 + ino_t new_ino = inode->i_ino;
71714 + dev_t new_dev = __get_dev(new_dentry);
71715 +
71716 + inodev = lookup_inodev_entry(new_ino, new_dev);
71717 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71718 + do_handle_delete(inodev, new_ino, new_dev);
71719 + }
71720 +
71721 + inodev = lookup_inodev_entry(old_ino, old_dev);
71722 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71723 + do_handle_delete(inodev, old_ino, old_dev);
71724 +
71725 + if (unlikely(matchn != NULL))
71726 + do_handle_create(matchn, old_dentry, mnt);
71727 +
71728 + if (unlikely(matchn2 != NULL))
71729 + do_handle_create(matchn2, new_dentry, mnt);
71730 +
71731 + write_unlock(&gr_inode_lock);
71732 + preempt_enable();
71733 +
71734 + return;
71735 +}
71736 +
71737 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71738 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71739 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71740 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71741 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71742 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71743 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71744 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71745 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71746 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71747 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71748 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71749 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71750 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71751 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71752 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71753 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71754 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71755 +};
71756 +
71757 +void
71758 +gr_learn_resource(const struct task_struct *task,
71759 + const int res, const unsigned long wanted, const int gt)
71760 +{
71761 + struct acl_subject_label *acl;
71762 + const struct cred *cred;
71763 +
71764 + if (unlikely((gr_status & GR_READY) &&
71765 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71766 + goto skip_reslog;
71767 +
71768 + gr_log_resource(task, res, wanted, gt);
71769 +skip_reslog:
71770 +
71771 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71772 + return;
71773 +
71774 + acl = task->acl;
71775 +
71776 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71777 + !(acl->resmask & (1U << (unsigned short) res))))
71778 + return;
71779 +
71780 + if (wanted >= acl->res[res].rlim_cur) {
71781 + unsigned long res_add;
71782 +
71783 + res_add = wanted + res_learn_bumps[res];
71784 +
71785 + acl->res[res].rlim_cur = res_add;
71786 +
71787 + if (wanted > acl->res[res].rlim_max)
71788 + acl->res[res].rlim_max = res_add;
71789 +
71790 + /* only log the subject filename, since resource logging is supported for
71791 + single-subject learning only */
71792 + rcu_read_lock();
71793 + cred = __task_cred(task);
71794 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71795 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71796 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71797 + "", (unsigned long) res, &task->signal->saved_ip);
71798 + rcu_read_unlock();
71799 + }
71800 +
71801 + return;
71802 +}
71803 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71804 +#endif
71805 +
71806 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71807 +void
71808 +pax_set_initial_flags(struct linux_binprm *bprm)
71809 +{
71810 + struct task_struct *task = current;
71811 + struct acl_subject_label *proc;
71812 + unsigned long flags;
71813 +
71814 + if (unlikely(!(gr_status & GR_READY)))
71815 + return;
71816 +
71817 + flags = pax_get_flags(task);
71818 +
71819 + proc = task->acl;
71820 +
71821 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71822 + flags &= ~MF_PAX_PAGEEXEC;
71823 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71824 + flags &= ~MF_PAX_SEGMEXEC;
71825 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71826 + flags &= ~MF_PAX_RANDMMAP;
71827 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71828 + flags &= ~MF_PAX_EMUTRAMP;
71829 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71830 + flags &= ~MF_PAX_MPROTECT;
71831 +
71832 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71833 + flags |= MF_PAX_PAGEEXEC;
71834 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71835 + flags |= MF_PAX_SEGMEXEC;
71836 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71837 + flags |= MF_PAX_RANDMMAP;
71838 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71839 + flags |= MF_PAX_EMUTRAMP;
71840 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71841 + flags |= MF_PAX_MPROTECT;
71842 +
71843 + pax_set_flags(task, flags);
71844 +
71845 + return;
71846 +}
71847 +#endif
71848 +
71849 +int
71850 +gr_handle_proc_ptrace(struct task_struct *task)
71851 +{
71852 + struct file *filp;
71853 + struct task_struct *tmp = task;
71854 + struct task_struct *curtemp = current;
71855 + __u32 retmode;
71856 +
71857 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71858 + if (unlikely(!(gr_status & GR_READY)))
71859 + return 0;
71860 +#endif
71861 +
71862 + read_lock(&tasklist_lock);
71863 + read_lock(&grsec_exec_file_lock);
71864 + filp = task->exec_file;
71865 +
71866 + while (task_pid_nr(tmp) > 0) {
71867 + if (tmp == curtemp)
71868 + break;
71869 + tmp = tmp->real_parent;
71870 + }
71871 +
71872 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71873 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71874 + read_unlock(&grsec_exec_file_lock);
71875 + read_unlock(&tasklist_lock);
71876 + return 1;
71877 + }
71878 +
71879 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71880 + if (!(gr_status & GR_READY)) {
71881 + read_unlock(&grsec_exec_file_lock);
71882 + read_unlock(&tasklist_lock);
71883 + return 0;
71884 + }
71885 +#endif
71886 +
71887 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71888 + read_unlock(&grsec_exec_file_lock);
71889 + read_unlock(&tasklist_lock);
71890 +
71891 + if (retmode & GR_NOPTRACE)
71892 + return 1;
71893 +
71894 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71895 + && (current->acl != task->acl || (current->acl != current->role->root_label
71896 + && task_pid_nr(current) != task_pid_nr(task))))
71897 + return 1;
71898 +
71899 + return 0;
71900 +}
71901 +
71902 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71903 +{
71904 + if (unlikely(!(gr_status & GR_READY)))
71905 + return;
71906 +
71907 + if (!(current->role->roletype & GR_ROLE_GOD))
71908 + return;
71909 +
71910 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71911 + p->role->rolename, gr_task_roletype_to_char(p),
71912 + p->acl->filename);
71913 +}
71914 +
71915 +int
71916 +gr_handle_ptrace(struct task_struct *task, const long request)
71917 +{
71918 + struct task_struct *tmp = task;
71919 + struct task_struct *curtemp = current;
71920 + __u32 retmode;
71921 +
71922 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71923 + if (unlikely(!(gr_status & GR_READY)))
71924 + return 0;
71925 +#endif
71926 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71927 + read_lock(&tasklist_lock);
71928 + while (task_pid_nr(tmp) > 0) {
71929 + if (tmp == curtemp)
71930 + break;
71931 + tmp = tmp->real_parent;
71932 + }
71933 +
71934 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71935 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71936 + read_unlock(&tasklist_lock);
71937 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71938 + return 1;
71939 + }
71940 + read_unlock(&tasklist_lock);
71941 + }
71942 +
71943 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71944 + if (!(gr_status & GR_READY))
71945 + return 0;
71946 +#endif
71947 +
71948 + read_lock(&grsec_exec_file_lock);
71949 + if (unlikely(!task->exec_file)) {
71950 + read_unlock(&grsec_exec_file_lock);
71951 + return 0;
71952 + }
71953 +
71954 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71955 + read_unlock(&grsec_exec_file_lock);
71956 +
71957 + if (retmode & GR_NOPTRACE) {
71958 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71959 + return 1;
71960 + }
71961 +
71962 + if (retmode & GR_PTRACERD) {
71963 + switch (request) {
71964 + case PTRACE_SEIZE:
71965 + case PTRACE_POKETEXT:
71966 + case PTRACE_POKEDATA:
71967 + case PTRACE_POKEUSR:
71968 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71969 + case PTRACE_SETREGS:
71970 + case PTRACE_SETFPREGS:
71971 +#endif
71972 +#ifdef CONFIG_X86
71973 + case PTRACE_SETFPXREGS:
71974 +#endif
71975 +#ifdef CONFIG_ALTIVEC
71976 + case PTRACE_SETVRREGS:
71977 +#endif
71978 + return 1;
71979 + default:
71980 + return 0;
71981 + }
71982 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
71983 + !(current->role->roletype & GR_ROLE_GOD) &&
71984 + (current->acl != task->acl)) {
71985 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71986 + return 1;
71987 + }
71988 +
71989 + return 0;
71990 +}
71991 +
71992 +static int is_writable_mmap(const struct file *filp)
71993 +{
71994 + struct task_struct *task = current;
71995 + struct acl_object_label *obj, *obj2;
71996 +
71997 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71998 + !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))) {
71999 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72000 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72001 + task->role->root_label);
72002 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72003 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72004 + return 1;
72005 + }
72006 + }
72007 + return 0;
72008 +}
72009 +
72010 +int
72011 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72012 +{
72013 + __u32 mode;
72014 +
72015 + if (unlikely(!file || !(prot & PROT_EXEC)))
72016 + return 1;
72017 +
72018 + if (is_writable_mmap(file))
72019 + return 0;
72020 +
72021 + mode =
72022 + gr_search_file(file->f_path.dentry,
72023 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72024 + file->f_path.mnt);
72025 +
72026 + if (!gr_tpe_allow(file))
72027 + return 0;
72028 +
72029 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72030 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72031 + return 0;
72032 + } else if (unlikely(!(mode & GR_EXEC))) {
72033 + return 0;
72034 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72035 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72036 + return 1;
72037 + }
72038 +
72039 + return 1;
72040 +}
72041 +
72042 +int
72043 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72044 +{
72045 + __u32 mode;
72046 +
72047 + if (unlikely(!file || !(prot & PROT_EXEC)))
72048 + return 1;
72049 +
72050 + if (is_writable_mmap(file))
72051 + return 0;
72052 +
72053 + mode =
72054 + gr_search_file(file->f_path.dentry,
72055 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72056 + file->f_path.mnt);
72057 +
72058 + if (!gr_tpe_allow(file))
72059 + return 0;
72060 +
72061 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72062 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72063 + return 0;
72064 + } else if (unlikely(!(mode & GR_EXEC))) {
72065 + return 0;
72066 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72067 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72068 + return 1;
72069 + }
72070 +
72071 + return 1;
72072 +}
72073 +
72074 +void
72075 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72076 +{
72077 + unsigned long runtime, cputime;
72078 + cputime_t utime, stime;
72079 + unsigned int wday, cday;
72080 + __u8 whr, chr;
72081 + __u8 wmin, cmin;
72082 + __u8 wsec, csec;
72083 + struct timespec curtime, starttime;
72084 +
72085 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72086 + !(task->acl->mode & GR_PROCACCT)))
72087 + return;
72088 +
72089 + curtime = ns_to_timespec(ktime_get_ns());
72090 + starttime = ns_to_timespec(task->start_time);
72091 + runtime = curtime.tv_sec - starttime.tv_sec;
72092 + wday = runtime / (60 * 60 * 24);
72093 + runtime -= wday * (60 * 60 * 24);
72094 + whr = runtime / (60 * 60);
72095 + runtime -= whr * (60 * 60);
72096 + wmin = runtime / 60;
72097 + runtime -= wmin * 60;
72098 + wsec = runtime;
72099 +
72100 + task_cputime(task, &utime, &stime);
72101 + cputime = cputime_to_secs(utime + stime);
72102 + cday = cputime / (60 * 60 * 24);
72103 + cputime -= cday * (60 * 60 * 24);
72104 + chr = cputime / (60 * 60);
72105 + cputime -= chr * (60 * 60);
72106 + cmin = cputime / 60;
72107 + cputime -= cmin * 60;
72108 + csec = cputime;
72109 +
72110 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72111 +
72112 + return;
72113 +}
72114 +
72115 +#ifdef CONFIG_TASKSTATS
72116 +int gr_is_taskstats_denied(int pid)
72117 +{
72118 + struct task_struct *task;
72119 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72120 + const struct cred *cred;
72121 +#endif
72122 + int ret = 0;
72123 +
72124 + /* restrict taskstats viewing to un-chrooted root users
72125 + who have the 'view' subject flag if the RBAC system is enabled
72126 + */
72127 +
72128 + rcu_read_lock();
72129 + read_lock(&tasklist_lock);
72130 + task = find_task_by_vpid(pid);
72131 + if (task) {
72132 +#ifdef CONFIG_GRKERNSEC_CHROOT
72133 + if (proc_is_chrooted(task))
72134 + ret = -EACCES;
72135 +#endif
72136 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72137 + cred = __task_cred(task);
72138 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72139 + if (gr_is_global_nonroot(cred->uid))
72140 + ret = -EACCES;
72141 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72142 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72143 + ret = -EACCES;
72144 +#endif
72145 +#endif
72146 + if (gr_status & GR_READY) {
72147 + if (!(task->acl->mode & GR_VIEW))
72148 + ret = -EACCES;
72149 + }
72150 + } else
72151 + ret = -ENOENT;
72152 +
72153 + read_unlock(&tasklist_lock);
72154 + rcu_read_unlock();
72155 +
72156 + return ret;
72157 +}
72158 +#endif
72159 +
72160 +/* AUXV entries are filled via a descendant of search_binary_handler
72161 + after we've already applied the subject for the target
72162 +*/
72163 +int gr_acl_enable_at_secure(void)
72164 +{
72165 + if (unlikely(!(gr_status & GR_READY)))
72166 + return 0;
72167 +
72168 + if (current->acl->mode & GR_ATSECURE)
72169 + return 1;
72170 +
72171 + return 0;
72172 +}
72173 +
72174 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72175 +{
72176 + struct task_struct *task = current;
72177 + struct dentry *dentry = file->f_path.dentry;
72178 + struct vfsmount *mnt = file->f_path.mnt;
72179 + struct acl_object_label *obj, *tmp;
72180 + struct acl_subject_label *subj;
72181 + unsigned int bufsize;
72182 + int is_not_root;
72183 + char *path;
72184 + dev_t dev = __get_dev(dentry);
72185 +
72186 + if (unlikely(!(gr_status & GR_READY)))
72187 + return 1;
72188 +
72189 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72190 + return 1;
72191 +
72192 + /* ignore Eric Biederman */
72193 + if (IS_PRIVATE(dentry->d_inode))
72194 + return 1;
72195 +
72196 + subj = task->acl;
72197 + read_lock(&gr_inode_lock);
72198 + do {
72199 + obj = lookup_acl_obj_label(ino, dev, subj);
72200 + if (obj != NULL) {
72201 + read_unlock(&gr_inode_lock);
72202 + return (obj->mode & GR_FIND) ? 1 : 0;
72203 + }
72204 + } while ((subj = subj->parent_subject));
72205 + read_unlock(&gr_inode_lock);
72206 +
72207 + /* this is purely an optimization since we're looking for an object
72208 + for the directory we're doing a readdir on
72209 + if it's possible for any globbed object to match the entry we're
72210 + filling into the directory, then the object we find here will be
72211 + an anchor point with attached globbed objects
72212 + */
72213 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72214 + if (obj->globbed == NULL)
72215 + return (obj->mode & GR_FIND) ? 1 : 0;
72216 +
72217 + is_not_root = ((obj->filename[0] == '/') &&
72218 + (obj->filename[1] == '\0')) ? 0 : 1;
72219 + bufsize = PAGE_SIZE - namelen - is_not_root;
72220 +
72221 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72222 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72223 + return 1;
72224 +
72225 + preempt_disable();
72226 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72227 + bufsize);
72228 +
72229 + bufsize = strlen(path);
72230 +
72231 + /* if base is "/", don't append an additional slash */
72232 + if (is_not_root)
72233 + *(path + bufsize) = '/';
72234 + memcpy(path + bufsize + is_not_root, name, namelen);
72235 + *(path + bufsize + namelen + is_not_root) = '\0';
72236 +
72237 + tmp = obj->globbed;
72238 + while (tmp) {
72239 + if (!glob_match(tmp->filename, path)) {
72240 + preempt_enable();
72241 + return (tmp->mode & GR_FIND) ? 1 : 0;
72242 + }
72243 + tmp = tmp->next;
72244 + }
72245 + preempt_enable();
72246 + return (obj->mode & GR_FIND) ? 1 : 0;
72247 +}
72248 +
72249 +void gr_put_exec_file(struct task_struct *task)
72250 +{
72251 + struct file *filp;
72252 +
72253 + write_lock(&grsec_exec_file_lock);
72254 + filp = task->exec_file;
72255 + task->exec_file = NULL;
72256 + write_unlock(&grsec_exec_file_lock);
72257 +
72258 + if (filp)
72259 + fput(filp);
72260 +
72261 + return;
72262 +}
72263 +
72264 +
72265 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72266 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72267 +#endif
72268 +#ifdef CONFIG_SECURITY
72269 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72270 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72271 +#endif
72272 +
72273 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72274 new file mode 100644
72275 index 0000000..18ffbbd
72276 --- /dev/null
72277 +++ b/grsecurity/gracl_alloc.c
72278 @@ -0,0 +1,105 @@
72279 +#include <linux/kernel.h>
72280 +#include <linux/mm.h>
72281 +#include <linux/slab.h>
72282 +#include <linux/vmalloc.h>
72283 +#include <linux/gracl.h>
72284 +#include <linux/grsecurity.h>
72285 +
72286 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72287 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72288 +
72289 +static __inline__ int
72290 +alloc_pop(void)
72291 +{
72292 + if (current_alloc_state->alloc_stack_next == 1)
72293 + return 0;
72294 +
72295 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72296 +
72297 + current_alloc_state->alloc_stack_next--;
72298 +
72299 + return 1;
72300 +}
72301 +
72302 +static __inline__ int
72303 +alloc_push(void *buf)
72304 +{
72305 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72306 + return 1;
72307 +
72308 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72309 +
72310 + current_alloc_state->alloc_stack_next++;
72311 +
72312 + return 0;
72313 +}
72314 +
72315 +void *
72316 +acl_alloc(unsigned long len)
72317 +{
72318 + void *ret = NULL;
72319 +
72320 + if (!len || len > PAGE_SIZE)
72321 + goto out;
72322 +
72323 + ret = kmalloc(len, GFP_KERNEL);
72324 +
72325 + if (ret) {
72326 + if (alloc_push(ret)) {
72327 + kfree(ret);
72328 + ret = NULL;
72329 + }
72330 + }
72331 +
72332 +out:
72333 + return ret;
72334 +}
72335 +
72336 +void *
72337 +acl_alloc_num(unsigned long num, unsigned long len)
72338 +{
72339 + if (!len || (num > (PAGE_SIZE / len)))
72340 + return NULL;
72341 +
72342 + return acl_alloc(num * len);
72343 +}
72344 +
72345 +void
72346 +acl_free_all(void)
72347 +{
72348 + if (!current_alloc_state->alloc_stack)
72349 + return;
72350 +
72351 + while (alloc_pop()) ;
72352 +
72353 + if (current_alloc_state->alloc_stack) {
72354 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72355 + kfree(current_alloc_state->alloc_stack);
72356 + else
72357 + vfree(current_alloc_state->alloc_stack);
72358 + }
72359 +
72360 + current_alloc_state->alloc_stack = NULL;
72361 + current_alloc_state->alloc_stack_size = 1;
72362 + current_alloc_state->alloc_stack_next = 1;
72363 +
72364 + return;
72365 +}
72366 +
72367 +int
72368 +acl_alloc_stack_init(unsigned long size)
72369 +{
72370 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72371 + current_alloc_state->alloc_stack =
72372 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72373 + else
72374 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72375 +
72376 + current_alloc_state->alloc_stack_size = size;
72377 + current_alloc_state->alloc_stack_next = 1;
72378 +
72379 + if (!current_alloc_state->alloc_stack)
72380 + return 0;
72381 + else
72382 + return 1;
72383 +}
72384 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72385 new file mode 100644
72386 index 0000000..1a94c11
72387 --- /dev/null
72388 +++ b/grsecurity/gracl_cap.c
72389 @@ -0,0 +1,127 @@
72390 +#include <linux/kernel.h>
72391 +#include <linux/module.h>
72392 +#include <linux/sched.h>
72393 +#include <linux/gracl.h>
72394 +#include <linux/grsecurity.h>
72395 +#include <linux/grinternal.h>
72396 +
72397 +extern const char *captab_log[];
72398 +extern int captab_log_entries;
72399 +
72400 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72401 +{
72402 + struct acl_subject_label *curracl;
72403 +
72404 + if (!gr_acl_is_enabled())
72405 + return 1;
72406 +
72407 + curracl = task->acl;
72408 +
72409 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72410 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72411 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72412 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72413 + gr_to_filename(task->exec_file->f_path.dentry,
72414 + task->exec_file->f_path.mnt) : curracl->filename,
72415 + curracl->filename, 0UL,
72416 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72417 + return 1;
72418 + }
72419 +
72420 + return 0;
72421 +}
72422 +
72423 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72424 +{
72425 + struct acl_subject_label *curracl;
72426 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72427 + kernel_cap_t cap_audit = __cap_empty_set;
72428 +
72429 + if (!gr_acl_is_enabled())
72430 + return 1;
72431 +
72432 + curracl = task->acl;
72433 +
72434 + cap_drop = curracl->cap_lower;
72435 + cap_mask = curracl->cap_mask;
72436 + cap_audit = curracl->cap_invert_audit;
72437 +
72438 + while ((curracl = curracl->parent_subject)) {
72439 + /* if the cap isn't specified in the current computed mask but is specified in the
72440 + current level subject, and is lowered in the current level subject, then add
72441 + it to the set of dropped capabilities
72442 + otherwise, add the current level subject's mask to the current computed mask
72443 + */
72444 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72445 + cap_raise(cap_mask, cap);
72446 + if (cap_raised(curracl->cap_lower, cap))
72447 + cap_raise(cap_drop, cap);
72448 + if (cap_raised(curracl->cap_invert_audit, cap))
72449 + cap_raise(cap_audit, cap);
72450 + }
72451 + }
72452 +
72453 + if (!cap_raised(cap_drop, cap)) {
72454 + if (cap_raised(cap_audit, cap))
72455 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72456 + return 1;
72457 + }
72458 +
72459 + /* only learn the capability use if the process has the capability in the
72460 + general case, the two uses in sys.c of gr_learn_cap are an exception
72461 + to this rule to ensure any role transition involves what the full-learned
72462 + policy believes in a privileged process
72463 + */
72464 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72465 + return 1;
72466 +
72467 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72468 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72469 +
72470 + return 0;
72471 +}
72472 +
72473 +int
72474 +gr_acl_is_capable(const int cap)
72475 +{
72476 + return gr_task_acl_is_capable(current, current_cred(), cap);
72477 +}
72478 +
72479 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72480 +{
72481 + struct acl_subject_label *curracl;
72482 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72483 +
72484 + if (!gr_acl_is_enabled())
72485 + return 1;
72486 +
72487 + curracl = task->acl;
72488 +
72489 + cap_drop = curracl->cap_lower;
72490 + cap_mask = curracl->cap_mask;
72491 +
72492 + while ((curracl = curracl->parent_subject)) {
72493 + /* if the cap isn't specified in the current computed mask but is specified in the
72494 + current level subject, and is lowered in the current level subject, then add
72495 + it to the set of dropped capabilities
72496 + otherwise, add the current level subject's mask to the current computed mask
72497 + */
72498 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72499 + cap_raise(cap_mask, cap);
72500 + if (cap_raised(curracl->cap_lower, cap))
72501 + cap_raise(cap_drop, cap);
72502 + }
72503 + }
72504 +
72505 + if (!cap_raised(cap_drop, cap))
72506 + return 1;
72507 +
72508 + return 0;
72509 +}
72510 +
72511 +int
72512 +gr_acl_is_capable_nolog(const int cap)
72513 +{
72514 + return gr_task_acl_is_capable_nolog(current, cap);
72515 +}
72516 +
72517 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72518 new file mode 100644
72519 index 0000000..ca25605
72520 --- /dev/null
72521 +++ b/grsecurity/gracl_compat.c
72522 @@ -0,0 +1,270 @@
72523 +#include <linux/kernel.h>
72524 +#include <linux/gracl.h>
72525 +#include <linux/compat.h>
72526 +#include <linux/gracl_compat.h>
72527 +
72528 +#include <asm/uaccess.h>
72529 +
72530 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72531 +{
72532 + struct gr_arg_wrapper_compat uwrapcompat;
72533 +
72534 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72535 + return -EFAULT;
72536 +
72537 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72538 + (uwrapcompat.version != 0x2901)) ||
72539 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72540 + return -EINVAL;
72541 +
72542 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72543 + uwrap->version = uwrapcompat.version;
72544 + uwrap->size = sizeof(struct gr_arg);
72545 +
72546 + return 0;
72547 +}
72548 +
72549 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72550 +{
72551 + struct gr_arg_compat argcompat;
72552 +
72553 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72554 + return -EFAULT;
72555 +
72556 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72557 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72558 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72559 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72560 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72561 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72562 +
72563 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72564 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72565 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72566 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72567 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72568 + arg->segv_device = argcompat.segv_device;
72569 + arg->segv_inode = argcompat.segv_inode;
72570 + arg->segv_uid = argcompat.segv_uid;
72571 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72572 + arg->mode = argcompat.mode;
72573 +
72574 + return 0;
72575 +}
72576 +
72577 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72578 +{
72579 + struct acl_object_label_compat objcompat;
72580 +
72581 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72582 + return -EFAULT;
72583 +
72584 + obj->filename = compat_ptr(objcompat.filename);
72585 + obj->inode = objcompat.inode;
72586 + obj->device = objcompat.device;
72587 + obj->mode = objcompat.mode;
72588 +
72589 + obj->nested = compat_ptr(objcompat.nested);
72590 + obj->globbed = compat_ptr(objcompat.globbed);
72591 +
72592 + obj->prev = compat_ptr(objcompat.prev);
72593 + obj->next = compat_ptr(objcompat.next);
72594 +
72595 + return 0;
72596 +}
72597 +
72598 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72599 +{
72600 + unsigned int i;
72601 + struct acl_subject_label_compat subjcompat;
72602 +
72603 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72604 + return -EFAULT;
72605 +
72606 + subj->filename = compat_ptr(subjcompat.filename);
72607 + subj->inode = subjcompat.inode;
72608 + subj->device = subjcompat.device;
72609 + subj->mode = subjcompat.mode;
72610 + subj->cap_mask = subjcompat.cap_mask;
72611 + subj->cap_lower = subjcompat.cap_lower;
72612 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72613 +
72614 + for (i = 0; i < GR_NLIMITS; i++) {
72615 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72616 + subj->res[i].rlim_cur = RLIM_INFINITY;
72617 + else
72618 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72619 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72620 + subj->res[i].rlim_max = RLIM_INFINITY;
72621 + else
72622 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72623 + }
72624 + subj->resmask = subjcompat.resmask;
72625 +
72626 + subj->user_trans_type = subjcompat.user_trans_type;
72627 + subj->group_trans_type = subjcompat.group_trans_type;
72628 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72629 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72630 + subj->user_trans_num = subjcompat.user_trans_num;
72631 + subj->group_trans_num = subjcompat.group_trans_num;
72632 +
72633 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72634 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72635 + subj->ip_type = subjcompat.ip_type;
72636 + subj->ips = compat_ptr(subjcompat.ips);
72637 + subj->ip_num = subjcompat.ip_num;
72638 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72639 +
72640 + subj->crashes = subjcompat.crashes;
72641 + subj->expires = subjcompat.expires;
72642 +
72643 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72644 + subj->hash = compat_ptr(subjcompat.hash);
72645 + subj->prev = compat_ptr(subjcompat.prev);
72646 + subj->next = compat_ptr(subjcompat.next);
72647 +
72648 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72649 + subj->obj_hash_size = subjcompat.obj_hash_size;
72650 + subj->pax_flags = subjcompat.pax_flags;
72651 +
72652 + return 0;
72653 +}
72654 +
72655 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72656 +{
72657 + struct acl_role_label_compat rolecompat;
72658 +
72659 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72660 + return -EFAULT;
72661 +
72662 + role->rolename = compat_ptr(rolecompat.rolename);
72663 + role->uidgid = rolecompat.uidgid;
72664 + role->roletype = rolecompat.roletype;
72665 +
72666 + role->auth_attempts = rolecompat.auth_attempts;
72667 + role->expires = rolecompat.expires;
72668 +
72669 + role->root_label = compat_ptr(rolecompat.root_label);
72670 + role->hash = compat_ptr(rolecompat.hash);
72671 +
72672 + role->prev = compat_ptr(rolecompat.prev);
72673 + role->next = compat_ptr(rolecompat.next);
72674 +
72675 + role->transitions = compat_ptr(rolecompat.transitions);
72676 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72677 + role->domain_children = compat_ptr(rolecompat.domain_children);
72678 + role->domain_child_num = rolecompat.domain_child_num;
72679 +
72680 + role->umask = rolecompat.umask;
72681 +
72682 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72683 + role->subj_hash_size = rolecompat.subj_hash_size;
72684 +
72685 + return 0;
72686 +}
72687 +
72688 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72689 +{
72690 + struct role_allowed_ip_compat roleip_compat;
72691 +
72692 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72693 + return -EFAULT;
72694 +
72695 + roleip->addr = roleip_compat.addr;
72696 + roleip->netmask = roleip_compat.netmask;
72697 +
72698 + roleip->prev = compat_ptr(roleip_compat.prev);
72699 + roleip->next = compat_ptr(roleip_compat.next);
72700 +
72701 + return 0;
72702 +}
72703 +
72704 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72705 +{
72706 + struct role_transition_compat trans_compat;
72707 +
72708 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72709 + return -EFAULT;
72710 +
72711 + trans->rolename = compat_ptr(trans_compat.rolename);
72712 +
72713 + trans->prev = compat_ptr(trans_compat.prev);
72714 + trans->next = compat_ptr(trans_compat.next);
72715 +
72716 + return 0;
72717 +
72718 +}
72719 +
72720 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72721 +{
72722 + struct gr_hash_struct_compat hash_compat;
72723 +
72724 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72725 + return -EFAULT;
72726 +
72727 + hash->table = compat_ptr(hash_compat.table);
72728 + hash->nametable = compat_ptr(hash_compat.nametable);
72729 + hash->first = compat_ptr(hash_compat.first);
72730 +
72731 + hash->table_size = hash_compat.table_size;
72732 + hash->used_size = hash_compat.used_size;
72733 +
72734 + hash->type = hash_compat.type;
72735 +
72736 + return 0;
72737 +}
72738 +
72739 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72740 +{
72741 + compat_uptr_t ptrcompat;
72742 +
72743 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72744 + return -EFAULT;
72745 +
72746 + *(void **)ptr = compat_ptr(ptrcompat);
72747 +
72748 + return 0;
72749 +}
72750 +
72751 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72752 +{
72753 + struct acl_ip_label_compat ip_compat;
72754 +
72755 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72756 + return -EFAULT;
72757 +
72758 + ip->iface = compat_ptr(ip_compat.iface);
72759 + ip->addr = ip_compat.addr;
72760 + ip->netmask = ip_compat.netmask;
72761 + ip->low = ip_compat.low;
72762 + ip->high = ip_compat.high;
72763 + ip->mode = ip_compat.mode;
72764 + ip->type = ip_compat.type;
72765 +
72766 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72767 +
72768 + ip->prev = compat_ptr(ip_compat.prev);
72769 + ip->next = compat_ptr(ip_compat.next);
72770 +
72771 + return 0;
72772 +}
72773 +
72774 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72775 +{
72776 + struct sprole_pw_compat pw_compat;
72777 +
72778 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72779 + return -EFAULT;
72780 +
72781 + pw->rolename = compat_ptr(pw_compat.rolename);
72782 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72783 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72784 +
72785 + return 0;
72786 +}
72787 +
72788 +size_t get_gr_arg_wrapper_size_compat(void)
72789 +{
72790 + return sizeof(struct gr_arg_wrapper_compat);
72791 +}
72792 +
72793 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72794 new file mode 100644
72795 index 0000000..8ee8e4f
72796 --- /dev/null
72797 +++ b/grsecurity/gracl_fs.c
72798 @@ -0,0 +1,447 @@
72799 +#include <linux/kernel.h>
72800 +#include <linux/sched.h>
72801 +#include <linux/types.h>
72802 +#include <linux/fs.h>
72803 +#include <linux/file.h>
72804 +#include <linux/stat.h>
72805 +#include <linux/grsecurity.h>
72806 +#include <linux/grinternal.h>
72807 +#include <linux/gracl.h>
72808 +
72809 +umode_t
72810 +gr_acl_umask(void)
72811 +{
72812 + if (unlikely(!gr_acl_is_enabled()))
72813 + return 0;
72814 +
72815 + return current->role->umask;
72816 +}
72817 +
72818 +__u32
72819 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72820 + const struct vfsmount * mnt)
72821 +{
72822 + __u32 mode;
72823 +
72824 + if (unlikely(d_is_negative(dentry)))
72825 + return GR_FIND;
72826 +
72827 + mode =
72828 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72829 +
72830 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72831 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72832 + return mode;
72833 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72834 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72835 + return 0;
72836 + } else if (unlikely(!(mode & GR_FIND)))
72837 + return 0;
72838 +
72839 + return GR_FIND;
72840 +}
72841 +
72842 +__u32
72843 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72844 + int acc_mode)
72845 +{
72846 + __u32 reqmode = GR_FIND;
72847 + __u32 mode;
72848 +
72849 + if (unlikely(d_is_negative(dentry)))
72850 + return reqmode;
72851 +
72852 + if (acc_mode & MAY_APPEND)
72853 + reqmode |= GR_APPEND;
72854 + else if (acc_mode & MAY_WRITE)
72855 + reqmode |= GR_WRITE;
72856 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72857 + reqmode |= GR_READ;
72858 +
72859 + mode =
72860 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72861 + mnt);
72862 +
72863 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72864 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72865 + reqmode & GR_READ ? " reading" : "",
72866 + reqmode & GR_WRITE ? " writing" : reqmode &
72867 + GR_APPEND ? " appending" : "");
72868 + return reqmode;
72869 + } else
72870 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72871 + {
72872 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72873 + reqmode & GR_READ ? " reading" : "",
72874 + reqmode & GR_WRITE ? " writing" : reqmode &
72875 + GR_APPEND ? " appending" : "");
72876 + return 0;
72877 + } else if (unlikely((mode & reqmode) != reqmode))
72878 + return 0;
72879 +
72880 + return reqmode;
72881 +}
72882 +
72883 +__u32
72884 +gr_acl_handle_creat(const struct dentry * dentry,
72885 + const struct dentry * p_dentry,
72886 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72887 + const int imode)
72888 +{
72889 + __u32 reqmode = GR_WRITE | GR_CREATE;
72890 + __u32 mode;
72891 +
72892 + if (acc_mode & MAY_APPEND)
72893 + reqmode |= GR_APPEND;
72894 + // if a directory was required or the directory already exists, then
72895 + // don't count this open as a read
72896 + if ((acc_mode & MAY_READ) &&
72897 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72898 + reqmode |= GR_READ;
72899 + if ((open_flags & O_CREAT) &&
72900 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72901 + reqmode |= GR_SETID;
72902 +
72903 + mode =
72904 + gr_check_create(dentry, p_dentry, p_mnt,
72905 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72906 +
72907 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72908 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72909 + reqmode & GR_READ ? " reading" : "",
72910 + reqmode & GR_WRITE ? " writing" : reqmode &
72911 + GR_APPEND ? " appending" : "");
72912 + return reqmode;
72913 + } else
72914 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72915 + {
72916 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72917 + reqmode & GR_READ ? " reading" : "",
72918 + reqmode & GR_WRITE ? " writing" : reqmode &
72919 + GR_APPEND ? " appending" : "");
72920 + return 0;
72921 + } else if (unlikely((mode & reqmode) != reqmode))
72922 + return 0;
72923 +
72924 + return reqmode;
72925 +}
72926 +
72927 +__u32
72928 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72929 + const int fmode)
72930 +{
72931 + __u32 mode, reqmode = GR_FIND;
72932 +
72933 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72934 + reqmode |= GR_EXEC;
72935 + if (fmode & S_IWOTH)
72936 + reqmode |= GR_WRITE;
72937 + if (fmode & S_IROTH)
72938 + reqmode |= GR_READ;
72939 +
72940 + mode =
72941 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72942 + mnt);
72943 +
72944 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72945 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72946 + reqmode & GR_READ ? " reading" : "",
72947 + reqmode & GR_WRITE ? " writing" : "",
72948 + reqmode & GR_EXEC ? " executing" : "");
72949 + return reqmode;
72950 + } else
72951 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72952 + {
72953 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72954 + reqmode & GR_READ ? " reading" : "",
72955 + reqmode & GR_WRITE ? " writing" : "",
72956 + reqmode & GR_EXEC ? " executing" : "");
72957 + return 0;
72958 + } else if (unlikely((mode & reqmode) != reqmode))
72959 + return 0;
72960 +
72961 + return reqmode;
72962 +}
72963 +
72964 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72965 +{
72966 + __u32 mode;
72967 +
72968 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72969 +
72970 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72971 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72972 + return mode;
72973 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72974 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72975 + return 0;
72976 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72977 + return 0;
72978 +
72979 + return (reqmode);
72980 +}
72981 +
72982 +__u32
72983 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72984 +{
72985 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72986 +}
72987 +
72988 +__u32
72989 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72990 +{
72991 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72992 +}
72993 +
72994 +__u32
72995 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72996 +{
72997 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72998 +}
72999 +
73000 +__u32
73001 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73002 +{
73003 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73004 +}
73005 +
73006 +__u32
73007 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73008 + umode_t *modeptr)
73009 +{
73010 + umode_t mode;
73011 +
73012 + *modeptr &= ~gr_acl_umask();
73013 + mode = *modeptr;
73014 +
73015 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73016 + return 1;
73017 +
73018 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73019 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73020 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73021 + GR_CHMOD_ACL_MSG);
73022 + } else {
73023 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73024 + }
73025 +}
73026 +
73027 +__u32
73028 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73029 +{
73030 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73031 +}
73032 +
73033 +__u32
73034 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73035 +{
73036 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73037 +}
73038 +
73039 +__u32
73040 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73041 +{
73042 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73043 +}
73044 +
73045 +__u32
73046 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73047 +{
73048 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73049 +}
73050 +
73051 +__u32
73052 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73053 +{
73054 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73055 + GR_UNIXCONNECT_ACL_MSG);
73056 +}
73057 +
73058 +/* hardlinks require at minimum create and link permission,
73059 + any additional privilege required is based on the
73060 + privilege of the file being linked to
73061 +*/
73062 +__u32
73063 +gr_acl_handle_link(const struct dentry * new_dentry,
73064 + const struct dentry * parent_dentry,
73065 + const struct vfsmount * parent_mnt,
73066 + const struct dentry * old_dentry,
73067 + const struct vfsmount * old_mnt, const struct filename *to)
73068 +{
73069 + __u32 mode;
73070 + __u32 needmode = GR_CREATE | GR_LINK;
73071 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73072 +
73073 + mode =
73074 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73075 + old_mnt);
73076 +
73077 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73078 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73079 + return mode;
73080 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73081 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73082 + return 0;
73083 + } else if (unlikely((mode & needmode) != needmode))
73084 + return 0;
73085 +
73086 + return 1;
73087 +}
73088 +
73089 +__u32
73090 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73091 + const struct dentry * parent_dentry,
73092 + const struct vfsmount * parent_mnt, const struct filename *from)
73093 +{
73094 + __u32 needmode = GR_WRITE | GR_CREATE;
73095 + __u32 mode;
73096 +
73097 + mode =
73098 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73099 + GR_CREATE | GR_AUDIT_CREATE |
73100 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73101 +
73102 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73103 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73104 + return mode;
73105 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73106 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73107 + return 0;
73108 + } else if (unlikely((mode & needmode) != needmode))
73109 + return 0;
73110 +
73111 + return (GR_WRITE | GR_CREATE);
73112 +}
73113 +
73114 +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)
73115 +{
73116 + __u32 mode;
73117 +
73118 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73119 +
73120 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73121 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73122 + return mode;
73123 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73124 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73125 + return 0;
73126 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73127 + return 0;
73128 +
73129 + return (reqmode);
73130 +}
73131 +
73132 +__u32
73133 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73134 + const struct dentry * parent_dentry,
73135 + const struct vfsmount * parent_mnt,
73136 + const int mode)
73137 +{
73138 + __u32 reqmode = GR_WRITE | GR_CREATE;
73139 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73140 + reqmode |= GR_SETID;
73141 +
73142 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73143 + reqmode, GR_MKNOD_ACL_MSG);
73144 +}
73145 +
73146 +__u32
73147 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73148 + const struct dentry *parent_dentry,
73149 + const struct vfsmount *parent_mnt)
73150 +{
73151 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73152 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73153 +}
73154 +
73155 +#define RENAME_CHECK_SUCCESS(old, new) \
73156 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73157 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73158 +
73159 +int
73160 +gr_acl_handle_rename(struct dentry *new_dentry,
73161 + struct dentry *parent_dentry,
73162 + const struct vfsmount *parent_mnt,
73163 + struct dentry *old_dentry,
73164 + struct inode *old_parent_inode,
73165 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73166 +{
73167 + __u32 comp1, comp2;
73168 + int error = 0;
73169 +
73170 + if (unlikely(!gr_acl_is_enabled()))
73171 + return 0;
73172 +
73173 + if (flags & RENAME_EXCHANGE) {
73174 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73175 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73176 + GR_SUPPRESS, parent_mnt);
73177 + comp2 =
73178 + gr_search_file(old_dentry,
73179 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73180 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73181 + } else if (d_is_negative(new_dentry)) {
73182 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73183 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73184 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73185 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73186 + GR_DELETE | GR_AUDIT_DELETE |
73187 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73188 + GR_SUPPRESS, old_mnt);
73189 + } else {
73190 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73191 + GR_CREATE | GR_DELETE |
73192 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73193 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73194 + GR_SUPPRESS, parent_mnt);
73195 + comp2 =
73196 + gr_search_file(old_dentry,
73197 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73198 + GR_DELETE | GR_AUDIT_DELETE |
73199 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73200 + }
73201 +
73202 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73203 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73204 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73205 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73206 + && !(comp2 & GR_SUPPRESS)) {
73207 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73208 + error = -EACCES;
73209 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73210 + error = -EACCES;
73211 +
73212 + return error;
73213 +}
73214 +
73215 +void
73216 +gr_acl_handle_exit(void)
73217 +{
73218 + u16 id;
73219 + char *rolename;
73220 +
73221 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73222 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73223 + id = current->acl_role_id;
73224 + rolename = current->role->rolename;
73225 + gr_set_acls(1);
73226 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73227 + }
73228 +
73229 + gr_put_exec_file(current);
73230 + return;
73231 +}
73232 +
73233 +int
73234 +gr_acl_handle_procpidmem(const struct task_struct *task)
73235 +{
73236 + if (unlikely(!gr_acl_is_enabled()))
73237 + return 0;
73238 +
73239 + if (task != current && (task->acl->mode & GR_PROTPROCFD) &&
73240 + !(current->acl->mode & GR_POVERRIDE) &&
73241 + !(current->role->roletype & GR_ROLE_GOD))
73242 + return -EACCES;
73243 +
73244 + return 0;
73245 +}
73246 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73247 new file mode 100644
73248 index 0000000..f056b81
73249 --- /dev/null
73250 +++ b/grsecurity/gracl_ip.c
73251 @@ -0,0 +1,386 @@
73252 +#include <linux/kernel.h>
73253 +#include <asm/uaccess.h>
73254 +#include <asm/errno.h>
73255 +#include <net/sock.h>
73256 +#include <linux/file.h>
73257 +#include <linux/fs.h>
73258 +#include <linux/net.h>
73259 +#include <linux/in.h>
73260 +#include <linux/skbuff.h>
73261 +#include <linux/ip.h>
73262 +#include <linux/udp.h>
73263 +#include <linux/types.h>
73264 +#include <linux/sched.h>
73265 +#include <linux/netdevice.h>
73266 +#include <linux/inetdevice.h>
73267 +#include <linux/gracl.h>
73268 +#include <linux/grsecurity.h>
73269 +#include <linux/grinternal.h>
73270 +
73271 +#define GR_BIND 0x01
73272 +#define GR_CONNECT 0x02
73273 +#define GR_INVERT 0x04
73274 +#define GR_BINDOVERRIDE 0x08
73275 +#define GR_CONNECTOVERRIDE 0x10
73276 +#define GR_SOCK_FAMILY 0x20
73277 +
73278 +static const char * gr_protocols[IPPROTO_MAX] = {
73279 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73280 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73281 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73282 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73283 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73284 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73285 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73286 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73287 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73288 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73289 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73290 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73291 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73292 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73293 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73294 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73295 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73296 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73297 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73298 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73299 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73300 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73301 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73302 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73303 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73304 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73305 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73306 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73307 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73308 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73309 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73310 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73311 + };
73312 +
73313 +static const char * gr_socktypes[SOCK_MAX] = {
73314 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73315 + "unknown:7", "unknown:8", "unknown:9", "packet"
73316 + };
73317 +
73318 +static const char * gr_sockfamilies[AF_MAX+1] = {
73319 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73320 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73321 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73322 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73323 + };
73324 +
73325 +const char *
73326 +gr_proto_to_name(unsigned char proto)
73327 +{
73328 + return gr_protocols[proto];
73329 +}
73330 +
73331 +const char *
73332 +gr_socktype_to_name(unsigned char type)
73333 +{
73334 + return gr_socktypes[type];
73335 +}
73336 +
73337 +const char *
73338 +gr_sockfamily_to_name(unsigned char family)
73339 +{
73340 + return gr_sockfamilies[family];
73341 +}
73342 +
73343 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73344 +
73345 +int
73346 +gr_search_socket(const int domain, const int type, const int protocol)
73347 +{
73348 + struct acl_subject_label *curr;
73349 + const struct cred *cred = current_cred();
73350 +
73351 + if (unlikely(!gr_acl_is_enabled()))
73352 + goto exit;
73353 +
73354 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73355 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73356 + goto exit; // let the kernel handle it
73357 +
73358 + curr = current->acl;
73359 +
73360 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73361 + /* the family is allowed, if this is PF_INET allow it only if
73362 + the extra sock type/protocol checks pass */
73363 + if (domain == PF_INET)
73364 + goto inet_check;
73365 + goto exit;
73366 + } else {
73367 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73368 + __u32 fakeip = 0;
73369 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73370 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73371 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73372 + gr_to_filename(current->exec_file->f_path.dentry,
73373 + current->exec_file->f_path.mnt) :
73374 + curr->filename, curr->filename,
73375 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73376 + &current->signal->saved_ip);
73377 + goto exit;
73378 + }
73379 + goto exit_fail;
73380 + }
73381 +
73382 +inet_check:
73383 + /* the rest of this checking is for IPv4 only */
73384 + if (!curr->ips)
73385 + goto exit;
73386 +
73387 + if ((curr->ip_type & (1U << type)) &&
73388 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73389 + goto exit;
73390 +
73391 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73392 + /* we don't place acls on raw sockets , and sometimes
73393 + dgram/ip sockets are opened for ioctl and not
73394 + bind/connect, so we'll fake a bind learn log */
73395 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73396 + __u32 fakeip = 0;
73397 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73398 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73399 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73400 + gr_to_filename(current->exec_file->f_path.dentry,
73401 + current->exec_file->f_path.mnt) :
73402 + curr->filename, curr->filename,
73403 + &fakeip, 0, type,
73404 + protocol, GR_CONNECT, &current->signal->saved_ip);
73405 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73406 + __u32 fakeip = 0;
73407 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73408 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73409 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73410 + gr_to_filename(current->exec_file->f_path.dentry,
73411 + current->exec_file->f_path.mnt) :
73412 + curr->filename, curr->filename,
73413 + &fakeip, 0, type,
73414 + protocol, GR_BIND, &current->signal->saved_ip);
73415 + }
73416 + /* we'll log when they use connect or bind */
73417 + goto exit;
73418 + }
73419 +
73420 +exit_fail:
73421 + if (domain == PF_INET)
73422 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73423 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73424 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73425 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73426 + gr_socktype_to_name(type), protocol);
73427 +
73428 + return 0;
73429 +exit:
73430 + return 1;
73431 +}
73432 +
73433 +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)
73434 +{
73435 + if ((ip->mode & mode) &&
73436 + (ip_port >= ip->low) &&
73437 + (ip_port <= ip->high) &&
73438 + ((ntohl(ip_addr) & our_netmask) ==
73439 + (ntohl(our_addr) & our_netmask))
73440 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73441 + && (ip->type & (1U << type))) {
73442 + if (ip->mode & GR_INVERT)
73443 + return 2; // specifically denied
73444 + else
73445 + return 1; // allowed
73446 + }
73447 +
73448 + return 0; // not specifically allowed, may continue parsing
73449 +}
73450 +
73451 +static int
73452 +gr_search_connectbind(const int full_mode, struct sock *sk,
73453 + struct sockaddr_in *addr, const int type)
73454 +{
73455 + char iface[IFNAMSIZ] = {0};
73456 + struct acl_subject_label *curr;
73457 + struct acl_ip_label *ip;
73458 + struct inet_sock *isk;
73459 + struct net_device *dev;
73460 + struct in_device *idev;
73461 + unsigned long i;
73462 + int ret;
73463 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73464 + __u32 ip_addr = 0;
73465 + __u32 our_addr;
73466 + __u32 our_netmask;
73467 + char *p;
73468 + __u16 ip_port = 0;
73469 + const struct cred *cred = current_cred();
73470 +
73471 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73472 + return 0;
73473 +
73474 + curr = current->acl;
73475 + isk = inet_sk(sk);
73476 +
73477 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73478 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73479 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73480 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73481 + struct sockaddr_in saddr;
73482 + int err;
73483 +
73484 + saddr.sin_family = AF_INET;
73485 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73486 + saddr.sin_port = isk->inet_sport;
73487 +
73488 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73489 + if (err)
73490 + return err;
73491 +
73492 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73493 + if (err)
73494 + return err;
73495 + }
73496 +
73497 + if (!curr->ips)
73498 + return 0;
73499 +
73500 + ip_addr = addr->sin_addr.s_addr;
73501 + ip_port = ntohs(addr->sin_port);
73502 +
73503 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73504 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73505 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73506 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73507 + gr_to_filename(current->exec_file->f_path.dentry,
73508 + current->exec_file->f_path.mnt) :
73509 + curr->filename, curr->filename,
73510 + &ip_addr, ip_port, type,
73511 + sk->sk_protocol, mode, &current->signal->saved_ip);
73512 + return 0;
73513 + }
73514 +
73515 + for (i = 0; i < curr->ip_num; i++) {
73516 + ip = *(curr->ips + i);
73517 + if (ip->iface != NULL) {
73518 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73519 + p = strchr(iface, ':');
73520 + if (p != NULL)
73521 + *p = '\0';
73522 + dev = dev_get_by_name(sock_net(sk), iface);
73523 + if (dev == NULL)
73524 + continue;
73525 + idev = in_dev_get(dev);
73526 + if (idev == NULL) {
73527 + dev_put(dev);
73528 + continue;
73529 + }
73530 + rcu_read_lock();
73531 + for_ifa(idev) {
73532 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73533 + our_addr = ifa->ifa_address;
73534 + our_netmask = 0xffffffff;
73535 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73536 + if (ret == 1) {
73537 + rcu_read_unlock();
73538 + in_dev_put(idev);
73539 + dev_put(dev);
73540 + return 0;
73541 + } else if (ret == 2) {
73542 + rcu_read_unlock();
73543 + in_dev_put(idev);
73544 + dev_put(dev);
73545 + goto denied;
73546 + }
73547 + }
73548 + } endfor_ifa(idev);
73549 + rcu_read_unlock();
73550 + in_dev_put(idev);
73551 + dev_put(dev);
73552 + } else {
73553 + our_addr = ip->addr;
73554 + our_netmask = ip->netmask;
73555 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73556 + if (ret == 1)
73557 + return 0;
73558 + else if (ret == 2)
73559 + goto denied;
73560 + }
73561 + }
73562 +
73563 +denied:
73564 + if (mode == GR_BIND)
73565 + 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));
73566 + else if (mode == GR_CONNECT)
73567 + 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));
73568 +
73569 + return -EACCES;
73570 +}
73571 +
73572 +int
73573 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73574 +{
73575 + /* always allow disconnection of dgram sockets with connect */
73576 + if (addr->sin_family == AF_UNSPEC)
73577 + return 0;
73578 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73579 +}
73580 +
73581 +int
73582 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73583 +{
73584 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73585 +}
73586 +
73587 +int gr_search_listen(struct socket *sock)
73588 +{
73589 + struct sock *sk = sock->sk;
73590 + struct sockaddr_in addr;
73591 +
73592 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73593 + addr.sin_port = inet_sk(sk)->inet_sport;
73594 +
73595 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73596 +}
73597 +
73598 +int gr_search_accept(struct socket *sock)
73599 +{
73600 + struct sock *sk = sock->sk;
73601 + struct sockaddr_in addr;
73602 +
73603 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73604 + addr.sin_port = inet_sk(sk)->inet_sport;
73605 +
73606 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73607 +}
73608 +
73609 +int
73610 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73611 +{
73612 + if (addr)
73613 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73614 + else {
73615 + struct sockaddr_in sin;
73616 + const struct inet_sock *inet = inet_sk(sk);
73617 +
73618 + sin.sin_addr.s_addr = inet->inet_daddr;
73619 + sin.sin_port = inet->inet_dport;
73620 +
73621 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73622 + }
73623 +}
73624 +
73625 +int
73626 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73627 +{
73628 + struct sockaddr_in sin;
73629 +
73630 + if (unlikely(skb->len < sizeof (struct udphdr)))
73631 + return 0; // skip this packet
73632 +
73633 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73634 + sin.sin_port = udp_hdr(skb)->source;
73635 +
73636 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73637 +}
73638 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73639 new file mode 100644
73640 index 0000000..25f54ef
73641 --- /dev/null
73642 +++ b/grsecurity/gracl_learn.c
73643 @@ -0,0 +1,207 @@
73644 +#include <linux/kernel.h>
73645 +#include <linux/mm.h>
73646 +#include <linux/sched.h>
73647 +#include <linux/poll.h>
73648 +#include <linux/string.h>
73649 +#include <linux/file.h>
73650 +#include <linux/types.h>
73651 +#include <linux/vmalloc.h>
73652 +#include <linux/grinternal.h>
73653 +
73654 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73655 + size_t count, loff_t *ppos);
73656 +extern int gr_acl_is_enabled(void);
73657 +
73658 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73659 +static int gr_learn_attached;
73660 +
73661 +/* use a 512k buffer */
73662 +#define LEARN_BUFFER_SIZE (512 * 1024)
73663 +
73664 +static DEFINE_SPINLOCK(gr_learn_lock);
73665 +static DEFINE_MUTEX(gr_learn_user_mutex);
73666 +
73667 +/* we need to maintain two buffers, so that the kernel context of grlearn
73668 + uses a semaphore around the userspace copying, and the other kernel contexts
73669 + use a spinlock when copying into the buffer, since they cannot sleep
73670 +*/
73671 +static char *learn_buffer;
73672 +static char *learn_buffer_user;
73673 +static int learn_buffer_len;
73674 +static int learn_buffer_user_len;
73675 +
73676 +static ssize_t
73677 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73678 +{
73679 + DECLARE_WAITQUEUE(wait, current);
73680 + ssize_t retval = 0;
73681 +
73682 + add_wait_queue(&learn_wait, &wait);
73683 + set_current_state(TASK_INTERRUPTIBLE);
73684 + do {
73685 + mutex_lock(&gr_learn_user_mutex);
73686 + spin_lock(&gr_learn_lock);
73687 + if (learn_buffer_len)
73688 + break;
73689 + spin_unlock(&gr_learn_lock);
73690 + mutex_unlock(&gr_learn_user_mutex);
73691 + if (file->f_flags & O_NONBLOCK) {
73692 + retval = -EAGAIN;
73693 + goto out;
73694 + }
73695 + if (signal_pending(current)) {
73696 + retval = -ERESTARTSYS;
73697 + goto out;
73698 + }
73699 +
73700 + schedule();
73701 + } while (1);
73702 +
73703 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73704 + learn_buffer_user_len = learn_buffer_len;
73705 + retval = learn_buffer_len;
73706 + learn_buffer_len = 0;
73707 +
73708 + spin_unlock(&gr_learn_lock);
73709 +
73710 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73711 + retval = -EFAULT;
73712 +
73713 + mutex_unlock(&gr_learn_user_mutex);
73714 +out:
73715 + set_current_state(TASK_RUNNING);
73716 + remove_wait_queue(&learn_wait, &wait);
73717 + return retval;
73718 +}
73719 +
73720 +static unsigned int
73721 +poll_learn(struct file * file, poll_table * wait)
73722 +{
73723 + poll_wait(file, &learn_wait, wait);
73724 +
73725 + if (learn_buffer_len)
73726 + return (POLLIN | POLLRDNORM);
73727 +
73728 + return 0;
73729 +}
73730 +
73731 +void
73732 +gr_clear_learn_entries(void)
73733 +{
73734 + char *tmp;
73735 +
73736 + mutex_lock(&gr_learn_user_mutex);
73737 + spin_lock(&gr_learn_lock);
73738 + tmp = learn_buffer;
73739 + learn_buffer = NULL;
73740 + spin_unlock(&gr_learn_lock);
73741 + if (tmp)
73742 + vfree(tmp);
73743 + if (learn_buffer_user != NULL) {
73744 + vfree(learn_buffer_user);
73745 + learn_buffer_user = NULL;
73746 + }
73747 + learn_buffer_len = 0;
73748 + mutex_unlock(&gr_learn_user_mutex);
73749 +
73750 + return;
73751 +}
73752 +
73753 +void
73754 +gr_add_learn_entry(const char *fmt, ...)
73755 +{
73756 + va_list args;
73757 + unsigned int len;
73758 +
73759 + if (!gr_learn_attached)
73760 + return;
73761 +
73762 + spin_lock(&gr_learn_lock);
73763 +
73764 + /* leave a gap at the end so we know when it's "full" but don't have to
73765 + compute the exact length of the string we're trying to append
73766 + */
73767 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73768 + spin_unlock(&gr_learn_lock);
73769 + wake_up_interruptible(&learn_wait);
73770 + return;
73771 + }
73772 + if (learn_buffer == NULL) {
73773 + spin_unlock(&gr_learn_lock);
73774 + return;
73775 + }
73776 +
73777 + va_start(args, fmt);
73778 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73779 + va_end(args);
73780 +
73781 + learn_buffer_len += len + 1;
73782 +
73783 + spin_unlock(&gr_learn_lock);
73784 + wake_up_interruptible(&learn_wait);
73785 +
73786 + return;
73787 +}
73788 +
73789 +static int
73790 +open_learn(struct inode *inode, struct file *file)
73791 +{
73792 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73793 + return -EBUSY;
73794 + if (file->f_mode & FMODE_READ) {
73795 + int retval = 0;
73796 + mutex_lock(&gr_learn_user_mutex);
73797 + if (learn_buffer == NULL)
73798 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73799 + if (learn_buffer_user == NULL)
73800 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73801 + if (learn_buffer == NULL) {
73802 + retval = -ENOMEM;
73803 + goto out_error;
73804 + }
73805 + if (learn_buffer_user == NULL) {
73806 + retval = -ENOMEM;
73807 + goto out_error;
73808 + }
73809 + learn_buffer_len = 0;
73810 + learn_buffer_user_len = 0;
73811 + gr_learn_attached = 1;
73812 +out_error:
73813 + mutex_unlock(&gr_learn_user_mutex);
73814 + return retval;
73815 + }
73816 + return 0;
73817 +}
73818 +
73819 +static int
73820 +close_learn(struct inode *inode, struct file *file)
73821 +{
73822 + if (file->f_mode & FMODE_READ) {
73823 + char *tmp = NULL;
73824 + mutex_lock(&gr_learn_user_mutex);
73825 + spin_lock(&gr_learn_lock);
73826 + tmp = learn_buffer;
73827 + learn_buffer = NULL;
73828 + spin_unlock(&gr_learn_lock);
73829 + if (tmp)
73830 + vfree(tmp);
73831 + if (learn_buffer_user != NULL) {
73832 + vfree(learn_buffer_user);
73833 + learn_buffer_user = NULL;
73834 + }
73835 + learn_buffer_len = 0;
73836 + learn_buffer_user_len = 0;
73837 + gr_learn_attached = 0;
73838 + mutex_unlock(&gr_learn_user_mutex);
73839 + }
73840 +
73841 + return 0;
73842 +}
73843 +
73844 +const struct file_operations grsec_fops = {
73845 + .read = read_learn,
73846 + .write = write_grsec_handler,
73847 + .open = open_learn,
73848 + .release = close_learn,
73849 + .poll = poll_learn,
73850 +};
73851 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73852 new file mode 100644
73853 index 0000000..7949dcd
73854 --- /dev/null
73855 +++ b/grsecurity/gracl_policy.c
73856 @@ -0,0 +1,1782 @@
73857 +#include <linux/kernel.h>
73858 +#include <linux/module.h>
73859 +#include <linux/sched.h>
73860 +#include <linux/mm.h>
73861 +#include <linux/file.h>
73862 +#include <linux/fs.h>
73863 +#include <linux/namei.h>
73864 +#include <linux/mount.h>
73865 +#include <linux/tty.h>
73866 +#include <linux/proc_fs.h>
73867 +#include <linux/lglock.h>
73868 +#include <linux/slab.h>
73869 +#include <linux/vmalloc.h>
73870 +#include <linux/types.h>
73871 +#include <linux/sysctl.h>
73872 +#include <linux/netdevice.h>
73873 +#include <linux/ptrace.h>
73874 +#include <linux/gracl.h>
73875 +#include <linux/gralloc.h>
73876 +#include <linux/security.h>
73877 +#include <linux/grinternal.h>
73878 +#include <linux/pid_namespace.h>
73879 +#include <linux/stop_machine.h>
73880 +#include <linux/fdtable.h>
73881 +#include <linux/percpu.h>
73882 +#include <linux/lglock.h>
73883 +#include <linux/hugetlb.h>
73884 +#include <linux/posix-timers.h>
73885 +#include "../fs/mount.h"
73886 +
73887 +#include <asm/uaccess.h>
73888 +#include <asm/errno.h>
73889 +#include <asm/mman.h>
73890 +
73891 +extern struct gr_policy_state *polstate;
73892 +
73893 +#define FOR_EACH_ROLE_START(role) \
73894 + role = polstate->role_list; \
73895 + while (role) {
73896 +
73897 +#define FOR_EACH_ROLE_END(role) \
73898 + role = role->prev; \
73899 + }
73900 +
73901 +struct path gr_real_root;
73902 +
73903 +extern struct gr_alloc_state *current_alloc_state;
73904 +
73905 +u16 acl_sp_role_value;
73906 +
73907 +static DEFINE_MUTEX(gr_dev_mutex);
73908 +
73909 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73910 +extern void gr_clear_learn_entries(void);
73911 +
73912 +struct gr_arg *gr_usermode __read_only;
73913 +unsigned char *gr_system_salt __read_only;
73914 +unsigned char *gr_system_sum __read_only;
73915 +
73916 +static unsigned int gr_auth_attempts = 0;
73917 +static unsigned long gr_auth_expires = 0UL;
73918 +
73919 +struct acl_object_label *fakefs_obj_rw;
73920 +struct acl_object_label *fakefs_obj_rwx;
73921 +
73922 +extern int gr_init_uidset(void);
73923 +extern void gr_free_uidset(void);
73924 +extern void gr_remove_uid(uid_t uid);
73925 +extern int gr_find_uid(uid_t uid);
73926 +
73927 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback);
73928 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73929 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73930 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73931 +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);
73932 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73933 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73934 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73935 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73936 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73937 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73938 +extern void assign_special_role(const char *rolename);
73939 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73940 +extern int gr_rbac_disable(void *unused);
73941 +extern void gr_enable_rbac_system(void);
73942 +
73943 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73944 +{
73945 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73946 + return -EFAULT;
73947 +
73948 + return 0;
73949 +}
73950 +
73951 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73952 +{
73953 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73954 + return -EFAULT;
73955 +
73956 + return 0;
73957 +}
73958 +
73959 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73960 +{
73961 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73962 + return -EFAULT;
73963 +
73964 + return 0;
73965 +}
73966 +
73967 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73968 +{
73969 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73970 + return -EFAULT;
73971 +
73972 + return 0;
73973 +}
73974 +
73975 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73976 +{
73977 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73978 + return -EFAULT;
73979 +
73980 + return 0;
73981 +}
73982 +
73983 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73984 +{
73985 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73986 + return -EFAULT;
73987 +
73988 + return 0;
73989 +}
73990 +
73991 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73992 +{
73993 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73994 + return -EFAULT;
73995 +
73996 + return 0;
73997 +}
73998 +
73999 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74000 +{
74001 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74002 + return -EFAULT;
74003 +
74004 + return 0;
74005 +}
74006 +
74007 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74008 +{
74009 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74010 + return -EFAULT;
74011 +
74012 + return 0;
74013 +}
74014 +
74015 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74016 +{
74017 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74018 + return -EFAULT;
74019 +
74020 + if (((uwrap->version != GRSECURITY_VERSION) &&
74021 + (uwrap->version != 0x2901)) ||
74022 + (uwrap->size != sizeof(struct gr_arg)))
74023 + return -EINVAL;
74024 +
74025 + return 0;
74026 +}
74027 +
74028 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74029 +{
74030 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74031 + return -EFAULT;
74032 +
74033 + return 0;
74034 +}
74035 +
74036 +static size_t get_gr_arg_wrapper_size_normal(void)
74037 +{
74038 + return sizeof(struct gr_arg_wrapper);
74039 +}
74040 +
74041 +#ifdef CONFIG_COMPAT
74042 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74043 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74044 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74045 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74046 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74047 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74048 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74049 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74050 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74051 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74052 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74053 +extern size_t get_gr_arg_wrapper_size_compat(void);
74054 +
74055 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74056 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74057 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74058 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74059 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74060 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74061 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74062 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74063 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74064 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74065 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74066 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74067 +
74068 +#else
74069 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74070 +#define copy_gr_arg copy_gr_arg_normal
74071 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74072 +#define copy_acl_object_label copy_acl_object_label_normal
74073 +#define copy_acl_subject_label copy_acl_subject_label_normal
74074 +#define copy_acl_role_label copy_acl_role_label_normal
74075 +#define copy_acl_ip_label copy_acl_ip_label_normal
74076 +#define copy_pointer_from_array copy_pointer_from_array_normal
74077 +#define copy_sprole_pw copy_sprole_pw_normal
74078 +#define copy_role_transition copy_role_transition_normal
74079 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74080 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74081 +#endif
74082 +
74083 +static struct acl_subject_label *
74084 +lookup_subject_map(const struct acl_subject_label *userp)
74085 +{
74086 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74087 + struct subject_map *match;
74088 +
74089 + match = polstate->subj_map_set.s_hash[index];
74090 +
74091 + while (match && match->user != userp)
74092 + match = match->next;
74093 +
74094 + if (match != NULL)
74095 + return match->kernel;
74096 + else
74097 + return NULL;
74098 +}
74099 +
74100 +static void
74101 +insert_subj_map_entry(struct subject_map *subjmap)
74102 +{
74103 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74104 + struct subject_map **curr;
74105 +
74106 + subjmap->prev = NULL;
74107 +
74108 + curr = &polstate->subj_map_set.s_hash[index];
74109 + if (*curr != NULL)
74110 + (*curr)->prev = subjmap;
74111 +
74112 + subjmap->next = *curr;
74113 + *curr = subjmap;
74114 +
74115 + return;
74116 +}
74117 +
74118 +static void
74119 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74120 +{
74121 + unsigned int index =
74122 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74123 + struct acl_role_label **curr;
74124 + struct acl_role_label *tmp, *tmp2;
74125 +
74126 + curr = &polstate->acl_role_set.r_hash[index];
74127 +
74128 + /* simple case, slot is empty, just set it to our role */
74129 + if (*curr == NULL) {
74130 + *curr = role;
74131 + } else {
74132 + /* example:
74133 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74134 + 2 -> 3
74135 + */
74136 + /* first check to see if we can already be reached via this slot */
74137 + tmp = *curr;
74138 + while (tmp && tmp != role)
74139 + tmp = tmp->next;
74140 + if (tmp == role) {
74141 + /* we don't need to add ourselves to this slot's chain */
74142 + return;
74143 + }
74144 + /* we need to add ourselves to this chain, two cases */
74145 + if (role->next == NULL) {
74146 + /* simple case, append the current chain to our role */
74147 + role->next = *curr;
74148 + *curr = role;
74149 + } else {
74150 + /* 1 -> 2 -> 3 -> 4
74151 + 2 -> 3 -> 4
74152 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74153 + */
74154 + /* trickier case: walk our role's chain until we find
74155 + the role for the start of the current slot's chain */
74156 + tmp = role;
74157 + tmp2 = *curr;
74158 + while (tmp->next && tmp->next != tmp2)
74159 + tmp = tmp->next;
74160 + if (tmp->next == tmp2) {
74161 + /* from example above, we found 3, so just
74162 + replace this slot's chain with ours */
74163 + *curr = role;
74164 + } else {
74165 + /* we didn't find a subset of our role's chain
74166 + in the current slot's chain, so append their
74167 + chain to ours, and set us as the first role in
74168 + the slot's chain
74169 +
74170 + we could fold this case with the case above,
74171 + but making it explicit for clarity
74172 + */
74173 + tmp->next = tmp2;
74174 + *curr = role;
74175 + }
74176 + }
74177 + }
74178 +
74179 + return;
74180 +}
74181 +
74182 +static void
74183 +insert_acl_role_label(struct acl_role_label *role)
74184 +{
74185 + int i;
74186 +
74187 + if (polstate->role_list == NULL) {
74188 + polstate->role_list = role;
74189 + role->prev = NULL;
74190 + } else {
74191 + role->prev = polstate->role_list;
74192 + polstate->role_list = role;
74193 + }
74194 +
74195 + /* used for hash chains */
74196 + role->next = NULL;
74197 +
74198 + if (role->roletype & GR_ROLE_DOMAIN) {
74199 + for (i = 0; i < role->domain_child_num; i++)
74200 + __insert_acl_role_label(role, role->domain_children[i]);
74201 + } else
74202 + __insert_acl_role_label(role, role->uidgid);
74203 +}
74204 +
74205 +static int
74206 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74207 +{
74208 + struct name_entry **curr, *nentry;
74209 + struct inodev_entry *ientry;
74210 + unsigned int len = strlen(name);
74211 + unsigned int key = full_name_hash(name, len);
74212 + unsigned int index = key % polstate->name_set.n_size;
74213 +
74214 + curr = &polstate->name_set.n_hash[index];
74215 +
74216 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74217 + curr = &((*curr)->next);
74218 +
74219 + if (*curr != NULL)
74220 + return 1;
74221 +
74222 + nentry = acl_alloc(sizeof (struct name_entry));
74223 + if (nentry == NULL)
74224 + return 0;
74225 + ientry = acl_alloc(sizeof (struct inodev_entry));
74226 + if (ientry == NULL)
74227 + return 0;
74228 + ientry->nentry = nentry;
74229 +
74230 + nentry->key = key;
74231 + nentry->name = name;
74232 + nentry->inode = inode;
74233 + nentry->device = device;
74234 + nentry->len = len;
74235 + nentry->deleted = deleted;
74236 +
74237 + nentry->prev = NULL;
74238 + curr = &polstate->name_set.n_hash[index];
74239 + if (*curr != NULL)
74240 + (*curr)->prev = nentry;
74241 + nentry->next = *curr;
74242 + *curr = nentry;
74243 +
74244 + /* insert us into the table searchable by inode/dev */
74245 + __insert_inodev_entry(polstate, ientry);
74246 +
74247 + return 1;
74248 +}
74249 +
74250 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74251 +
74252 +static void *
74253 +create_table(__u32 * len, int elementsize)
74254 +{
74255 + unsigned int table_sizes[] = {
74256 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74257 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74258 + 4194301, 8388593, 16777213, 33554393, 67108859
74259 + };
74260 + void *newtable = NULL;
74261 + unsigned int pwr = 0;
74262 +
74263 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74264 + table_sizes[pwr] <= *len)
74265 + pwr++;
74266 +
74267 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74268 + return newtable;
74269 +
74270 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74271 + newtable =
74272 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74273 + else
74274 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74275 +
74276 + *len = table_sizes[pwr];
74277 +
74278 + return newtable;
74279 +}
74280 +
74281 +static int
74282 +init_variables(const struct gr_arg *arg, bool reload)
74283 +{
74284 + struct task_struct *reaper = init_pid_ns.child_reaper;
74285 + unsigned int stacksize;
74286 +
74287 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74288 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74289 + polstate->name_set.n_size = arg->role_db.num_objects;
74290 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74291 +
74292 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74293 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74294 + return 1;
74295 +
74296 + if (!reload) {
74297 + if (!gr_init_uidset())
74298 + return 1;
74299 + }
74300 +
74301 + /* set up the stack that holds allocation info */
74302 +
74303 + stacksize = arg->role_db.num_pointers + 5;
74304 +
74305 + if (!acl_alloc_stack_init(stacksize))
74306 + return 1;
74307 +
74308 + if (!reload) {
74309 + /* grab reference for the real root dentry and vfsmount */
74310 + get_fs_root(reaper->fs, &gr_real_root);
74311 +
74312 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74313 + 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);
74314 +#endif
74315 +
74316 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74317 + if (fakefs_obj_rw == NULL)
74318 + return 1;
74319 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74320 +
74321 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74322 + if (fakefs_obj_rwx == NULL)
74323 + return 1;
74324 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74325 + }
74326 +
74327 + polstate->subj_map_set.s_hash =
74328 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74329 + polstate->acl_role_set.r_hash =
74330 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74331 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74332 + polstate->inodev_set.i_hash =
74333 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74334 +
74335 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74336 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74337 + return 1;
74338 +
74339 + memset(polstate->subj_map_set.s_hash, 0,
74340 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74341 + memset(polstate->acl_role_set.r_hash, 0,
74342 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74343 + memset(polstate->name_set.n_hash, 0,
74344 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74345 + memset(polstate->inodev_set.i_hash, 0,
74346 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74347 +
74348 + return 0;
74349 +}
74350 +
74351 +/* free information not needed after startup
74352 + currently contains user->kernel pointer mappings for subjects
74353 +*/
74354 +
74355 +static void
74356 +free_init_variables(void)
74357 +{
74358 + __u32 i;
74359 +
74360 + if (polstate->subj_map_set.s_hash) {
74361 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74362 + if (polstate->subj_map_set.s_hash[i]) {
74363 + kfree(polstate->subj_map_set.s_hash[i]);
74364 + polstate->subj_map_set.s_hash[i] = NULL;
74365 + }
74366 + }
74367 +
74368 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74369 + PAGE_SIZE)
74370 + kfree(polstate->subj_map_set.s_hash);
74371 + else
74372 + vfree(polstate->subj_map_set.s_hash);
74373 + }
74374 +
74375 + return;
74376 +}
74377 +
74378 +static void
74379 +free_variables(bool reload)
74380 +{
74381 + struct acl_subject_label *s;
74382 + struct acl_role_label *r;
74383 + struct task_struct *task, *task2;
74384 + unsigned int x;
74385 +
74386 + if (!reload) {
74387 + gr_clear_learn_entries();
74388 +
74389 + read_lock(&tasklist_lock);
74390 + do_each_thread(task2, task) {
74391 + task->acl_sp_role = 0;
74392 + task->acl_role_id = 0;
74393 + task->inherited = 0;
74394 + task->acl = NULL;
74395 + task->role = NULL;
74396 + } while_each_thread(task2, task);
74397 + read_unlock(&tasklist_lock);
74398 +
74399 + kfree(fakefs_obj_rw);
74400 + fakefs_obj_rw = NULL;
74401 + kfree(fakefs_obj_rwx);
74402 + fakefs_obj_rwx = NULL;
74403 +
74404 + /* release the reference to the real root dentry and vfsmount */
74405 + path_put(&gr_real_root);
74406 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74407 + }
74408 +
74409 + /* free all object hash tables */
74410 +
74411 + FOR_EACH_ROLE_START(r)
74412 + if (r->subj_hash == NULL)
74413 + goto next_role;
74414 + FOR_EACH_SUBJECT_START(r, s, x)
74415 + if (s->obj_hash == NULL)
74416 + break;
74417 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74418 + kfree(s->obj_hash);
74419 + else
74420 + vfree(s->obj_hash);
74421 + FOR_EACH_SUBJECT_END(s, x)
74422 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74423 + if (s->obj_hash == NULL)
74424 + break;
74425 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74426 + kfree(s->obj_hash);
74427 + else
74428 + vfree(s->obj_hash);
74429 + FOR_EACH_NESTED_SUBJECT_END(s)
74430 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74431 + kfree(r->subj_hash);
74432 + else
74433 + vfree(r->subj_hash);
74434 + r->subj_hash = NULL;
74435 +next_role:
74436 + FOR_EACH_ROLE_END(r)
74437 +
74438 + acl_free_all();
74439 +
74440 + if (polstate->acl_role_set.r_hash) {
74441 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74442 + PAGE_SIZE)
74443 + kfree(polstate->acl_role_set.r_hash);
74444 + else
74445 + vfree(polstate->acl_role_set.r_hash);
74446 + }
74447 + if (polstate->name_set.n_hash) {
74448 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74449 + PAGE_SIZE)
74450 + kfree(polstate->name_set.n_hash);
74451 + else
74452 + vfree(polstate->name_set.n_hash);
74453 + }
74454 +
74455 + if (polstate->inodev_set.i_hash) {
74456 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74457 + PAGE_SIZE)
74458 + kfree(polstate->inodev_set.i_hash);
74459 + else
74460 + vfree(polstate->inodev_set.i_hash);
74461 + }
74462 +
74463 + if (!reload)
74464 + gr_free_uidset();
74465 +
74466 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74467 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74468 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74469 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74470 +
74471 + polstate->default_role = NULL;
74472 + polstate->kernel_role = NULL;
74473 + polstate->role_list = NULL;
74474 +
74475 + return;
74476 +}
74477 +
74478 +static struct acl_subject_label *
74479 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74480 +
74481 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74482 +{
74483 + unsigned int len = strnlen_user(*name, maxlen);
74484 + char *tmp;
74485 +
74486 + if (!len || len >= maxlen)
74487 + return -EINVAL;
74488 +
74489 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74490 + return -ENOMEM;
74491 +
74492 + if (copy_from_user(tmp, *name, len))
74493 + return -EFAULT;
74494 +
74495 + tmp[len-1] = '\0';
74496 + *name = tmp;
74497 +
74498 + return 0;
74499 +}
74500 +
74501 +static int
74502 +copy_user_glob(struct acl_object_label *obj)
74503 +{
74504 + struct acl_object_label *g_tmp, **guser;
74505 + int error;
74506 +
74507 + if (obj->globbed == NULL)
74508 + return 0;
74509 +
74510 + guser = &obj->globbed;
74511 + while (*guser) {
74512 + g_tmp = (struct acl_object_label *)
74513 + acl_alloc(sizeof (struct acl_object_label));
74514 + if (g_tmp == NULL)
74515 + return -ENOMEM;
74516 +
74517 + if (copy_acl_object_label(g_tmp, *guser))
74518 + return -EFAULT;
74519 +
74520 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74521 + if (error)
74522 + return error;
74523 +
74524 + *guser = g_tmp;
74525 + guser = &(g_tmp->next);
74526 + }
74527 +
74528 + return 0;
74529 +}
74530 +
74531 +static int
74532 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74533 + struct acl_role_label *role)
74534 +{
74535 + struct acl_object_label *o_tmp;
74536 + int ret;
74537 +
74538 + while (userp) {
74539 + if ((o_tmp = (struct acl_object_label *)
74540 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74541 + return -ENOMEM;
74542 +
74543 + if (copy_acl_object_label(o_tmp, userp))
74544 + return -EFAULT;
74545 +
74546 + userp = o_tmp->prev;
74547 +
74548 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74549 + if (ret)
74550 + return ret;
74551 +
74552 + insert_acl_obj_label(o_tmp, subj);
74553 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74554 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74555 + return -ENOMEM;
74556 +
74557 + ret = copy_user_glob(o_tmp);
74558 + if (ret)
74559 + return ret;
74560 +
74561 + if (o_tmp->nested) {
74562 + int already_copied;
74563 +
74564 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74565 + if (IS_ERR(o_tmp->nested))
74566 + return PTR_ERR(o_tmp->nested);
74567 +
74568 + /* insert into nested subject list if we haven't copied this one yet
74569 + to prevent duplicate entries */
74570 + if (!already_copied) {
74571 + o_tmp->nested->next = role->hash->first;
74572 + role->hash->first = o_tmp->nested;
74573 + }
74574 + }
74575 + }
74576 +
74577 + return 0;
74578 +}
74579 +
74580 +static __u32
74581 +count_user_subjs(struct acl_subject_label *userp)
74582 +{
74583 + struct acl_subject_label s_tmp;
74584 + __u32 num = 0;
74585 +
74586 + while (userp) {
74587 + if (copy_acl_subject_label(&s_tmp, userp))
74588 + break;
74589 +
74590 + userp = s_tmp.prev;
74591 + }
74592 +
74593 + return num;
74594 +}
74595 +
74596 +static int
74597 +copy_user_allowedips(struct acl_role_label *rolep)
74598 +{
74599 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74600 +
74601 + ruserip = rolep->allowed_ips;
74602 +
74603 + while (ruserip) {
74604 + rlast = rtmp;
74605 +
74606 + if ((rtmp = (struct role_allowed_ip *)
74607 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74608 + return -ENOMEM;
74609 +
74610 + if (copy_role_allowed_ip(rtmp, ruserip))
74611 + return -EFAULT;
74612 +
74613 + ruserip = rtmp->prev;
74614 +
74615 + if (!rlast) {
74616 + rtmp->prev = NULL;
74617 + rolep->allowed_ips = rtmp;
74618 + } else {
74619 + rlast->next = rtmp;
74620 + rtmp->prev = rlast;
74621 + }
74622 +
74623 + if (!ruserip)
74624 + rtmp->next = NULL;
74625 + }
74626 +
74627 + return 0;
74628 +}
74629 +
74630 +static int
74631 +copy_user_transitions(struct acl_role_label *rolep)
74632 +{
74633 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74634 + int error;
74635 +
74636 + rusertp = rolep->transitions;
74637 +
74638 + while (rusertp) {
74639 + rlast = rtmp;
74640 +
74641 + if ((rtmp = (struct role_transition *)
74642 + acl_alloc(sizeof (struct role_transition))) == NULL)
74643 + return -ENOMEM;
74644 +
74645 + if (copy_role_transition(rtmp, rusertp))
74646 + return -EFAULT;
74647 +
74648 + rusertp = rtmp->prev;
74649 +
74650 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74651 + if (error)
74652 + return error;
74653 +
74654 + if (!rlast) {
74655 + rtmp->prev = NULL;
74656 + rolep->transitions = rtmp;
74657 + } else {
74658 + rlast->next = rtmp;
74659 + rtmp->prev = rlast;
74660 + }
74661 +
74662 + if (!rusertp)
74663 + rtmp->next = NULL;
74664 + }
74665 +
74666 + return 0;
74667 +}
74668 +
74669 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74670 +{
74671 + struct acl_object_label o_tmp;
74672 + __u32 num = 0;
74673 +
74674 + while (userp) {
74675 + if (copy_acl_object_label(&o_tmp, userp))
74676 + break;
74677 +
74678 + userp = o_tmp.prev;
74679 + num++;
74680 + }
74681 +
74682 + return num;
74683 +}
74684 +
74685 +static struct acl_subject_label *
74686 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74687 +{
74688 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74689 + __u32 num_objs;
74690 + struct acl_ip_label **i_tmp, *i_utmp2;
74691 + struct gr_hash_struct ghash;
74692 + struct subject_map *subjmap;
74693 + unsigned int i_num;
74694 + int err;
74695 +
74696 + if (already_copied != NULL)
74697 + *already_copied = 0;
74698 +
74699 + s_tmp = lookup_subject_map(userp);
74700 +
74701 + /* we've already copied this subject into the kernel, just return
74702 + the reference to it, and don't copy it over again
74703 + */
74704 + if (s_tmp) {
74705 + if (already_copied != NULL)
74706 + *already_copied = 1;
74707 + return(s_tmp);
74708 + }
74709 +
74710 + if ((s_tmp = (struct acl_subject_label *)
74711 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74712 + return ERR_PTR(-ENOMEM);
74713 +
74714 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74715 + if (subjmap == NULL)
74716 + return ERR_PTR(-ENOMEM);
74717 +
74718 + subjmap->user = userp;
74719 + subjmap->kernel = s_tmp;
74720 + insert_subj_map_entry(subjmap);
74721 +
74722 + if (copy_acl_subject_label(s_tmp, userp))
74723 + return ERR_PTR(-EFAULT);
74724 +
74725 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74726 + if (err)
74727 + return ERR_PTR(err);
74728 +
74729 + if (!strcmp(s_tmp->filename, "/"))
74730 + role->root_label = s_tmp;
74731 +
74732 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74733 + return ERR_PTR(-EFAULT);
74734 +
74735 + /* copy user and group transition tables */
74736 +
74737 + if (s_tmp->user_trans_num) {
74738 + uid_t *uidlist;
74739 +
74740 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74741 + if (uidlist == NULL)
74742 + return ERR_PTR(-ENOMEM);
74743 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74744 + return ERR_PTR(-EFAULT);
74745 +
74746 + s_tmp->user_transitions = uidlist;
74747 + }
74748 +
74749 + if (s_tmp->group_trans_num) {
74750 + gid_t *gidlist;
74751 +
74752 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74753 + if (gidlist == NULL)
74754 + return ERR_PTR(-ENOMEM);
74755 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74756 + return ERR_PTR(-EFAULT);
74757 +
74758 + s_tmp->group_transitions = gidlist;
74759 + }
74760 +
74761 + /* set up object hash table */
74762 + num_objs = count_user_objs(ghash.first);
74763 +
74764 + s_tmp->obj_hash_size = num_objs;
74765 + s_tmp->obj_hash =
74766 + (struct acl_object_label **)
74767 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74768 +
74769 + if (!s_tmp->obj_hash)
74770 + return ERR_PTR(-ENOMEM);
74771 +
74772 + memset(s_tmp->obj_hash, 0,
74773 + s_tmp->obj_hash_size *
74774 + sizeof (struct acl_object_label *));
74775 +
74776 + /* add in objects */
74777 + err = copy_user_objs(ghash.first, s_tmp, role);
74778 +
74779 + if (err)
74780 + return ERR_PTR(err);
74781 +
74782 + /* set pointer for parent subject */
74783 + if (s_tmp->parent_subject) {
74784 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74785 +
74786 + if (IS_ERR(s_tmp2))
74787 + return s_tmp2;
74788 +
74789 + s_tmp->parent_subject = s_tmp2;
74790 + }
74791 +
74792 + /* add in ip acls */
74793 +
74794 + if (!s_tmp->ip_num) {
74795 + s_tmp->ips = NULL;
74796 + goto insert;
74797 + }
74798 +
74799 + i_tmp =
74800 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74801 + sizeof (struct acl_ip_label *));
74802 +
74803 + if (!i_tmp)
74804 + return ERR_PTR(-ENOMEM);
74805 +
74806 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74807 + *(i_tmp + i_num) =
74808 + (struct acl_ip_label *)
74809 + acl_alloc(sizeof (struct acl_ip_label));
74810 + if (!*(i_tmp + i_num))
74811 + return ERR_PTR(-ENOMEM);
74812 +
74813 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74814 + return ERR_PTR(-EFAULT);
74815 +
74816 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74817 + return ERR_PTR(-EFAULT);
74818 +
74819 + if ((*(i_tmp + i_num))->iface == NULL)
74820 + continue;
74821 +
74822 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74823 + if (err)
74824 + return ERR_PTR(err);
74825 + }
74826 +
74827 + s_tmp->ips = i_tmp;
74828 +
74829 +insert:
74830 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74831 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74832 + return ERR_PTR(-ENOMEM);
74833 +
74834 + return s_tmp;
74835 +}
74836 +
74837 +static int
74838 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74839 +{
74840 + struct acl_subject_label s_pre;
74841 + struct acl_subject_label * ret;
74842 + int err;
74843 +
74844 + while (userp) {
74845 + if (copy_acl_subject_label(&s_pre, userp))
74846 + return -EFAULT;
74847 +
74848 + ret = do_copy_user_subj(userp, role, NULL);
74849 +
74850 + err = PTR_ERR(ret);
74851 + if (IS_ERR(ret))
74852 + return err;
74853 +
74854 + insert_acl_subj_label(ret, role);
74855 +
74856 + userp = s_pre.prev;
74857 + }
74858 +
74859 + return 0;
74860 +}
74861 +
74862 +static int
74863 +copy_user_acl(struct gr_arg *arg)
74864 +{
74865 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74866 + struct acl_subject_label *subj_list;
74867 + struct sprole_pw *sptmp;
74868 + struct gr_hash_struct *ghash;
74869 + uid_t *domainlist;
74870 + unsigned int r_num;
74871 + int err = 0;
74872 + __u16 i;
74873 + __u32 num_subjs;
74874 +
74875 + /* we need a default and kernel role */
74876 + if (arg->role_db.num_roles < 2)
74877 + return -EINVAL;
74878 +
74879 + /* copy special role authentication info from userspace */
74880 +
74881 + polstate->num_sprole_pws = arg->num_sprole_pws;
74882 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74883 +
74884 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74885 + return -ENOMEM;
74886 +
74887 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74888 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74889 + if (!sptmp)
74890 + return -ENOMEM;
74891 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74892 + return -EFAULT;
74893 +
74894 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74895 + if (err)
74896 + return err;
74897 +
74898 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74899 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74900 +#endif
74901 +
74902 + polstate->acl_special_roles[i] = sptmp;
74903 + }
74904 +
74905 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74906 +
74907 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74908 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74909 +
74910 + if (!r_tmp)
74911 + return -ENOMEM;
74912 +
74913 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74914 + return -EFAULT;
74915 +
74916 + if (copy_acl_role_label(r_tmp, r_utmp2))
74917 + return -EFAULT;
74918 +
74919 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74920 + if (err)
74921 + return err;
74922 +
74923 + if (!strcmp(r_tmp->rolename, "default")
74924 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74925 + polstate->default_role = r_tmp;
74926 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74927 + polstate->kernel_role = r_tmp;
74928 + }
74929 +
74930 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74931 + return -ENOMEM;
74932 +
74933 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74934 + return -EFAULT;
74935 +
74936 + r_tmp->hash = ghash;
74937 +
74938 + num_subjs = count_user_subjs(r_tmp->hash->first);
74939 +
74940 + r_tmp->subj_hash_size = num_subjs;
74941 + r_tmp->subj_hash =
74942 + (struct acl_subject_label **)
74943 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74944 +
74945 + if (!r_tmp->subj_hash)
74946 + return -ENOMEM;
74947 +
74948 + err = copy_user_allowedips(r_tmp);
74949 + if (err)
74950 + return err;
74951 +
74952 + /* copy domain info */
74953 + if (r_tmp->domain_children != NULL) {
74954 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74955 + if (domainlist == NULL)
74956 + return -ENOMEM;
74957 +
74958 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74959 + return -EFAULT;
74960 +
74961 + r_tmp->domain_children = domainlist;
74962 + }
74963 +
74964 + err = copy_user_transitions(r_tmp);
74965 + if (err)
74966 + return err;
74967 +
74968 + memset(r_tmp->subj_hash, 0,
74969 + r_tmp->subj_hash_size *
74970 + sizeof (struct acl_subject_label *));
74971 +
74972 + /* acquire the list of subjects, then NULL out
74973 + the list prior to parsing the subjects for this role,
74974 + as during this parsing the list is replaced with a list
74975 + of *nested* subjects for the role
74976 + */
74977 + subj_list = r_tmp->hash->first;
74978 +
74979 + /* set nested subject list to null */
74980 + r_tmp->hash->first = NULL;
74981 +
74982 + err = copy_user_subjs(subj_list, r_tmp);
74983 +
74984 + if (err)
74985 + return err;
74986 +
74987 + insert_acl_role_label(r_tmp);
74988 + }
74989 +
74990 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74991 + return -EINVAL;
74992 +
74993 + return err;
74994 +}
74995 +
74996 +static int gracl_reload_apply_policies(void *reload)
74997 +{
74998 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74999 + struct task_struct *task, *task2;
75000 + struct acl_role_label *role, *rtmp;
75001 + struct acl_subject_label *subj;
75002 + const struct cred *cred;
75003 + int role_applied;
75004 + int ret = 0;
75005 +
75006 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75007 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75008 +
75009 + /* first make sure we'll be able to apply the new policy cleanly */
75010 + do_each_thread(task2, task) {
75011 + if (task->exec_file == NULL)
75012 + continue;
75013 + role_applied = 0;
75014 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75015 + /* preserve special roles */
75016 + FOR_EACH_ROLE_START(role)
75017 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75018 + rtmp = task->role;
75019 + task->role = role;
75020 + role_applied = 1;
75021 + break;
75022 + }
75023 + FOR_EACH_ROLE_END(role)
75024 + }
75025 + if (!role_applied) {
75026 + cred = __task_cred(task);
75027 + rtmp = task->role;
75028 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75029 + }
75030 + /* this handles non-nested inherited subjects, nested subjects will still
75031 + be dropped currently */
75032 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75033 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL, 1);
75034 + /* change the role back so that we've made no modifications to the policy */
75035 + task->role = rtmp;
75036 +
75037 + if (subj == NULL || task->tmpacl == NULL) {
75038 + ret = -EINVAL;
75039 + goto out;
75040 + }
75041 + } while_each_thread(task2, task);
75042 +
75043 + /* now actually apply the policy */
75044 +
75045 + do_each_thread(task2, task) {
75046 + if (task->exec_file) {
75047 + role_applied = 0;
75048 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75049 + /* preserve special roles */
75050 + FOR_EACH_ROLE_START(role)
75051 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75052 + task->role = role;
75053 + role_applied = 1;
75054 + break;
75055 + }
75056 + FOR_EACH_ROLE_END(role)
75057 + }
75058 + if (!role_applied) {
75059 + cred = __task_cred(task);
75060 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75061 + }
75062 + /* this handles non-nested inherited subjects, nested subjects will still
75063 + be dropped currently */
75064 + if (!reload_state->oldmode && task->inherited)
75065 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75066 + else {
75067 + /* looked up and tagged to the task previously */
75068 + subj = task->tmpacl;
75069 + }
75070 + /* subj will be non-null */
75071 + __gr_apply_subject_to_task(polstate, task, subj);
75072 + if (reload_state->oldmode) {
75073 + task->acl_role_id = 0;
75074 + task->acl_sp_role = 0;
75075 + task->inherited = 0;
75076 + }
75077 + } else {
75078 + // it's a kernel process
75079 + task->role = polstate->kernel_role;
75080 + task->acl = polstate->kernel_role->root_label;
75081 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75082 + task->acl->mode &= ~GR_PROCFIND;
75083 +#endif
75084 + }
75085 + } while_each_thread(task2, task);
75086 +
75087 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75088 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75089 +
75090 +out:
75091 +
75092 + return ret;
75093 +}
75094 +
75095 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75096 +{
75097 + struct gr_reload_state new_reload_state = { };
75098 + int err;
75099 +
75100 + new_reload_state.oldpolicy_ptr = polstate;
75101 + new_reload_state.oldalloc_ptr = current_alloc_state;
75102 + new_reload_state.oldmode = oldmode;
75103 +
75104 + current_alloc_state = &new_reload_state.newalloc;
75105 + polstate = &new_reload_state.newpolicy;
75106 +
75107 + /* everything relevant is now saved off, copy in the new policy */
75108 + if (init_variables(args, true)) {
75109 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75110 + err = -ENOMEM;
75111 + goto error;
75112 + }
75113 +
75114 + err = copy_user_acl(args);
75115 + free_init_variables();
75116 + if (err)
75117 + goto error;
75118 + /* the new policy is copied in, with the old policy available via saved_state
75119 + first go through applying roles, making sure to preserve special roles
75120 + then apply new subjects, making sure to preserve inherited and nested subjects,
75121 + though currently only inherited subjects will be preserved
75122 + */
75123 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75124 + if (err)
75125 + goto error;
75126 +
75127 + /* we've now applied the new policy, so restore the old policy state to free it */
75128 + polstate = &new_reload_state.oldpolicy;
75129 + current_alloc_state = &new_reload_state.oldalloc;
75130 + free_variables(true);
75131 +
75132 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75133 + to running_polstate/current_alloc_state inside stop_machine
75134 + */
75135 + err = 0;
75136 + goto out;
75137 +error:
75138 + /* on error of loading the new policy, we'll just keep the previous
75139 + policy set around
75140 + */
75141 + free_variables(true);
75142 +
75143 + /* doesn't affect runtime, but maintains consistent state */
75144 +out:
75145 + polstate = new_reload_state.oldpolicy_ptr;
75146 + current_alloc_state = new_reload_state.oldalloc_ptr;
75147 +
75148 + return err;
75149 +}
75150 +
75151 +static int
75152 +gracl_init(struct gr_arg *args)
75153 +{
75154 + int error = 0;
75155 +
75156 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75157 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75158 +
75159 + if (init_variables(args, false)) {
75160 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75161 + error = -ENOMEM;
75162 + goto out;
75163 + }
75164 +
75165 + error = copy_user_acl(args);
75166 + free_init_variables();
75167 + if (error)
75168 + goto out;
75169 +
75170 + error = gr_set_acls(0);
75171 + if (error)
75172 + goto out;
75173 +
75174 + gr_enable_rbac_system();
75175 +
75176 + return 0;
75177 +
75178 +out:
75179 + free_variables(false);
75180 + return error;
75181 +}
75182 +
75183 +static int
75184 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75185 + unsigned char **sum)
75186 +{
75187 + struct acl_role_label *r;
75188 + struct role_allowed_ip *ipp;
75189 + struct role_transition *trans;
75190 + unsigned int i;
75191 + int found = 0;
75192 + u32 curr_ip = current->signal->curr_ip;
75193 +
75194 + current->signal->saved_ip = curr_ip;
75195 +
75196 + /* check transition table */
75197 +
75198 + for (trans = current->role->transitions; trans; trans = trans->next) {
75199 + if (!strcmp(rolename, trans->rolename)) {
75200 + found = 1;
75201 + break;
75202 + }
75203 + }
75204 +
75205 + if (!found)
75206 + return 0;
75207 +
75208 + /* handle special roles that do not require authentication
75209 + and check ip */
75210 +
75211 + FOR_EACH_ROLE_START(r)
75212 + if (!strcmp(rolename, r->rolename) &&
75213 + (r->roletype & GR_ROLE_SPECIAL)) {
75214 + found = 0;
75215 + if (r->allowed_ips != NULL) {
75216 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75217 + if ((ntohl(curr_ip) & ipp->netmask) ==
75218 + (ntohl(ipp->addr) & ipp->netmask))
75219 + found = 1;
75220 + }
75221 + } else
75222 + found = 2;
75223 + if (!found)
75224 + return 0;
75225 +
75226 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75227 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75228 + *salt = NULL;
75229 + *sum = NULL;
75230 + return 1;
75231 + }
75232 + }
75233 + FOR_EACH_ROLE_END(r)
75234 +
75235 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75236 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75237 + *salt = polstate->acl_special_roles[i]->salt;
75238 + *sum = polstate->acl_special_roles[i]->sum;
75239 + return 1;
75240 + }
75241 + }
75242 +
75243 + return 0;
75244 +}
75245 +
75246 +int gr_check_secure_terminal(struct task_struct *task)
75247 +{
75248 + struct task_struct *p, *p2, *p3;
75249 + struct files_struct *files;
75250 + struct fdtable *fdt;
75251 + struct file *our_file = NULL, *file;
75252 + int i;
75253 +
75254 + if (task->signal->tty == NULL)
75255 + return 1;
75256 +
75257 + files = get_files_struct(task);
75258 + if (files != NULL) {
75259 + rcu_read_lock();
75260 + fdt = files_fdtable(files);
75261 + for (i=0; i < fdt->max_fds; i++) {
75262 + file = fcheck_files(files, i);
75263 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75264 + get_file(file);
75265 + our_file = file;
75266 + }
75267 + }
75268 + rcu_read_unlock();
75269 + put_files_struct(files);
75270 + }
75271 +
75272 + if (our_file == NULL)
75273 + return 1;
75274 +
75275 + read_lock(&tasklist_lock);
75276 + do_each_thread(p2, p) {
75277 + files = get_files_struct(p);
75278 + if (files == NULL ||
75279 + (p->signal && p->signal->tty == task->signal->tty)) {
75280 + if (files != NULL)
75281 + put_files_struct(files);
75282 + continue;
75283 + }
75284 + rcu_read_lock();
75285 + fdt = files_fdtable(files);
75286 + for (i=0; i < fdt->max_fds; i++) {
75287 + file = fcheck_files(files, i);
75288 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75289 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75290 + p3 = task;
75291 + while (task_pid_nr(p3) > 0) {
75292 + if (p3 == p)
75293 + break;
75294 + p3 = p3->real_parent;
75295 + }
75296 + if (p3 == p)
75297 + break;
75298 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75299 + gr_handle_alertkill(p);
75300 + rcu_read_unlock();
75301 + put_files_struct(files);
75302 + read_unlock(&tasklist_lock);
75303 + fput(our_file);
75304 + return 0;
75305 + }
75306 + }
75307 + rcu_read_unlock();
75308 + put_files_struct(files);
75309 + } while_each_thread(p2, p);
75310 + read_unlock(&tasklist_lock);
75311 +
75312 + fput(our_file);
75313 + return 1;
75314 +}
75315 +
75316 +ssize_t
75317 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75318 +{
75319 + struct gr_arg_wrapper uwrap;
75320 + unsigned char *sprole_salt = NULL;
75321 + unsigned char *sprole_sum = NULL;
75322 + int error = 0;
75323 + int error2 = 0;
75324 + size_t req_count = 0;
75325 + unsigned char oldmode = 0;
75326 +
75327 + mutex_lock(&gr_dev_mutex);
75328 +
75329 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75330 + error = -EPERM;
75331 + goto out;
75332 + }
75333 +
75334 +#ifdef CONFIG_COMPAT
75335 + pax_open_kernel();
75336 + if (is_compat_task()) {
75337 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75338 + copy_gr_arg = &copy_gr_arg_compat;
75339 + copy_acl_object_label = &copy_acl_object_label_compat;
75340 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75341 + copy_acl_role_label = &copy_acl_role_label_compat;
75342 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75343 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75344 + copy_role_transition = &copy_role_transition_compat;
75345 + copy_sprole_pw = &copy_sprole_pw_compat;
75346 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75347 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75348 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75349 + } else {
75350 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75351 + copy_gr_arg = &copy_gr_arg_normal;
75352 + copy_acl_object_label = &copy_acl_object_label_normal;
75353 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75354 + copy_acl_role_label = &copy_acl_role_label_normal;
75355 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75356 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75357 + copy_role_transition = &copy_role_transition_normal;
75358 + copy_sprole_pw = &copy_sprole_pw_normal;
75359 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75360 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75361 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75362 + }
75363 + pax_close_kernel();
75364 +#endif
75365 +
75366 + req_count = get_gr_arg_wrapper_size();
75367 +
75368 + if (count != req_count) {
75369 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75370 + error = -EINVAL;
75371 + goto out;
75372 + }
75373 +
75374 +
75375 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75376 + gr_auth_expires = 0;
75377 + gr_auth_attempts = 0;
75378 + }
75379 +
75380 + error = copy_gr_arg_wrapper(buf, &uwrap);
75381 + if (error)
75382 + goto out;
75383 +
75384 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75385 + if (error)
75386 + goto out;
75387 +
75388 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75389 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75390 + time_after(gr_auth_expires, get_seconds())) {
75391 + error = -EBUSY;
75392 + goto out;
75393 + }
75394 +
75395 + /* if non-root trying to do anything other than use a special role,
75396 + do not attempt authentication, do not count towards authentication
75397 + locking
75398 + */
75399 +
75400 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75401 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75402 + gr_is_global_nonroot(current_uid())) {
75403 + error = -EPERM;
75404 + goto out;
75405 + }
75406 +
75407 + /* ensure pw and special role name are null terminated */
75408 +
75409 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75410 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75411 +
75412 + /* Okay.
75413 + * We have our enough of the argument structure..(we have yet
75414 + * to copy_from_user the tables themselves) . Copy the tables
75415 + * only if we need them, i.e. for loading operations. */
75416 +
75417 + switch (gr_usermode->mode) {
75418 + case GR_STATUS:
75419 + if (gr_acl_is_enabled()) {
75420 + error = 1;
75421 + if (!gr_check_secure_terminal(current))
75422 + error = 3;
75423 + } else
75424 + error = 2;
75425 + goto out;
75426 + case GR_SHUTDOWN:
75427 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75428 + stop_machine(gr_rbac_disable, NULL, NULL);
75429 + free_variables(false);
75430 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75431 + memset(gr_system_salt, 0, GR_SALT_LEN);
75432 + memset(gr_system_sum, 0, GR_SHA_LEN);
75433 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75434 + } else if (gr_acl_is_enabled()) {
75435 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75436 + error = -EPERM;
75437 + } else {
75438 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75439 + error = -EAGAIN;
75440 + }
75441 + break;
75442 + case GR_ENABLE:
75443 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75444 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75445 + else {
75446 + if (gr_acl_is_enabled())
75447 + error = -EAGAIN;
75448 + else
75449 + error = error2;
75450 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75451 + }
75452 + break;
75453 + case GR_OLDRELOAD:
75454 + oldmode = 1;
75455 + case GR_RELOAD:
75456 + if (!gr_acl_is_enabled()) {
75457 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75458 + error = -EAGAIN;
75459 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75460 + error2 = gracl_reload(gr_usermode, oldmode);
75461 + if (!error2)
75462 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75463 + else {
75464 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75465 + error = error2;
75466 + }
75467 + } else {
75468 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75469 + error = -EPERM;
75470 + }
75471 + break;
75472 + case GR_SEGVMOD:
75473 + if (unlikely(!gr_acl_is_enabled())) {
75474 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75475 + error = -EAGAIN;
75476 + break;
75477 + }
75478 +
75479 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75480 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75481 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75482 + struct acl_subject_label *segvacl;
75483 + segvacl =
75484 + lookup_acl_subj_label(gr_usermode->segv_inode,
75485 + gr_usermode->segv_device,
75486 + current->role);
75487 + if (segvacl) {
75488 + segvacl->crashes = 0;
75489 + segvacl->expires = 0;
75490 + }
75491 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75492 + gr_remove_uid(gr_usermode->segv_uid);
75493 + }
75494 + } else {
75495 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75496 + error = -EPERM;
75497 + }
75498 + break;
75499 + case GR_SPROLE:
75500 + case GR_SPROLEPAM:
75501 + if (unlikely(!gr_acl_is_enabled())) {
75502 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75503 + error = -EAGAIN;
75504 + break;
75505 + }
75506 +
75507 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75508 + current->role->expires = 0;
75509 + current->role->auth_attempts = 0;
75510 + }
75511 +
75512 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75513 + time_after(current->role->expires, get_seconds())) {
75514 + error = -EBUSY;
75515 + goto out;
75516 + }
75517 +
75518 + if (lookup_special_role_auth
75519 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75520 + && ((!sprole_salt && !sprole_sum)
75521 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75522 + char *p = "";
75523 + assign_special_role(gr_usermode->sp_role);
75524 + read_lock(&tasklist_lock);
75525 + if (current->real_parent)
75526 + p = current->real_parent->role->rolename;
75527 + read_unlock(&tasklist_lock);
75528 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75529 + p, acl_sp_role_value);
75530 + } else {
75531 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75532 + error = -EPERM;
75533 + if(!(current->role->auth_attempts++))
75534 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75535 +
75536 + goto out;
75537 + }
75538 + break;
75539 + case GR_UNSPROLE:
75540 + if (unlikely(!gr_acl_is_enabled())) {
75541 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75542 + error = -EAGAIN;
75543 + break;
75544 + }
75545 +
75546 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75547 + char *p = "";
75548 + int i = 0;
75549 +
75550 + read_lock(&tasklist_lock);
75551 + if (current->real_parent) {
75552 + p = current->real_parent->role->rolename;
75553 + i = current->real_parent->acl_role_id;
75554 + }
75555 + read_unlock(&tasklist_lock);
75556 +
75557 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75558 + gr_set_acls(1);
75559 + } else {
75560 + error = -EPERM;
75561 + goto out;
75562 + }
75563 + break;
75564 + default:
75565 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75566 + error = -EINVAL;
75567 + break;
75568 + }
75569 +
75570 + if (error != -EPERM)
75571 + goto out;
75572 +
75573 + if(!(gr_auth_attempts++))
75574 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75575 +
75576 + out:
75577 + mutex_unlock(&gr_dev_mutex);
75578 +
75579 + if (!error)
75580 + error = req_count;
75581 +
75582 + return error;
75583 +}
75584 +
75585 +int
75586 +gr_set_acls(const int type)
75587 +{
75588 + struct task_struct *task, *task2;
75589 + struct acl_role_label *role = current->role;
75590 + struct acl_subject_label *subj;
75591 + __u16 acl_role_id = current->acl_role_id;
75592 + const struct cred *cred;
75593 + int ret;
75594 +
75595 + rcu_read_lock();
75596 + read_lock(&tasklist_lock);
75597 + read_lock(&grsec_exec_file_lock);
75598 + do_each_thread(task2, task) {
75599 + /* check to see if we're called from the exit handler,
75600 + if so, only replace ACLs that have inherited the admin
75601 + ACL */
75602 +
75603 + if (type && (task->role != role ||
75604 + task->acl_role_id != acl_role_id))
75605 + continue;
75606 +
75607 + task->acl_role_id = 0;
75608 + task->acl_sp_role = 0;
75609 + task->inherited = 0;
75610 +
75611 + if (task->exec_file) {
75612 + cred = __task_cred(task);
75613 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75614 + subj = __gr_get_subject_for_task(polstate, task, NULL, 1);
75615 + if (subj == NULL) {
75616 + ret = -EINVAL;
75617 + read_unlock(&grsec_exec_file_lock);
75618 + read_unlock(&tasklist_lock);
75619 + rcu_read_unlock();
75620 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75621 + return ret;
75622 + }
75623 + __gr_apply_subject_to_task(polstate, task, subj);
75624 + } else {
75625 + // it's a kernel process
75626 + task->role = polstate->kernel_role;
75627 + task->acl = polstate->kernel_role->root_label;
75628 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75629 + task->acl->mode &= ~GR_PROCFIND;
75630 +#endif
75631 + }
75632 + } while_each_thread(task2, task);
75633 + read_unlock(&grsec_exec_file_lock);
75634 + read_unlock(&tasklist_lock);
75635 + rcu_read_unlock();
75636 +
75637 + return 0;
75638 +}
75639 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75640 new file mode 100644
75641 index 0000000..39645c9
75642 --- /dev/null
75643 +++ b/grsecurity/gracl_res.c
75644 @@ -0,0 +1,68 @@
75645 +#include <linux/kernel.h>
75646 +#include <linux/sched.h>
75647 +#include <linux/gracl.h>
75648 +#include <linux/grinternal.h>
75649 +
75650 +static const char *restab_log[] = {
75651 + [RLIMIT_CPU] = "RLIMIT_CPU",
75652 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75653 + [RLIMIT_DATA] = "RLIMIT_DATA",
75654 + [RLIMIT_STACK] = "RLIMIT_STACK",
75655 + [RLIMIT_CORE] = "RLIMIT_CORE",
75656 + [RLIMIT_RSS] = "RLIMIT_RSS",
75657 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75658 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75659 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75660 + [RLIMIT_AS] = "RLIMIT_AS",
75661 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75662 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75663 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75664 + [RLIMIT_NICE] = "RLIMIT_NICE",
75665 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75666 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75667 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75668 +};
75669 +
75670 +void
75671 +gr_log_resource(const struct task_struct *task,
75672 + const int res, const unsigned long wanted, const int gt)
75673 +{
75674 + const struct cred *cred;
75675 + unsigned long rlim;
75676 +
75677 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75678 + return;
75679 +
75680 + // not yet supported resource
75681 + if (unlikely(!restab_log[res]))
75682 + return;
75683 +
75684 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75685 + rlim = task_rlimit_max(task, res);
75686 + else
75687 + rlim = task_rlimit(task, res);
75688 +
75689 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75690 + return;
75691 +
75692 + rcu_read_lock();
75693 + cred = __task_cred(task);
75694 +
75695 + if (res == RLIMIT_NPROC &&
75696 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75697 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75698 + goto out_rcu_unlock;
75699 + else if (res == RLIMIT_MEMLOCK &&
75700 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75701 + goto out_rcu_unlock;
75702 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75703 + goto out_rcu_unlock;
75704 + rcu_read_unlock();
75705 +
75706 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75707 +
75708 + return;
75709 +out_rcu_unlock:
75710 + rcu_read_unlock();
75711 + return;
75712 +}
75713 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75714 new file mode 100644
75715 index 0000000..2040e61
75716 --- /dev/null
75717 +++ b/grsecurity/gracl_segv.c
75718 @@ -0,0 +1,313 @@
75719 +#include <linux/kernel.h>
75720 +#include <linux/mm.h>
75721 +#include <asm/uaccess.h>
75722 +#include <asm/errno.h>
75723 +#include <asm/mman.h>
75724 +#include <net/sock.h>
75725 +#include <linux/file.h>
75726 +#include <linux/fs.h>
75727 +#include <linux/net.h>
75728 +#include <linux/in.h>
75729 +#include <linux/slab.h>
75730 +#include <linux/types.h>
75731 +#include <linux/sched.h>
75732 +#include <linux/timer.h>
75733 +#include <linux/gracl.h>
75734 +#include <linux/grsecurity.h>
75735 +#include <linux/grinternal.h>
75736 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75737 +#include <linux/magic.h>
75738 +#include <linux/pagemap.h>
75739 +#include "../fs/btrfs/async-thread.h"
75740 +#include "../fs/btrfs/ctree.h"
75741 +#include "../fs/btrfs/btrfs_inode.h"
75742 +#endif
75743 +
75744 +static struct crash_uid *uid_set;
75745 +static unsigned short uid_used;
75746 +static DEFINE_SPINLOCK(gr_uid_lock);
75747 +extern rwlock_t gr_inode_lock;
75748 +extern struct acl_subject_label *
75749 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75750 + struct acl_role_label *role);
75751 +
75752 +static inline dev_t __get_dev(const struct dentry *dentry)
75753 +{
75754 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75755 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75756 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75757 + else
75758 +#endif
75759 + return dentry->d_sb->s_dev;
75760 +}
75761 +
75762 +int
75763 +gr_init_uidset(void)
75764 +{
75765 + uid_set =
75766 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75767 + uid_used = 0;
75768 +
75769 + return uid_set ? 1 : 0;
75770 +}
75771 +
75772 +void
75773 +gr_free_uidset(void)
75774 +{
75775 + if (uid_set) {
75776 + struct crash_uid *tmpset;
75777 + spin_lock(&gr_uid_lock);
75778 + tmpset = uid_set;
75779 + uid_set = NULL;
75780 + uid_used = 0;
75781 + spin_unlock(&gr_uid_lock);
75782 + if (tmpset)
75783 + kfree(tmpset);
75784 + }
75785 +
75786 + return;
75787 +}
75788 +
75789 +int
75790 +gr_find_uid(const uid_t uid)
75791 +{
75792 + struct crash_uid *tmp = uid_set;
75793 + uid_t buid;
75794 + int low = 0, high = uid_used - 1, mid;
75795 +
75796 + while (high >= low) {
75797 + mid = (low + high) >> 1;
75798 + buid = tmp[mid].uid;
75799 + if (buid == uid)
75800 + return mid;
75801 + if (buid > uid)
75802 + high = mid - 1;
75803 + if (buid < uid)
75804 + low = mid + 1;
75805 + }
75806 +
75807 + return -1;
75808 +}
75809 +
75810 +static __inline__ void
75811 +gr_insertsort(void)
75812 +{
75813 + unsigned short i, j;
75814 + struct crash_uid index;
75815 +
75816 + for (i = 1; i < uid_used; i++) {
75817 + index = uid_set[i];
75818 + j = i;
75819 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75820 + uid_set[j] = uid_set[j - 1];
75821 + j--;
75822 + }
75823 + uid_set[j] = index;
75824 + }
75825 +
75826 + return;
75827 +}
75828 +
75829 +static __inline__ void
75830 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75831 +{
75832 + int loc;
75833 + uid_t uid = GR_GLOBAL_UID(kuid);
75834 +
75835 + if (uid_used == GR_UIDTABLE_MAX)
75836 + return;
75837 +
75838 + loc = gr_find_uid(uid);
75839 +
75840 + if (loc >= 0) {
75841 + uid_set[loc].expires = expires;
75842 + return;
75843 + }
75844 +
75845 + uid_set[uid_used].uid = uid;
75846 + uid_set[uid_used].expires = expires;
75847 + uid_used++;
75848 +
75849 + gr_insertsort();
75850 +
75851 + return;
75852 +}
75853 +
75854 +void
75855 +gr_remove_uid(const unsigned short loc)
75856 +{
75857 + unsigned short i;
75858 +
75859 + for (i = loc + 1; i < uid_used; i++)
75860 + uid_set[i - 1] = uid_set[i];
75861 +
75862 + uid_used--;
75863 +
75864 + return;
75865 +}
75866 +
75867 +int
75868 +gr_check_crash_uid(const kuid_t kuid)
75869 +{
75870 + int loc;
75871 + int ret = 0;
75872 + uid_t uid;
75873 +
75874 + if (unlikely(!gr_acl_is_enabled()))
75875 + return 0;
75876 +
75877 + uid = GR_GLOBAL_UID(kuid);
75878 +
75879 + spin_lock(&gr_uid_lock);
75880 + loc = gr_find_uid(uid);
75881 +
75882 + if (loc < 0)
75883 + goto out_unlock;
75884 +
75885 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75886 + gr_remove_uid(loc);
75887 + else
75888 + ret = 1;
75889 +
75890 +out_unlock:
75891 + spin_unlock(&gr_uid_lock);
75892 + return ret;
75893 +}
75894 +
75895 +static __inline__ int
75896 +proc_is_setxid(const struct cred *cred)
75897 +{
75898 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75899 + !uid_eq(cred->uid, cred->fsuid))
75900 + return 1;
75901 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75902 + !gid_eq(cred->gid, cred->fsgid))
75903 + return 1;
75904 +
75905 + return 0;
75906 +}
75907 +
75908 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75909 +
75910 +void
75911 +gr_handle_crash(struct task_struct *task, const int sig)
75912 +{
75913 + struct acl_subject_label *curr;
75914 + struct task_struct *tsk, *tsk2;
75915 + const struct cred *cred;
75916 + const struct cred *cred2;
75917 +
75918 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75919 + return;
75920 +
75921 + if (unlikely(!gr_acl_is_enabled()))
75922 + return;
75923 +
75924 + curr = task->acl;
75925 +
75926 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75927 + return;
75928 +
75929 + if (time_before_eq(curr->expires, get_seconds())) {
75930 + curr->expires = 0;
75931 + curr->crashes = 0;
75932 + }
75933 +
75934 + curr->crashes++;
75935 +
75936 + if (!curr->expires)
75937 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75938 +
75939 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75940 + time_after(curr->expires, get_seconds())) {
75941 + rcu_read_lock();
75942 + cred = __task_cred(task);
75943 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75944 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75945 + spin_lock(&gr_uid_lock);
75946 + gr_insert_uid(cred->uid, curr->expires);
75947 + spin_unlock(&gr_uid_lock);
75948 + curr->expires = 0;
75949 + curr->crashes = 0;
75950 + read_lock(&tasklist_lock);
75951 + do_each_thread(tsk2, tsk) {
75952 + cred2 = __task_cred(tsk);
75953 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
75954 + gr_fake_force_sig(SIGKILL, tsk);
75955 + } while_each_thread(tsk2, tsk);
75956 + read_unlock(&tasklist_lock);
75957 + } else {
75958 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75959 + read_lock(&tasklist_lock);
75960 + read_lock(&grsec_exec_file_lock);
75961 + do_each_thread(tsk2, tsk) {
75962 + if (likely(tsk != task)) {
75963 + // if this thread has the same subject as the one that triggered
75964 + // RES_CRASH and it's the same binary, kill it
75965 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75966 + gr_fake_force_sig(SIGKILL, tsk);
75967 + }
75968 + } while_each_thread(tsk2, tsk);
75969 + read_unlock(&grsec_exec_file_lock);
75970 + read_unlock(&tasklist_lock);
75971 + }
75972 + rcu_read_unlock();
75973 + }
75974 +
75975 + return;
75976 +}
75977 +
75978 +int
75979 +gr_check_crash_exec(const struct file *filp)
75980 +{
75981 + struct acl_subject_label *curr;
75982 +
75983 + if (unlikely(!gr_acl_is_enabled()))
75984 + return 0;
75985 +
75986 + read_lock(&gr_inode_lock);
75987 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75988 + __get_dev(filp->f_path.dentry),
75989 + current->role);
75990 + read_unlock(&gr_inode_lock);
75991 +
75992 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75993 + (!curr->crashes && !curr->expires))
75994 + return 0;
75995 +
75996 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75997 + time_after(curr->expires, get_seconds()))
75998 + return 1;
75999 + else if (time_before_eq(curr->expires, get_seconds())) {
76000 + curr->crashes = 0;
76001 + curr->expires = 0;
76002 + }
76003 +
76004 + return 0;
76005 +}
76006 +
76007 +void
76008 +gr_handle_alertkill(struct task_struct *task)
76009 +{
76010 + struct acl_subject_label *curracl;
76011 + __u32 curr_ip;
76012 + struct task_struct *p, *p2;
76013 +
76014 + if (unlikely(!gr_acl_is_enabled()))
76015 + return;
76016 +
76017 + curracl = task->acl;
76018 + curr_ip = task->signal->curr_ip;
76019 +
76020 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76021 + read_lock(&tasklist_lock);
76022 + do_each_thread(p2, p) {
76023 + if (p->signal->curr_ip == curr_ip)
76024 + gr_fake_force_sig(SIGKILL, p);
76025 + } while_each_thread(p2, p);
76026 + read_unlock(&tasklist_lock);
76027 + } else if (curracl->mode & GR_KILLPROC)
76028 + gr_fake_force_sig(SIGKILL, task);
76029 +
76030 + return;
76031 +}
76032 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76033 new file mode 100644
76034 index 0000000..6b0c9cc
76035 --- /dev/null
76036 +++ b/grsecurity/gracl_shm.c
76037 @@ -0,0 +1,40 @@
76038 +#include <linux/kernel.h>
76039 +#include <linux/mm.h>
76040 +#include <linux/sched.h>
76041 +#include <linux/file.h>
76042 +#include <linux/ipc.h>
76043 +#include <linux/gracl.h>
76044 +#include <linux/grsecurity.h>
76045 +#include <linux/grinternal.h>
76046 +
76047 +int
76048 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76049 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76050 +{
76051 + struct task_struct *task;
76052 +
76053 + if (!gr_acl_is_enabled())
76054 + return 1;
76055 +
76056 + rcu_read_lock();
76057 + read_lock(&tasklist_lock);
76058 +
76059 + task = find_task_by_vpid(shm_cprid);
76060 +
76061 + if (unlikely(!task))
76062 + task = find_task_by_vpid(shm_lapid);
76063 +
76064 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76065 + (task_pid_nr(task) == shm_lapid)) &&
76066 + (task->acl->mode & GR_PROTSHM) &&
76067 + (task->acl != current->acl))) {
76068 + read_unlock(&tasklist_lock);
76069 + rcu_read_unlock();
76070 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76071 + return 0;
76072 + }
76073 + read_unlock(&tasklist_lock);
76074 + rcu_read_unlock();
76075 +
76076 + return 1;
76077 +}
76078 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76079 new file mode 100644
76080 index 0000000..bc0be01
76081 --- /dev/null
76082 +++ b/grsecurity/grsec_chdir.c
76083 @@ -0,0 +1,19 @@
76084 +#include <linux/kernel.h>
76085 +#include <linux/sched.h>
76086 +#include <linux/fs.h>
76087 +#include <linux/file.h>
76088 +#include <linux/grsecurity.h>
76089 +#include <linux/grinternal.h>
76090 +
76091 +void
76092 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76093 +{
76094 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76095 + if ((grsec_enable_chdir && grsec_enable_group &&
76096 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76097 + !grsec_enable_group)) {
76098 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76099 + }
76100 +#endif
76101 + return;
76102 +}
76103 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76104 new file mode 100644
76105 index 0000000..114ea4f
76106 --- /dev/null
76107 +++ b/grsecurity/grsec_chroot.c
76108 @@ -0,0 +1,467 @@
76109 +#include <linux/kernel.h>
76110 +#include <linux/module.h>
76111 +#include <linux/sched.h>
76112 +#include <linux/file.h>
76113 +#include <linux/fs.h>
76114 +#include <linux/mount.h>
76115 +#include <linux/types.h>
76116 +#include "../fs/mount.h"
76117 +#include <linux/grsecurity.h>
76118 +#include <linux/grinternal.h>
76119 +
76120 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76121 +int gr_init_ran;
76122 +#endif
76123 +
76124 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76125 +{
76126 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76127 + struct dentry *tmpd = dentry;
76128 +
76129 + read_seqlock_excl(&mount_lock);
76130 + write_seqlock(&rename_lock);
76131 +
76132 + while (tmpd != mnt->mnt_root) {
76133 + atomic_inc(&tmpd->chroot_refcnt);
76134 + tmpd = tmpd->d_parent;
76135 + }
76136 + atomic_inc(&tmpd->chroot_refcnt);
76137 +
76138 + write_sequnlock(&rename_lock);
76139 + read_sequnlock_excl(&mount_lock);
76140 +#endif
76141 +}
76142 +
76143 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76144 +{
76145 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76146 + struct dentry *tmpd = dentry;
76147 +
76148 + read_seqlock_excl(&mount_lock);
76149 + write_seqlock(&rename_lock);
76150 +
76151 + while (tmpd != mnt->mnt_root) {
76152 + atomic_dec(&tmpd->chroot_refcnt);
76153 + tmpd = tmpd->d_parent;
76154 + }
76155 + atomic_dec(&tmpd->chroot_refcnt);
76156 +
76157 + write_sequnlock(&rename_lock);
76158 + read_sequnlock_excl(&mount_lock);
76159 +#endif
76160 +}
76161 +
76162 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76163 +static struct dentry *get_closest_chroot(struct dentry *dentry)
76164 +{
76165 + write_seqlock(&rename_lock);
76166 + do {
76167 + if (atomic_read(&dentry->chroot_refcnt)) {
76168 + write_sequnlock(&rename_lock);
76169 + return dentry;
76170 + }
76171 + dentry = dentry->d_parent;
76172 + } while (!IS_ROOT(dentry));
76173 + write_sequnlock(&rename_lock);
76174 + return NULL;
76175 +}
76176 +#endif
76177 +
76178 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
76179 + struct dentry *newdentry, struct vfsmount *newmnt)
76180 +{
76181 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76182 + struct dentry *chroot;
76183 +
76184 + if (unlikely(!grsec_enable_chroot_rename))
76185 + return 0;
76186 +
76187 + if (likely(!proc_is_chrooted(current) && gr_is_global_root(current_uid())))
76188 + return 0;
76189 +
76190 + chroot = get_closest_chroot(olddentry);
76191 +
76192 + if (chroot == NULL)
76193 + return 0;
76194 +
76195 + if (is_subdir(newdentry, chroot))
76196 + return 0;
76197 +
76198 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_RENAME_MSG, olddentry, oldmnt);
76199 +
76200 + return 1;
76201 +#else
76202 + return 0;
76203 +#endif
76204 +}
76205 +
76206 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76207 +{
76208 +#ifdef CONFIG_GRKERNSEC
76209 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76210 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76211 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76212 + && gr_init_ran
76213 +#endif
76214 + )
76215 + task->gr_is_chrooted = 1;
76216 + else {
76217 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76218 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76219 + gr_init_ran = 1;
76220 +#endif
76221 + task->gr_is_chrooted = 0;
76222 + }
76223 +
76224 + task->gr_chroot_dentry = path->dentry;
76225 +#endif
76226 + return;
76227 +}
76228 +
76229 +void gr_clear_chroot_entries(struct task_struct *task)
76230 +{
76231 +#ifdef CONFIG_GRKERNSEC
76232 + task->gr_is_chrooted = 0;
76233 + task->gr_chroot_dentry = NULL;
76234 +#endif
76235 + return;
76236 +}
76237 +
76238 +int
76239 +gr_handle_chroot_unix(const pid_t pid)
76240 +{
76241 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76242 + struct task_struct *p;
76243 +
76244 + if (unlikely(!grsec_enable_chroot_unix))
76245 + return 1;
76246 +
76247 + if (likely(!proc_is_chrooted(current)))
76248 + return 1;
76249 +
76250 + rcu_read_lock();
76251 + read_lock(&tasklist_lock);
76252 + p = find_task_by_vpid_unrestricted(pid);
76253 + if (unlikely(p && !have_same_root(current, p))) {
76254 + read_unlock(&tasklist_lock);
76255 + rcu_read_unlock();
76256 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76257 + return 0;
76258 + }
76259 + read_unlock(&tasklist_lock);
76260 + rcu_read_unlock();
76261 +#endif
76262 + return 1;
76263 +}
76264 +
76265 +int
76266 +gr_handle_chroot_nice(void)
76267 +{
76268 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76269 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76270 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76271 + return -EPERM;
76272 + }
76273 +#endif
76274 + return 0;
76275 +}
76276 +
76277 +int
76278 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76279 +{
76280 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76281 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76282 + && proc_is_chrooted(current)) {
76283 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76284 + return -EACCES;
76285 + }
76286 +#endif
76287 + return 0;
76288 +}
76289 +
76290 +int
76291 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76292 +{
76293 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76294 + struct task_struct *p;
76295 + int ret = 0;
76296 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76297 + return ret;
76298 +
76299 + read_lock(&tasklist_lock);
76300 + do_each_pid_task(pid, type, p) {
76301 + if (!have_same_root(current, p)) {
76302 + ret = 1;
76303 + goto out;
76304 + }
76305 + } while_each_pid_task(pid, type, p);
76306 +out:
76307 + read_unlock(&tasklist_lock);
76308 + return ret;
76309 +#endif
76310 + return 0;
76311 +}
76312 +
76313 +int
76314 +gr_pid_is_chrooted(struct task_struct *p)
76315 +{
76316 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76317 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76318 + return 0;
76319 +
76320 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76321 + !have_same_root(current, p)) {
76322 + return 1;
76323 + }
76324 +#endif
76325 + return 0;
76326 +}
76327 +
76328 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76329 +
76330 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76331 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76332 +{
76333 + struct path path, currentroot;
76334 + int ret = 0;
76335 +
76336 + path.dentry = (struct dentry *)u_dentry;
76337 + path.mnt = (struct vfsmount *)u_mnt;
76338 + get_fs_root(current->fs, &currentroot);
76339 + if (path_is_under(&path, &currentroot))
76340 + ret = 1;
76341 + path_put(&currentroot);
76342 +
76343 + return ret;
76344 +}
76345 +#endif
76346 +
76347 +int
76348 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76349 +{
76350 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76351 + if (!grsec_enable_chroot_fchdir)
76352 + return 1;
76353 +
76354 + if (!proc_is_chrooted(current))
76355 + return 1;
76356 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76357 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76358 + return 0;
76359 + }
76360 +#endif
76361 + return 1;
76362 +}
76363 +
76364 +int
76365 +gr_chroot_fhandle(void)
76366 +{
76367 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76368 + if (!grsec_enable_chroot_fchdir)
76369 + return 1;
76370 +
76371 + if (!proc_is_chrooted(current))
76372 + return 1;
76373 + else {
76374 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76375 + return 0;
76376 + }
76377 +#endif
76378 + return 1;
76379 +}
76380 +
76381 +int
76382 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76383 + const u64 shm_createtime)
76384 +{
76385 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76386 + struct task_struct *p;
76387 +
76388 + if (unlikely(!grsec_enable_chroot_shmat))
76389 + return 1;
76390 +
76391 + if (likely(!proc_is_chrooted(current)))
76392 + return 1;
76393 +
76394 + rcu_read_lock();
76395 + read_lock(&tasklist_lock);
76396 +
76397 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76398 + if (time_before_eq64(p->start_time, shm_createtime)) {
76399 + if (have_same_root(current, p)) {
76400 + goto allow;
76401 + } else {
76402 + read_unlock(&tasklist_lock);
76403 + rcu_read_unlock();
76404 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76405 + return 0;
76406 + }
76407 + }
76408 + /* creator exited, pid reuse, fall through to next check */
76409 + }
76410 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76411 + if (unlikely(!have_same_root(current, p))) {
76412 + read_unlock(&tasklist_lock);
76413 + rcu_read_unlock();
76414 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76415 + return 0;
76416 + }
76417 + }
76418 +
76419 +allow:
76420 + read_unlock(&tasklist_lock);
76421 + rcu_read_unlock();
76422 +#endif
76423 + return 1;
76424 +}
76425 +
76426 +void
76427 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76428 +{
76429 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76430 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76431 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76432 +#endif
76433 + return;
76434 +}
76435 +
76436 +int
76437 +gr_handle_chroot_mknod(const struct dentry *dentry,
76438 + const struct vfsmount *mnt, const int mode)
76439 +{
76440 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76441 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76442 + proc_is_chrooted(current)) {
76443 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76444 + return -EPERM;
76445 + }
76446 +#endif
76447 + return 0;
76448 +}
76449 +
76450 +int
76451 +gr_handle_chroot_mount(const struct dentry *dentry,
76452 + const struct vfsmount *mnt, const char *dev_name)
76453 +{
76454 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76455 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76456 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76457 + return -EPERM;
76458 + }
76459 +#endif
76460 + return 0;
76461 +}
76462 +
76463 +int
76464 +gr_handle_chroot_pivot(void)
76465 +{
76466 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76467 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76468 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76469 + return -EPERM;
76470 + }
76471 +#endif
76472 + return 0;
76473 +}
76474 +
76475 +int
76476 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76477 +{
76478 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76479 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76480 + !gr_is_outside_chroot(dentry, mnt)) {
76481 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76482 + return -EPERM;
76483 + }
76484 +#endif
76485 + return 0;
76486 +}
76487 +
76488 +extern const char *captab_log[];
76489 +extern int captab_log_entries;
76490 +
76491 +int
76492 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76493 +{
76494 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76495 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76496 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76497 + if (cap_raised(chroot_caps, cap)) {
76498 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76499 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76500 + }
76501 + return 0;
76502 + }
76503 + }
76504 +#endif
76505 + return 1;
76506 +}
76507 +
76508 +int
76509 +gr_chroot_is_capable(const int cap)
76510 +{
76511 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76512 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76513 +#endif
76514 + return 1;
76515 +}
76516 +
76517 +int
76518 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76519 +{
76520 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76521 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76522 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76523 + if (cap_raised(chroot_caps, cap)) {
76524 + return 0;
76525 + }
76526 + }
76527 +#endif
76528 + return 1;
76529 +}
76530 +
76531 +int
76532 +gr_chroot_is_capable_nolog(const int cap)
76533 +{
76534 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76535 + return gr_task_chroot_is_capable_nolog(current, cap);
76536 +#endif
76537 + return 1;
76538 +}
76539 +
76540 +int
76541 +gr_handle_chroot_sysctl(const int op)
76542 +{
76543 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76544 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76545 + proc_is_chrooted(current))
76546 + return -EACCES;
76547 +#endif
76548 + return 0;
76549 +}
76550 +
76551 +void
76552 +gr_handle_chroot_chdir(const struct path *path)
76553 +{
76554 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76555 + if (grsec_enable_chroot_chdir)
76556 + set_fs_pwd(current->fs, path);
76557 +#endif
76558 + return;
76559 +}
76560 +
76561 +int
76562 +gr_handle_chroot_chmod(const struct dentry *dentry,
76563 + const struct vfsmount *mnt, const int mode)
76564 +{
76565 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76566 + /* allow chmod +s on directories, but not files */
76567 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76568 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76569 + proc_is_chrooted(current)) {
76570 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76571 + return -EPERM;
76572 + }
76573 +#endif
76574 + return 0;
76575 +}
76576 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76577 new file mode 100644
76578 index 0000000..0f9ac91
76579 --- /dev/null
76580 +++ b/grsecurity/grsec_disabled.c
76581 @@ -0,0 +1,440 @@
76582 +#include <linux/kernel.h>
76583 +#include <linux/module.h>
76584 +#include <linux/sched.h>
76585 +#include <linux/file.h>
76586 +#include <linux/fs.h>
76587 +#include <linux/kdev_t.h>
76588 +#include <linux/net.h>
76589 +#include <linux/in.h>
76590 +#include <linux/ip.h>
76591 +#include <linux/skbuff.h>
76592 +#include <linux/sysctl.h>
76593 +
76594 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76595 +void
76596 +pax_set_initial_flags(struct linux_binprm *bprm)
76597 +{
76598 + return;
76599 +}
76600 +#endif
76601 +
76602 +#ifdef CONFIG_SYSCTL
76603 +__u32
76604 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76605 +{
76606 + return 0;
76607 +}
76608 +#endif
76609 +
76610 +#ifdef CONFIG_TASKSTATS
76611 +int gr_is_taskstats_denied(int pid)
76612 +{
76613 + return 0;
76614 +}
76615 +#endif
76616 +
76617 +int
76618 +gr_acl_is_enabled(void)
76619 +{
76620 + return 0;
76621 +}
76622 +
76623 +int
76624 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76625 +{
76626 + return 0;
76627 +}
76628 +
76629 +void
76630 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76631 +{
76632 + return;
76633 +}
76634 +
76635 +int
76636 +gr_handle_rawio(const struct inode *inode)
76637 +{
76638 + return 0;
76639 +}
76640 +
76641 +void
76642 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76643 +{
76644 + return;
76645 +}
76646 +
76647 +int
76648 +gr_handle_ptrace(struct task_struct *task, const long request)
76649 +{
76650 + return 0;
76651 +}
76652 +
76653 +int
76654 +gr_handle_proc_ptrace(struct task_struct *task)
76655 +{
76656 + return 0;
76657 +}
76658 +
76659 +int
76660 +gr_set_acls(const int type)
76661 +{
76662 + return 0;
76663 +}
76664 +
76665 +int
76666 +gr_check_hidden_task(const struct task_struct *tsk)
76667 +{
76668 + return 0;
76669 +}
76670 +
76671 +int
76672 +gr_check_protected_task(const struct task_struct *task)
76673 +{
76674 + return 0;
76675 +}
76676 +
76677 +int
76678 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76679 +{
76680 + return 0;
76681 +}
76682 +
76683 +void
76684 +gr_copy_label(struct task_struct *tsk)
76685 +{
76686 + return;
76687 +}
76688 +
76689 +void
76690 +gr_set_pax_flags(struct task_struct *task)
76691 +{
76692 + return;
76693 +}
76694 +
76695 +int
76696 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76697 + const int unsafe_share)
76698 +{
76699 + return 0;
76700 +}
76701 +
76702 +void
76703 +gr_handle_delete(const ino_t ino, const dev_t dev)
76704 +{
76705 + return;
76706 +}
76707 +
76708 +void
76709 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76710 +{
76711 + return;
76712 +}
76713 +
76714 +void
76715 +gr_handle_crash(struct task_struct *task, const int sig)
76716 +{
76717 + return;
76718 +}
76719 +
76720 +int
76721 +gr_check_crash_exec(const struct file *filp)
76722 +{
76723 + return 0;
76724 +}
76725 +
76726 +int
76727 +gr_check_crash_uid(const kuid_t uid)
76728 +{
76729 + return 0;
76730 +}
76731 +
76732 +void
76733 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76734 + struct dentry *old_dentry,
76735 + struct dentry *new_dentry,
76736 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76737 +{
76738 + return;
76739 +}
76740 +
76741 +int
76742 +gr_search_socket(const int family, const int type, const int protocol)
76743 +{
76744 + return 1;
76745 +}
76746 +
76747 +int
76748 +gr_search_connectbind(const int mode, const struct socket *sock,
76749 + const struct sockaddr_in *addr)
76750 +{
76751 + return 0;
76752 +}
76753 +
76754 +void
76755 +gr_handle_alertkill(struct task_struct *task)
76756 +{
76757 + return;
76758 +}
76759 +
76760 +__u32
76761 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76762 +{
76763 + return 1;
76764 +}
76765 +
76766 +__u32
76767 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76768 + const struct vfsmount * mnt)
76769 +{
76770 + return 1;
76771 +}
76772 +
76773 +__u32
76774 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76775 + int acc_mode)
76776 +{
76777 + return 1;
76778 +}
76779 +
76780 +__u32
76781 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76782 +{
76783 + return 1;
76784 +}
76785 +
76786 +__u32
76787 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76788 +{
76789 + return 1;
76790 +}
76791 +
76792 +int
76793 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76794 + unsigned int *vm_flags)
76795 +{
76796 + return 1;
76797 +}
76798 +
76799 +__u32
76800 +gr_acl_handle_truncate(const struct dentry * dentry,
76801 + const struct vfsmount * mnt)
76802 +{
76803 + return 1;
76804 +}
76805 +
76806 +__u32
76807 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76808 +{
76809 + return 1;
76810 +}
76811 +
76812 +__u32
76813 +gr_acl_handle_access(const struct dentry * dentry,
76814 + const struct vfsmount * mnt, const int fmode)
76815 +{
76816 + return 1;
76817 +}
76818 +
76819 +__u32
76820 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76821 + umode_t *mode)
76822 +{
76823 + return 1;
76824 +}
76825 +
76826 +__u32
76827 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76828 +{
76829 + return 1;
76830 +}
76831 +
76832 +__u32
76833 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76834 +{
76835 + return 1;
76836 +}
76837 +
76838 +__u32
76839 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76840 +{
76841 + return 1;
76842 +}
76843 +
76844 +void
76845 +grsecurity_init(void)
76846 +{
76847 + return;
76848 +}
76849 +
76850 +umode_t gr_acl_umask(void)
76851 +{
76852 + return 0;
76853 +}
76854 +
76855 +__u32
76856 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76857 + const struct dentry * parent_dentry,
76858 + const struct vfsmount * parent_mnt,
76859 + const int mode)
76860 +{
76861 + return 1;
76862 +}
76863 +
76864 +__u32
76865 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76866 + const struct dentry * parent_dentry,
76867 + const struct vfsmount * parent_mnt)
76868 +{
76869 + return 1;
76870 +}
76871 +
76872 +__u32
76873 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76874 + const struct dentry * parent_dentry,
76875 + const struct vfsmount * parent_mnt, const struct filename *from)
76876 +{
76877 + return 1;
76878 +}
76879 +
76880 +__u32
76881 +gr_acl_handle_link(const struct dentry * new_dentry,
76882 + const struct dentry * parent_dentry,
76883 + const struct vfsmount * parent_mnt,
76884 + const struct dentry * old_dentry,
76885 + const struct vfsmount * old_mnt, const struct filename *to)
76886 +{
76887 + return 1;
76888 +}
76889 +
76890 +int
76891 +gr_acl_handle_rename(const struct dentry *new_dentry,
76892 + const struct dentry *parent_dentry,
76893 + const struct vfsmount *parent_mnt,
76894 + const struct dentry *old_dentry,
76895 + const struct inode *old_parent_inode,
76896 + const struct vfsmount *old_mnt, const struct filename *newname,
76897 + unsigned int flags)
76898 +{
76899 + return 0;
76900 +}
76901 +
76902 +int
76903 +gr_acl_handle_filldir(const struct file *file, const char *name,
76904 + const int namelen, const ino_t ino)
76905 +{
76906 + return 1;
76907 +}
76908 +
76909 +int
76910 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76911 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76912 +{
76913 + return 1;
76914 +}
76915 +
76916 +int
76917 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76918 +{
76919 + return 0;
76920 +}
76921 +
76922 +int
76923 +gr_search_accept(const struct socket *sock)
76924 +{
76925 + return 0;
76926 +}
76927 +
76928 +int
76929 +gr_search_listen(const struct socket *sock)
76930 +{
76931 + return 0;
76932 +}
76933 +
76934 +int
76935 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76936 +{
76937 + return 0;
76938 +}
76939 +
76940 +__u32
76941 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76942 +{
76943 + return 1;
76944 +}
76945 +
76946 +__u32
76947 +gr_acl_handle_creat(const struct dentry * dentry,
76948 + const struct dentry * p_dentry,
76949 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76950 + const int imode)
76951 +{
76952 + return 1;
76953 +}
76954 +
76955 +void
76956 +gr_acl_handle_exit(void)
76957 +{
76958 + return;
76959 +}
76960 +
76961 +int
76962 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76963 +{
76964 + return 1;
76965 +}
76966 +
76967 +void
76968 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
76969 +{
76970 + return;
76971 +}
76972 +
76973 +int
76974 +gr_acl_handle_procpidmem(const struct task_struct *task)
76975 +{
76976 + return 0;
76977 +}
76978 +
76979 +int
76980 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76981 +{
76982 + return 0;
76983 +}
76984 +
76985 +int
76986 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76987 +{
76988 + return 0;
76989 +}
76990 +
76991 +int
76992 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76993 +{
76994 + return 0;
76995 +}
76996 +
76997 +int
76998 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76999 +{
77000 + return 0;
77001 +}
77002 +
77003 +int gr_acl_enable_at_secure(void)
77004 +{
77005 + return 0;
77006 +}
77007 +
77008 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77009 +{
77010 + return dentry->d_sb->s_dev;
77011 +}
77012 +
77013 +void gr_put_exec_file(struct task_struct *task)
77014 +{
77015 + return;
77016 +}
77017 +
77018 +#ifdef CONFIG_SECURITY
77019 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77020 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77021 +#endif
77022 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77023 new file mode 100644
77024 index 0000000..14638ff
77025 --- /dev/null
77026 +++ b/grsecurity/grsec_exec.c
77027 @@ -0,0 +1,188 @@
77028 +#include <linux/kernel.h>
77029 +#include <linux/sched.h>
77030 +#include <linux/file.h>
77031 +#include <linux/binfmts.h>
77032 +#include <linux/fs.h>
77033 +#include <linux/types.h>
77034 +#include <linux/grdefs.h>
77035 +#include <linux/grsecurity.h>
77036 +#include <linux/grinternal.h>
77037 +#include <linux/capability.h>
77038 +#include <linux/module.h>
77039 +#include <linux/compat.h>
77040 +
77041 +#include <asm/uaccess.h>
77042 +
77043 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77044 +static char gr_exec_arg_buf[132];
77045 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77046 +#endif
77047 +
77048 +struct user_arg_ptr {
77049 +#ifdef CONFIG_COMPAT
77050 + bool is_compat;
77051 +#endif
77052 + union {
77053 + const char __user *const __user *native;
77054 +#ifdef CONFIG_COMPAT
77055 + const compat_uptr_t __user *compat;
77056 +#endif
77057 + } ptr;
77058 +};
77059 +
77060 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77061 +
77062 +void
77063 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77064 +{
77065 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77066 + char *grarg = gr_exec_arg_buf;
77067 + unsigned int i, x, execlen = 0;
77068 + char c;
77069 +
77070 + if (!((grsec_enable_execlog && grsec_enable_group &&
77071 + in_group_p(grsec_audit_gid))
77072 + || (grsec_enable_execlog && !grsec_enable_group)))
77073 + return;
77074 +
77075 + mutex_lock(&gr_exec_arg_mutex);
77076 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77077 +
77078 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77079 + const char __user *p;
77080 + unsigned int len;
77081 +
77082 + p = get_user_arg_ptr(argv, i);
77083 + if (IS_ERR(p))
77084 + goto log;
77085 +
77086 + len = strnlen_user(p, 128 - execlen);
77087 + if (len > 128 - execlen)
77088 + len = 128 - execlen;
77089 + else if (len > 0)
77090 + len--;
77091 + if (copy_from_user(grarg + execlen, p, len))
77092 + goto log;
77093 +
77094 + /* rewrite unprintable characters */
77095 + for (x = 0; x < len; x++) {
77096 + c = *(grarg + execlen + x);
77097 + if (c < 32 || c > 126)
77098 + *(grarg + execlen + x) = ' ';
77099 + }
77100 +
77101 + execlen += len;
77102 + *(grarg + execlen) = ' ';
77103 + *(grarg + execlen + 1) = '\0';
77104 + execlen++;
77105 + }
77106 +
77107 + log:
77108 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77109 + bprm->file->f_path.mnt, grarg);
77110 + mutex_unlock(&gr_exec_arg_mutex);
77111 +#endif
77112 + return;
77113 +}
77114 +
77115 +#ifdef CONFIG_GRKERNSEC
77116 +extern int gr_acl_is_capable(const int cap);
77117 +extern int gr_acl_is_capable_nolog(const int cap);
77118 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77119 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77120 +extern int gr_chroot_is_capable(const int cap);
77121 +extern int gr_chroot_is_capable_nolog(const int cap);
77122 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77123 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77124 +#endif
77125 +
77126 +const char *captab_log[] = {
77127 + "CAP_CHOWN",
77128 + "CAP_DAC_OVERRIDE",
77129 + "CAP_DAC_READ_SEARCH",
77130 + "CAP_FOWNER",
77131 + "CAP_FSETID",
77132 + "CAP_KILL",
77133 + "CAP_SETGID",
77134 + "CAP_SETUID",
77135 + "CAP_SETPCAP",
77136 + "CAP_LINUX_IMMUTABLE",
77137 + "CAP_NET_BIND_SERVICE",
77138 + "CAP_NET_BROADCAST",
77139 + "CAP_NET_ADMIN",
77140 + "CAP_NET_RAW",
77141 + "CAP_IPC_LOCK",
77142 + "CAP_IPC_OWNER",
77143 + "CAP_SYS_MODULE",
77144 + "CAP_SYS_RAWIO",
77145 + "CAP_SYS_CHROOT",
77146 + "CAP_SYS_PTRACE",
77147 + "CAP_SYS_PACCT",
77148 + "CAP_SYS_ADMIN",
77149 + "CAP_SYS_BOOT",
77150 + "CAP_SYS_NICE",
77151 + "CAP_SYS_RESOURCE",
77152 + "CAP_SYS_TIME",
77153 + "CAP_SYS_TTY_CONFIG",
77154 + "CAP_MKNOD",
77155 + "CAP_LEASE",
77156 + "CAP_AUDIT_WRITE",
77157 + "CAP_AUDIT_CONTROL",
77158 + "CAP_SETFCAP",
77159 + "CAP_MAC_OVERRIDE",
77160 + "CAP_MAC_ADMIN",
77161 + "CAP_SYSLOG",
77162 + "CAP_WAKE_ALARM",
77163 + "CAP_BLOCK_SUSPEND"
77164 +};
77165 +
77166 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77167 +
77168 +int gr_is_capable(const int cap)
77169 +{
77170 +#ifdef CONFIG_GRKERNSEC
77171 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77172 + return 1;
77173 + return 0;
77174 +#else
77175 + return 1;
77176 +#endif
77177 +}
77178 +
77179 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77180 +{
77181 +#ifdef CONFIG_GRKERNSEC
77182 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77183 + return 1;
77184 + return 0;
77185 +#else
77186 + return 1;
77187 +#endif
77188 +}
77189 +
77190 +int gr_is_capable_nolog(const int cap)
77191 +{
77192 +#ifdef CONFIG_GRKERNSEC
77193 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77194 + return 1;
77195 + return 0;
77196 +#else
77197 + return 1;
77198 +#endif
77199 +}
77200 +
77201 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77202 +{
77203 +#ifdef CONFIG_GRKERNSEC
77204 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77205 + return 1;
77206 + return 0;
77207 +#else
77208 + return 1;
77209 +#endif
77210 +}
77211 +
77212 +EXPORT_SYMBOL_GPL(gr_is_capable);
77213 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77214 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77215 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77216 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77217 new file mode 100644
77218 index 0000000..06cc6ea
77219 --- /dev/null
77220 +++ b/grsecurity/grsec_fifo.c
77221 @@ -0,0 +1,24 @@
77222 +#include <linux/kernel.h>
77223 +#include <linux/sched.h>
77224 +#include <linux/fs.h>
77225 +#include <linux/file.h>
77226 +#include <linux/grinternal.h>
77227 +
77228 +int
77229 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77230 + const struct dentry *dir, const int flag, const int acc_mode)
77231 +{
77232 +#ifdef CONFIG_GRKERNSEC_FIFO
77233 + const struct cred *cred = current_cred();
77234 +
77235 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77236 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77237 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77238 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77239 + if (!inode_permission(dentry->d_inode, acc_mode))
77240 + 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));
77241 + return -EACCES;
77242 + }
77243 +#endif
77244 + return 0;
77245 +}
77246 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77247 new file mode 100644
77248 index 0000000..8ca18bf
77249 --- /dev/null
77250 +++ b/grsecurity/grsec_fork.c
77251 @@ -0,0 +1,23 @@
77252 +#include <linux/kernel.h>
77253 +#include <linux/sched.h>
77254 +#include <linux/grsecurity.h>
77255 +#include <linux/grinternal.h>
77256 +#include <linux/errno.h>
77257 +
77258 +void
77259 +gr_log_forkfail(const int retval)
77260 +{
77261 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77262 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77263 + switch (retval) {
77264 + case -EAGAIN:
77265 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77266 + break;
77267 + case -ENOMEM:
77268 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77269 + break;
77270 + }
77271 + }
77272 +#endif
77273 + return;
77274 +}
77275 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77276 new file mode 100644
77277 index 0000000..4ed9e7d
77278 --- /dev/null
77279 +++ b/grsecurity/grsec_init.c
77280 @@ -0,0 +1,290 @@
77281 +#include <linux/kernel.h>
77282 +#include <linux/sched.h>
77283 +#include <linux/mm.h>
77284 +#include <linux/gracl.h>
77285 +#include <linux/slab.h>
77286 +#include <linux/vmalloc.h>
77287 +#include <linux/percpu.h>
77288 +#include <linux/module.h>
77289 +
77290 +int grsec_enable_ptrace_readexec;
77291 +int grsec_enable_setxid;
77292 +int grsec_enable_symlinkown;
77293 +kgid_t grsec_symlinkown_gid;
77294 +int grsec_enable_brute;
77295 +int grsec_enable_link;
77296 +int grsec_enable_dmesg;
77297 +int grsec_enable_harden_ptrace;
77298 +int grsec_enable_harden_ipc;
77299 +int grsec_enable_fifo;
77300 +int grsec_enable_execlog;
77301 +int grsec_enable_signal;
77302 +int grsec_enable_forkfail;
77303 +int grsec_enable_audit_ptrace;
77304 +int grsec_enable_time;
77305 +int grsec_enable_group;
77306 +kgid_t grsec_audit_gid;
77307 +int grsec_enable_chdir;
77308 +int grsec_enable_mount;
77309 +int grsec_enable_rofs;
77310 +int grsec_deny_new_usb;
77311 +int grsec_enable_chroot_findtask;
77312 +int grsec_enable_chroot_mount;
77313 +int grsec_enable_chroot_shmat;
77314 +int grsec_enable_chroot_fchdir;
77315 +int grsec_enable_chroot_double;
77316 +int grsec_enable_chroot_pivot;
77317 +int grsec_enable_chroot_chdir;
77318 +int grsec_enable_chroot_chmod;
77319 +int grsec_enable_chroot_mknod;
77320 +int grsec_enable_chroot_nice;
77321 +int grsec_enable_chroot_execlog;
77322 +int grsec_enable_chroot_caps;
77323 +int grsec_enable_chroot_rename;
77324 +int grsec_enable_chroot_sysctl;
77325 +int grsec_enable_chroot_unix;
77326 +int grsec_enable_tpe;
77327 +kgid_t grsec_tpe_gid;
77328 +int grsec_enable_blackhole;
77329 +#ifdef CONFIG_IPV6_MODULE
77330 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77331 +#endif
77332 +int grsec_lastack_retries;
77333 +int grsec_enable_tpe_all;
77334 +int grsec_enable_tpe_invert;
77335 +int grsec_enable_socket_all;
77336 +kgid_t grsec_socket_all_gid;
77337 +int grsec_enable_socket_client;
77338 +kgid_t grsec_socket_client_gid;
77339 +int grsec_enable_socket_server;
77340 +kgid_t grsec_socket_server_gid;
77341 +int grsec_resource_logging;
77342 +int grsec_disable_privio;
77343 +int grsec_enable_log_rwxmaps;
77344 +int grsec_lock;
77345 +
77346 +DEFINE_SPINLOCK(grsec_alert_lock);
77347 +unsigned long grsec_alert_wtime = 0;
77348 +unsigned long grsec_alert_fyet = 0;
77349 +
77350 +DEFINE_SPINLOCK(grsec_audit_lock);
77351 +
77352 +DEFINE_RWLOCK(grsec_exec_file_lock);
77353 +
77354 +char *gr_shared_page[4];
77355 +
77356 +char *gr_alert_log_fmt;
77357 +char *gr_audit_log_fmt;
77358 +char *gr_alert_log_buf;
77359 +char *gr_audit_log_buf;
77360 +
77361 +extern struct gr_arg *gr_usermode;
77362 +extern unsigned char *gr_system_salt;
77363 +extern unsigned char *gr_system_sum;
77364 +
77365 +void __init
77366 +grsecurity_init(void)
77367 +{
77368 + int j;
77369 + /* create the per-cpu shared pages */
77370 +
77371 +#ifdef CONFIG_X86
77372 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77373 +#endif
77374 +
77375 + for (j = 0; j < 4; j++) {
77376 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77377 + if (gr_shared_page[j] == NULL) {
77378 + panic("Unable to allocate grsecurity shared page");
77379 + return;
77380 + }
77381 + }
77382 +
77383 + /* allocate log buffers */
77384 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77385 + if (!gr_alert_log_fmt) {
77386 + panic("Unable to allocate grsecurity alert log format buffer");
77387 + return;
77388 + }
77389 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77390 + if (!gr_audit_log_fmt) {
77391 + panic("Unable to allocate grsecurity audit log format buffer");
77392 + return;
77393 + }
77394 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77395 + if (!gr_alert_log_buf) {
77396 + panic("Unable to allocate grsecurity alert log buffer");
77397 + return;
77398 + }
77399 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77400 + if (!gr_audit_log_buf) {
77401 + panic("Unable to allocate grsecurity audit log buffer");
77402 + return;
77403 + }
77404 +
77405 + /* allocate memory for authentication structure */
77406 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77407 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77408 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77409 +
77410 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77411 + panic("Unable to allocate grsecurity authentication structure");
77412 + return;
77413 + }
77414 +
77415 +#ifdef CONFIG_GRKERNSEC_IO
77416 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77417 + grsec_disable_privio = 1;
77418 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77419 + grsec_disable_privio = 1;
77420 +#else
77421 + grsec_disable_privio = 0;
77422 +#endif
77423 +#endif
77424 +
77425 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77426 + /* for backward compatibility, tpe_invert always defaults to on if
77427 + enabled in the kernel
77428 + */
77429 + grsec_enable_tpe_invert = 1;
77430 +#endif
77431 +
77432 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77433 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77434 + grsec_lock = 1;
77435 +#endif
77436 +
77437 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77438 + grsec_enable_log_rwxmaps = 1;
77439 +#endif
77440 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77441 + grsec_enable_group = 1;
77442 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77443 +#endif
77444 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77445 + grsec_enable_ptrace_readexec = 1;
77446 +#endif
77447 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77448 + grsec_enable_chdir = 1;
77449 +#endif
77450 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77451 + grsec_enable_harden_ptrace = 1;
77452 +#endif
77453 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77454 + grsec_enable_harden_ipc = 1;
77455 +#endif
77456 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77457 + grsec_enable_mount = 1;
77458 +#endif
77459 +#ifdef CONFIG_GRKERNSEC_LINK
77460 + grsec_enable_link = 1;
77461 +#endif
77462 +#ifdef CONFIG_GRKERNSEC_BRUTE
77463 + grsec_enable_brute = 1;
77464 +#endif
77465 +#ifdef CONFIG_GRKERNSEC_DMESG
77466 + grsec_enable_dmesg = 1;
77467 +#endif
77468 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77469 + grsec_enable_blackhole = 1;
77470 + grsec_lastack_retries = 4;
77471 +#endif
77472 +#ifdef CONFIG_GRKERNSEC_FIFO
77473 + grsec_enable_fifo = 1;
77474 +#endif
77475 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77476 + grsec_enable_execlog = 1;
77477 +#endif
77478 +#ifdef CONFIG_GRKERNSEC_SETXID
77479 + grsec_enable_setxid = 1;
77480 +#endif
77481 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77482 + grsec_enable_signal = 1;
77483 +#endif
77484 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77485 + grsec_enable_forkfail = 1;
77486 +#endif
77487 +#ifdef CONFIG_GRKERNSEC_TIME
77488 + grsec_enable_time = 1;
77489 +#endif
77490 +#ifdef CONFIG_GRKERNSEC_RESLOG
77491 + grsec_resource_logging = 1;
77492 +#endif
77493 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77494 + grsec_enable_chroot_findtask = 1;
77495 +#endif
77496 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77497 + grsec_enable_chroot_unix = 1;
77498 +#endif
77499 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77500 + grsec_enable_chroot_mount = 1;
77501 +#endif
77502 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77503 + grsec_enable_chroot_fchdir = 1;
77504 +#endif
77505 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77506 + grsec_enable_chroot_shmat = 1;
77507 +#endif
77508 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77509 + grsec_enable_audit_ptrace = 1;
77510 +#endif
77511 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77512 + grsec_enable_chroot_double = 1;
77513 +#endif
77514 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77515 + grsec_enable_chroot_pivot = 1;
77516 +#endif
77517 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77518 + grsec_enable_chroot_chdir = 1;
77519 +#endif
77520 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77521 + grsec_enable_chroot_chmod = 1;
77522 +#endif
77523 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77524 + grsec_enable_chroot_mknod = 1;
77525 +#endif
77526 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77527 + grsec_enable_chroot_nice = 1;
77528 +#endif
77529 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77530 + grsec_enable_chroot_execlog = 1;
77531 +#endif
77532 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77533 + grsec_enable_chroot_caps = 1;
77534 +#endif
77535 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
77536 + grsec_enable_chroot_rename = 1;
77537 +#endif
77538 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77539 + grsec_enable_chroot_sysctl = 1;
77540 +#endif
77541 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77542 + grsec_enable_symlinkown = 1;
77543 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77544 +#endif
77545 +#ifdef CONFIG_GRKERNSEC_TPE
77546 + grsec_enable_tpe = 1;
77547 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77548 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77549 + grsec_enable_tpe_all = 1;
77550 +#endif
77551 +#endif
77552 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77553 + grsec_enable_socket_all = 1;
77554 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77555 +#endif
77556 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77557 + grsec_enable_socket_client = 1;
77558 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77559 +#endif
77560 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77561 + grsec_enable_socket_server = 1;
77562 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77563 +#endif
77564 +#endif
77565 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77566 + grsec_deny_new_usb = 1;
77567 +#endif
77568 +
77569 + return;
77570 +}
77571 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77572 new file mode 100644
77573 index 0000000..1773300
77574 --- /dev/null
77575 +++ b/grsecurity/grsec_ipc.c
77576 @@ -0,0 +1,48 @@
77577 +#include <linux/kernel.h>
77578 +#include <linux/mm.h>
77579 +#include <linux/sched.h>
77580 +#include <linux/file.h>
77581 +#include <linux/ipc.h>
77582 +#include <linux/ipc_namespace.h>
77583 +#include <linux/grsecurity.h>
77584 +#include <linux/grinternal.h>
77585 +
77586 +int
77587 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77588 +{
77589 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77590 + int write;
77591 + int orig_granted_mode;
77592 + kuid_t euid;
77593 + kgid_t egid;
77594 +
77595 + if (!grsec_enable_harden_ipc)
77596 + return 1;
77597 +
77598 + euid = current_euid();
77599 + egid = current_egid();
77600 +
77601 + write = requested_mode & 00002;
77602 + orig_granted_mode = ipcp->mode;
77603 +
77604 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77605 + orig_granted_mode >>= 6;
77606 + else {
77607 + /* if likely wrong permissions, lock to user */
77608 + if (orig_granted_mode & 0007)
77609 + orig_granted_mode = 0;
77610 + /* otherwise do a egid-only check */
77611 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77612 + orig_granted_mode >>= 3;
77613 + /* otherwise, no access */
77614 + else
77615 + orig_granted_mode = 0;
77616 + }
77617 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77618 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77619 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77620 + return 0;
77621 + }
77622 +#endif
77623 + return 1;
77624 +}
77625 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77626 new file mode 100644
77627 index 0000000..5e05e20
77628 --- /dev/null
77629 +++ b/grsecurity/grsec_link.c
77630 @@ -0,0 +1,58 @@
77631 +#include <linux/kernel.h>
77632 +#include <linux/sched.h>
77633 +#include <linux/fs.h>
77634 +#include <linux/file.h>
77635 +#include <linux/grinternal.h>
77636 +
77637 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77638 +{
77639 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77640 + const struct inode *link_inode = link->dentry->d_inode;
77641 +
77642 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77643 + /* ignore root-owned links, e.g. /proc/self */
77644 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77645 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77646 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77647 + return 1;
77648 + }
77649 +#endif
77650 + return 0;
77651 +}
77652 +
77653 +int
77654 +gr_handle_follow_link(const struct inode *parent,
77655 + const struct inode *inode,
77656 + const struct dentry *dentry, const struct vfsmount *mnt)
77657 +{
77658 +#ifdef CONFIG_GRKERNSEC_LINK
77659 + const struct cred *cred = current_cred();
77660 +
77661 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77662 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77663 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77664 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77665 + return -EACCES;
77666 + }
77667 +#endif
77668 + return 0;
77669 +}
77670 +
77671 +int
77672 +gr_handle_hardlink(const struct dentry *dentry,
77673 + const struct vfsmount *mnt,
77674 + struct inode *inode, const int mode, const struct filename *to)
77675 +{
77676 +#ifdef CONFIG_GRKERNSEC_LINK
77677 + const struct cred *cred = current_cred();
77678 +
77679 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77680 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77681 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77682 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77683 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77684 + return -EPERM;
77685 + }
77686 +#endif
77687 + return 0;
77688 +}
77689 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77690 new file mode 100644
77691 index 0000000..dbe0a6b
77692 --- /dev/null
77693 +++ b/grsecurity/grsec_log.c
77694 @@ -0,0 +1,341 @@
77695 +#include <linux/kernel.h>
77696 +#include <linux/sched.h>
77697 +#include <linux/file.h>
77698 +#include <linux/tty.h>
77699 +#include <linux/fs.h>
77700 +#include <linux/mm.h>
77701 +#include <linux/grinternal.h>
77702 +
77703 +#ifdef CONFIG_TREE_PREEMPT_RCU
77704 +#define DISABLE_PREEMPT() preempt_disable()
77705 +#define ENABLE_PREEMPT() preempt_enable()
77706 +#else
77707 +#define DISABLE_PREEMPT()
77708 +#define ENABLE_PREEMPT()
77709 +#endif
77710 +
77711 +#define BEGIN_LOCKS(x) \
77712 + DISABLE_PREEMPT(); \
77713 + rcu_read_lock(); \
77714 + read_lock(&tasklist_lock); \
77715 + read_lock(&grsec_exec_file_lock); \
77716 + if (x != GR_DO_AUDIT) \
77717 + spin_lock(&grsec_alert_lock); \
77718 + else \
77719 + spin_lock(&grsec_audit_lock)
77720 +
77721 +#define END_LOCKS(x) \
77722 + if (x != GR_DO_AUDIT) \
77723 + spin_unlock(&grsec_alert_lock); \
77724 + else \
77725 + spin_unlock(&grsec_audit_lock); \
77726 + read_unlock(&grsec_exec_file_lock); \
77727 + read_unlock(&tasklist_lock); \
77728 + rcu_read_unlock(); \
77729 + ENABLE_PREEMPT(); \
77730 + if (x == GR_DONT_AUDIT) \
77731 + gr_handle_alertkill(current)
77732 +
77733 +enum {
77734 + FLOODING,
77735 + NO_FLOODING
77736 +};
77737 +
77738 +extern char *gr_alert_log_fmt;
77739 +extern char *gr_audit_log_fmt;
77740 +extern char *gr_alert_log_buf;
77741 +extern char *gr_audit_log_buf;
77742 +
77743 +static int gr_log_start(int audit)
77744 +{
77745 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77746 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77747 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77748 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77749 + unsigned long curr_secs = get_seconds();
77750 +
77751 + if (audit == GR_DO_AUDIT)
77752 + goto set_fmt;
77753 +
77754 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77755 + grsec_alert_wtime = curr_secs;
77756 + grsec_alert_fyet = 0;
77757 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77758 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77759 + grsec_alert_fyet++;
77760 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77761 + grsec_alert_wtime = curr_secs;
77762 + grsec_alert_fyet++;
77763 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77764 + return FLOODING;
77765 + }
77766 + else return FLOODING;
77767 +
77768 +set_fmt:
77769 +#endif
77770 + memset(buf, 0, PAGE_SIZE);
77771 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77772 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77773 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77774 + } else if (current->signal->curr_ip) {
77775 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77776 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77777 + } else if (gr_acl_is_enabled()) {
77778 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77779 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77780 + } else {
77781 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77782 + strcpy(buf, fmt);
77783 + }
77784 +
77785 + return NO_FLOODING;
77786 +}
77787 +
77788 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77789 + __attribute__ ((format (printf, 2, 0)));
77790 +
77791 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77792 +{
77793 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77794 + unsigned int len = strlen(buf);
77795 +
77796 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77797 +
77798 + return;
77799 +}
77800 +
77801 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77802 + __attribute__ ((format (printf, 2, 3)));
77803 +
77804 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77805 +{
77806 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77807 + unsigned int len = strlen(buf);
77808 + va_list ap;
77809 +
77810 + va_start(ap, msg);
77811 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77812 + va_end(ap);
77813 +
77814 + return;
77815 +}
77816 +
77817 +static void gr_log_end(int audit, int append_default)
77818 +{
77819 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77820 + if (append_default) {
77821 + struct task_struct *task = current;
77822 + struct task_struct *parent = task->real_parent;
77823 + const struct cred *cred = __task_cred(task);
77824 + const struct cred *pcred = __task_cred(parent);
77825 + unsigned int len = strlen(buf);
77826 +
77827 + 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));
77828 + }
77829 +
77830 + printk("%s\n", buf);
77831 +
77832 + return;
77833 +}
77834 +
77835 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77836 +{
77837 + int logtype;
77838 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77839 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77840 + void *voidptr = NULL;
77841 + int num1 = 0, num2 = 0;
77842 + unsigned long ulong1 = 0, ulong2 = 0;
77843 + struct dentry *dentry = NULL;
77844 + struct vfsmount *mnt = NULL;
77845 + struct file *file = NULL;
77846 + struct task_struct *task = NULL;
77847 + struct vm_area_struct *vma = NULL;
77848 + const struct cred *cred, *pcred;
77849 + va_list ap;
77850 +
77851 + BEGIN_LOCKS(audit);
77852 + logtype = gr_log_start(audit);
77853 + if (logtype == FLOODING) {
77854 + END_LOCKS(audit);
77855 + return;
77856 + }
77857 + va_start(ap, argtypes);
77858 + switch (argtypes) {
77859 + case GR_TTYSNIFF:
77860 + task = va_arg(ap, struct task_struct *);
77861 + 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));
77862 + break;
77863 + case GR_SYSCTL_HIDDEN:
77864 + str1 = va_arg(ap, char *);
77865 + gr_log_middle_varargs(audit, msg, result, str1);
77866 + break;
77867 + case GR_RBAC:
77868 + dentry = va_arg(ap, struct dentry *);
77869 + mnt = va_arg(ap, struct vfsmount *);
77870 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77871 + break;
77872 + case GR_RBAC_STR:
77873 + dentry = va_arg(ap, struct dentry *);
77874 + mnt = va_arg(ap, struct vfsmount *);
77875 + str1 = va_arg(ap, char *);
77876 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77877 + break;
77878 + case GR_STR_RBAC:
77879 + str1 = va_arg(ap, char *);
77880 + dentry = va_arg(ap, struct dentry *);
77881 + mnt = va_arg(ap, struct vfsmount *);
77882 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77883 + break;
77884 + case GR_RBAC_MODE2:
77885 + dentry = va_arg(ap, struct dentry *);
77886 + mnt = va_arg(ap, struct vfsmount *);
77887 + str1 = va_arg(ap, char *);
77888 + str2 = va_arg(ap, char *);
77889 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77890 + break;
77891 + case GR_RBAC_MODE3:
77892 + dentry = va_arg(ap, struct dentry *);
77893 + mnt = va_arg(ap, struct vfsmount *);
77894 + str1 = va_arg(ap, char *);
77895 + str2 = va_arg(ap, char *);
77896 + str3 = va_arg(ap, char *);
77897 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77898 + break;
77899 + case GR_FILENAME:
77900 + dentry = va_arg(ap, struct dentry *);
77901 + mnt = va_arg(ap, struct vfsmount *);
77902 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77903 + break;
77904 + case GR_STR_FILENAME:
77905 + str1 = va_arg(ap, char *);
77906 + dentry = va_arg(ap, struct dentry *);
77907 + mnt = va_arg(ap, struct vfsmount *);
77908 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77909 + break;
77910 + case GR_FILENAME_STR:
77911 + dentry = va_arg(ap, struct dentry *);
77912 + mnt = va_arg(ap, struct vfsmount *);
77913 + str1 = va_arg(ap, char *);
77914 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77915 + break;
77916 + case GR_FILENAME_TWO_INT:
77917 + dentry = va_arg(ap, struct dentry *);
77918 + mnt = va_arg(ap, struct vfsmount *);
77919 + num1 = va_arg(ap, int);
77920 + num2 = va_arg(ap, int);
77921 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77922 + break;
77923 + case GR_FILENAME_TWO_INT_STR:
77924 + dentry = va_arg(ap, struct dentry *);
77925 + mnt = va_arg(ap, struct vfsmount *);
77926 + num1 = va_arg(ap, int);
77927 + num2 = va_arg(ap, int);
77928 + str1 = va_arg(ap, char *);
77929 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77930 + break;
77931 + case GR_TEXTREL:
77932 + file = va_arg(ap, struct file *);
77933 + ulong1 = va_arg(ap, unsigned long);
77934 + ulong2 = va_arg(ap, unsigned long);
77935 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77936 + break;
77937 + case GR_PTRACE:
77938 + task = va_arg(ap, struct task_struct *);
77939 + 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));
77940 + break;
77941 + case GR_RESOURCE:
77942 + task = va_arg(ap, struct task_struct *);
77943 + cred = __task_cred(task);
77944 + pcred = __task_cred(task->real_parent);
77945 + ulong1 = va_arg(ap, unsigned long);
77946 + str1 = va_arg(ap, char *);
77947 + ulong2 = va_arg(ap, unsigned long);
77948 + 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));
77949 + break;
77950 + case GR_CAP:
77951 + task = va_arg(ap, struct task_struct *);
77952 + cred = __task_cred(task);
77953 + pcred = __task_cred(task->real_parent);
77954 + str1 = va_arg(ap, char *);
77955 + 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));
77956 + break;
77957 + case GR_SIG:
77958 + str1 = va_arg(ap, char *);
77959 + voidptr = va_arg(ap, void *);
77960 + gr_log_middle_varargs(audit, msg, str1, voidptr);
77961 + break;
77962 + case GR_SIG2:
77963 + task = va_arg(ap, struct task_struct *);
77964 + cred = __task_cred(task);
77965 + pcred = __task_cred(task->real_parent);
77966 + num1 = va_arg(ap, int);
77967 + 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));
77968 + break;
77969 + case GR_CRASH1:
77970 + task = va_arg(ap, struct task_struct *);
77971 + cred = __task_cred(task);
77972 + pcred = __task_cred(task->real_parent);
77973 + ulong1 = va_arg(ap, unsigned long);
77974 + 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);
77975 + break;
77976 + case GR_CRASH2:
77977 + task = va_arg(ap, struct task_struct *);
77978 + cred = __task_cred(task);
77979 + pcred = __task_cred(task->real_parent);
77980 + ulong1 = va_arg(ap, unsigned long);
77981 + 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);
77982 + break;
77983 + case GR_RWXMAP:
77984 + file = va_arg(ap, struct file *);
77985 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77986 + break;
77987 + case GR_RWXMAPVMA:
77988 + vma = va_arg(ap, struct vm_area_struct *);
77989 + if (vma->vm_file)
77990 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77991 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77992 + str1 = "<stack>";
77993 + else if (vma->vm_start <= current->mm->brk &&
77994 + vma->vm_end >= current->mm->start_brk)
77995 + str1 = "<heap>";
77996 + else
77997 + str1 = "<anonymous mapping>";
77998 + gr_log_middle_varargs(audit, msg, str1);
77999 + break;
78000 + case GR_PSACCT:
78001 + {
78002 + unsigned int wday, cday;
78003 + __u8 whr, chr;
78004 + __u8 wmin, cmin;
78005 + __u8 wsec, csec;
78006 + char cur_tty[64] = { 0 };
78007 + char parent_tty[64] = { 0 };
78008 +
78009 + task = va_arg(ap, struct task_struct *);
78010 + wday = va_arg(ap, unsigned int);
78011 + cday = va_arg(ap, unsigned int);
78012 + whr = va_arg(ap, int);
78013 + chr = va_arg(ap, int);
78014 + wmin = va_arg(ap, int);
78015 + cmin = va_arg(ap, int);
78016 + wsec = va_arg(ap, int);
78017 + csec = va_arg(ap, int);
78018 + ulong1 = va_arg(ap, unsigned long);
78019 + cred = __task_cred(task);
78020 + pcred = __task_cred(task->real_parent);
78021 +
78022 + 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));
78023 + }
78024 + break;
78025 + default:
78026 + gr_log_middle(audit, msg, ap);
78027 + }
78028 + va_end(ap);
78029 + // these don't need DEFAULTSECARGS printed on the end
78030 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78031 + gr_log_end(audit, 0);
78032 + else
78033 + gr_log_end(audit, 1);
78034 + END_LOCKS(audit);
78035 +}
78036 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78037 new file mode 100644
78038 index 0000000..0e39d8c
78039 --- /dev/null
78040 +++ b/grsecurity/grsec_mem.c
78041 @@ -0,0 +1,48 @@
78042 +#include <linux/kernel.h>
78043 +#include <linux/sched.h>
78044 +#include <linux/mm.h>
78045 +#include <linux/mman.h>
78046 +#include <linux/module.h>
78047 +#include <linux/grinternal.h>
78048 +
78049 +void gr_handle_msr_write(void)
78050 +{
78051 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78052 + return;
78053 +}
78054 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78055 +
78056 +void
78057 +gr_handle_ioperm(void)
78058 +{
78059 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78060 + return;
78061 +}
78062 +
78063 +void
78064 +gr_handle_iopl(void)
78065 +{
78066 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78067 + return;
78068 +}
78069 +
78070 +void
78071 +gr_handle_mem_readwrite(u64 from, u64 to)
78072 +{
78073 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78074 + return;
78075 +}
78076 +
78077 +void
78078 +gr_handle_vm86(void)
78079 +{
78080 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78081 + return;
78082 +}
78083 +
78084 +void
78085 +gr_log_badprocpid(const char *entry)
78086 +{
78087 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78088 + return;
78089 +}
78090 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78091 new file mode 100644
78092 index 0000000..6f9eb73
78093 --- /dev/null
78094 +++ b/grsecurity/grsec_mount.c
78095 @@ -0,0 +1,65 @@
78096 +#include <linux/kernel.h>
78097 +#include <linux/sched.h>
78098 +#include <linux/mount.h>
78099 +#include <linux/major.h>
78100 +#include <linux/grsecurity.h>
78101 +#include <linux/grinternal.h>
78102 +
78103 +void
78104 +gr_log_remount(const char *devname, const int retval)
78105 +{
78106 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78107 + if (grsec_enable_mount && (retval >= 0))
78108 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78109 +#endif
78110 + return;
78111 +}
78112 +
78113 +void
78114 +gr_log_unmount(const char *devname, const int retval)
78115 +{
78116 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78117 + if (grsec_enable_mount && (retval >= 0))
78118 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78119 +#endif
78120 + return;
78121 +}
78122 +
78123 +void
78124 +gr_log_mount(const char *from, struct path *to, const int retval)
78125 +{
78126 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78127 + if (grsec_enable_mount && (retval >= 0))
78128 + gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
78129 +#endif
78130 + return;
78131 +}
78132 +
78133 +int
78134 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78135 +{
78136 +#ifdef CONFIG_GRKERNSEC_ROFS
78137 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78138 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78139 + return -EPERM;
78140 + } else
78141 + return 0;
78142 +#endif
78143 + return 0;
78144 +}
78145 +
78146 +int
78147 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78148 +{
78149 +#ifdef CONFIG_GRKERNSEC_ROFS
78150 + struct inode *inode = dentry->d_inode;
78151 +
78152 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78153 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78154 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78155 + return -EPERM;
78156 + } else
78157 + return 0;
78158 +#endif
78159 + return 0;
78160 +}
78161 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78162 new file mode 100644
78163 index 0000000..6ee9d50
78164 --- /dev/null
78165 +++ b/grsecurity/grsec_pax.c
78166 @@ -0,0 +1,45 @@
78167 +#include <linux/kernel.h>
78168 +#include <linux/sched.h>
78169 +#include <linux/mm.h>
78170 +#include <linux/file.h>
78171 +#include <linux/grinternal.h>
78172 +#include <linux/grsecurity.h>
78173 +
78174 +void
78175 +gr_log_textrel(struct vm_area_struct * vma)
78176 +{
78177 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78178 + if (grsec_enable_log_rwxmaps)
78179 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78180 +#endif
78181 + return;
78182 +}
78183 +
78184 +void gr_log_ptgnustack(struct file *file)
78185 +{
78186 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78187 + if (grsec_enable_log_rwxmaps)
78188 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78189 +#endif
78190 + return;
78191 +}
78192 +
78193 +void
78194 +gr_log_rwxmmap(struct file *file)
78195 +{
78196 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78197 + if (grsec_enable_log_rwxmaps)
78198 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78199 +#endif
78200 + return;
78201 +}
78202 +
78203 +void
78204 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78205 +{
78206 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78207 + if (grsec_enable_log_rwxmaps)
78208 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78209 +#endif
78210 + return;
78211 +}
78212 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78213 new file mode 100644
78214 index 0000000..2005a3a
78215 --- /dev/null
78216 +++ b/grsecurity/grsec_proc.c
78217 @@ -0,0 +1,20 @@
78218 +#include <linux/kernel.h>
78219 +#include <linux/sched.h>
78220 +#include <linux/grsecurity.h>
78221 +#include <linux/grinternal.h>
78222 +
78223 +int gr_proc_is_restricted(void)
78224 +{
78225 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78226 + const struct cred *cred = current_cred();
78227 +#endif
78228 +
78229 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78230 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78231 + return -EACCES;
78232 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78233 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78234 + return -EACCES;
78235 +#endif
78236 + return 0;
78237 +}
78238 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78239 new file mode 100644
78240 index 0000000..f7f29aa
78241 --- /dev/null
78242 +++ b/grsecurity/grsec_ptrace.c
78243 @@ -0,0 +1,30 @@
78244 +#include <linux/kernel.h>
78245 +#include <linux/sched.h>
78246 +#include <linux/grinternal.h>
78247 +#include <linux/security.h>
78248 +
78249 +void
78250 +gr_audit_ptrace(struct task_struct *task)
78251 +{
78252 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78253 + if (grsec_enable_audit_ptrace)
78254 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78255 +#endif
78256 + return;
78257 +}
78258 +
78259 +int
78260 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78261 +{
78262 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78263 + const struct dentry *dentry = file->f_path.dentry;
78264 + const struct vfsmount *mnt = file->f_path.mnt;
78265 +
78266 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78267 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78268 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78269 + return -EACCES;
78270 + }
78271 +#endif
78272 + return 0;
78273 +}
78274 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78275 new file mode 100644
78276 index 0000000..3860c7e
78277 --- /dev/null
78278 +++ b/grsecurity/grsec_sig.c
78279 @@ -0,0 +1,236 @@
78280 +#include <linux/kernel.h>
78281 +#include <linux/sched.h>
78282 +#include <linux/fs.h>
78283 +#include <linux/delay.h>
78284 +#include <linux/grsecurity.h>
78285 +#include <linux/grinternal.h>
78286 +#include <linux/hardirq.h>
78287 +
78288 +char *signames[] = {
78289 + [SIGSEGV] = "Segmentation fault",
78290 + [SIGILL] = "Illegal instruction",
78291 + [SIGABRT] = "Abort",
78292 + [SIGBUS] = "Invalid alignment/Bus error"
78293 +};
78294 +
78295 +void
78296 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78297 +{
78298 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78299 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78300 + (sig == SIGABRT) || (sig == SIGBUS))) {
78301 + if (task_pid_nr(t) == task_pid_nr(current)) {
78302 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78303 + } else {
78304 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78305 + }
78306 + }
78307 +#endif
78308 + return;
78309 +}
78310 +
78311 +int
78312 +gr_handle_signal(const struct task_struct *p, const int sig)
78313 +{
78314 +#ifdef CONFIG_GRKERNSEC
78315 + /* ignore the 0 signal for protected task checks */
78316 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78317 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78318 + return -EPERM;
78319 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78320 + return -EPERM;
78321 + }
78322 +#endif
78323 + return 0;
78324 +}
78325 +
78326 +#ifdef CONFIG_GRKERNSEC
78327 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78328 +
78329 +int gr_fake_force_sig(int sig, struct task_struct *t)
78330 +{
78331 + unsigned long int flags;
78332 + int ret, blocked, ignored;
78333 + struct k_sigaction *action;
78334 +
78335 + spin_lock_irqsave(&t->sighand->siglock, flags);
78336 + action = &t->sighand->action[sig-1];
78337 + ignored = action->sa.sa_handler == SIG_IGN;
78338 + blocked = sigismember(&t->blocked, sig);
78339 + if (blocked || ignored) {
78340 + action->sa.sa_handler = SIG_DFL;
78341 + if (blocked) {
78342 + sigdelset(&t->blocked, sig);
78343 + recalc_sigpending_and_wake(t);
78344 + }
78345 + }
78346 + if (action->sa.sa_handler == SIG_DFL)
78347 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78348 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78349 +
78350 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78351 +
78352 + return ret;
78353 +}
78354 +#endif
78355 +
78356 +#define GR_USER_BAN_TIME (15 * 60)
78357 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78358 +
78359 +void gr_handle_brute_attach(int dumpable)
78360 +{
78361 +#ifdef CONFIG_GRKERNSEC_BRUTE
78362 + struct task_struct *p = current;
78363 + kuid_t uid = GLOBAL_ROOT_UID;
78364 + int daemon = 0;
78365 +
78366 + if (!grsec_enable_brute)
78367 + return;
78368 +
78369 + rcu_read_lock();
78370 + read_lock(&tasklist_lock);
78371 + read_lock(&grsec_exec_file_lock);
78372 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78373 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78374 + p->real_parent->brute = 1;
78375 + daemon = 1;
78376 + } else {
78377 + const struct cred *cred = __task_cred(p), *cred2;
78378 + struct task_struct *tsk, *tsk2;
78379 +
78380 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78381 + struct user_struct *user;
78382 +
78383 + uid = cred->uid;
78384 +
78385 + /* this is put upon execution past expiration */
78386 + user = find_user(uid);
78387 + if (user == NULL)
78388 + goto unlock;
78389 + user->suid_banned = 1;
78390 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78391 + if (user->suid_ban_expires == ~0UL)
78392 + user->suid_ban_expires--;
78393 +
78394 + /* only kill other threads of the same binary, from the same user */
78395 + do_each_thread(tsk2, tsk) {
78396 + cred2 = __task_cred(tsk);
78397 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78398 + gr_fake_force_sig(SIGKILL, tsk);
78399 + } while_each_thread(tsk2, tsk);
78400 + }
78401 + }
78402 +unlock:
78403 + read_unlock(&grsec_exec_file_lock);
78404 + read_unlock(&tasklist_lock);
78405 + rcu_read_unlock();
78406 +
78407 + if (gr_is_global_nonroot(uid))
78408 + 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);
78409 + else if (daemon)
78410 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78411 +
78412 +#endif
78413 + return;
78414 +}
78415 +
78416 +void gr_handle_brute_check(void)
78417 +{
78418 +#ifdef CONFIG_GRKERNSEC_BRUTE
78419 + struct task_struct *p = current;
78420 +
78421 + if (unlikely(p->brute)) {
78422 + if (!grsec_enable_brute)
78423 + p->brute = 0;
78424 + else if (time_before(get_seconds(), p->brute_expires))
78425 + msleep(30 * 1000);
78426 + }
78427 +#endif
78428 + return;
78429 +}
78430 +
78431 +void gr_handle_kernel_exploit(void)
78432 +{
78433 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78434 + const struct cred *cred;
78435 + struct task_struct *tsk, *tsk2;
78436 + struct user_struct *user;
78437 + kuid_t uid;
78438 +
78439 + if (in_irq() || in_serving_softirq() || in_nmi())
78440 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78441 +
78442 + uid = current_uid();
78443 +
78444 + if (gr_is_global_root(uid))
78445 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78446 + else {
78447 + /* kill all the processes of this user, hold a reference
78448 + to their creds struct, and prevent them from creating
78449 + another process until system reset
78450 + */
78451 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78452 + GR_GLOBAL_UID(uid));
78453 + /* we intentionally leak this ref */
78454 + user = get_uid(current->cred->user);
78455 + if (user)
78456 + user->kernel_banned = 1;
78457 +
78458 + /* kill all processes of this user */
78459 + read_lock(&tasklist_lock);
78460 + do_each_thread(tsk2, tsk) {
78461 + cred = __task_cred(tsk);
78462 + if (uid_eq(cred->uid, uid))
78463 + gr_fake_force_sig(SIGKILL, tsk);
78464 + } while_each_thread(tsk2, tsk);
78465 + read_unlock(&tasklist_lock);
78466 + }
78467 +#endif
78468 +}
78469 +
78470 +#ifdef CONFIG_GRKERNSEC_BRUTE
78471 +static bool suid_ban_expired(struct user_struct *user)
78472 +{
78473 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78474 + user->suid_banned = 0;
78475 + user->suid_ban_expires = 0;
78476 + free_uid(user);
78477 + return true;
78478 + }
78479 +
78480 + return false;
78481 +}
78482 +#endif
78483 +
78484 +int gr_process_kernel_exec_ban(void)
78485 +{
78486 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78487 + if (unlikely(current->cred->user->kernel_banned))
78488 + return -EPERM;
78489 +#endif
78490 + return 0;
78491 +}
78492 +
78493 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78494 +{
78495 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78496 + if (unlikely(user->kernel_banned))
78497 + gr_fake_force_sig(SIGKILL, current);
78498 +#endif
78499 + return 0;
78500 +}
78501 +
78502 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78503 +{
78504 +#ifdef CONFIG_GRKERNSEC_BRUTE
78505 + struct user_struct *user = current->cred->user;
78506 + if (unlikely(user->suid_banned)) {
78507 + if (suid_ban_expired(user))
78508 + return 0;
78509 + /* disallow execution of suid binaries only */
78510 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78511 + return -EPERM;
78512 + }
78513 +#endif
78514 + return 0;
78515 +}
78516 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78517 new file mode 100644
78518 index 0000000..e3650b6
78519 --- /dev/null
78520 +++ b/grsecurity/grsec_sock.c
78521 @@ -0,0 +1,244 @@
78522 +#include <linux/kernel.h>
78523 +#include <linux/module.h>
78524 +#include <linux/sched.h>
78525 +#include <linux/file.h>
78526 +#include <linux/net.h>
78527 +#include <linux/in.h>
78528 +#include <linux/ip.h>
78529 +#include <net/sock.h>
78530 +#include <net/inet_sock.h>
78531 +#include <linux/grsecurity.h>
78532 +#include <linux/grinternal.h>
78533 +#include <linux/gracl.h>
78534 +
78535 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78536 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78537 +
78538 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78539 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78540 +
78541 +#ifdef CONFIG_UNIX_MODULE
78542 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78543 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78544 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78545 +EXPORT_SYMBOL_GPL(gr_handle_create);
78546 +#endif
78547 +
78548 +#ifdef CONFIG_GRKERNSEC
78549 +#define gr_conn_table_size 32749
78550 +struct conn_table_entry {
78551 + struct conn_table_entry *next;
78552 + struct signal_struct *sig;
78553 +};
78554 +
78555 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78556 +DEFINE_SPINLOCK(gr_conn_table_lock);
78557 +
78558 +extern const char * gr_socktype_to_name(unsigned char type);
78559 +extern const char * gr_proto_to_name(unsigned char proto);
78560 +extern const char * gr_sockfamily_to_name(unsigned char family);
78561 +
78562 +static __inline__ int
78563 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78564 +{
78565 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78566 +}
78567 +
78568 +static __inline__ int
78569 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78570 + __u16 sport, __u16 dport)
78571 +{
78572 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78573 + sig->gr_sport == sport && sig->gr_dport == dport))
78574 + return 1;
78575 + else
78576 + return 0;
78577 +}
78578 +
78579 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78580 +{
78581 + struct conn_table_entry **match;
78582 + unsigned int index;
78583 +
78584 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78585 + sig->gr_sport, sig->gr_dport,
78586 + gr_conn_table_size);
78587 +
78588 + newent->sig = sig;
78589 +
78590 + match = &gr_conn_table[index];
78591 + newent->next = *match;
78592 + *match = newent;
78593 +
78594 + return;
78595 +}
78596 +
78597 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78598 +{
78599 + struct conn_table_entry *match, *last = NULL;
78600 + unsigned int index;
78601 +
78602 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78603 + sig->gr_sport, sig->gr_dport,
78604 + gr_conn_table_size);
78605 +
78606 + match = gr_conn_table[index];
78607 + while (match && !conn_match(match->sig,
78608 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78609 + sig->gr_dport)) {
78610 + last = match;
78611 + match = match->next;
78612 + }
78613 +
78614 + if (match) {
78615 + if (last)
78616 + last->next = match->next;
78617 + else
78618 + gr_conn_table[index] = NULL;
78619 + kfree(match);
78620 + }
78621 +
78622 + return;
78623 +}
78624 +
78625 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78626 + __u16 sport, __u16 dport)
78627 +{
78628 + struct conn_table_entry *match;
78629 + unsigned int index;
78630 +
78631 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78632 +
78633 + match = gr_conn_table[index];
78634 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78635 + match = match->next;
78636 +
78637 + if (match)
78638 + return match->sig;
78639 + else
78640 + return NULL;
78641 +}
78642 +
78643 +#endif
78644 +
78645 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78646 +{
78647 +#ifdef CONFIG_GRKERNSEC
78648 + struct signal_struct *sig = current->signal;
78649 + struct conn_table_entry *newent;
78650 +
78651 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78652 + if (newent == NULL)
78653 + return;
78654 + /* no bh lock needed since we are called with bh disabled */
78655 + spin_lock(&gr_conn_table_lock);
78656 + gr_del_task_from_ip_table_nolock(sig);
78657 + sig->gr_saddr = inet->inet_rcv_saddr;
78658 + sig->gr_daddr = inet->inet_daddr;
78659 + sig->gr_sport = inet->inet_sport;
78660 + sig->gr_dport = inet->inet_dport;
78661 + gr_add_to_task_ip_table_nolock(sig, newent);
78662 + spin_unlock(&gr_conn_table_lock);
78663 +#endif
78664 + return;
78665 +}
78666 +
78667 +void gr_del_task_from_ip_table(struct task_struct *task)
78668 +{
78669 +#ifdef CONFIG_GRKERNSEC
78670 + spin_lock_bh(&gr_conn_table_lock);
78671 + gr_del_task_from_ip_table_nolock(task->signal);
78672 + spin_unlock_bh(&gr_conn_table_lock);
78673 +#endif
78674 + return;
78675 +}
78676 +
78677 +void
78678 +gr_attach_curr_ip(const struct sock *sk)
78679 +{
78680 +#ifdef CONFIG_GRKERNSEC
78681 + struct signal_struct *p, *set;
78682 + const struct inet_sock *inet = inet_sk(sk);
78683 +
78684 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78685 + return;
78686 +
78687 + set = current->signal;
78688 +
78689 + spin_lock_bh(&gr_conn_table_lock);
78690 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78691 + inet->inet_dport, inet->inet_sport);
78692 + if (unlikely(p != NULL)) {
78693 + set->curr_ip = p->curr_ip;
78694 + set->used_accept = 1;
78695 + gr_del_task_from_ip_table_nolock(p);
78696 + spin_unlock_bh(&gr_conn_table_lock);
78697 + return;
78698 + }
78699 + spin_unlock_bh(&gr_conn_table_lock);
78700 +
78701 + set->curr_ip = inet->inet_daddr;
78702 + set->used_accept = 1;
78703 +#endif
78704 + return;
78705 +}
78706 +
78707 +int
78708 +gr_handle_sock_all(const int family, const int type, const int protocol)
78709 +{
78710 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78711 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78712 + (family != AF_UNIX)) {
78713 + if (family == AF_INET)
78714 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78715 + else
78716 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78717 + return -EACCES;
78718 + }
78719 +#endif
78720 + return 0;
78721 +}
78722 +
78723 +int
78724 +gr_handle_sock_server(const struct sockaddr *sck)
78725 +{
78726 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78727 + if (grsec_enable_socket_server &&
78728 + in_group_p(grsec_socket_server_gid) &&
78729 + sck && (sck->sa_family != AF_UNIX) &&
78730 + (sck->sa_family != AF_LOCAL)) {
78731 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78732 + return -EACCES;
78733 + }
78734 +#endif
78735 + return 0;
78736 +}
78737 +
78738 +int
78739 +gr_handle_sock_server_other(const struct sock *sck)
78740 +{
78741 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78742 + if (grsec_enable_socket_server &&
78743 + in_group_p(grsec_socket_server_gid) &&
78744 + sck && (sck->sk_family != AF_UNIX) &&
78745 + (sck->sk_family != AF_LOCAL)) {
78746 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78747 + return -EACCES;
78748 + }
78749 +#endif
78750 + return 0;
78751 +}
78752 +
78753 +int
78754 +gr_handle_sock_client(const struct sockaddr *sck)
78755 +{
78756 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78757 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78758 + sck && (sck->sa_family != AF_UNIX) &&
78759 + (sck->sa_family != AF_LOCAL)) {
78760 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78761 + return -EACCES;
78762 + }
78763 +#endif
78764 + return 0;
78765 +}
78766 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78767 new file mode 100644
78768 index 0000000..cce889e
78769 --- /dev/null
78770 +++ b/grsecurity/grsec_sysctl.c
78771 @@ -0,0 +1,488 @@
78772 +#include <linux/kernel.h>
78773 +#include <linux/sched.h>
78774 +#include <linux/sysctl.h>
78775 +#include <linux/grsecurity.h>
78776 +#include <linux/grinternal.h>
78777 +
78778 +int
78779 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78780 +{
78781 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78782 + if (dirname == NULL || name == NULL)
78783 + return 0;
78784 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78785 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78786 + return -EACCES;
78787 + }
78788 +#endif
78789 + return 0;
78790 +}
78791 +
78792 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78793 +static int __maybe_unused __read_only one = 1;
78794 +#endif
78795 +
78796 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78797 + defined(CONFIG_GRKERNSEC_DENYUSB)
78798 +struct ctl_table grsecurity_table[] = {
78799 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78800 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78801 +#ifdef CONFIG_GRKERNSEC_IO
78802 + {
78803 + .procname = "disable_priv_io",
78804 + .data = &grsec_disable_privio,
78805 + .maxlen = sizeof(int),
78806 + .mode = 0600,
78807 + .proc_handler = &proc_dointvec,
78808 + },
78809 +#endif
78810 +#endif
78811 +#ifdef CONFIG_GRKERNSEC_LINK
78812 + {
78813 + .procname = "linking_restrictions",
78814 + .data = &grsec_enable_link,
78815 + .maxlen = sizeof(int),
78816 + .mode = 0600,
78817 + .proc_handler = &proc_dointvec,
78818 + },
78819 +#endif
78820 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78821 + {
78822 + .procname = "enforce_symlinksifowner",
78823 + .data = &grsec_enable_symlinkown,
78824 + .maxlen = sizeof(int),
78825 + .mode = 0600,
78826 + .proc_handler = &proc_dointvec,
78827 + },
78828 + {
78829 + .procname = "symlinkown_gid",
78830 + .data = &grsec_symlinkown_gid,
78831 + .maxlen = sizeof(int),
78832 + .mode = 0600,
78833 + .proc_handler = &proc_dointvec,
78834 + },
78835 +#endif
78836 +#ifdef CONFIG_GRKERNSEC_BRUTE
78837 + {
78838 + .procname = "deter_bruteforce",
78839 + .data = &grsec_enable_brute,
78840 + .maxlen = sizeof(int),
78841 + .mode = 0600,
78842 + .proc_handler = &proc_dointvec,
78843 + },
78844 +#endif
78845 +#ifdef CONFIG_GRKERNSEC_FIFO
78846 + {
78847 + .procname = "fifo_restrictions",
78848 + .data = &grsec_enable_fifo,
78849 + .maxlen = sizeof(int),
78850 + .mode = 0600,
78851 + .proc_handler = &proc_dointvec,
78852 + },
78853 +#endif
78854 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78855 + {
78856 + .procname = "ptrace_readexec",
78857 + .data = &grsec_enable_ptrace_readexec,
78858 + .maxlen = sizeof(int),
78859 + .mode = 0600,
78860 + .proc_handler = &proc_dointvec,
78861 + },
78862 +#endif
78863 +#ifdef CONFIG_GRKERNSEC_SETXID
78864 + {
78865 + .procname = "consistent_setxid",
78866 + .data = &grsec_enable_setxid,
78867 + .maxlen = sizeof(int),
78868 + .mode = 0600,
78869 + .proc_handler = &proc_dointvec,
78870 + },
78871 +#endif
78872 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78873 + {
78874 + .procname = "ip_blackhole",
78875 + .data = &grsec_enable_blackhole,
78876 + .maxlen = sizeof(int),
78877 + .mode = 0600,
78878 + .proc_handler = &proc_dointvec,
78879 + },
78880 + {
78881 + .procname = "lastack_retries",
78882 + .data = &grsec_lastack_retries,
78883 + .maxlen = sizeof(int),
78884 + .mode = 0600,
78885 + .proc_handler = &proc_dointvec,
78886 + },
78887 +#endif
78888 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78889 + {
78890 + .procname = "exec_logging",
78891 + .data = &grsec_enable_execlog,
78892 + .maxlen = sizeof(int),
78893 + .mode = 0600,
78894 + .proc_handler = &proc_dointvec,
78895 + },
78896 +#endif
78897 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78898 + {
78899 + .procname = "rwxmap_logging",
78900 + .data = &grsec_enable_log_rwxmaps,
78901 + .maxlen = sizeof(int),
78902 + .mode = 0600,
78903 + .proc_handler = &proc_dointvec,
78904 + },
78905 +#endif
78906 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78907 + {
78908 + .procname = "signal_logging",
78909 + .data = &grsec_enable_signal,
78910 + .maxlen = sizeof(int),
78911 + .mode = 0600,
78912 + .proc_handler = &proc_dointvec,
78913 + },
78914 +#endif
78915 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78916 + {
78917 + .procname = "forkfail_logging",
78918 + .data = &grsec_enable_forkfail,
78919 + .maxlen = sizeof(int),
78920 + .mode = 0600,
78921 + .proc_handler = &proc_dointvec,
78922 + },
78923 +#endif
78924 +#ifdef CONFIG_GRKERNSEC_TIME
78925 + {
78926 + .procname = "timechange_logging",
78927 + .data = &grsec_enable_time,
78928 + .maxlen = sizeof(int),
78929 + .mode = 0600,
78930 + .proc_handler = &proc_dointvec,
78931 + },
78932 +#endif
78933 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78934 + {
78935 + .procname = "chroot_deny_shmat",
78936 + .data = &grsec_enable_chroot_shmat,
78937 + .maxlen = sizeof(int),
78938 + .mode = 0600,
78939 + .proc_handler = &proc_dointvec,
78940 + },
78941 +#endif
78942 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78943 + {
78944 + .procname = "chroot_deny_unix",
78945 + .data = &grsec_enable_chroot_unix,
78946 + .maxlen = sizeof(int),
78947 + .mode = 0600,
78948 + .proc_handler = &proc_dointvec,
78949 + },
78950 +#endif
78951 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78952 + {
78953 + .procname = "chroot_deny_mount",
78954 + .data = &grsec_enable_chroot_mount,
78955 + .maxlen = sizeof(int),
78956 + .mode = 0600,
78957 + .proc_handler = &proc_dointvec,
78958 + },
78959 +#endif
78960 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78961 + {
78962 + .procname = "chroot_deny_fchdir",
78963 + .data = &grsec_enable_chroot_fchdir,
78964 + .maxlen = sizeof(int),
78965 + .mode = 0600,
78966 + .proc_handler = &proc_dointvec,
78967 + },
78968 +#endif
78969 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78970 + {
78971 + .procname = "chroot_deny_chroot",
78972 + .data = &grsec_enable_chroot_double,
78973 + .maxlen = sizeof(int),
78974 + .mode = 0600,
78975 + .proc_handler = &proc_dointvec,
78976 + },
78977 +#endif
78978 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78979 + {
78980 + .procname = "chroot_deny_pivot",
78981 + .data = &grsec_enable_chroot_pivot,
78982 + .maxlen = sizeof(int),
78983 + .mode = 0600,
78984 + .proc_handler = &proc_dointvec,
78985 + },
78986 +#endif
78987 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78988 + {
78989 + .procname = "chroot_enforce_chdir",
78990 + .data = &grsec_enable_chroot_chdir,
78991 + .maxlen = sizeof(int),
78992 + .mode = 0600,
78993 + .proc_handler = &proc_dointvec,
78994 + },
78995 +#endif
78996 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78997 + {
78998 + .procname = "chroot_deny_chmod",
78999 + .data = &grsec_enable_chroot_chmod,
79000 + .maxlen = sizeof(int),
79001 + .mode = 0600,
79002 + .proc_handler = &proc_dointvec,
79003 + },
79004 +#endif
79005 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79006 + {
79007 + .procname = "chroot_deny_mknod",
79008 + .data = &grsec_enable_chroot_mknod,
79009 + .maxlen = sizeof(int),
79010 + .mode = 0600,
79011 + .proc_handler = &proc_dointvec,
79012 + },
79013 +#endif
79014 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79015 + {
79016 + .procname = "chroot_restrict_nice",
79017 + .data = &grsec_enable_chroot_nice,
79018 + .maxlen = sizeof(int),
79019 + .mode = 0600,
79020 + .proc_handler = &proc_dointvec,
79021 + },
79022 +#endif
79023 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79024 + {
79025 + .procname = "chroot_execlog",
79026 + .data = &grsec_enable_chroot_execlog,
79027 + .maxlen = sizeof(int),
79028 + .mode = 0600,
79029 + .proc_handler = &proc_dointvec,
79030 + },
79031 +#endif
79032 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79033 + {
79034 + .procname = "chroot_caps",
79035 + .data = &grsec_enable_chroot_caps,
79036 + .maxlen = sizeof(int),
79037 + .mode = 0600,
79038 + .proc_handler = &proc_dointvec,
79039 + },
79040 +#endif
79041 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
79042 + {
79043 + .procname = "chroot_deny_bad_rename",
79044 + .data = &grsec_enable_chroot_rename,
79045 + .maxlen = sizeof(int),
79046 + .mode = 0600,
79047 + .proc_handler = &proc_dointvec,
79048 + },
79049 +#endif
79050 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79051 + {
79052 + .procname = "chroot_deny_sysctl",
79053 + .data = &grsec_enable_chroot_sysctl,
79054 + .maxlen = sizeof(int),
79055 + .mode = 0600,
79056 + .proc_handler = &proc_dointvec,
79057 + },
79058 +#endif
79059 +#ifdef CONFIG_GRKERNSEC_TPE
79060 + {
79061 + .procname = "tpe",
79062 + .data = &grsec_enable_tpe,
79063 + .maxlen = sizeof(int),
79064 + .mode = 0600,
79065 + .proc_handler = &proc_dointvec,
79066 + },
79067 + {
79068 + .procname = "tpe_gid",
79069 + .data = &grsec_tpe_gid,
79070 + .maxlen = sizeof(int),
79071 + .mode = 0600,
79072 + .proc_handler = &proc_dointvec,
79073 + },
79074 +#endif
79075 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79076 + {
79077 + .procname = "tpe_invert",
79078 + .data = &grsec_enable_tpe_invert,
79079 + .maxlen = sizeof(int),
79080 + .mode = 0600,
79081 + .proc_handler = &proc_dointvec,
79082 + },
79083 +#endif
79084 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79085 + {
79086 + .procname = "tpe_restrict_all",
79087 + .data = &grsec_enable_tpe_all,
79088 + .maxlen = sizeof(int),
79089 + .mode = 0600,
79090 + .proc_handler = &proc_dointvec,
79091 + },
79092 +#endif
79093 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79094 + {
79095 + .procname = "socket_all",
79096 + .data = &grsec_enable_socket_all,
79097 + .maxlen = sizeof(int),
79098 + .mode = 0600,
79099 + .proc_handler = &proc_dointvec,
79100 + },
79101 + {
79102 + .procname = "socket_all_gid",
79103 + .data = &grsec_socket_all_gid,
79104 + .maxlen = sizeof(int),
79105 + .mode = 0600,
79106 + .proc_handler = &proc_dointvec,
79107 + },
79108 +#endif
79109 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79110 + {
79111 + .procname = "socket_client",
79112 + .data = &grsec_enable_socket_client,
79113 + .maxlen = sizeof(int),
79114 + .mode = 0600,
79115 + .proc_handler = &proc_dointvec,
79116 + },
79117 + {
79118 + .procname = "socket_client_gid",
79119 + .data = &grsec_socket_client_gid,
79120 + .maxlen = sizeof(int),
79121 + .mode = 0600,
79122 + .proc_handler = &proc_dointvec,
79123 + },
79124 +#endif
79125 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79126 + {
79127 + .procname = "socket_server",
79128 + .data = &grsec_enable_socket_server,
79129 + .maxlen = sizeof(int),
79130 + .mode = 0600,
79131 + .proc_handler = &proc_dointvec,
79132 + },
79133 + {
79134 + .procname = "socket_server_gid",
79135 + .data = &grsec_socket_server_gid,
79136 + .maxlen = sizeof(int),
79137 + .mode = 0600,
79138 + .proc_handler = &proc_dointvec,
79139 + },
79140 +#endif
79141 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79142 + {
79143 + .procname = "audit_group",
79144 + .data = &grsec_enable_group,
79145 + .maxlen = sizeof(int),
79146 + .mode = 0600,
79147 + .proc_handler = &proc_dointvec,
79148 + },
79149 + {
79150 + .procname = "audit_gid",
79151 + .data = &grsec_audit_gid,
79152 + .maxlen = sizeof(int),
79153 + .mode = 0600,
79154 + .proc_handler = &proc_dointvec,
79155 + },
79156 +#endif
79157 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79158 + {
79159 + .procname = "audit_chdir",
79160 + .data = &grsec_enable_chdir,
79161 + .maxlen = sizeof(int),
79162 + .mode = 0600,
79163 + .proc_handler = &proc_dointvec,
79164 + },
79165 +#endif
79166 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79167 + {
79168 + .procname = "audit_mount",
79169 + .data = &grsec_enable_mount,
79170 + .maxlen = sizeof(int),
79171 + .mode = 0600,
79172 + .proc_handler = &proc_dointvec,
79173 + },
79174 +#endif
79175 +#ifdef CONFIG_GRKERNSEC_DMESG
79176 + {
79177 + .procname = "dmesg",
79178 + .data = &grsec_enable_dmesg,
79179 + .maxlen = sizeof(int),
79180 + .mode = 0600,
79181 + .proc_handler = &proc_dointvec,
79182 + },
79183 +#endif
79184 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79185 + {
79186 + .procname = "chroot_findtask",
79187 + .data = &grsec_enable_chroot_findtask,
79188 + .maxlen = sizeof(int),
79189 + .mode = 0600,
79190 + .proc_handler = &proc_dointvec,
79191 + },
79192 +#endif
79193 +#ifdef CONFIG_GRKERNSEC_RESLOG
79194 + {
79195 + .procname = "resource_logging",
79196 + .data = &grsec_resource_logging,
79197 + .maxlen = sizeof(int),
79198 + .mode = 0600,
79199 + .proc_handler = &proc_dointvec,
79200 + },
79201 +#endif
79202 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79203 + {
79204 + .procname = "audit_ptrace",
79205 + .data = &grsec_enable_audit_ptrace,
79206 + .maxlen = sizeof(int),
79207 + .mode = 0600,
79208 + .proc_handler = &proc_dointvec,
79209 + },
79210 +#endif
79211 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79212 + {
79213 + .procname = "harden_ptrace",
79214 + .data = &grsec_enable_harden_ptrace,
79215 + .maxlen = sizeof(int),
79216 + .mode = 0600,
79217 + .proc_handler = &proc_dointvec,
79218 + },
79219 +#endif
79220 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79221 + {
79222 + .procname = "harden_ipc",
79223 + .data = &grsec_enable_harden_ipc,
79224 + .maxlen = sizeof(int),
79225 + .mode = 0600,
79226 + .proc_handler = &proc_dointvec,
79227 + },
79228 +#endif
79229 + {
79230 + .procname = "grsec_lock",
79231 + .data = &grsec_lock,
79232 + .maxlen = sizeof(int),
79233 + .mode = 0600,
79234 + .proc_handler = &proc_dointvec,
79235 + },
79236 +#endif
79237 +#ifdef CONFIG_GRKERNSEC_ROFS
79238 + {
79239 + .procname = "romount_protect",
79240 + .data = &grsec_enable_rofs,
79241 + .maxlen = sizeof(int),
79242 + .mode = 0600,
79243 + .proc_handler = &proc_dointvec_minmax,
79244 + .extra1 = &one,
79245 + .extra2 = &one,
79246 + },
79247 +#endif
79248 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79249 + {
79250 + .procname = "deny_new_usb",
79251 + .data = &grsec_deny_new_usb,
79252 + .maxlen = sizeof(int),
79253 + .mode = 0600,
79254 + .proc_handler = &proc_dointvec,
79255 + },
79256 +#endif
79257 + { }
79258 +};
79259 +#endif
79260 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79261 new file mode 100644
79262 index 0000000..61b514e
79263 --- /dev/null
79264 +++ b/grsecurity/grsec_time.c
79265 @@ -0,0 +1,16 @@
79266 +#include <linux/kernel.h>
79267 +#include <linux/sched.h>
79268 +#include <linux/grinternal.h>
79269 +#include <linux/module.h>
79270 +
79271 +void
79272 +gr_log_timechange(void)
79273 +{
79274 +#ifdef CONFIG_GRKERNSEC_TIME
79275 + if (grsec_enable_time)
79276 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79277 +#endif
79278 + return;
79279 +}
79280 +
79281 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79282 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79283 new file mode 100644
79284 index 0000000..d1953de
79285 --- /dev/null
79286 +++ b/grsecurity/grsec_tpe.c
79287 @@ -0,0 +1,78 @@
79288 +#include <linux/kernel.h>
79289 +#include <linux/sched.h>
79290 +#include <linux/file.h>
79291 +#include <linux/fs.h>
79292 +#include <linux/grinternal.h>
79293 +
79294 +extern int gr_acl_tpe_check(void);
79295 +
79296 +int
79297 +gr_tpe_allow(const struct file *file)
79298 +{
79299 +#ifdef CONFIG_GRKERNSEC
79300 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79301 + struct inode *file_inode = file->f_path.dentry->d_inode;
79302 + const struct cred *cred = current_cred();
79303 + char *msg = NULL;
79304 + char *msg2 = NULL;
79305 +
79306 + // never restrict root
79307 + if (gr_is_global_root(cred->uid))
79308 + return 1;
79309 +
79310 + if (grsec_enable_tpe) {
79311 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79312 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79313 + msg = "not being in trusted group";
79314 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79315 + msg = "being in untrusted group";
79316 +#else
79317 + if (in_group_p(grsec_tpe_gid))
79318 + msg = "being in untrusted group";
79319 +#endif
79320 + }
79321 + if (!msg && gr_acl_tpe_check())
79322 + msg = "being in untrusted role";
79323 +
79324 + // not in any affected group/role
79325 + if (!msg)
79326 + goto next_check;
79327 +
79328 + if (gr_is_global_nonroot(inode->i_uid))
79329 + msg2 = "file in non-root-owned directory";
79330 + else if (inode->i_mode & S_IWOTH)
79331 + msg2 = "file in world-writable directory";
79332 + else if (inode->i_mode & S_IWGRP)
79333 + msg2 = "file in group-writable directory";
79334 + else if (file_inode->i_mode & S_IWOTH)
79335 + msg2 = "file is world-writable";
79336 +
79337 + if (msg && msg2) {
79338 + char fullmsg[70] = {0};
79339 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79340 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79341 + return 0;
79342 + }
79343 + msg = NULL;
79344 +next_check:
79345 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79346 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79347 + return 1;
79348 +
79349 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79350 + msg = "directory not owned by user";
79351 + else if (inode->i_mode & S_IWOTH)
79352 + msg = "file in world-writable directory";
79353 + else if (inode->i_mode & S_IWGRP)
79354 + msg = "file in group-writable directory";
79355 + else if (file_inode->i_mode & S_IWOTH)
79356 + msg = "file is world-writable";
79357 +
79358 + if (msg) {
79359 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79360 + return 0;
79361 + }
79362 +#endif
79363 +#endif
79364 + return 1;
79365 +}
79366 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79367 new file mode 100644
79368 index 0000000..ae02d8e
79369 --- /dev/null
79370 +++ b/grsecurity/grsec_usb.c
79371 @@ -0,0 +1,15 @@
79372 +#include <linux/kernel.h>
79373 +#include <linux/grinternal.h>
79374 +#include <linux/module.h>
79375 +
79376 +int gr_handle_new_usb(void)
79377 +{
79378 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79379 + if (grsec_deny_new_usb) {
79380 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79381 + return 1;
79382 + }
79383 +#endif
79384 + return 0;
79385 +}
79386 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79387 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79388 new file mode 100644
79389 index 0000000..158b330
79390 --- /dev/null
79391 +++ b/grsecurity/grsum.c
79392 @@ -0,0 +1,64 @@
79393 +#include <linux/err.h>
79394 +#include <linux/kernel.h>
79395 +#include <linux/sched.h>
79396 +#include <linux/mm.h>
79397 +#include <linux/scatterlist.h>
79398 +#include <linux/crypto.h>
79399 +#include <linux/gracl.h>
79400 +
79401 +
79402 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79403 +#error "crypto and sha256 must be built into the kernel"
79404 +#endif
79405 +
79406 +int
79407 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79408 +{
79409 + struct crypto_hash *tfm;
79410 + struct hash_desc desc;
79411 + struct scatterlist sg[2];
79412 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79413 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79414 + unsigned long *sumptr = (unsigned long *)sum;
79415 + int cryptres;
79416 + int retval = 1;
79417 + volatile int mismatched = 0;
79418 + volatile int dummy = 0;
79419 + unsigned int i;
79420 +
79421 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79422 + if (IS_ERR(tfm)) {
79423 + /* should never happen, since sha256 should be built in */
79424 + memset(entry->pw, 0, GR_PW_LEN);
79425 + return 1;
79426 + }
79427 +
79428 + sg_init_table(sg, 2);
79429 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79430 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79431 +
79432 + desc.tfm = tfm;
79433 + desc.flags = 0;
79434 +
79435 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79436 + temp_sum);
79437 +
79438 + memset(entry->pw, 0, GR_PW_LEN);
79439 +
79440 + if (cryptres)
79441 + goto out;
79442 +
79443 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79444 + if (sumptr[i] != tmpsumptr[i])
79445 + mismatched = 1;
79446 + else
79447 + dummy = 1; // waste a cycle
79448 +
79449 + if (!mismatched)
79450 + retval = dummy - 1;
79451 +
79452 +out:
79453 + crypto_free_hash(tfm);
79454 +
79455 + return retval;
79456 +}
79457 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79458 index 77ff547..181834f 100644
79459 --- a/include/asm-generic/4level-fixup.h
79460 +++ b/include/asm-generic/4level-fixup.h
79461 @@ -13,8 +13,10 @@
79462 #define pmd_alloc(mm, pud, address) \
79463 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79464 NULL: pmd_offset(pud, address))
79465 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79466
79467 #define pud_alloc(mm, pgd, address) (pgd)
79468 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79469 #define pud_offset(pgd, start) (pgd)
79470 #define pud_none(pud) 0
79471 #define pud_bad(pud) 0
79472 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79473 index b7babf0..1e4b4f1 100644
79474 --- a/include/asm-generic/atomic-long.h
79475 +++ b/include/asm-generic/atomic-long.h
79476 @@ -22,6 +22,12 @@
79477
79478 typedef atomic64_t atomic_long_t;
79479
79480 +#ifdef CONFIG_PAX_REFCOUNT
79481 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79482 +#else
79483 +typedef atomic64_t atomic_long_unchecked_t;
79484 +#endif
79485 +
79486 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79487
79488 static inline long atomic_long_read(atomic_long_t *l)
79489 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79490 return (long)atomic64_read(v);
79491 }
79492
79493 +#ifdef CONFIG_PAX_REFCOUNT
79494 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79495 +{
79496 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79497 +
79498 + return (long)atomic64_read_unchecked(v);
79499 +}
79500 +#endif
79501 +
79502 static inline void atomic_long_set(atomic_long_t *l, long i)
79503 {
79504 atomic64_t *v = (atomic64_t *)l;
79505 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79506 atomic64_set(v, i);
79507 }
79508
79509 +#ifdef CONFIG_PAX_REFCOUNT
79510 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79511 +{
79512 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79513 +
79514 + atomic64_set_unchecked(v, i);
79515 +}
79516 +#endif
79517 +
79518 static inline void atomic_long_inc(atomic_long_t *l)
79519 {
79520 atomic64_t *v = (atomic64_t *)l;
79521 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79522 atomic64_inc(v);
79523 }
79524
79525 +#ifdef CONFIG_PAX_REFCOUNT
79526 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79527 +{
79528 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79529 +
79530 + atomic64_inc_unchecked(v);
79531 +}
79532 +#endif
79533 +
79534 static inline void atomic_long_dec(atomic_long_t *l)
79535 {
79536 atomic64_t *v = (atomic64_t *)l;
79537 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79538 atomic64_dec(v);
79539 }
79540
79541 +#ifdef CONFIG_PAX_REFCOUNT
79542 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79543 +{
79544 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79545 +
79546 + atomic64_dec_unchecked(v);
79547 +}
79548 +#endif
79549 +
79550 static inline void atomic_long_add(long i, atomic_long_t *l)
79551 {
79552 atomic64_t *v = (atomic64_t *)l;
79553 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79554 atomic64_add(i, v);
79555 }
79556
79557 +#ifdef CONFIG_PAX_REFCOUNT
79558 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79559 +{
79560 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79561 +
79562 + atomic64_add_unchecked(i, v);
79563 +}
79564 +#endif
79565 +
79566 static inline void atomic_long_sub(long i, atomic_long_t *l)
79567 {
79568 atomic64_t *v = (atomic64_t *)l;
79569 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79570 atomic64_sub(i, v);
79571 }
79572
79573 +#ifdef CONFIG_PAX_REFCOUNT
79574 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79575 +{
79576 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79577 +
79578 + atomic64_sub_unchecked(i, v);
79579 +}
79580 +#endif
79581 +
79582 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79583 {
79584 atomic64_t *v = (atomic64_t *)l;
79585 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79586 return atomic64_add_negative(i, v);
79587 }
79588
79589 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79590 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79591 {
79592 atomic64_t *v = (atomic64_t *)l;
79593
79594 return (long)atomic64_add_return(i, v);
79595 }
79596
79597 +#ifdef CONFIG_PAX_REFCOUNT
79598 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79599 +{
79600 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79601 +
79602 + return (long)atomic64_add_return_unchecked(i, v);
79603 +}
79604 +#endif
79605 +
79606 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79607 {
79608 atomic64_t *v = (atomic64_t *)l;
79609 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79610 return (long)atomic64_inc_return(v);
79611 }
79612
79613 +#ifdef CONFIG_PAX_REFCOUNT
79614 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79615 +{
79616 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79617 +
79618 + return (long)atomic64_inc_return_unchecked(v);
79619 +}
79620 +#endif
79621 +
79622 static inline long atomic_long_dec_return(atomic_long_t *l)
79623 {
79624 atomic64_t *v = (atomic64_t *)l;
79625 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79626
79627 typedef atomic_t atomic_long_t;
79628
79629 +#ifdef CONFIG_PAX_REFCOUNT
79630 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79631 +#else
79632 +typedef atomic_t atomic_long_unchecked_t;
79633 +#endif
79634 +
79635 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79636 static inline long atomic_long_read(atomic_long_t *l)
79637 {
79638 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79639 return (long)atomic_read(v);
79640 }
79641
79642 +#ifdef CONFIG_PAX_REFCOUNT
79643 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79644 +{
79645 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79646 +
79647 + return (long)atomic_read_unchecked(v);
79648 +}
79649 +#endif
79650 +
79651 static inline void atomic_long_set(atomic_long_t *l, long i)
79652 {
79653 atomic_t *v = (atomic_t *)l;
79654 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79655 atomic_set(v, i);
79656 }
79657
79658 +#ifdef CONFIG_PAX_REFCOUNT
79659 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79660 +{
79661 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79662 +
79663 + atomic_set_unchecked(v, i);
79664 +}
79665 +#endif
79666 +
79667 static inline void atomic_long_inc(atomic_long_t *l)
79668 {
79669 atomic_t *v = (atomic_t *)l;
79670 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79671 atomic_inc(v);
79672 }
79673
79674 +#ifdef CONFIG_PAX_REFCOUNT
79675 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79676 +{
79677 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79678 +
79679 + atomic_inc_unchecked(v);
79680 +}
79681 +#endif
79682 +
79683 static inline void atomic_long_dec(atomic_long_t *l)
79684 {
79685 atomic_t *v = (atomic_t *)l;
79686 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79687 atomic_dec(v);
79688 }
79689
79690 +#ifdef CONFIG_PAX_REFCOUNT
79691 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79692 +{
79693 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79694 +
79695 + atomic_dec_unchecked(v);
79696 +}
79697 +#endif
79698 +
79699 static inline void atomic_long_add(long i, atomic_long_t *l)
79700 {
79701 atomic_t *v = (atomic_t *)l;
79702 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79703 atomic_add(i, v);
79704 }
79705
79706 +#ifdef CONFIG_PAX_REFCOUNT
79707 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79708 +{
79709 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79710 +
79711 + atomic_add_unchecked(i, v);
79712 +}
79713 +#endif
79714 +
79715 static inline void atomic_long_sub(long i, atomic_long_t *l)
79716 {
79717 atomic_t *v = (atomic_t *)l;
79718 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79719 atomic_sub(i, v);
79720 }
79721
79722 +#ifdef CONFIG_PAX_REFCOUNT
79723 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79724 +{
79725 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79726 +
79727 + atomic_sub_unchecked(i, v);
79728 +}
79729 +#endif
79730 +
79731 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79732 {
79733 atomic_t *v = (atomic_t *)l;
79734 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79735 return atomic_add_negative(i, v);
79736 }
79737
79738 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79739 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79740 {
79741 atomic_t *v = (atomic_t *)l;
79742
79743 return (long)atomic_add_return(i, v);
79744 }
79745
79746 +#ifdef CONFIG_PAX_REFCOUNT
79747 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79748 +{
79749 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79750 +
79751 + return (long)atomic_add_return_unchecked(i, v);
79752 +}
79753 +
79754 +#endif
79755 +
79756 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79757 {
79758 atomic_t *v = (atomic_t *)l;
79759 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79760 return (long)atomic_inc_return(v);
79761 }
79762
79763 +#ifdef CONFIG_PAX_REFCOUNT
79764 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79765 +{
79766 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79767 +
79768 + return (long)atomic_inc_return_unchecked(v);
79769 +}
79770 +#endif
79771 +
79772 static inline long atomic_long_dec_return(atomic_long_t *l)
79773 {
79774 atomic_t *v = (atomic_t *)l;
79775 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79776
79777 #endif /* BITS_PER_LONG == 64 */
79778
79779 +#ifdef CONFIG_PAX_REFCOUNT
79780 +static inline void pax_refcount_needs_these_functions(void)
79781 +{
79782 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79783 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79784 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79785 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79786 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79787 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79788 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79789 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79790 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79791 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79792 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79793 +#ifdef CONFIG_X86
79794 + atomic_clear_mask_unchecked(0, NULL);
79795 + atomic_set_mask_unchecked(0, NULL);
79796 +#endif
79797 +
79798 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79799 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79800 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79801 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79802 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79803 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79804 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79805 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79806 +}
79807 +#else
79808 +#define atomic_read_unchecked(v) atomic_read(v)
79809 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79810 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79811 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79812 +#define atomic_inc_unchecked(v) atomic_inc(v)
79813 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79814 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79815 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79816 +#define atomic_dec_unchecked(v) atomic_dec(v)
79817 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79818 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79819 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79820 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79821 +
79822 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79823 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79824 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79825 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79826 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79827 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79828 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79829 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79830 +#endif
79831 +
79832 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79833 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79834 index 30ad9c8..c70c170 100644
79835 --- a/include/asm-generic/atomic64.h
79836 +++ b/include/asm-generic/atomic64.h
79837 @@ -16,6 +16,8 @@ typedef struct {
79838 long long counter;
79839 } atomic64_t;
79840
79841 +typedef atomic64_t atomic64_unchecked_t;
79842 +
79843 #define ATOMIC64_INIT(i) { (i) }
79844
79845 extern long long atomic64_read(const atomic64_t *v);
79846 @@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79847 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79848 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79849
79850 +#define atomic64_read_unchecked(v) atomic64_read(v)
79851 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79852 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79853 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79854 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79855 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79856 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79857 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79858 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79859 +
79860 #endif /* _ASM_GENERIC_ATOMIC64_H */
79861 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79862 index 1402fa8..025a736 100644
79863 --- a/include/asm-generic/barrier.h
79864 +++ b/include/asm-generic/barrier.h
79865 @@ -74,7 +74,7 @@
79866 do { \
79867 compiletime_assert_atomic_type(*p); \
79868 smp_mb(); \
79869 - ACCESS_ONCE(*p) = (v); \
79870 + ACCESS_ONCE_RW(*p) = (v); \
79871 } while (0)
79872
79873 #define smp_load_acquire(p) \
79874 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79875 index a60a7cc..0fe12f2 100644
79876 --- a/include/asm-generic/bitops/__fls.h
79877 +++ b/include/asm-generic/bitops/__fls.h
79878 @@ -9,7 +9,7 @@
79879 *
79880 * Undefined if no set bit exists, so code should check against 0 first.
79881 */
79882 -static __always_inline unsigned long __fls(unsigned long word)
79883 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79884 {
79885 int num = BITS_PER_LONG - 1;
79886
79887 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79888 index 0576d1f..dad6c71 100644
79889 --- a/include/asm-generic/bitops/fls.h
79890 +++ b/include/asm-generic/bitops/fls.h
79891 @@ -9,7 +9,7 @@
79892 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79893 */
79894
79895 -static __always_inline int fls(int x)
79896 +static __always_inline int __intentional_overflow(-1) fls(int x)
79897 {
79898 int r = 32;
79899
79900 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79901 index b097cf8..3d40e14 100644
79902 --- a/include/asm-generic/bitops/fls64.h
79903 +++ b/include/asm-generic/bitops/fls64.h
79904 @@ -15,7 +15,7 @@
79905 * at position 64.
79906 */
79907 #if BITS_PER_LONG == 32
79908 -static __always_inline int fls64(__u64 x)
79909 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79910 {
79911 __u32 h = x >> 32;
79912 if (h)
79913 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79914 return fls(x);
79915 }
79916 #elif BITS_PER_LONG == 64
79917 -static __always_inline int fls64(__u64 x)
79918 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79919 {
79920 if (x == 0)
79921 return 0;
79922 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79923 index 1bfcfe5..e04c5c9 100644
79924 --- a/include/asm-generic/cache.h
79925 +++ b/include/asm-generic/cache.h
79926 @@ -6,7 +6,7 @@
79927 * cache lines need to provide their own cache.h.
79928 */
79929
79930 -#define L1_CACHE_SHIFT 5
79931 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79932 +#define L1_CACHE_SHIFT 5UL
79933 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79934
79935 #endif /* __ASM_GENERIC_CACHE_H */
79936 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79937 index 0d68a1e..b74a761 100644
79938 --- a/include/asm-generic/emergency-restart.h
79939 +++ b/include/asm-generic/emergency-restart.h
79940 @@ -1,7 +1,7 @@
79941 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79942 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79943
79944 -static inline void machine_emergency_restart(void)
79945 +static inline __noreturn void machine_emergency_restart(void)
79946 {
79947 machine_restart(NULL);
79948 }
79949 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79950 index b8fdc57..c6d5a5c 100644
79951 --- a/include/asm-generic/io.h
79952 +++ b/include/asm-generic/io.h
79953 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79954 * These are pretty trivial
79955 */
79956 #ifndef virt_to_phys
79957 -static inline unsigned long virt_to_phys(volatile void *address)
79958 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79959 {
79960 return __pa((unsigned long)address);
79961 }
79962 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79963 index 90f99c7..00ce236 100644
79964 --- a/include/asm-generic/kmap_types.h
79965 +++ b/include/asm-generic/kmap_types.h
79966 @@ -2,9 +2,9 @@
79967 #define _ASM_GENERIC_KMAP_TYPES_H
79968
79969 #ifdef __WITH_KM_FENCE
79970 -# define KM_TYPE_NR 41
79971 +# define KM_TYPE_NR 42
79972 #else
79973 -# define KM_TYPE_NR 20
79974 +# define KM_TYPE_NR 21
79975 #endif
79976
79977 #endif
79978 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79979 index 9ceb03b..62b0b8f 100644
79980 --- a/include/asm-generic/local.h
79981 +++ b/include/asm-generic/local.h
79982 @@ -23,24 +23,37 @@ typedef struct
79983 atomic_long_t a;
79984 } local_t;
79985
79986 +typedef struct {
79987 + atomic_long_unchecked_t a;
79988 +} local_unchecked_t;
79989 +
79990 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79991
79992 #define local_read(l) atomic_long_read(&(l)->a)
79993 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79994 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79995 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79996 #define local_inc(l) atomic_long_inc(&(l)->a)
79997 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79998 #define local_dec(l) atomic_long_dec(&(l)->a)
79999 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80000 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80001 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80002 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80003 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80004
80005 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80006 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80007 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80008 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80009 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80010 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80011 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80012 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80013 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80014
80015 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80016 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80017 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80018 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80019 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80020 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80021 index 725612b..9cc513a 100644
80022 --- a/include/asm-generic/pgtable-nopmd.h
80023 +++ b/include/asm-generic/pgtable-nopmd.h
80024 @@ -1,14 +1,19 @@
80025 #ifndef _PGTABLE_NOPMD_H
80026 #define _PGTABLE_NOPMD_H
80027
80028 -#ifndef __ASSEMBLY__
80029 -
80030 #include <asm-generic/pgtable-nopud.h>
80031
80032 -struct mm_struct;
80033 -
80034 #define __PAGETABLE_PMD_FOLDED
80035
80036 +#define PMD_SHIFT PUD_SHIFT
80037 +#define PTRS_PER_PMD 1
80038 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80039 +#define PMD_MASK (~(PMD_SIZE-1))
80040 +
80041 +#ifndef __ASSEMBLY__
80042 +
80043 +struct mm_struct;
80044 +
80045 /*
80046 * Having the pmd type consist of a pud gets the size right, and allows
80047 * us to conceptually access the pud entry that this pmd is folded into
80048 @@ -16,11 +21,6 @@ struct mm_struct;
80049 */
80050 typedef struct { pud_t pud; } pmd_t;
80051
80052 -#define PMD_SHIFT PUD_SHIFT
80053 -#define PTRS_PER_PMD 1
80054 -#define PMD_SIZE (1UL << PMD_SHIFT)
80055 -#define PMD_MASK (~(PMD_SIZE-1))
80056 -
80057 /*
80058 * The "pud_xxx()" functions here are trivial for a folded two-level
80059 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80060 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80061 index 810431d..0ec4804f 100644
80062 --- a/include/asm-generic/pgtable-nopud.h
80063 +++ b/include/asm-generic/pgtable-nopud.h
80064 @@ -1,10 +1,15 @@
80065 #ifndef _PGTABLE_NOPUD_H
80066 #define _PGTABLE_NOPUD_H
80067
80068 -#ifndef __ASSEMBLY__
80069 -
80070 #define __PAGETABLE_PUD_FOLDED
80071
80072 +#define PUD_SHIFT PGDIR_SHIFT
80073 +#define PTRS_PER_PUD 1
80074 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80075 +#define PUD_MASK (~(PUD_SIZE-1))
80076 +
80077 +#ifndef __ASSEMBLY__
80078 +
80079 /*
80080 * Having the pud type consist of a pgd gets the size right, and allows
80081 * us to conceptually access the pgd entry that this pud is folded into
80082 @@ -12,11 +17,6 @@
80083 */
80084 typedef struct { pgd_t pgd; } pud_t;
80085
80086 -#define PUD_SHIFT PGDIR_SHIFT
80087 -#define PTRS_PER_PUD 1
80088 -#define PUD_SIZE (1UL << PUD_SHIFT)
80089 -#define PUD_MASK (~(PUD_SIZE-1))
80090 -
80091 /*
80092 * The "pgd_xxx()" functions here are trivial for a folded two-level
80093 * setup: the pud is never bad, and a pud always exists (as it's folded
80094 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80095 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80096
80097 #define pgd_populate(mm, pgd, pud) do { } while (0)
80098 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80099 /*
80100 * (puds are folded into pgds so this doesn't get actually called,
80101 * but the define is needed for a generic inline function.)
80102 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80103 index 752e30d..87f172d 100644
80104 --- a/include/asm-generic/pgtable.h
80105 +++ b/include/asm-generic/pgtable.h
80106 @@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80107 }
80108 #endif /* CONFIG_NUMA_BALANCING */
80109
80110 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80111 +#ifdef CONFIG_PAX_KERNEXEC
80112 +#error KERNEXEC requires pax_open_kernel
80113 +#else
80114 +static inline unsigned long pax_open_kernel(void) { return 0; }
80115 +#endif
80116 +#endif
80117 +
80118 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80119 +#ifdef CONFIG_PAX_KERNEXEC
80120 +#error KERNEXEC requires pax_close_kernel
80121 +#else
80122 +static inline unsigned long pax_close_kernel(void) { return 0; }
80123 +#endif
80124 +#endif
80125 +
80126 #endif /* CONFIG_MMU */
80127
80128 #endif /* !__ASSEMBLY__ */
80129 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80130 index 72d8803..cb9749c 100644
80131 --- a/include/asm-generic/uaccess.h
80132 +++ b/include/asm-generic/uaccess.h
80133 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80134 return __clear_user(to, n);
80135 }
80136
80137 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80138 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80139 +#error UDEREF requires pax_open_userland
80140 +#else
80141 +static inline unsigned long pax_open_userland(void) { return 0; }
80142 +#endif
80143 +#endif
80144 +
80145 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80146 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80147 +#error UDEREF requires pax_close_userland
80148 +#else
80149 +static inline unsigned long pax_close_userland(void) { return 0; }
80150 +#endif
80151 +#endif
80152 +
80153 #endif /* __ASM_GENERIC_UACCESS_H */
80154 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80155 index aa70cbd..fd72c7a 100644
80156 --- a/include/asm-generic/vmlinux.lds.h
80157 +++ b/include/asm-generic/vmlinux.lds.h
80158 @@ -233,6 +233,7 @@
80159 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80160 VMLINUX_SYMBOL(__start_rodata) = .; \
80161 *(.rodata) *(.rodata.*) \
80162 + *(.data..read_only) \
80163 *(__vermagic) /* Kernel version magic */ \
80164 . = ALIGN(8); \
80165 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80166 @@ -724,17 +725,18 @@
80167 * section in the linker script will go there too. @phdr should have
80168 * a leading colon.
80169 *
80170 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80171 + * Note that this macros defines per_cpu_load as an absolute symbol.
80172 * If there is no need to put the percpu section at a predetermined
80173 * address, use PERCPU_SECTION.
80174 */
80175 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80176 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80177 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80178 + per_cpu_load = .; \
80179 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80180 - LOAD_OFFSET) { \
80181 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80182 PERCPU_INPUT(cacheline) \
80183 } phdr \
80184 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80185 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80186
80187 /**
80188 * PERCPU_SECTION - define output section for percpu area, simple version
80189 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80190 index 623a59c..1e79ab9 100644
80191 --- a/include/crypto/algapi.h
80192 +++ b/include/crypto/algapi.h
80193 @@ -34,7 +34,7 @@ struct crypto_type {
80194 unsigned int maskclear;
80195 unsigned int maskset;
80196 unsigned int tfmsize;
80197 -};
80198 +} __do_const;
80199
80200 struct crypto_instance {
80201 struct crypto_alg alg;
80202 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80203 index 53ed876..5bb09be 100644
80204 --- a/include/drm/drmP.h
80205 +++ b/include/drm/drmP.h
80206 @@ -59,6 +59,7 @@
80207
80208 #include <asm/mman.h>
80209 #include <asm/pgalloc.h>
80210 +#include <asm/local.h>
80211 #include <asm/uaccess.h>
80212
80213 #include <uapi/drm/drm.h>
80214 @@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80215 * \param cmd command.
80216 * \param arg argument.
80217 */
80218 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80219 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80220 + struct drm_file *file_priv);
80221 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80222 struct drm_file *file_priv);
80223
80224 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80225 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80226 unsigned long arg);
80227
80228 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80229 @@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80230 struct drm_ioctl_desc {
80231 unsigned int cmd;
80232 int flags;
80233 - drm_ioctl_t *func;
80234 + drm_ioctl_t func;
80235 unsigned int cmd_drv;
80236 const char *name;
80237 -};
80238 +} __do_const;
80239
80240 /**
80241 * Creates a driver or general drm_ioctl_desc array entry for the given
80242 @@ -629,7 +632,8 @@ struct drm_info_list {
80243 int (*show)(struct seq_file*, void*); /** show callback */
80244 u32 driver_features; /**< Required driver features for this entry */
80245 void *data;
80246 -};
80247 +} __do_const;
80248 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80249
80250 /**
80251 * debugfs node structure. This structure represents a debugfs file.
80252 @@ -713,7 +717,7 @@ struct drm_device {
80253
80254 /** \name Usage Counters */
80255 /*@{ */
80256 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80257 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80258 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80259 int buf_use; /**< Buffers in use -- cannot alloc */
80260 atomic_t buf_alloc; /**< Buffer allocation in progress */
80261 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80262 index a3d75fe..6802f9c 100644
80263 --- a/include/drm/drm_crtc_helper.h
80264 +++ b/include/drm/drm_crtc_helper.h
80265 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80266 struct drm_connector *connector);
80267 /* disable encoder when not in use - more explicit than dpms off */
80268 void (*disable)(struct drm_encoder *encoder);
80269 -};
80270 +} __no_const;
80271
80272 /**
80273 * drm_connector_helper_funcs - helper operations for connectors
80274 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80275 index a70d456..6ea07cd 100644
80276 --- a/include/drm/i915_pciids.h
80277 +++ b/include/drm/i915_pciids.h
80278 @@ -37,7 +37,7 @@
80279 */
80280 #define INTEL_VGA_DEVICE(id, info) { \
80281 0x8086, id, \
80282 - ~0, ~0, \
80283 + PCI_ANY_ID, PCI_ANY_ID, \
80284 0x030000, 0xff0000, \
80285 (unsigned long) info }
80286
80287 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80288 index 72dcbe8..8db58d7 100644
80289 --- a/include/drm/ttm/ttm_memory.h
80290 +++ b/include/drm/ttm/ttm_memory.h
80291 @@ -48,7 +48,7 @@
80292
80293 struct ttm_mem_shrink {
80294 int (*do_shrink) (struct ttm_mem_shrink *);
80295 -};
80296 +} __no_const;
80297
80298 /**
80299 * struct ttm_mem_global - Global memory accounting structure.
80300 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80301 index 49a8284..9643967 100644
80302 --- a/include/drm/ttm/ttm_page_alloc.h
80303 +++ b/include/drm/ttm/ttm_page_alloc.h
80304 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80305 */
80306 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80307
80308 +struct device;
80309 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80310 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80311
80312 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80313 index 4b840e8..155d235 100644
80314 --- a/include/keys/asymmetric-subtype.h
80315 +++ b/include/keys/asymmetric-subtype.h
80316 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80317 /* Verify the signature on a key of this subtype (optional) */
80318 int (*verify_signature)(const struct key *key,
80319 const struct public_key_signature *sig);
80320 -};
80321 +} __do_const;
80322
80323 /**
80324 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80325 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80326 index c1da539..1dcec55 100644
80327 --- a/include/linux/atmdev.h
80328 +++ b/include/linux/atmdev.h
80329 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80330 #endif
80331
80332 struct k_atm_aal_stats {
80333 -#define __HANDLE_ITEM(i) atomic_t i
80334 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80335 __AAL_STAT_ITEMS
80336 #undef __HANDLE_ITEM
80337 };
80338 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80339 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80340 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80341 struct module *owner;
80342 -};
80343 +} __do_const ;
80344
80345 struct atmphy_ops {
80346 int (*start)(struct atm_dev *dev);
80347 diff --git a/include/linux/audit.h b/include/linux/audit.h
80348 index 10f155b..6c73ffe 100644
80349 --- a/include/linux/audit.h
80350 +++ b/include/linux/audit.h
80351 @@ -219,7 +219,7 @@ static inline void audit_ptrace(struct task_struct *t)
80352 extern unsigned int audit_serial(void);
80353 extern int auditsc_get_stamp(struct audit_context *ctx,
80354 struct timespec *t, unsigned int *serial);
80355 -extern int audit_set_loginuid(kuid_t loginuid);
80356 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80357
80358 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80359 {
80360 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80361 index 61f29e5..e67c658 100644
80362 --- a/include/linux/binfmts.h
80363 +++ b/include/linux/binfmts.h
80364 @@ -44,7 +44,7 @@ struct linux_binprm {
80365 unsigned interp_flags;
80366 unsigned interp_data;
80367 unsigned long loader, exec;
80368 -};
80369 +} __randomize_layout;
80370
80371 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80372 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80373 @@ -73,8 +73,10 @@ struct linux_binfmt {
80374 int (*load_binary)(struct linux_binprm *);
80375 int (*load_shlib)(struct file *);
80376 int (*core_dump)(struct coredump_params *cprm);
80377 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80378 + void (*handle_mmap)(struct file *);
80379 unsigned long min_coredump; /* minimal dump size */
80380 -};
80381 +} __do_const __randomize_layout;
80382
80383 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80384
80385 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80386 index 5d858e0..336c1d9 100644
80387 --- a/include/linux/bitops.h
80388 +++ b/include/linux/bitops.h
80389 @@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80390 * @word: value to rotate
80391 * @shift: bits to roll
80392 */
80393 -static inline __u32 rol32(__u32 word, unsigned int shift)
80394 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80395 {
80396 return (word << shift) | (word >> (32 - shift));
80397 }
80398 @@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80399 * @word: value to rotate
80400 * @shift: bits to roll
80401 */
80402 -static inline __u32 ror32(__u32 word, unsigned int shift)
80403 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80404 {
80405 return (word >> shift) | (word << (32 - shift));
80406 }
80407 @@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80408 return (__s32)(value << shift) >> shift;
80409 }
80410
80411 -static inline unsigned fls_long(unsigned long l)
80412 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80413 {
80414 if (sizeof(l) == 4)
80415 return fls(l);
80416 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80417 index aac0f9e..73c9869 100644
80418 --- a/include/linux/blkdev.h
80419 +++ b/include/linux/blkdev.h
80420 @@ -1615,7 +1615,7 @@ struct block_device_operations {
80421 /* this callback is with swap_lock and sometimes page table lock held */
80422 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80423 struct module *owner;
80424 -};
80425 +} __do_const;
80426
80427 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80428 unsigned long);
80429 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80430 index afc1343..9735539 100644
80431 --- a/include/linux/blktrace_api.h
80432 +++ b/include/linux/blktrace_api.h
80433 @@ -25,7 +25,7 @@ struct blk_trace {
80434 struct dentry *dropped_file;
80435 struct dentry *msg_file;
80436 struct list_head running_list;
80437 - atomic_t dropped;
80438 + atomic_unchecked_t dropped;
80439 };
80440
80441 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80442 diff --git a/include/linux/cache.h b/include/linux/cache.h
80443 index 17e7e82..1d7da26 100644
80444 --- a/include/linux/cache.h
80445 +++ b/include/linux/cache.h
80446 @@ -16,6 +16,14 @@
80447 #define __read_mostly
80448 #endif
80449
80450 +#ifndef __read_only
80451 +#ifdef CONFIG_PAX_KERNEXEC
80452 +#error KERNEXEC requires __read_only
80453 +#else
80454 +#define __read_only __read_mostly
80455 +#endif
80456 +#endif
80457 +
80458 #ifndef ____cacheline_aligned
80459 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80460 #endif
80461 diff --git a/include/linux/capability.h b/include/linux/capability.h
80462 index aa93e5e..985a1b0 100644
80463 --- a/include/linux/capability.h
80464 +++ b/include/linux/capability.h
80465 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80466 extern bool capable(int cap);
80467 extern bool ns_capable(struct user_namespace *ns, int cap);
80468 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80469 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80470 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80471 +extern bool capable_nolog(int cap);
80472 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80473
80474 /* audit system wants to get cap info from files as well */
80475 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80476
80477 +extern int is_privileged_binary(const struct dentry *dentry);
80478 +
80479 #endif /* !_LINUX_CAPABILITY_H */
80480 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80481 index 8609d57..86e4d79 100644
80482 --- a/include/linux/cdrom.h
80483 +++ b/include/linux/cdrom.h
80484 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80485
80486 /* driver specifications */
80487 const int capability; /* capability flags */
80488 - int n_minors; /* number of active minor devices */
80489 /* handle uniform packets for scsi type devices (scsi,atapi) */
80490 int (*generic_packet) (struct cdrom_device_info *,
80491 struct packet_command *);
80492 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80493 index 4ce9056..86caac6 100644
80494 --- a/include/linux/cleancache.h
80495 +++ b/include/linux/cleancache.h
80496 @@ -31,7 +31,7 @@ struct cleancache_ops {
80497 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80498 void (*invalidate_inode)(int, struct cleancache_filekey);
80499 void (*invalidate_fs)(int);
80500 -};
80501 +} __no_const;
80502
80503 extern struct cleancache_ops *
80504 cleancache_register_ops(struct cleancache_ops *ops);
80505 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80506 index 2839c63..5b06b6b 100644
80507 --- a/include/linux/clk-provider.h
80508 +++ b/include/linux/clk-provider.h
80509 @@ -191,6 +191,7 @@ struct clk_ops {
80510 void (*init)(struct clk_hw *hw);
80511 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80512 };
80513 +typedef struct clk_ops __no_const clk_ops_no_const;
80514
80515 /**
80516 * struct clk_init_data - holds init data that's common to all clocks and is
80517 diff --git a/include/linux/compat.h b/include/linux/compat.h
80518 index e649426..a74047b 100644
80519 --- a/include/linux/compat.h
80520 +++ b/include/linux/compat.h
80521 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80522 compat_size_t __user *len_ptr);
80523
80524 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80525 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80526 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80527 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80528 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80529 compat_ssize_t msgsz, int msgflg);
80530 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80531 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80532 compat_ulong_t addr, compat_ulong_t data);
80533 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80534 - compat_long_t addr, compat_long_t data);
80535 + compat_ulong_t addr, compat_ulong_t data);
80536
80537 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80538 /*
80539 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80540 index d1a5582..4424efa 100644
80541 --- a/include/linux/compiler-gcc4.h
80542 +++ b/include/linux/compiler-gcc4.h
80543 @@ -39,9 +39,34 @@
80544 # define __compiletime_warning(message) __attribute__((warning(message)))
80545 # define __compiletime_error(message) __attribute__((error(message)))
80546 #endif /* __CHECKER__ */
80547 +
80548 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80549 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80550 +#define __bos0(ptr) __bos((ptr), 0)
80551 +#define __bos1(ptr) __bos((ptr), 1)
80552 #endif /* GCC_VERSION >= 40300 */
80553
80554 #if GCC_VERSION >= 40500
80555 +
80556 +#ifdef RANDSTRUCT_PLUGIN
80557 +#define __randomize_layout __attribute__((randomize_layout))
80558 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80559 +#endif
80560 +
80561 +#ifdef CONSTIFY_PLUGIN
80562 +#define __no_const __attribute__((no_const))
80563 +#define __do_const __attribute__((do_const))
80564 +#endif
80565 +
80566 +#ifdef SIZE_OVERFLOW_PLUGIN
80567 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80568 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80569 +#endif
80570 +
80571 +#ifdef LATENT_ENTROPY_PLUGIN
80572 +#define __latent_entropy __attribute__((latent_entropy))
80573 +#endif
80574 +
80575 /*
80576 * Mark a position in code as unreachable. This can be used to
80577 * suppress control flow warnings after asm blocks that transfer
80578 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80579 index d5ad7b1..3b74638 100644
80580 --- a/include/linux/compiler.h
80581 +++ b/include/linux/compiler.h
80582 @@ -5,11 +5,14 @@
80583
80584 #ifdef __CHECKER__
80585 # define __user __attribute__((noderef, address_space(1)))
80586 +# define __force_user __force __user
80587 # define __kernel __attribute__((address_space(0)))
80588 +# define __force_kernel __force __kernel
80589 # define __safe __attribute__((safe))
80590 # define __force __attribute__((force))
80591 # define __nocast __attribute__((nocast))
80592 # define __iomem __attribute__((noderef, address_space(2)))
80593 +# define __force_iomem __force __iomem
80594 # define __must_hold(x) __attribute__((context(x,1,1)))
80595 # define __acquires(x) __attribute__((context(x,0,1)))
80596 # define __releases(x) __attribute__((context(x,1,0)))
80597 @@ -17,20 +20,37 @@
80598 # define __release(x) __context__(x,-1)
80599 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80600 # define __percpu __attribute__((noderef, address_space(3)))
80601 +# define __force_percpu __force __percpu
80602 #ifdef CONFIG_SPARSE_RCU_POINTER
80603 # define __rcu __attribute__((noderef, address_space(4)))
80604 +# define __force_rcu __force __rcu
80605 #else
80606 # define __rcu
80607 +# define __force_rcu
80608 #endif
80609 extern void __chk_user_ptr(const volatile void __user *);
80610 extern void __chk_io_ptr(const volatile void __iomem *);
80611 #else
80612 -# define __user
80613 -# define __kernel
80614 +# ifdef CHECKER_PLUGIN
80615 +//# define __user
80616 +//# define __force_user
80617 +//# define __kernel
80618 +//# define __force_kernel
80619 +# else
80620 +# ifdef STRUCTLEAK_PLUGIN
80621 +# define __user __attribute__((user))
80622 +# else
80623 +# define __user
80624 +# endif
80625 +# define __force_user
80626 +# define __kernel
80627 +# define __force_kernel
80628 +# endif
80629 # define __safe
80630 # define __force
80631 # define __nocast
80632 # define __iomem
80633 +# define __force_iomem
80634 # define __chk_user_ptr(x) (void)0
80635 # define __chk_io_ptr(x) (void)0
80636 # define __builtin_warning(x, y...) (1)
80637 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80638 # define __release(x) (void)0
80639 # define __cond_lock(x,c) (c)
80640 # define __percpu
80641 +# define __force_percpu
80642 # define __rcu
80643 +# define __force_rcu
80644 #endif
80645
80646 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80647 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80648 # define __attribute_const__ /* unimplemented */
80649 #endif
80650
80651 +#ifndef __randomize_layout
80652 +# define __randomize_layout
80653 +#endif
80654 +
80655 +#ifndef __no_randomize_layout
80656 +# define __no_randomize_layout
80657 +#endif
80658 +
80659 +#ifndef __no_const
80660 +# define __no_const
80661 +#endif
80662 +
80663 +#ifndef __do_const
80664 +# define __do_const
80665 +#endif
80666 +
80667 +#ifndef __size_overflow
80668 +# define __size_overflow(...)
80669 +#endif
80670 +
80671 +#ifndef __intentional_overflow
80672 +# define __intentional_overflow(...)
80673 +#endif
80674 +
80675 +#ifndef __latent_entropy
80676 +# define __latent_entropy
80677 +#endif
80678 +
80679 /*
80680 * Tell gcc if a function is cold. The compiler will assume any path
80681 * directly leading to the call is unlikely.
80682 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80683 #define __cold
80684 #endif
80685
80686 +#ifndef __alloc_size
80687 +#define __alloc_size(...)
80688 +#endif
80689 +
80690 +#ifndef __bos
80691 +#define __bos(ptr, arg)
80692 +#endif
80693 +
80694 +#ifndef __bos0
80695 +#define __bos0(ptr)
80696 +#endif
80697 +
80698 +#ifndef __bos1
80699 +#define __bos1(ptr)
80700 +#endif
80701 +
80702 /* Simple shorthand for a section definition */
80703 #ifndef __section
80704 # define __section(S) __attribute__ ((__section__(#S)))
80705 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80706 * use is to mediate communication between process-level code and irq/NMI
80707 * handlers, all running on the same CPU.
80708 */
80709 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80710 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80711 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80712
80713 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80714 #ifdef CONFIG_KPROBES
80715 diff --git a/include/linux/completion.h b/include/linux/completion.h
80716 index 5d5aaae..0ea9b84 100644
80717 --- a/include/linux/completion.h
80718 +++ b/include/linux/completion.h
80719 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80720
80721 extern void wait_for_completion(struct completion *);
80722 extern void wait_for_completion_io(struct completion *);
80723 -extern int wait_for_completion_interruptible(struct completion *x);
80724 -extern int wait_for_completion_killable(struct completion *x);
80725 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80726 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80727 extern unsigned long wait_for_completion_timeout(struct completion *x,
80728 - unsigned long timeout);
80729 + unsigned long timeout) __intentional_overflow(-1);
80730 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80731 - unsigned long timeout);
80732 + unsigned long timeout) __intentional_overflow(-1);
80733 extern long wait_for_completion_interruptible_timeout(
80734 - struct completion *x, unsigned long timeout);
80735 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80736 extern long wait_for_completion_killable_timeout(
80737 - struct completion *x, unsigned long timeout);
80738 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80739 extern bool try_wait_for_completion(struct completion *x);
80740 extern bool completion_done(struct completion *x);
80741
80742 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80743 index 34025df..d94bbbc 100644
80744 --- a/include/linux/configfs.h
80745 +++ b/include/linux/configfs.h
80746 @@ -125,7 +125,7 @@ struct configfs_attribute {
80747 const char *ca_name;
80748 struct module *ca_owner;
80749 umode_t ca_mode;
80750 -};
80751 +} __do_const;
80752
80753 /*
80754 * Users often need to create attribute structures for their configurable
80755 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80756 index 503b085b..1638c9e 100644
80757 --- a/include/linux/cpufreq.h
80758 +++ b/include/linux/cpufreq.h
80759 @@ -206,6 +206,7 @@ struct global_attr {
80760 ssize_t (*store)(struct kobject *a, struct attribute *b,
80761 const char *c, size_t count);
80762 };
80763 +typedef struct global_attr __no_const global_attr_no_const;
80764
80765 #define define_one_global_ro(_name) \
80766 static struct global_attr _name = \
80767 @@ -273,7 +274,7 @@ struct cpufreq_driver {
80768 bool boost_supported;
80769 bool boost_enabled;
80770 int (*set_boost) (int state);
80771 -};
80772 +} __do_const;
80773
80774 /* flags */
80775 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80776 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80777 index 25e0df6..952dffd 100644
80778 --- a/include/linux/cpuidle.h
80779 +++ b/include/linux/cpuidle.h
80780 @@ -50,7 +50,8 @@ struct cpuidle_state {
80781 int index);
80782
80783 int (*enter_dead) (struct cpuidle_device *dev, int index);
80784 -};
80785 +} __do_const;
80786 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80787
80788 /* Idle State Flags */
80789 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80790 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80791 void (*reflect) (struct cpuidle_device *dev, int index);
80792
80793 struct module *owner;
80794 -};
80795 +} __do_const;
80796
80797 #ifdef CONFIG_CPU_IDLE
80798 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80799 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80800 index 0a9a6da..ea597ca 100644
80801 --- a/include/linux/cpumask.h
80802 +++ b/include/linux/cpumask.h
80803 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80804 }
80805
80806 /* Valid inputs for n are -1 and 0. */
80807 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80808 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80809 {
80810 return n+1;
80811 }
80812
80813 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80814 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80815 {
80816 return n+1;
80817 }
80818
80819 -static inline unsigned int cpumask_next_and(int n,
80820 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80821 const struct cpumask *srcp,
80822 const struct cpumask *andp)
80823 {
80824 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80825 *
80826 * Returns >= nr_cpu_ids if no further cpus set.
80827 */
80828 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80829 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80830 {
80831 /* -1 is a legal arg here. */
80832 if (n != -1)
80833 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80834 *
80835 * Returns >= nr_cpu_ids if no further cpus unset.
80836 */
80837 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80838 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80839 {
80840 /* -1 is a legal arg here. */
80841 if (n != -1)
80842 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80843 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80844 }
80845
80846 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80847 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80848 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80849 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80850
80851 diff --git a/include/linux/cred.h b/include/linux/cred.h
80852 index 2fb2ca2..d6a3340 100644
80853 --- a/include/linux/cred.h
80854 +++ b/include/linux/cred.h
80855 @@ -35,7 +35,7 @@ struct group_info {
80856 int nblocks;
80857 kgid_t small_block[NGROUPS_SMALL];
80858 kgid_t *blocks[0];
80859 -};
80860 +} __randomize_layout;
80861
80862 /**
80863 * get_group_info - Get a reference to a group info structure
80864 @@ -137,7 +137,7 @@ struct cred {
80865 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80866 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80867 struct rcu_head rcu; /* RCU deletion hook */
80868 -};
80869 +} __randomize_layout;
80870
80871 extern void __put_cred(struct cred *);
80872 extern void exit_creds(struct task_struct *);
80873 @@ -195,6 +195,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80874 static inline void validate_process_creds(void)
80875 {
80876 }
80877 +static inline void validate_task_creds(struct task_struct *task)
80878 +{
80879 +}
80880 #endif
80881
80882 /**
80883 @@ -332,6 +335,7 @@ static inline void put_cred(const struct cred *_cred)
80884
80885 #define task_uid(task) (task_cred_xxx((task), uid))
80886 #define task_euid(task) (task_cred_xxx((task), euid))
80887 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80888
80889 #define current_cred_xxx(xxx) \
80890 ({ \
80891 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80892 index dc34dfc..bdf9b5d 100644
80893 --- a/include/linux/crypto.h
80894 +++ b/include/linux/crypto.h
80895 @@ -386,7 +386,7 @@ struct cipher_tfm {
80896 const u8 *key, unsigned int keylen);
80897 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80898 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80899 -};
80900 +} __no_const;
80901
80902 struct hash_tfm {
80903 int (*init)(struct hash_desc *desc);
80904 @@ -407,13 +407,13 @@ struct compress_tfm {
80905 int (*cot_decompress)(struct crypto_tfm *tfm,
80906 const u8 *src, unsigned int slen,
80907 u8 *dst, unsigned int *dlen);
80908 -};
80909 +} __no_const;
80910
80911 struct rng_tfm {
80912 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80913 unsigned int dlen);
80914 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80915 -};
80916 +} __no_const;
80917
80918 #define crt_ablkcipher crt_u.ablkcipher
80919 #define crt_aead crt_u.aead
80920 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80921 index 653589e..4ef254a 100644
80922 --- a/include/linux/ctype.h
80923 +++ b/include/linux/ctype.h
80924 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80925 * Fast implementation of tolower() for internal usage. Do not use in your
80926 * code.
80927 */
80928 -static inline char _tolower(const char c)
80929 +static inline unsigned char _tolower(const unsigned char c)
80930 {
80931 return c | 0x20;
80932 }
80933 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80934 index 1c2f1b8..7b9f50c 100644
80935 --- a/include/linux/dcache.h
80936 +++ b/include/linux/dcache.h
80937 @@ -123,6 +123,9 @@ struct dentry {
80938 unsigned long d_time; /* used by d_revalidate */
80939 void *d_fsdata; /* fs-specific data */
80940
80941 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
80942 + atomic_t chroot_refcnt; /* tracks use of directory in chroot */
80943 +#endif
80944 struct list_head d_lru; /* LRU list */
80945 struct list_head d_child; /* child of parent list */
80946 struct list_head d_subdirs; /* our children */
80947 @@ -133,7 +136,7 @@ struct dentry {
80948 struct hlist_node d_alias; /* inode alias list */
80949 struct rcu_head d_rcu;
80950 } d_u;
80951 -};
80952 +} __randomize_layout;
80953
80954 /*
80955 * dentry->d_lock spinlock nesting subclasses:
80956 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80957 index 7925bf0..d5143d2 100644
80958 --- a/include/linux/decompress/mm.h
80959 +++ b/include/linux/decompress/mm.h
80960 @@ -77,7 +77,7 @@ static void free(void *where)
80961 * warnings when not needed (indeed large_malloc / large_free are not
80962 * needed by inflate */
80963
80964 -#define malloc(a) kmalloc(a, GFP_KERNEL)
80965 +#define malloc(a) kmalloc((a), GFP_KERNEL)
80966 #define free(a) kfree(a)
80967
80968 #define large_malloc(a) vmalloc(a)
80969 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80970 index f1863dc..5c26074 100644
80971 --- a/include/linux/devfreq.h
80972 +++ b/include/linux/devfreq.h
80973 @@ -114,7 +114,7 @@ struct devfreq_governor {
80974 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80975 int (*event_handler)(struct devfreq *devfreq,
80976 unsigned int event, void *data);
80977 -};
80978 +} __do_const;
80979
80980 /**
80981 * struct devfreq - Device devfreq structure
80982 diff --git a/include/linux/device.h b/include/linux/device.h
80983 index ce1f2160..189bc33 100644
80984 --- a/include/linux/device.h
80985 +++ b/include/linux/device.h
80986 @@ -311,7 +311,7 @@ struct subsys_interface {
80987 struct list_head node;
80988 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80989 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80990 -};
80991 +} __do_const;
80992
80993 int subsys_interface_register(struct subsys_interface *sif);
80994 void subsys_interface_unregister(struct subsys_interface *sif);
80995 @@ -507,7 +507,7 @@ struct device_type {
80996 void (*release)(struct device *dev);
80997
80998 const struct dev_pm_ops *pm;
80999 -};
81000 +} __do_const;
81001
81002 /* interface for exporting device attributes */
81003 struct device_attribute {
81004 @@ -517,11 +517,12 @@ struct device_attribute {
81005 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81006 const char *buf, size_t count);
81007 };
81008 +typedef struct device_attribute __no_const device_attribute_no_const;
81009
81010 struct dev_ext_attribute {
81011 struct device_attribute attr;
81012 void *var;
81013 -};
81014 +} __do_const;
81015
81016 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81017 char *buf);
81018 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81019 index d5d3881..7ed54af 100644
81020 --- a/include/linux/dma-mapping.h
81021 +++ b/include/linux/dma-mapping.h
81022 @@ -60,7 +60,7 @@ struct dma_map_ops {
81023 u64 (*get_required_mask)(struct device *dev);
81024 #endif
81025 int is_phys;
81026 -};
81027 +} __do_const;
81028
81029 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81030
81031 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81032 index 653a1fd..9133cd1 100644
81033 --- a/include/linux/dmaengine.h
81034 +++ b/include/linux/dmaengine.h
81035 @@ -1136,9 +1136,9 @@ struct dma_pinned_list {
81036 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81037 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81038
81039 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81040 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81041 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81042 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81043 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81044 struct dma_pinned_list *pinned_list, struct page *page,
81045 unsigned int offset, size_t len);
81046
81047 diff --git a/include/linux/efi.h b/include/linux/efi.h
81048 index 0949f9c..04cb9a5 100644
81049 --- a/include/linux/efi.h
81050 +++ b/include/linux/efi.h
81051 @@ -1050,6 +1050,7 @@ struct efivar_operations {
81052 efi_set_variable_nonblocking_t *set_variable_nonblocking;
81053 efi_query_variable_store_t *query_variable_store;
81054 };
81055 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81056
81057 struct efivars {
81058 /*
81059 diff --git a/include/linux/elf.h b/include/linux/elf.h
81060 index 67a5fa7..b817372 100644
81061 --- a/include/linux/elf.h
81062 +++ b/include/linux/elf.h
81063 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81064 #define elf_note elf32_note
81065 #define elf_addr_t Elf32_Off
81066 #define Elf_Half Elf32_Half
81067 +#define elf_dyn Elf32_Dyn
81068
81069 #else
81070
81071 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81072 #define elf_note elf64_note
81073 #define elf_addr_t Elf64_Off
81074 #define Elf_Half Elf64_Half
81075 +#define elf_dyn Elf64_Dyn
81076
81077 #endif
81078
81079 diff --git a/include/linux/err.h b/include/linux/err.h
81080 index a729120..6ede2c9 100644
81081 --- a/include/linux/err.h
81082 +++ b/include/linux/err.h
81083 @@ -20,12 +20,12 @@
81084
81085 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81086
81087 -static inline void * __must_check ERR_PTR(long error)
81088 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81089 {
81090 return (void *) error;
81091 }
81092
81093 -static inline long __must_check PTR_ERR(__force const void *ptr)
81094 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81095 {
81096 return (long) ptr;
81097 }
81098 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81099 index 36f49c4..a2a1f4c 100644
81100 --- a/include/linux/extcon.h
81101 +++ b/include/linux/extcon.h
81102 @@ -135,7 +135,7 @@ struct extcon_dev {
81103 /* /sys/class/extcon/.../mutually_exclusive/... */
81104 struct attribute_group attr_g_muex;
81105 struct attribute **attrs_muex;
81106 - struct device_attribute *d_attrs_muex;
81107 + device_attribute_no_const *d_attrs_muex;
81108 };
81109
81110 /**
81111 diff --git a/include/linux/fb.h b/include/linux/fb.h
81112 index 09bb7a1..d98870a 100644
81113 --- a/include/linux/fb.h
81114 +++ b/include/linux/fb.h
81115 @@ -305,7 +305,7 @@ struct fb_ops {
81116 /* called at KDB enter and leave time to prepare the console */
81117 int (*fb_debug_enter)(struct fb_info *info);
81118 int (*fb_debug_leave)(struct fb_info *info);
81119 -};
81120 +} __do_const;
81121
81122 #ifdef CONFIG_FB_TILEBLITTING
81123 #define FB_TILE_CURSOR_NONE 0
81124 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81125 index 230f87b..1fd0485 100644
81126 --- a/include/linux/fdtable.h
81127 +++ b/include/linux/fdtable.h
81128 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81129 void put_files_struct(struct files_struct *fs);
81130 void reset_files_struct(struct files_struct *);
81131 int unshare_files(struct files_struct **);
81132 -struct files_struct *dup_fd(struct files_struct *, int *);
81133 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81134 void do_close_on_exec(struct files_struct *);
81135 int iterate_fd(struct files_struct *, unsigned,
81136 int (*)(const void *, struct file *, unsigned),
81137 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81138 index 8293262..2b3b8bd 100644
81139 --- a/include/linux/frontswap.h
81140 +++ b/include/linux/frontswap.h
81141 @@ -11,7 +11,7 @@ struct frontswap_ops {
81142 int (*load)(unsigned, pgoff_t, struct page *);
81143 void (*invalidate_page)(unsigned, pgoff_t);
81144 void (*invalidate_area)(unsigned);
81145 -};
81146 +} __no_const;
81147
81148 extern bool frontswap_enabled;
81149 extern struct frontswap_ops *
81150 diff --git a/include/linux/fs.h b/include/linux/fs.h
81151 index 9ab779e..0c636f2 100644
81152 --- a/include/linux/fs.h
81153 +++ b/include/linux/fs.h
81154 @@ -412,7 +412,7 @@ struct address_space {
81155 spinlock_t private_lock; /* for use by the address_space */
81156 struct list_head private_list; /* ditto */
81157 void *private_data; /* ditto */
81158 -} __attribute__((aligned(sizeof(long))));
81159 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81160 /*
81161 * On most architectures that alignment is already the case; but
81162 * must be enforced here for CRIS, to let the least significant bit
81163 @@ -455,7 +455,7 @@ struct block_device {
81164 int bd_fsfreeze_count;
81165 /* Mutex for freeze */
81166 struct mutex bd_fsfreeze_mutex;
81167 -};
81168 +} __randomize_layout;
81169
81170 /*
81171 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81172 @@ -624,7 +624,7 @@ struct inode {
81173 #endif
81174
81175 void *i_private; /* fs or device private pointer */
81176 -};
81177 +} __randomize_layout;
81178
81179 static inline int inode_unhashed(struct inode *inode)
81180 {
81181 @@ -820,7 +820,7 @@ struct file {
81182 struct list_head f_tfile_llink;
81183 #endif /* #ifdef CONFIG_EPOLL */
81184 struct address_space *f_mapping;
81185 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81186 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81187
81188 struct file_handle {
81189 __u32 handle_bytes;
81190 @@ -945,7 +945,7 @@ struct file_lock {
81191 int state; /* state of grant or error if -ve */
81192 } afs;
81193 } fl_u;
81194 -};
81195 +} __randomize_layout;
81196
81197 /* The following constant reflects the upper bound of the file/locking space */
81198 #ifndef OFFSET_MAX
81199 @@ -1287,7 +1287,7 @@ struct super_block {
81200 * Indicates how deep in a filesystem stack this SB is
81201 */
81202 int s_stack_depth;
81203 -};
81204 +} __randomize_layout;
81205
81206 extern struct timespec current_fs_time(struct super_block *sb);
81207
81208 @@ -1514,7 +1514,8 @@ struct file_operations {
81209 long (*fallocate)(struct file *file, int mode, loff_t offset,
81210 loff_t len);
81211 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81212 -};
81213 +} __do_const __randomize_layout;
81214 +typedef struct file_operations __no_const file_operations_no_const;
81215
81216 struct inode_operations {
81217 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81218 @@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81219 return !IS_DEADDIR(inode);
81220 }
81221
81222 +static inline bool is_sidechannel_device(const struct inode *inode)
81223 +{
81224 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81225 + umode_t mode = inode->i_mode;
81226 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81227 +#else
81228 + return false;
81229 +#endif
81230 +}
81231 +
81232 #endif /* _LINUX_FS_H */
81233 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81234 index 0efc3e6..fd23610 100644
81235 --- a/include/linux/fs_struct.h
81236 +++ b/include/linux/fs_struct.h
81237 @@ -6,13 +6,13 @@
81238 #include <linux/seqlock.h>
81239
81240 struct fs_struct {
81241 - int users;
81242 + atomic_t users;
81243 spinlock_t lock;
81244 seqcount_t seq;
81245 int umask;
81246 int in_exec;
81247 struct path root, pwd;
81248 -};
81249 +} __randomize_layout;
81250
81251 extern struct kmem_cache *fs_cachep;
81252
81253 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81254 index 7714849..a4a5c7a 100644
81255 --- a/include/linux/fscache-cache.h
81256 +++ b/include/linux/fscache-cache.h
81257 @@ -113,7 +113,7 @@ struct fscache_operation {
81258 fscache_operation_release_t release;
81259 };
81260
81261 -extern atomic_t fscache_op_debug_id;
81262 +extern atomic_unchecked_t fscache_op_debug_id;
81263 extern void fscache_op_work_func(struct work_struct *work);
81264
81265 extern void fscache_enqueue_operation(struct fscache_operation *);
81266 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81267 INIT_WORK(&op->work, fscache_op_work_func);
81268 atomic_set(&op->usage, 1);
81269 op->state = FSCACHE_OP_ST_INITIALISED;
81270 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81271 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81272 op->processor = processor;
81273 op->release = release;
81274 INIT_LIST_HEAD(&op->pend_link);
81275 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81276 index 115bb81..e7b812b 100644
81277 --- a/include/linux/fscache.h
81278 +++ b/include/linux/fscache.h
81279 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81280 * - this is mandatory for any object that may have data
81281 */
81282 void (*now_uncached)(void *cookie_netfs_data);
81283 -};
81284 +} __do_const;
81285
81286 /*
81287 * fscache cached network filesystem type
81288 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81289 index 1c804b0..1432c2b 100644
81290 --- a/include/linux/fsnotify.h
81291 +++ b/include/linux/fsnotify.h
81292 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81293 struct inode *inode = file_inode(file);
81294 __u32 mask = FS_ACCESS;
81295
81296 + if (is_sidechannel_device(inode))
81297 + return;
81298 +
81299 if (S_ISDIR(inode->i_mode))
81300 mask |= FS_ISDIR;
81301
81302 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81303 struct inode *inode = file_inode(file);
81304 __u32 mask = FS_MODIFY;
81305
81306 + if (is_sidechannel_device(inode))
81307 + return;
81308 +
81309 if (S_ISDIR(inode->i_mode))
81310 mask |= FS_ISDIR;
81311
81312 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81313 */
81314 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81315 {
81316 - return kstrdup(name, GFP_KERNEL);
81317 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81318 }
81319
81320 /*
81321 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81322 index ec274e0..e678159 100644
81323 --- a/include/linux/genhd.h
81324 +++ b/include/linux/genhd.h
81325 @@ -194,7 +194,7 @@ struct gendisk {
81326 struct kobject *slave_dir;
81327
81328 struct timer_rand_state *random;
81329 - atomic_t sync_io; /* RAID */
81330 + atomic_unchecked_t sync_io; /* RAID */
81331 struct disk_events *ev;
81332 #ifdef CONFIG_BLK_DEV_INTEGRITY
81333 struct blk_integrity *integrity;
81334 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81335 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81336
81337 /* drivers/char/random.c */
81338 -extern void add_disk_randomness(struct gendisk *disk);
81339 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81340 extern void rand_initialize_disk(struct gendisk *disk);
81341
81342 static inline sector_t get_start_sect(struct block_device *bdev)
81343 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81344 index 667c311..abac2a7 100644
81345 --- a/include/linux/genl_magic_func.h
81346 +++ b/include/linux/genl_magic_func.h
81347 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81348 },
81349
81350 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81351 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81352 +static struct genl_ops ZZZ_genl_ops[] = {
81353 #include GENL_MAGIC_INCLUDE_FILE
81354 };
81355
81356 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81357 index 41b30fd..a3718cf 100644
81358 --- a/include/linux/gfp.h
81359 +++ b/include/linux/gfp.h
81360 @@ -34,6 +34,13 @@ struct vm_area_struct;
81361 #define ___GFP_NO_KSWAPD 0x400000u
81362 #define ___GFP_OTHER_NODE 0x800000u
81363 #define ___GFP_WRITE 0x1000000u
81364 +
81365 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81366 +#define ___GFP_USERCOPY 0x2000000u
81367 +#else
81368 +#define ___GFP_USERCOPY 0
81369 +#endif
81370 +
81371 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81372
81373 /*
81374 @@ -90,6 +97,7 @@ struct vm_area_struct;
81375 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81376 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81377 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81378 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81379
81380 /*
81381 * This may seem redundant, but it's a way of annotating false positives vs.
81382 @@ -97,7 +105,7 @@ struct vm_area_struct;
81383 */
81384 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81385
81386 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81387 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81388 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81389
81390 /* This equals 0, but use constants in case they ever change */
81391 @@ -155,6 +163,8 @@ struct vm_area_struct;
81392 /* 4GB DMA on some platforms */
81393 #define GFP_DMA32 __GFP_DMA32
81394
81395 +#define GFP_USERCOPY __GFP_USERCOPY
81396 +
81397 /* Convert GFP flags to their corresponding migrate type */
81398 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81399 {
81400 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81401 new file mode 100644
81402 index 0000000..edb2cb6
81403 --- /dev/null
81404 +++ b/include/linux/gracl.h
81405 @@ -0,0 +1,340 @@
81406 +#ifndef GR_ACL_H
81407 +#define GR_ACL_H
81408 +
81409 +#include <linux/grdefs.h>
81410 +#include <linux/resource.h>
81411 +#include <linux/capability.h>
81412 +#include <linux/dcache.h>
81413 +#include <asm/resource.h>
81414 +
81415 +/* Major status information */
81416 +
81417 +#define GR_VERSION "grsecurity 3.0"
81418 +#define GRSECURITY_VERSION 0x3000
81419 +
81420 +enum {
81421 + GR_SHUTDOWN = 0,
81422 + GR_ENABLE = 1,
81423 + GR_SPROLE = 2,
81424 + GR_OLDRELOAD = 3,
81425 + GR_SEGVMOD = 4,
81426 + GR_STATUS = 5,
81427 + GR_UNSPROLE = 6,
81428 + GR_PASSSET = 7,
81429 + GR_SPROLEPAM = 8,
81430 + GR_RELOAD = 9,
81431 +};
81432 +
81433 +/* Password setup definitions
81434 + * kernel/grhash.c */
81435 +enum {
81436 + GR_PW_LEN = 128,
81437 + GR_SALT_LEN = 16,
81438 + GR_SHA_LEN = 32,
81439 +};
81440 +
81441 +enum {
81442 + GR_SPROLE_LEN = 64,
81443 +};
81444 +
81445 +enum {
81446 + GR_NO_GLOB = 0,
81447 + GR_REG_GLOB,
81448 + GR_CREATE_GLOB
81449 +};
81450 +
81451 +#define GR_NLIMITS 32
81452 +
81453 +/* Begin Data Structures */
81454 +
81455 +struct sprole_pw {
81456 + unsigned char *rolename;
81457 + unsigned char salt[GR_SALT_LEN];
81458 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81459 +};
81460 +
81461 +struct name_entry {
81462 + __u32 key;
81463 + ino_t inode;
81464 + dev_t device;
81465 + char *name;
81466 + __u16 len;
81467 + __u8 deleted;
81468 + struct name_entry *prev;
81469 + struct name_entry *next;
81470 +};
81471 +
81472 +struct inodev_entry {
81473 + struct name_entry *nentry;
81474 + struct inodev_entry *prev;
81475 + struct inodev_entry *next;
81476 +};
81477 +
81478 +struct acl_role_db {
81479 + struct acl_role_label **r_hash;
81480 + __u32 r_size;
81481 +};
81482 +
81483 +struct inodev_db {
81484 + struct inodev_entry **i_hash;
81485 + __u32 i_size;
81486 +};
81487 +
81488 +struct name_db {
81489 + struct name_entry **n_hash;
81490 + __u32 n_size;
81491 +};
81492 +
81493 +struct crash_uid {
81494 + uid_t uid;
81495 + unsigned long expires;
81496 +};
81497 +
81498 +struct gr_hash_struct {
81499 + void **table;
81500 + void **nametable;
81501 + void *first;
81502 + __u32 table_size;
81503 + __u32 used_size;
81504 + int type;
81505 +};
81506 +
81507 +/* Userspace Grsecurity ACL data structures */
81508 +
81509 +struct acl_subject_label {
81510 + char *filename;
81511 + ino_t inode;
81512 + dev_t device;
81513 + __u32 mode;
81514 + kernel_cap_t cap_mask;
81515 + kernel_cap_t cap_lower;
81516 + kernel_cap_t cap_invert_audit;
81517 +
81518 + struct rlimit res[GR_NLIMITS];
81519 + __u32 resmask;
81520 +
81521 + __u8 user_trans_type;
81522 + __u8 group_trans_type;
81523 + uid_t *user_transitions;
81524 + gid_t *group_transitions;
81525 + __u16 user_trans_num;
81526 + __u16 group_trans_num;
81527 +
81528 + __u32 sock_families[2];
81529 + __u32 ip_proto[8];
81530 + __u32 ip_type;
81531 + struct acl_ip_label **ips;
81532 + __u32 ip_num;
81533 + __u32 inaddr_any_override;
81534 +
81535 + __u32 crashes;
81536 + unsigned long expires;
81537 +
81538 + struct acl_subject_label *parent_subject;
81539 + struct gr_hash_struct *hash;
81540 + struct acl_subject_label *prev;
81541 + struct acl_subject_label *next;
81542 +
81543 + struct acl_object_label **obj_hash;
81544 + __u32 obj_hash_size;
81545 + __u16 pax_flags;
81546 +};
81547 +
81548 +struct role_allowed_ip {
81549 + __u32 addr;
81550 + __u32 netmask;
81551 +
81552 + struct role_allowed_ip *prev;
81553 + struct role_allowed_ip *next;
81554 +};
81555 +
81556 +struct role_transition {
81557 + char *rolename;
81558 +
81559 + struct role_transition *prev;
81560 + struct role_transition *next;
81561 +};
81562 +
81563 +struct acl_role_label {
81564 + char *rolename;
81565 + uid_t uidgid;
81566 + __u16 roletype;
81567 +
81568 + __u16 auth_attempts;
81569 + unsigned long expires;
81570 +
81571 + struct acl_subject_label *root_label;
81572 + struct gr_hash_struct *hash;
81573 +
81574 + struct acl_role_label *prev;
81575 + struct acl_role_label *next;
81576 +
81577 + struct role_transition *transitions;
81578 + struct role_allowed_ip *allowed_ips;
81579 + uid_t *domain_children;
81580 + __u16 domain_child_num;
81581 +
81582 + umode_t umask;
81583 +
81584 + struct acl_subject_label **subj_hash;
81585 + __u32 subj_hash_size;
81586 +};
81587 +
81588 +struct user_acl_role_db {
81589 + struct acl_role_label **r_table;
81590 + __u32 num_pointers; /* Number of allocations to track */
81591 + __u32 num_roles; /* Number of roles */
81592 + __u32 num_domain_children; /* Number of domain children */
81593 + __u32 num_subjects; /* Number of subjects */
81594 + __u32 num_objects; /* Number of objects */
81595 +};
81596 +
81597 +struct acl_object_label {
81598 + char *filename;
81599 + ino_t inode;
81600 + dev_t device;
81601 + __u32 mode;
81602 +
81603 + struct acl_subject_label *nested;
81604 + struct acl_object_label *globbed;
81605 +
81606 + /* next two structures not used */
81607 +
81608 + struct acl_object_label *prev;
81609 + struct acl_object_label *next;
81610 +};
81611 +
81612 +struct acl_ip_label {
81613 + char *iface;
81614 + __u32 addr;
81615 + __u32 netmask;
81616 + __u16 low, high;
81617 + __u8 mode;
81618 + __u32 type;
81619 + __u32 proto[8];
81620 +
81621 + /* next two structures not used */
81622 +
81623 + struct acl_ip_label *prev;
81624 + struct acl_ip_label *next;
81625 +};
81626 +
81627 +struct gr_arg {
81628 + struct user_acl_role_db role_db;
81629 + unsigned char pw[GR_PW_LEN];
81630 + unsigned char salt[GR_SALT_LEN];
81631 + unsigned char sum[GR_SHA_LEN];
81632 + unsigned char sp_role[GR_SPROLE_LEN];
81633 + struct sprole_pw *sprole_pws;
81634 + dev_t segv_device;
81635 + ino_t segv_inode;
81636 + uid_t segv_uid;
81637 + __u16 num_sprole_pws;
81638 + __u16 mode;
81639 +};
81640 +
81641 +struct gr_arg_wrapper {
81642 + struct gr_arg *arg;
81643 + __u32 version;
81644 + __u32 size;
81645 +};
81646 +
81647 +struct subject_map {
81648 + struct acl_subject_label *user;
81649 + struct acl_subject_label *kernel;
81650 + struct subject_map *prev;
81651 + struct subject_map *next;
81652 +};
81653 +
81654 +struct acl_subj_map_db {
81655 + struct subject_map **s_hash;
81656 + __u32 s_size;
81657 +};
81658 +
81659 +struct gr_policy_state {
81660 + struct sprole_pw **acl_special_roles;
81661 + __u16 num_sprole_pws;
81662 + struct acl_role_label *kernel_role;
81663 + struct acl_role_label *role_list;
81664 + struct acl_role_label *default_role;
81665 + struct acl_role_db acl_role_set;
81666 + struct acl_subj_map_db subj_map_set;
81667 + struct name_db name_set;
81668 + struct inodev_db inodev_set;
81669 +};
81670 +
81671 +struct gr_alloc_state {
81672 + unsigned long alloc_stack_next;
81673 + unsigned long alloc_stack_size;
81674 + void **alloc_stack;
81675 +};
81676 +
81677 +struct gr_reload_state {
81678 + struct gr_policy_state oldpolicy;
81679 + struct gr_alloc_state oldalloc;
81680 + struct gr_policy_state newpolicy;
81681 + struct gr_alloc_state newalloc;
81682 + struct gr_policy_state *oldpolicy_ptr;
81683 + struct gr_alloc_state *oldalloc_ptr;
81684 + unsigned char oldmode;
81685 +};
81686 +
81687 +/* End Data Structures Section */
81688 +
81689 +/* Hash functions generated by empirical testing by Brad Spengler
81690 + Makes good use of the low bits of the inode. Generally 0-1 times
81691 + in loop for successful match. 0-3 for unsuccessful match.
81692 + Shift/add algorithm with modulus of table size and an XOR*/
81693 +
81694 +static __inline__ unsigned int
81695 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81696 +{
81697 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81698 +}
81699 +
81700 + static __inline__ unsigned int
81701 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81702 +{
81703 + return ((const unsigned long)userp % sz);
81704 +}
81705 +
81706 +static __inline__ unsigned int
81707 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81708 +{
81709 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81710 +}
81711 +
81712 +static __inline__ unsigned int
81713 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81714 +{
81715 + return full_name_hash((const unsigned char *)name, len) % sz;
81716 +}
81717 +
81718 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81719 + subj = NULL; \
81720 + iter = 0; \
81721 + while (iter < role->subj_hash_size) { \
81722 + if (subj == NULL) \
81723 + subj = role->subj_hash[iter]; \
81724 + if (subj == NULL) { \
81725 + iter++; \
81726 + continue; \
81727 + }
81728 +
81729 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81730 + subj = subj->next; \
81731 + if (subj == NULL) \
81732 + iter++; \
81733 + }
81734 +
81735 +
81736 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81737 + subj = role->hash->first; \
81738 + while (subj != NULL) {
81739 +
81740 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81741 + subj = subj->next; \
81742 + }
81743 +
81744 +#endif
81745 +
81746 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81747 new file mode 100644
81748 index 0000000..33ebd1f
81749 --- /dev/null
81750 +++ b/include/linux/gracl_compat.h
81751 @@ -0,0 +1,156 @@
81752 +#ifndef GR_ACL_COMPAT_H
81753 +#define GR_ACL_COMPAT_H
81754 +
81755 +#include <linux/resource.h>
81756 +#include <asm/resource.h>
81757 +
81758 +struct sprole_pw_compat {
81759 + compat_uptr_t rolename;
81760 + unsigned char salt[GR_SALT_LEN];
81761 + unsigned char sum[GR_SHA_LEN];
81762 +};
81763 +
81764 +struct gr_hash_struct_compat {
81765 + compat_uptr_t table;
81766 + compat_uptr_t nametable;
81767 + compat_uptr_t first;
81768 + __u32 table_size;
81769 + __u32 used_size;
81770 + int type;
81771 +};
81772 +
81773 +struct acl_subject_label_compat {
81774 + compat_uptr_t filename;
81775 + compat_ino_t inode;
81776 + __u32 device;
81777 + __u32 mode;
81778 + kernel_cap_t cap_mask;
81779 + kernel_cap_t cap_lower;
81780 + kernel_cap_t cap_invert_audit;
81781 +
81782 + struct compat_rlimit res[GR_NLIMITS];
81783 + __u32 resmask;
81784 +
81785 + __u8 user_trans_type;
81786 + __u8 group_trans_type;
81787 + compat_uptr_t user_transitions;
81788 + compat_uptr_t group_transitions;
81789 + __u16 user_trans_num;
81790 + __u16 group_trans_num;
81791 +
81792 + __u32 sock_families[2];
81793 + __u32 ip_proto[8];
81794 + __u32 ip_type;
81795 + compat_uptr_t ips;
81796 + __u32 ip_num;
81797 + __u32 inaddr_any_override;
81798 +
81799 + __u32 crashes;
81800 + compat_ulong_t expires;
81801 +
81802 + compat_uptr_t parent_subject;
81803 + compat_uptr_t hash;
81804 + compat_uptr_t prev;
81805 + compat_uptr_t next;
81806 +
81807 + compat_uptr_t obj_hash;
81808 + __u32 obj_hash_size;
81809 + __u16 pax_flags;
81810 +};
81811 +
81812 +struct role_allowed_ip_compat {
81813 + __u32 addr;
81814 + __u32 netmask;
81815 +
81816 + compat_uptr_t prev;
81817 + compat_uptr_t next;
81818 +};
81819 +
81820 +struct role_transition_compat {
81821 + compat_uptr_t rolename;
81822 +
81823 + compat_uptr_t prev;
81824 + compat_uptr_t next;
81825 +};
81826 +
81827 +struct acl_role_label_compat {
81828 + compat_uptr_t rolename;
81829 + uid_t uidgid;
81830 + __u16 roletype;
81831 +
81832 + __u16 auth_attempts;
81833 + compat_ulong_t expires;
81834 +
81835 + compat_uptr_t root_label;
81836 + compat_uptr_t hash;
81837 +
81838 + compat_uptr_t prev;
81839 + compat_uptr_t next;
81840 +
81841 + compat_uptr_t transitions;
81842 + compat_uptr_t allowed_ips;
81843 + compat_uptr_t domain_children;
81844 + __u16 domain_child_num;
81845 +
81846 + umode_t umask;
81847 +
81848 + compat_uptr_t subj_hash;
81849 + __u32 subj_hash_size;
81850 +};
81851 +
81852 +struct user_acl_role_db_compat {
81853 + compat_uptr_t r_table;
81854 + __u32 num_pointers;
81855 + __u32 num_roles;
81856 + __u32 num_domain_children;
81857 + __u32 num_subjects;
81858 + __u32 num_objects;
81859 +};
81860 +
81861 +struct acl_object_label_compat {
81862 + compat_uptr_t filename;
81863 + compat_ino_t inode;
81864 + __u32 device;
81865 + __u32 mode;
81866 +
81867 + compat_uptr_t nested;
81868 + compat_uptr_t globbed;
81869 +
81870 + compat_uptr_t prev;
81871 + compat_uptr_t next;
81872 +};
81873 +
81874 +struct acl_ip_label_compat {
81875 + compat_uptr_t iface;
81876 + __u32 addr;
81877 + __u32 netmask;
81878 + __u16 low, high;
81879 + __u8 mode;
81880 + __u32 type;
81881 + __u32 proto[8];
81882 +
81883 + compat_uptr_t prev;
81884 + compat_uptr_t next;
81885 +};
81886 +
81887 +struct gr_arg_compat {
81888 + struct user_acl_role_db_compat role_db;
81889 + unsigned char pw[GR_PW_LEN];
81890 + unsigned char salt[GR_SALT_LEN];
81891 + unsigned char sum[GR_SHA_LEN];
81892 + unsigned char sp_role[GR_SPROLE_LEN];
81893 + compat_uptr_t sprole_pws;
81894 + __u32 segv_device;
81895 + compat_ino_t segv_inode;
81896 + uid_t segv_uid;
81897 + __u16 num_sprole_pws;
81898 + __u16 mode;
81899 +};
81900 +
81901 +struct gr_arg_wrapper_compat {
81902 + compat_uptr_t arg;
81903 + __u32 version;
81904 + __u32 size;
81905 +};
81906 +
81907 +#endif
81908 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81909 new file mode 100644
81910 index 0000000..323ecf2
81911 --- /dev/null
81912 +++ b/include/linux/gralloc.h
81913 @@ -0,0 +1,9 @@
81914 +#ifndef __GRALLOC_H
81915 +#define __GRALLOC_H
81916 +
81917 +void acl_free_all(void);
81918 +int acl_alloc_stack_init(unsigned long size);
81919 +void *acl_alloc(unsigned long len);
81920 +void *acl_alloc_num(unsigned long num, unsigned long len);
81921 +
81922 +#endif
81923 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81924 new file mode 100644
81925 index 0000000..be66033
81926 --- /dev/null
81927 +++ b/include/linux/grdefs.h
81928 @@ -0,0 +1,140 @@
81929 +#ifndef GRDEFS_H
81930 +#define GRDEFS_H
81931 +
81932 +/* Begin grsecurity status declarations */
81933 +
81934 +enum {
81935 + GR_READY = 0x01,
81936 + GR_STATUS_INIT = 0x00 // disabled state
81937 +};
81938 +
81939 +/* Begin ACL declarations */
81940 +
81941 +/* Role flags */
81942 +
81943 +enum {
81944 + GR_ROLE_USER = 0x0001,
81945 + GR_ROLE_GROUP = 0x0002,
81946 + GR_ROLE_DEFAULT = 0x0004,
81947 + GR_ROLE_SPECIAL = 0x0008,
81948 + GR_ROLE_AUTH = 0x0010,
81949 + GR_ROLE_NOPW = 0x0020,
81950 + GR_ROLE_GOD = 0x0040,
81951 + GR_ROLE_LEARN = 0x0080,
81952 + GR_ROLE_TPE = 0x0100,
81953 + GR_ROLE_DOMAIN = 0x0200,
81954 + GR_ROLE_PAM = 0x0400,
81955 + GR_ROLE_PERSIST = 0x0800
81956 +};
81957 +
81958 +/* ACL Subject and Object mode flags */
81959 +enum {
81960 + GR_DELETED = 0x80000000
81961 +};
81962 +
81963 +/* ACL Object-only mode flags */
81964 +enum {
81965 + GR_READ = 0x00000001,
81966 + GR_APPEND = 0x00000002,
81967 + GR_WRITE = 0x00000004,
81968 + GR_EXEC = 0x00000008,
81969 + GR_FIND = 0x00000010,
81970 + GR_INHERIT = 0x00000020,
81971 + GR_SETID = 0x00000040,
81972 + GR_CREATE = 0x00000080,
81973 + GR_DELETE = 0x00000100,
81974 + GR_LINK = 0x00000200,
81975 + GR_AUDIT_READ = 0x00000400,
81976 + GR_AUDIT_APPEND = 0x00000800,
81977 + GR_AUDIT_WRITE = 0x00001000,
81978 + GR_AUDIT_EXEC = 0x00002000,
81979 + GR_AUDIT_FIND = 0x00004000,
81980 + GR_AUDIT_INHERIT= 0x00008000,
81981 + GR_AUDIT_SETID = 0x00010000,
81982 + GR_AUDIT_CREATE = 0x00020000,
81983 + GR_AUDIT_DELETE = 0x00040000,
81984 + GR_AUDIT_LINK = 0x00080000,
81985 + GR_PTRACERD = 0x00100000,
81986 + GR_NOPTRACE = 0x00200000,
81987 + GR_SUPPRESS = 0x00400000,
81988 + GR_NOLEARN = 0x00800000,
81989 + GR_INIT_TRANSFER= 0x01000000
81990 +};
81991 +
81992 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81993 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81994 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81995 +
81996 +/* ACL subject-only mode flags */
81997 +enum {
81998 + GR_KILL = 0x00000001,
81999 + GR_VIEW = 0x00000002,
82000 + GR_PROTECTED = 0x00000004,
82001 + GR_LEARN = 0x00000008,
82002 + GR_OVERRIDE = 0x00000010,
82003 + /* just a placeholder, this mode is only used in userspace */
82004 + GR_DUMMY = 0x00000020,
82005 + GR_PROTSHM = 0x00000040,
82006 + GR_KILLPROC = 0x00000080,
82007 + GR_KILLIPPROC = 0x00000100,
82008 + /* just a placeholder, this mode is only used in userspace */
82009 + GR_NOTROJAN = 0x00000200,
82010 + GR_PROTPROCFD = 0x00000400,
82011 + GR_PROCACCT = 0x00000800,
82012 + GR_RELAXPTRACE = 0x00001000,
82013 + //GR_NESTED = 0x00002000,
82014 + GR_INHERITLEARN = 0x00004000,
82015 + GR_PROCFIND = 0x00008000,
82016 + GR_POVERRIDE = 0x00010000,
82017 + GR_KERNELAUTH = 0x00020000,
82018 + GR_ATSECURE = 0x00040000,
82019 + GR_SHMEXEC = 0x00080000
82020 +};
82021 +
82022 +enum {
82023 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82024 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82025 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82026 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82027 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82028 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82029 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82030 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82031 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82032 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82033 +};
82034 +
82035 +enum {
82036 + GR_ID_USER = 0x01,
82037 + GR_ID_GROUP = 0x02,
82038 +};
82039 +
82040 +enum {
82041 + GR_ID_ALLOW = 0x01,
82042 + GR_ID_DENY = 0x02,
82043 +};
82044 +
82045 +#define GR_CRASH_RES 31
82046 +#define GR_UIDTABLE_MAX 500
82047 +
82048 +/* begin resource learning section */
82049 +enum {
82050 + GR_RLIM_CPU_BUMP = 60,
82051 + GR_RLIM_FSIZE_BUMP = 50000,
82052 + GR_RLIM_DATA_BUMP = 10000,
82053 + GR_RLIM_STACK_BUMP = 1000,
82054 + GR_RLIM_CORE_BUMP = 10000,
82055 + GR_RLIM_RSS_BUMP = 500000,
82056 + GR_RLIM_NPROC_BUMP = 1,
82057 + GR_RLIM_NOFILE_BUMP = 5,
82058 + GR_RLIM_MEMLOCK_BUMP = 50000,
82059 + GR_RLIM_AS_BUMP = 500000,
82060 + GR_RLIM_LOCKS_BUMP = 2,
82061 + GR_RLIM_SIGPENDING_BUMP = 5,
82062 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82063 + GR_RLIM_NICE_BUMP = 1,
82064 + GR_RLIM_RTPRIO_BUMP = 1,
82065 + GR_RLIM_RTTIME_BUMP = 1000000
82066 +};
82067 +
82068 +#endif
82069 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82070 new file mode 100644
82071 index 0000000..fb1de5d
82072 --- /dev/null
82073 +++ b/include/linux/grinternal.h
82074 @@ -0,0 +1,230 @@
82075 +#ifndef __GRINTERNAL_H
82076 +#define __GRINTERNAL_H
82077 +
82078 +#ifdef CONFIG_GRKERNSEC
82079 +
82080 +#include <linux/fs.h>
82081 +#include <linux/mnt_namespace.h>
82082 +#include <linux/nsproxy.h>
82083 +#include <linux/gracl.h>
82084 +#include <linux/grdefs.h>
82085 +#include <linux/grmsg.h>
82086 +
82087 +void gr_add_learn_entry(const char *fmt, ...)
82088 + __attribute__ ((format (printf, 1, 2)));
82089 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82090 + const struct vfsmount *mnt);
82091 +__u32 gr_check_create(const struct dentry *new_dentry,
82092 + const struct dentry *parent,
82093 + const struct vfsmount *mnt, const __u32 mode);
82094 +int gr_check_protected_task(const struct task_struct *task);
82095 +__u32 to_gr_audit(const __u32 reqmode);
82096 +int gr_set_acls(const int type);
82097 +int gr_acl_is_enabled(void);
82098 +char gr_roletype_to_char(void);
82099 +
82100 +void gr_handle_alertkill(struct task_struct *task);
82101 +char *gr_to_filename(const struct dentry *dentry,
82102 + const struct vfsmount *mnt);
82103 +char *gr_to_filename1(const struct dentry *dentry,
82104 + const struct vfsmount *mnt);
82105 +char *gr_to_filename2(const struct dentry *dentry,
82106 + const struct vfsmount *mnt);
82107 +char *gr_to_filename3(const struct dentry *dentry,
82108 + const struct vfsmount *mnt);
82109 +
82110 +extern int grsec_enable_ptrace_readexec;
82111 +extern int grsec_enable_harden_ptrace;
82112 +extern int grsec_enable_link;
82113 +extern int grsec_enable_fifo;
82114 +extern int grsec_enable_execve;
82115 +extern int grsec_enable_shm;
82116 +extern int grsec_enable_execlog;
82117 +extern int grsec_enable_signal;
82118 +extern int grsec_enable_audit_ptrace;
82119 +extern int grsec_enable_forkfail;
82120 +extern int grsec_enable_time;
82121 +extern int grsec_enable_rofs;
82122 +extern int grsec_deny_new_usb;
82123 +extern int grsec_enable_chroot_shmat;
82124 +extern int grsec_enable_chroot_mount;
82125 +extern int grsec_enable_chroot_double;
82126 +extern int grsec_enable_chroot_pivot;
82127 +extern int grsec_enable_chroot_chdir;
82128 +extern int grsec_enable_chroot_chmod;
82129 +extern int grsec_enable_chroot_mknod;
82130 +extern int grsec_enable_chroot_fchdir;
82131 +extern int grsec_enable_chroot_nice;
82132 +extern int grsec_enable_chroot_execlog;
82133 +extern int grsec_enable_chroot_caps;
82134 +extern int grsec_enable_chroot_rename;
82135 +extern int grsec_enable_chroot_sysctl;
82136 +extern int grsec_enable_chroot_unix;
82137 +extern int grsec_enable_symlinkown;
82138 +extern kgid_t grsec_symlinkown_gid;
82139 +extern int grsec_enable_tpe;
82140 +extern kgid_t grsec_tpe_gid;
82141 +extern int grsec_enable_tpe_all;
82142 +extern int grsec_enable_tpe_invert;
82143 +extern int grsec_enable_socket_all;
82144 +extern kgid_t grsec_socket_all_gid;
82145 +extern int grsec_enable_socket_client;
82146 +extern kgid_t grsec_socket_client_gid;
82147 +extern int grsec_enable_socket_server;
82148 +extern kgid_t grsec_socket_server_gid;
82149 +extern kgid_t grsec_audit_gid;
82150 +extern int grsec_enable_group;
82151 +extern int grsec_enable_log_rwxmaps;
82152 +extern int grsec_enable_mount;
82153 +extern int grsec_enable_chdir;
82154 +extern int grsec_resource_logging;
82155 +extern int grsec_enable_blackhole;
82156 +extern int grsec_lastack_retries;
82157 +extern int grsec_enable_brute;
82158 +extern int grsec_enable_harden_ipc;
82159 +extern int grsec_lock;
82160 +
82161 +extern spinlock_t grsec_alert_lock;
82162 +extern unsigned long grsec_alert_wtime;
82163 +extern unsigned long grsec_alert_fyet;
82164 +
82165 +extern spinlock_t grsec_audit_lock;
82166 +
82167 +extern rwlock_t grsec_exec_file_lock;
82168 +
82169 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82170 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82171 + (tsk)->exec_file->f_path.mnt) : "/")
82172 +
82173 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82174 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82175 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82176 +
82177 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82178 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82179 + (tsk)->exec_file->f_path.mnt) : "/")
82180 +
82181 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82182 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82183 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82184 +
82185 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82186 +
82187 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82188 +
82189 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82190 +{
82191 + if (file1 && file2) {
82192 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82193 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82194 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82195 + return true;
82196 + }
82197 +
82198 + return false;
82199 +}
82200 +
82201 +#define GR_CHROOT_CAPS {{ \
82202 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82203 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82204 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82205 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82206 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82207 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82208 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82209 +
82210 +#define security_learn(normal_msg,args...) \
82211 +({ \
82212 + read_lock(&grsec_exec_file_lock); \
82213 + gr_add_learn_entry(normal_msg "\n", ## args); \
82214 + read_unlock(&grsec_exec_file_lock); \
82215 +})
82216 +
82217 +enum {
82218 + GR_DO_AUDIT,
82219 + GR_DONT_AUDIT,
82220 + /* used for non-audit messages that we shouldn't kill the task on */
82221 + GR_DONT_AUDIT_GOOD
82222 +};
82223 +
82224 +enum {
82225 + GR_TTYSNIFF,
82226 + GR_RBAC,
82227 + GR_RBAC_STR,
82228 + GR_STR_RBAC,
82229 + GR_RBAC_MODE2,
82230 + GR_RBAC_MODE3,
82231 + GR_FILENAME,
82232 + GR_SYSCTL_HIDDEN,
82233 + GR_NOARGS,
82234 + GR_ONE_INT,
82235 + GR_ONE_INT_TWO_STR,
82236 + GR_ONE_STR,
82237 + GR_STR_INT,
82238 + GR_TWO_STR_INT,
82239 + GR_TWO_INT,
82240 + GR_TWO_U64,
82241 + GR_THREE_INT,
82242 + GR_FIVE_INT_TWO_STR,
82243 + GR_TWO_STR,
82244 + GR_THREE_STR,
82245 + GR_FOUR_STR,
82246 + GR_STR_FILENAME,
82247 + GR_FILENAME_STR,
82248 + GR_FILENAME_TWO_INT,
82249 + GR_FILENAME_TWO_INT_STR,
82250 + GR_TEXTREL,
82251 + GR_PTRACE,
82252 + GR_RESOURCE,
82253 + GR_CAP,
82254 + GR_SIG,
82255 + GR_SIG2,
82256 + GR_CRASH1,
82257 + GR_CRASH2,
82258 + GR_PSACCT,
82259 + GR_RWXMAP,
82260 + GR_RWXMAPVMA
82261 +};
82262 +
82263 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82264 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82265 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82266 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82267 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82268 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82269 +#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)
82270 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82271 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82272 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82273 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82274 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82275 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82276 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82277 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82278 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82279 +#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)
82280 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82281 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82282 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82283 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82284 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82285 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82286 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82287 +#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)
82288 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82289 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82290 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82291 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82292 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82293 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82294 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82295 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82296 +#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)
82297 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82298 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82299 +
82300 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82301 +
82302 +#endif
82303 +
82304 +#endif
82305 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82306 new file mode 100644
82307 index 0000000..26ef560
82308 --- /dev/null
82309 +++ b/include/linux/grmsg.h
82310 @@ -0,0 +1,118 @@
82311 +#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"
82312 +#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"
82313 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82314 +#define GR_STOPMOD_MSG "denied modification of module state by "
82315 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82316 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82317 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82318 +#define GR_IOPL_MSG "denied use of iopl() by "
82319 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82320 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82321 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82322 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82323 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82324 +#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"
82325 +#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"
82326 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82327 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82328 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82329 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82330 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82331 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82332 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82333 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82334 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82335 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82336 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82337 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82338 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82339 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82340 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82341 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82342 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82343 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82344 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82345 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82346 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82347 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82348 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82349 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82350 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82351 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82352 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82353 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82354 +#define GR_CHROOT_RENAME_MSG "denied bad rename of %.950s out of a chroot by "
82355 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82356 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82357 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82358 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82359 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82360 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82361 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82362 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82363 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82364 +#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"
82365 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82366 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82367 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82368 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82369 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82370 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82371 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82372 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82373 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82374 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82375 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82376 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82377 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82378 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82379 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82380 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82381 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82382 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82383 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82384 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82385 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82386 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82387 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82388 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82389 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82390 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82391 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82392 +#define GR_TIME_MSG "time set by "
82393 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82394 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82395 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82396 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82397 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82398 +#define GR_BIND_MSG "denied bind() by "
82399 +#define GR_CONNECT_MSG "denied connect() by "
82400 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82401 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82402 +#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"
82403 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82404 +#define GR_CAP_ACL_MSG "use of %s denied for "
82405 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82406 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82407 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82408 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82409 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82410 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82411 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82412 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82413 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82414 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82415 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82416 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82417 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82418 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82419 +#define GR_VM86_MSG "denied use of vm86 by "
82420 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82421 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82422 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82423 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82424 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82425 +#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 "
82426 +#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 "
82427 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82428 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82429 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82430 new file mode 100644
82431 index 0000000..6c76fcb
82432 --- /dev/null
82433 +++ b/include/linux/grsecurity.h
82434 @@ -0,0 +1,249 @@
82435 +#ifndef GR_SECURITY_H
82436 +#define GR_SECURITY_H
82437 +#include <linux/fs.h>
82438 +#include <linux/fs_struct.h>
82439 +#include <linux/binfmts.h>
82440 +#include <linux/gracl.h>
82441 +
82442 +/* notify of brain-dead configs */
82443 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82444 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82445 +#endif
82446 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82447 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82448 +#endif
82449 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82450 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82451 +#endif
82452 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82453 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82454 +#endif
82455 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82456 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82457 +#endif
82458 +
82459 +int gr_handle_new_usb(void);
82460 +
82461 +void gr_handle_brute_attach(int dumpable);
82462 +void gr_handle_brute_check(void);
82463 +void gr_handle_kernel_exploit(void);
82464 +
82465 +char gr_roletype_to_char(void);
82466 +
82467 +int gr_proc_is_restricted(void);
82468 +
82469 +int gr_acl_enable_at_secure(void);
82470 +
82471 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82472 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82473 +
82474 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82475 +
82476 +void gr_del_task_from_ip_table(struct task_struct *p);
82477 +
82478 +int gr_pid_is_chrooted(struct task_struct *p);
82479 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82480 +int gr_handle_chroot_nice(void);
82481 +int gr_handle_chroot_sysctl(const int op);
82482 +int gr_handle_chroot_setpriority(struct task_struct *p,
82483 + const int niceval);
82484 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82485 +int gr_chroot_fhandle(void);
82486 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82487 + const struct vfsmount *mnt);
82488 +void gr_handle_chroot_chdir(const struct path *path);
82489 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82490 + const struct vfsmount *mnt, const int mode);
82491 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82492 + const struct vfsmount *mnt, const int mode);
82493 +int gr_handle_chroot_mount(const struct dentry *dentry,
82494 + const struct vfsmount *mnt,
82495 + const char *dev_name);
82496 +int gr_handle_chroot_pivot(void);
82497 +int gr_handle_chroot_unix(const pid_t pid);
82498 +
82499 +int gr_handle_rawio(const struct inode *inode);
82500 +
82501 +void gr_handle_ioperm(void);
82502 +void gr_handle_iopl(void);
82503 +void gr_handle_msr_write(void);
82504 +
82505 +umode_t gr_acl_umask(void);
82506 +
82507 +int gr_tpe_allow(const struct file *file);
82508 +
82509 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82510 +void gr_clear_chroot_entries(struct task_struct *task);
82511 +
82512 +void gr_log_forkfail(const int retval);
82513 +void gr_log_timechange(void);
82514 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82515 +void gr_log_chdir(const struct dentry *dentry,
82516 + const struct vfsmount *mnt);
82517 +void gr_log_chroot_exec(const struct dentry *dentry,
82518 + const struct vfsmount *mnt);
82519 +void gr_log_remount(const char *devname, const int retval);
82520 +void gr_log_unmount(const char *devname, const int retval);
82521 +void gr_log_mount(const char *from, struct path *to, const int retval);
82522 +void gr_log_textrel(struct vm_area_struct *vma);
82523 +void gr_log_ptgnustack(struct file *file);
82524 +void gr_log_rwxmmap(struct file *file);
82525 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82526 +
82527 +int gr_handle_follow_link(const struct inode *parent,
82528 + const struct inode *inode,
82529 + const struct dentry *dentry,
82530 + const struct vfsmount *mnt);
82531 +int gr_handle_fifo(const struct dentry *dentry,
82532 + const struct vfsmount *mnt,
82533 + const struct dentry *dir, const int flag,
82534 + const int acc_mode);
82535 +int gr_handle_hardlink(const struct dentry *dentry,
82536 + const struct vfsmount *mnt,
82537 + struct inode *inode,
82538 + const int mode, const struct filename *to);
82539 +
82540 +int gr_is_capable(const int cap);
82541 +int gr_is_capable_nolog(const int cap);
82542 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82543 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82544 +
82545 +void gr_copy_label(struct task_struct *tsk);
82546 +void gr_handle_crash(struct task_struct *task, const int sig);
82547 +int gr_handle_signal(const struct task_struct *p, const int sig);
82548 +int gr_check_crash_uid(const kuid_t uid);
82549 +int gr_check_protected_task(const struct task_struct *task);
82550 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82551 +int gr_acl_handle_mmap(const struct file *file,
82552 + const unsigned long prot);
82553 +int gr_acl_handle_mprotect(const struct file *file,
82554 + const unsigned long prot);
82555 +int gr_check_hidden_task(const struct task_struct *tsk);
82556 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82557 + const struct vfsmount *mnt);
82558 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82559 + const struct vfsmount *mnt);
82560 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82561 + const struct vfsmount *mnt, const int fmode);
82562 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82563 + const struct vfsmount *mnt, umode_t *mode);
82564 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82565 + const struct vfsmount *mnt);
82566 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82567 + const struct vfsmount *mnt);
82568 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82569 + const struct vfsmount *mnt);
82570 +int gr_handle_ptrace(struct task_struct *task, const long request);
82571 +int gr_handle_proc_ptrace(struct task_struct *task);
82572 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82573 + const struct vfsmount *mnt);
82574 +int gr_check_crash_exec(const struct file *filp);
82575 +int gr_acl_is_enabled(void);
82576 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82577 + const kgid_t gid);
82578 +int gr_set_proc_label(const struct dentry *dentry,
82579 + const struct vfsmount *mnt,
82580 + const int unsafe_flags);
82581 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82582 + const struct vfsmount *mnt);
82583 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82584 + const struct vfsmount *mnt, int acc_mode);
82585 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82586 + const struct dentry *p_dentry,
82587 + const struct vfsmount *p_mnt,
82588 + int open_flags, int acc_mode, const int imode);
82589 +void gr_handle_create(const struct dentry *dentry,
82590 + const struct vfsmount *mnt);
82591 +void gr_handle_proc_create(const struct dentry *dentry,
82592 + const struct inode *inode);
82593 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82594 + const struct dentry *parent_dentry,
82595 + const struct vfsmount *parent_mnt,
82596 + const int mode);
82597 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82598 + const struct dentry *parent_dentry,
82599 + const struct vfsmount *parent_mnt);
82600 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82601 + const struct vfsmount *mnt);
82602 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82603 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82604 + const struct vfsmount *mnt);
82605 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82606 + const struct dentry *parent_dentry,
82607 + const struct vfsmount *parent_mnt,
82608 + const struct filename *from);
82609 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82610 + const struct dentry *parent_dentry,
82611 + const struct vfsmount *parent_mnt,
82612 + const struct dentry *old_dentry,
82613 + const struct vfsmount *old_mnt, const struct filename *to);
82614 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82615 +int gr_acl_handle_rename(struct dentry *new_dentry,
82616 + struct dentry *parent_dentry,
82617 + const struct vfsmount *parent_mnt,
82618 + struct dentry *old_dentry,
82619 + struct inode *old_parent_inode,
82620 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82621 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82622 + struct dentry *old_dentry,
82623 + struct dentry *new_dentry,
82624 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82625 +__u32 gr_check_link(const struct dentry *new_dentry,
82626 + const struct dentry *parent_dentry,
82627 + const struct vfsmount *parent_mnt,
82628 + const struct dentry *old_dentry,
82629 + const struct vfsmount *old_mnt);
82630 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82631 + const unsigned int namelen, const ino_t ino);
82632 +
82633 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82634 + const struct vfsmount *mnt);
82635 +void gr_acl_handle_exit(void);
82636 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82637 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82638 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82639 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82640 +void gr_audit_ptrace(struct task_struct *task);
82641 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82642 +void gr_put_exec_file(struct task_struct *task);
82643 +
82644 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82645 +
82646 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82647 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82648 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
82649 + struct dentry *newdentry, struct vfsmount *newmnt);
82650 +
82651 +#ifdef CONFIG_GRKERNSEC_RESLOG
82652 +extern void gr_log_resource(const struct task_struct *task, const int res,
82653 + const unsigned long wanted, const int gt);
82654 +#else
82655 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82656 + const unsigned long wanted, const int gt)
82657 +{
82658 +}
82659 +#endif
82660 +
82661 +#ifdef CONFIG_GRKERNSEC
82662 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82663 +void gr_handle_vm86(void);
82664 +void gr_handle_mem_readwrite(u64 from, u64 to);
82665 +
82666 +void gr_log_badprocpid(const char *entry);
82667 +
82668 +extern int grsec_enable_dmesg;
82669 +extern int grsec_disable_privio;
82670 +
82671 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82672 +extern kgid_t grsec_proc_gid;
82673 +#endif
82674 +
82675 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82676 +extern int grsec_enable_chroot_findtask;
82677 +#endif
82678 +#ifdef CONFIG_GRKERNSEC_SETXID
82679 +extern int grsec_enable_setxid;
82680 +#endif
82681 +#endif
82682 +
82683 +#endif
82684 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82685 new file mode 100644
82686 index 0000000..e7ffaaf
82687 --- /dev/null
82688 +++ b/include/linux/grsock.h
82689 @@ -0,0 +1,19 @@
82690 +#ifndef __GRSOCK_H
82691 +#define __GRSOCK_H
82692 +
82693 +extern void gr_attach_curr_ip(const struct sock *sk);
82694 +extern int gr_handle_sock_all(const int family, const int type,
82695 + const int protocol);
82696 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82697 +extern int gr_handle_sock_server_other(const struct sock *sck);
82698 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82699 +extern int gr_search_connect(struct socket * sock,
82700 + struct sockaddr_in * addr);
82701 +extern int gr_search_bind(struct socket * sock,
82702 + struct sockaddr_in * addr);
82703 +extern int gr_search_listen(struct socket * sock);
82704 +extern int gr_search_accept(struct socket * sock);
82705 +extern int gr_search_socket(const int domain, const int type,
82706 + const int protocol);
82707 +
82708 +#endif
82709 diff --git a/include/linux/hash.h b/include/linux/hash.h
82710 index d0494c3..69b7715 100644
82711 --- a/include/linux/hash.h
82712 +++ b/include/linux/hash.h
82713 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82714 struct fast_hash_ops {
82715 u32 (*hash)(const void *data, u32 len, u32 seed);
82716 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82717 -};
82718 +} __no_const;
82719
82720 /**
82721 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82722 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82723 index 9286a46..373f27f 100644
82724 --- a/include/linux/highmem.h
82725 +++ b/include/linux/highmem.h
82726 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82727 kunmap_atomic(kaddr);
82728 }
82729
82730 +static inline void sanitize_highpage(struct page *page)
82731 +{
82732 + void *kaddr;
82733 + unsigned long flags;
82734 +
82735 + local_irq_save(flags);
82736 + kaddr = kmap_atomic(page);
82737 + clear_page(kaddr);
82738 + kunmap_atomic(kaddr);
82739 + local_irq_restore(flags);
82740 +}
82741 +
82742 static inline void zero_user_segments(struct page *page,
82743 unsigned start1, unsigned end1,
82744 unsigned start2, unsigned end2)
82745 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82746 index 1c7b89a..7dda400 100644
82747 --- a/include/linux/hwmon-sysfs.h
82748 +++ b/include/linux/hwmon-sysfs.h
82749 @@ -25,7 +25,8 @@
82750 struct sensor_device_attribute{
82751 struct device_attribute dev_attr;
82752 int index;
82753 -};
82754 +} __do_const;
82755 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82756 #define to_sensor_dev_attr(_dev_attr) \
82757 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82758
82759 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82760 struct device_attribute dev_attr;
82761 u8 index;
82762 u8 nr;
82763 -};
82764 +} __do_const;
82765 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82766 #define to_sensor_dev_attr_2(_dev_attr) \
82767 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82768
82769 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82770 index b556e0a..c10a515 100644
82771 --- a/include/linux/i2c.h
82772 +++ b/include/linux/i2c.h
82773 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82774 /* To determine what the adapter supports */
82775 u32 (*functionality) (struct i2c_adapter *);
82776 };
82777 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82778
82779 /**
82780 * struct i2c_bus_recovery_info - I2C bus recovery information
82781 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82782 index d23c3c2..eb63c81 100644
82783 --- a/include/linux/i2o.h
82784 +++ b/include/linux/i2o.h
82785 @@ -565,7 +565,7 @@ struct i2o_controller {
82786 struct i2o_device *exec; /* Executive */
82787 #if BITS_PER_LONG == 64
82788 spinlock_t context_list_lock; /* lock for context_list */
82789 - atomic_t context_list_counter; /* needed for unique contexts */
82790 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82791 struct list_head context_list; /* list of context id's
82792 and pointers */
82793 #endif
82794 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82795 index aff7ad8..3942bbd 100644
82796 --- a/include/linux/if_pppox.h
82797 +++ b/include/linux/if_pppox.h
82798 @@ -76,7 +76,7 @@ struct pppox_proto {
82799 int (*ioctl)(struct socket *sock, unsigned int cmd,
82800 unsigned long arg);
82801 struct module *owner;
82802 -};
82803 +} __do_const;
82804
82805 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82806 extern void unregister_pppox_proto(int proto_num);
82807 diff --git a/include/linux/init.h b/include/linux/init.h
82808 index 2df8e8d..3e1280d 100644
82809 --- a/include/linux/init.h
82810 +++ b/include/linux/init.h
82811 @@ -37,9 +37,17 @@
82812 * section.
82813 */
82814
82815 +#define add_init_latent_entropy __latent_entropy
82816 +
82817 +#ifdef CONFIG_MEMORY_HOTPLUG
82818 +#define add_meminit_latent_entropy
82819 +#else
82820 +#define add_meminit_latent_entropy __latent_entropy
82821 +#endif
82822 +
82823 /* These are for everybody (although not all archs will actually
82824 discard it in modules) */
82825 -#define __init __section(.init.text) __cold notrace
82826 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82827 #define __initdata __section(.init.data)
82828 #define __initconst __constsection(.init.rodata)
82829 #define __exitdata __section(.exit.data)
82830 @@ -100,7 +108,7 @@
82831 #define __cpuexitconst
82832
82833 /* Used for MEMORY_HOTPLUG */
82834 -#define __meminit __section(.meminit.text) __cold notrace
82835 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82836 #define __meminitdata __section(.meminit.data)
82837 #define __meminitconst __constsection(.meminit.rodata)
82838 #define __memexit __section(.memexit.text) __exitused __cold notrace
82839 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82840 index 77fc43f..73caf92 100644
82841 --- a/include/linux/init_task.h
82842 +++ b/include/linux/init_task.h
82843 @@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82844
82845 #define INIT_TASK_COMM "swapper"
82846
82847 +#ifdef CONFIG_X86
82848 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82849 +#else
82850 +#define INIT_TASK_THREAD_INFO
82851 +#endif
82852 +
82853 #ifdef CONFIG_RT_MUTEXES
82854 # define INIT_RT_MUTEXES(tsk) \
82855 .pi_waiters = RB_ROOT, \
82856 @@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82857 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82858 .comm = INIT_TASK_COMM, \
82859 .thread = INIT_THREAD, \
82860 + INIT_TASK_THREAD_INFO \
82861 .fs = &init_fs, \
82862 .files = &init_files, \
82863 .signal = &init_signals, \
82864 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82865 index 69517a2..6b12d37 100644
82866 --- a/include/linux/interrupt.h
82867 +++ b/include/linux/interrupt.h
82868 @@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82869
82870 struct softirq_action
82871 {
82872 - void (*action)(struct softirq_action *);
82873 -};
82874 + void (*action)(void);
82875 +} __no_const;
82876
82877 asmlinkage void do_softirq(void);
82878 asmlinkage void __do_softirq(void);
82879 @@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82880 }
82881 #endif
82882
82883 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82884 +extern void open_softirq(int nr, void (*action)(void));
82885 extern void softirq_init(void);
82886 extern void __raise_softirq_irqoff(unsigned int nr);
82887
82888 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82889 index e6a7c9f..5804745 100644
82890 --- a/include/linux/iommu.h
82891 +++ b/include/linux/iommu.h
82892 @@ -133,7 +133,7 @@ struct iommu_ops {
82893 u32 (*domain_get_windows)(struct iommu_domain *domain);
82894
82895 unsigned long pgsize_bitmap;
82896 -};
82897 +} __do_const;
82898
82899 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82900 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82901 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82902 index 2c525022..345b106 100644
82903 --- a/include/linux/ioport.h
82904 +++ b/include/linux/ioport.h
82905 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82906 int adjust_resource(struct resource *res, resource_size_t start,
82907 resource_size_t size);
82908 resource_size_t resource_alignment(struct resource *res);
82909 -static inline resource_size_t resource_size(const struct resource *res)
82910 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82911 {
82912 return res->end - res->start + 1;
82913 }
82914 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82915 index 35e7eca..6afb7ad 100644
82916 --- a/include/linux/ipc_namespace.h
82917 +++ b/include/linux/ipc_namespace.h
82918 @@ -69,7 +69,7 @@ struct ipc_namespace {
82919 struct user_namespace *user_ns;
82920
82921 unsigned int proc_inum;
82922 -};
82923 +} __randomize_layout;
82924
82925 extern struct ipc_namespace init_ipc_ns;
82926 extern atomic_t nr_ipc_ns;
82927 diff --git a/include/linux/irq.h b/include/linux/irq.h
82928 index 03f48d9..e86af0c 100644
82929 --- a/include/linux/irq.h
82930 +++ b/include/linux/irq.h
82931 @@ -352,7 +352,8 @@ struct irq_chip {
82932 void (*irq_release_resources)(struct irq_data *data);
82933
82934 unsigned long flags;
82935 -};
82936 +} __do_const;
82937 +typedef struct irq_chip __no_const irq_chip_no_const;
82938
82939 /*
82940 * irq_chip specific flags
82941 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82942 index 13eed92..3261c86 100644
82943 --- a/include/linux/irqchip/arm-gic.h
82944 +++ b/include/linux/irqchip/arm-gic.h
82945 @@ -91,9 +91,11 @@
82946
82947 #ifndef __ASSEMBLY__
82948
82949 +#include <linux/irq.h>
82950 +
82951 struct device_node;
82952
82953 -extern struct irq_chip gic_arch_extn;
82954 +extern irq_chip_no_const gic_arch_extn;
82955
82956 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82957 u32 offset, struct device_node *);
82958 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82959 index c367cbd..c9b79e6 100644
82960 --- a/include/linux/jiffies.h
82961 +++ b/include/linux/jiffies.h
82962 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82963 /*
82964 * Convert various time units to each other:
82965 */
82966 -extern unsigned int jiffies_to_msecs(const unsigned long j);
82967 -extern unsigned int jiffies_to_usecs(const unsigned long j);
82968 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82969 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82970
82971 -static inline u64 jiffies_to_nsecs(const unsigned long j)
82972 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82973 {
82974 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82975 }
82976
82977 -extern unsigned long msecs_to_jiffies(const unsigned int m);
82978 -extern unsigned long usecs_to_jiffies(const unsigned int u);
82979 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82980 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82981 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82982 extern void jiffies_to_timespec(const unsigned long jiffies,
82983 - struct timespec *value);
82984 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
82985 + struct timespec *value) __intentional_overflow(-1);
82986 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82987 extern void jiffies_to_timeval(const unsigned long jiffies,
82988 struct timeval *value);
82989
82990 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82991 index 6883e19..e854fcb 100644
82992 --- a/include/linux/kallsyms.h
82993 +++ b/include/linux/kallsyms.h
82994 @@ -15,7 +15,8 @@
82995
82996 struct module;
82997
82998 -#ifdef CONFIG_KALLSYMS
82999 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83000 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83001 /* Lookup the address for a symbol. Returns 0 if not found. */
83002 unsigned long kallsyms_lookup_name(const char *name);
83003
83004 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83005 /* Stupid that this does nothing, but I didn't create this mess. */
83006 #define __print_symbol(fmt, addr)
83007 #endif /*CONFIG_KALLSYMS*/
83008 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83009 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83010 +extern unsigned long kallsyms_lookup_name(const char *name);
83011 +extern void __print_symbol(const char *fmt, unsigned long address);
83012 +extern int sprint_backtrace(char *buffer, unsigned long address);
83013 +extern int sprint_symbol(char *buffer, unsigned long address);
83014 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83015 +const char *kallsyms_lookup(unsigned long addr,
83016 + unsigned long *symbolsize,
83017 + unsigned long *offset,
83018 + char **modname, char *namebuf);
83019 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83020 + unsigned long *symbolsize,
83021 + unsigned long *offset);
83022 +#endif
83023
83024 /* This macro allows us to keep printk typechecking */
83025 static __printf(1, 2)
83026 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83027 index ff9f1d3..6712be5 100644
83028 --- a/include/linux/key-type.h
83029 +++ b/include/linux/key-type.h
83030 @@ -152,7 +152,7 @@ struct key_type {
83031 /* internal fields */
83032 struct list_head link; /* link in types list */
83033 struct lock_class_key lock_class; /* key->sem lock class */
83034 -};
83035 +} __do_const;
83036
83037 extern struct key_type key_type_keyring;
83038
83039 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83040 index e465bb1..19f605fd 100644
83041 --- a/include/linux/kgdb.h
83042 +++ b/include/linux/kgdb.h
83043 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83044 extern int kgdb_io_module_registered;
83045
83046 extern atomic_t kgdb_setting_breakpoint;
83047 -extern atomic_t kgdb_cpu_doing_single_step;
83048 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83049
83050 extern struct task_struct *kgdb_usethread;
83051 extern struct task_struct *kgdb_contthread;
83052 @@ -254,7 +254,7 @@ struct kgdb_arch {
83053 void (*correct_hw_break)(void);
83054
83055 void (*enable_nmi)(bool on);
83056 -};
83057 +} __do_const;
83058
83059 /**
83060 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83061 @@ -279,7 +279,7 @@ struct kgdb_io {
83062 void (*pre_exception) (void);
83063 void (*post_exception) (void);
83064 int is_console;
83065 -};
83066 +} __do_const;
83067
83068 extern struct kgdb_arch arch_kgdb_ops;
83069
83070 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83071 index 0555cc6..40116ce 100644
83072 --- a/include/linux/kmod.h
83073 +++ b/include/linux/kmod.h
83074 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83075 * usually useless though. */
83076 extern __printf(2, 3)
83077 int __request_module(bool wait, const char *name, ...);
83078 +extern __printf(3, 4)
83079 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83080 #define request_module(mod...) __request_module(true, mod)
83081 #define request_module_nowait(mod...) __request_module(false, mod)
83082 #define try_then_request_module(x, mod...) \
83083 @@ -57,6 +59,9 @@ struct subprocess_info {
83084 struct work_struct work;
83085 struct completion *complete;
83086 char *path;
83087 +#ifdef CONFIG_GRKERNSEC
83088 + char *origpath;
83089 +#endif
83090 char **argv;
83091 char **envp;
83092 int wait;
83093 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83094 index 2d61b90..a1d0a13 100644
83095 --- a/include/linux/kobject.h
83096 +++ b/include/linux/kobject.h
83097 @@ -118,7 +118,7 @@ struct kobj_type {
83098 struct attribute **default_attrs;
83099 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83100 const void *(*namespace)(struct kobject *kobj);
83101 -};
83102 +} __do_const;
83103
83104 struct kobj_uevent_env {
83105 char *argv[3];
83106 @@ -142,6 +142,7 @@ struct kobj_attribute {
83107 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83108 const char *buf, size_t count);
83109 };
83110 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83111
83112 extern const struct sysfs_ops kobj_sysfs_ops;
83113
83114 @@ -169,7 +170,7 @@ struct kset {
83115 spinlock_t list_lock;
83116 struct kobject kobj;
83117 const struct kset_uevent_ops *uevent_ops;
83118 -};
83119 +} __randomize_layout;
83120
83121 extern void kset_init(struct kset *kset);
83122 extern int __must_check kset_register(struct kset *kset);
83123 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83124 index df32d25..fb52e27 100644
83125 --- a/include/linux/kobject_ns.h
83126 +++ b/include/linux/kobject_ns.h
83127 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83128 const void *(*netlink_ns)(struct sock *sk);
83129 const void *(*initial_ns)(void);
83130 void (*drop_ns)(void *);
83131 -};
83132 +} __do_const;
83133
83134 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83135 int kobj_ns_type_registered(enum kobj_ns_type type);
83136 diff --git a/include/linux/kref.h b/include/linux/kref.h
83137 index 484604d..0f6c5b6 100644
83138 --- a/include/linux/kref.h
83139 +++ b/include/linux/kref.h
83140 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83141 static inline int kref_sub(struct kref *kref, unsigned int count,
83142 void (*release)(struct kref *kref))
83143 {
83144 - WARN_ON(release == NULL);
83145 + BUG_ON(release == NULL);
83146
83147 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83148 release(kref);
83149 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83150 index a6059bd..8126d5c 100644
83151 --- a/include/linux/kvm_host.h
83152 +++ b/include/linux/kvm_host.h
83153 @@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
83154 {
83155 }
83156 #endif
83157 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83158 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83159 struct module *module);
83160 void kvm_exit(void);
83161
83162 @@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83163 struct kvm_guest_debug *dbg);
83164 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83165
83166 -int kvm_arch_init(void *opaque);
83167 +int kvm_arch_init(const void *opaque);
83168 void kvm_arch_exit(void);
83169
83170 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83171 diff --git a/include/linux/libata.h b/include/linux/libata.h
83172 index fe0bf8d..c511ca6 100644
83173 --- a/include/linux/libata.h
83174 +++ b/include/linux/libata.h
83175 @@ -977,7 +977,7 @@ struct ata_port_operations {
83176 * fields must be pointers.
83177 */
83178 const struct ata_port_operations *inherits;
83179 -};
83180 +} __do_const;
83181
83182 struct ata_port_info {
83183 unsigned long flags;
83184 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83185 index a6a42dd..6c5ebce 100644
83186 --- a/include/linux/linkage.h
83187 +++ b/include/linux/linkage.h
83188 @@ -36,6 +36,7 @@
83189 #endif
83190
83191 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83192 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83193 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83194
83195 /*
83196 diff --git a/include/linux/list.h b/include/linux/list.h
83197 index f33f831..1ffe5e2 100644
83198 --- a/include/linux/list.h
83199 +++ b/include/linux/list.h
83200 @@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
83201 extern void list_del(struct list_head *entry);
83202 #endif
83203
83204 +extern void __pax_list_add(struct list_head *new,
83205 + struct list_head *prev,
83206 + struct list_head *next);
83207 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83208 +{
83209 + __pax_list_add(new, head, head->next);
83210 +}
83211 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83212 +{
83213 + __pax_list_add(new, head->prev, head);
83214 +}
83215 +extern void pax_list_del(struct list_head *entry);
83216 +
83217 /**
83218 * list_replace - replace old entry by new one
83219 * @old : the element to be replaced
83220 @@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
83221 INIT_LIST_HEAD(entry);
83222 }
83223
83224 +extern void pax_list_del_init(struct list_head *entry);
83225 +
83226 /**
83227 * list_move - delete from one list and add as another's head
83228 * @list: the entry to move
83229 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83230 index 4bfde0e..d6e2e09 100644
83231 --- a/include/linux/lockref.h
83232 +++ b/include/linux/lockref.h
83233 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83234 return ((int)l->count < 0);
83235 }
83236
83237 +static inline unsigned int __lockref_read(struct lockref *lockref)
83238 +{
83239 + return lockref->count;
83240 +}
83241 +
83242 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83243 +{
83244 + lockref->count = count;
83245 +}
83246 +
83247 +static inline void __lockref_inc(struct lockref *lockref)
83248 +{
83249 +
83250 +#ifdef CONFIG_PAX_REFCOUNT
83251 + atomic_inc((atomic_t *)&lockref->count);
83252 +#else
83253 + lockref->count++;
83254 +#endif
83255 +
83256 +}
83257 +
83258 +static inline void __lockref_dec(struct lockref *lockref)
83259 +{
83260 +
83261 +#ifdef CONFIG_PAX_REFCOUNT
83262 + atomic_dec((atomic_t *)&lockref->count);
83263 +#else
83264 + lockref->count--;
83265 +#endif
83266 +
83267 +}
83268 +
83269 #endif /* __LINUX_LOCKREF_H */
83270 diff --git a/include/linux/math64.h b/include/linux/math64.h
83271 index c45c089..298841c 100644
83272 --- a/include/linux/math64.h
83273 +++ b/include/linux/math64.h
83274 @@ -15,7 +15,7 @@
83275 * This is commonly provided by 32bit archs to provide an optimized 64bit
83276 * divide.
83277 */
83278 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83279 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83280 {
83281 *remainder = dividend % divisor;
83282 return dividend / divisor;
83283 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83284 /**
83285 * div64_u64 - unsigned 64bit divide with 64bit divisor
83286 */
83287 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83288 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83289 {
83290 return dividend / divisor;
83291 }
83292 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83293 #define div64_ul(x, y) div_u64((x), (y))
83294
83295 #ifndef div_u64_rem
83296 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83297 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83298 {
83299 *remainder = do_div(dividend, divisor);
83300 return dividend;
83301 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83302 #endif
83303
83304 #ifndef div64_u64
83305 -extern u64 div64_u64(u64 dividend, u64 divisor);
83306 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83307 #endif
83308
83309 #ifndef div64_s64
83310 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83311 * divide.
83312 */
83313 #ifndef div_u64
83314 -static inline u64 div_u64(u64 dividend, u32 divisor)
83315 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83316 {
83317 u32 remainder;
83318 return div_u64_rem(dividend, divisor, &remainder);
83319 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83320 index 3d385c8..deacb6a 100644
83321 --- a/include/linux/mempolicy.h
83322 +++ b/include/linux/mempolicy.h
83323 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83324 }
83325
83326 #define vma_policy(vma) ((vma)->vm_policy)
83327 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83328 +{
83329 + vma->vm_policy = pol;
83330 +}
83331
83332 static inline void mpol_get(struct mempolicy *pol)
83333 {
83334 @@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83335 }
83336
83337 #define vma_policy(vma) NULL
83338 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83339 +{
83340 +}
83341
83342 static inline int
83343 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83344 diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
83345 index 37e4404..26ebbd0 100644
83346 --- a/include/linux/mlx4/device.h
83347 +++ b/include/linux/mlx4/device.h
83348 @@ -97,7 +97,7 @@ enum {
83349 MLX4_MAX_NUM_PF = 16,
83350 MLX4_MAX_NUM_VF = 64,
83351 MLX4_MAX_NUM_VF_P_PORT = 64,
83352 - MLX4_MFUNC_MAX = 80,
83353 + MLX4_MFUNC_MAX = 128,
83354 MLX4_MAX_EQ_NUM = 1024,
83355 MLX4_MFUNC_EQ_NUM = 4,
83356 MLX4_MFUNC_MAX_EQES = 8,
83357 diff --git a/include/linux/mm.h b/include/linux/mm.h
83358 index 5ab2da9..5f0b3df 100644
83359 --- a/include/linux/mm.h
83360 +++ b/include/linux/mm.h
83361 @@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83362 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83363 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83364 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83365 +
83366 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83367 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83368 +#endif
83369 +
83370 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83371
83372 #ifdef CONFIG_MEM_SOFT_DIRTY
83373 @@ -238,8 +243,8 @@ struct vm_operations_struct {
83374 /* called by access_process_vm when get_user_pages() fails, typically
83375 * for use by special VMAs that can switch between memory and hardware
83376 */
83377 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83378 - void *buf, int len, int write);
83379 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83380 + void *buf, size_t len, int write);
83381
83382 /* Called by the /proc/PID/maps code to ask the vma whether it
83383 * has a special name. Returning non-NULL will also cause this
83384 @@ -275,6 +280,7 @@ struct vm_operations_struct {
83385 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83386 unsigned long size, pgoff_t pgoff);
83387 };
83388 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83389
83390 struct mmu_gather;
83391 struct inode;
83392 @@ -1165,8 +1171,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83393 unsigned long *pfn);
83394 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83395 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83396 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83397 - void *buf, int len, int write);
83398 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83399 + void *buf, size_t len, int write);
83400
83401 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83402 loff_t const holebegin, loff_t const holelen)
83403 @@ -1206,9 +1212,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83404 }
83405 #endif
83406
83407 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83408 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83409 - void *buf, int len, int write);
83410 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83411 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83412 + void *buf, size_t len, int write);
83413
83414 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83415 unsigned long start, unsigned long nr_pages,
83416 @@ -1240,34 +1246,6 @@ int set_page_dirty_lock(struct page *page);
83417 int clear_page_dirty_for_io(struct page *page);
83418 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83419
83420 -/* Is the vma a continuation of the stack vma above it? */
83421 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83422 -{
83423 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83424 -}
83425 -
83426 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83427 - unsigned long addr)
83428 -{
83429 - return (vma->vm_flags & VM_GROWSDOWN) &&
83430 - (vma->vm_start == addr) &&
83431 - !vma_growsdown(vma->vm_prev, addr);
83432 -}
83433 -
83434 -/* Is the vma a continuation of the stack vma below it? */
83435 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83436 -{
83437 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83438 -}
83439 -
83440 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83441 - unsigned long addr)
83442 -{
83443 - return (vma->vm_flags & VM_GROWSUP) &&
83444 - (vma->vm_end == addr) &&
83445 - !vma_growsup(vma->vm_next, addr);
83446 -}
83447 -
83448 extern struct task_struct *task_of_stack(struct task_struct *task,
83449 struct vm_area_struct *vma, bool in_group);
83450
83451 @@ -1385,8 +1363,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83452 {
83453 return 0;
83454 }
83455 +
83456 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83457 + unsigned long address)
83458 +{
83459 + return 0;
83460 +}
83461 #else
83462 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83463 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83464 #endif
83465
83466 #ifdef __PAGETABLE_PMD_FOLDED
83467 @@ -1395,8 +1380,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83468 {
83469 return 0;
83470 }
83471 +
83472 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83473 + unsigned long address)
83474 +{
83475 + return 0;
83476 +}
83477 #else
83478 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83479 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83480 #endif
83481
83482 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83483 @@ -1414,11 +1406,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83484 NULL: pud_offset(pgd, address);
83485 }
83486
83487 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83488 +{
83489 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83490 + NULL: pud_offset(pgd, address);
83491 +}
83492 +
83493 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83494 {
83495 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83496 NULL: pmd_offset(pud, address);
83497 }
83498 +
83499 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83500 +{
83501 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83502 + NULL: pmd_offset(pud, address);
83503 +}
83504 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83505
83506 #if USE_SPLIT_PTE_PTLOCKS
83507 @@ -1801,12 +1805,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83508 bool *need_rmap_locks);
83509 extern void exit_mmap(struct mm_struct *);
83510
83511 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83512 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83513 + const unsigned long wanted, const int gt);
83514 +#else
83515 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83516 + const unsigned long wanted, const int gt)
83517 +{
83518 +}
83519 +#endif
83520 +
83521 static inline int check_data_rlimit(unsigned long rlim,
83522 unsigned long new,
83523 unsigned long start,
83524 unsigned long end_data,
83525 unsigned long start_data)
83526 {
83527 + gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83528 if (rlim < RLIM_INFINITY) {
83529 if (((new - start) + (end_data - start_data)) > rlim)
83530 return -ENOSPC;
83531 @@ -1831,7 +1846,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83532 unsigned long addr, unsigned long len,
83533 unsigned long flags, struct page **pages);
83534
83535 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83536 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83537
83538 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83539 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83540 @@ -1839,6 +1854,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83541 unsigned long len, unsigned long prot, unsigned long flags,
83542 unsigned long pgoff, unsigned long *populate);
83543 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83544 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83545
83546 #ifdef CONFIG_MMU
83547 extern int __mm_populate(unsigned long addr, unsigned long len,
83548 @@ -1867,10 +1883,11 @@ struct vm_unmapped_area_info {
83549 unsigned long high_limit;
83550 unsigned long align_mask;
83551 unsigned long align_offset;
83552 + unsigned long threadstack_offset;
83553 };
83554
83555 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83556 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83557 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83558 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83559
83560 /*
83561 * Search for an unmapped address range.
83562 @@ -1882,7 +1899,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83563 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83564 */
83565 static inline unsigned long
83566 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83567 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83568 {
83569 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83570 return unmapped_area(info);
83571 @@ -1944,6 +1961,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83572 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83573 struct vm_area_struct **pprev);
83574
83575 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83576 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83577 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83578 +
83579 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83580 NULL if none. Assume start_addr < end_addr. */
83581 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83582 @@ -1973,10 +1994,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83583 }
83584
83585 #ifdef CONFIG_MMU
83586 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83587 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83588 void vma_set_page_prot(struct vm_area_struct *vma);
83589 #else
83590 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83591 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83592 {
83593 return __pgprot(0);
83594 }
83595 @@ -2038,6 +2059,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83596 static inline void vm_stat_account(struct mm_struct *mm,
83597 unsigned long flags, struct file *file, long pages)
83598 {
83599 +
83600 +#ifdef CONFIG_PAX_RANDMMAP
83601 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83602 +#endif
83603 +
83604 mm->total_vm += pages;
83605 }
83606 #endif /* CONFIG_PROC_FS */
83607 @@ -2126,7 +2152,7 @@ extern int unpoison_memory(unsigned long pfn);
83608 extern int sysctl_memory_failure_early_kill;
83609 extern int sysctl_memory_failure_recovery;
83610 extern void shake_page(struct page *p, int access);
83611 -extern atomic_long_t num_poisoned_pages;
83612 +extern atomic_long_unchecked_t num_poisoned_pages;
83613 extern int soft_offline_page(struct page *page, int flags);
83614
83615 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83616 @@ -2161,5 +2187,11 @@ void __init setup_nr_node_ids(void);
83617 static inline void setup_nr_node_ids(void) {}
83618 #endif
83619
83620 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83621 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83622 +#else
83623 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83624 +#endif
83625 +
83626 #endif /* __KERNEL__ */
83627 #endif /* _LINUX_MM_H */
83628 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83629 index 6e0b286..90d9c0d 100644
83630 --- a/include/linux/mm_types.h
83631 +++ b/include/linux/mm_types.h
83632 @@ -308,7 +308,9 @@ struct vm_area_struct {
83633 #ifdef CONFIG_NUMA
83634 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83635 #endif
83636 -};
83637 +
83638 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83639 +} __randomize_layout;
83640
83641 struct core_thread {
83642 struct task_struct *task;
83643 @@ -454,7 +456,25 @@ struct mm_struct {
83644 bool tlb_flush_pending;
83645 #endif
83646 struct uprobes_state uprobes_state;
83647 -};
83648 +
83649 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83650 + unsigned long pax_flags;
83651 +#endif
83652 +
83653 +#ifdef CONFIG_PAX_DLRESOLVE
83654 + unsigned long call_dl_resolve;
83655 +#endif
83656 +
83657 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83658 + unsigned long call_syscall;
83659 +#endif
83660 +
83661 +#ifdef CONFIG_PAX_ASLR
83662 + unsigned long delta_mmap; /* randomized offset */
83663 + unsigned long delta_stack; /* randomized offset */
83664 +#endif
83665 +
83666 +} __randomize_layout;
83667
83668 static inline void mm_init_cpumask(struct mm_struct *mm)
83669 {
83670 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83671 index c5d5278..f0b68c8 100644
83672 --- a/include/linux/mmiotrace.h
83673 +++ b/include/linux/mmiotrace.h
83674 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83675 /* Called from ioremap.c */
83676 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83677 void __iomem *addr);
83678 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83679 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83680
83681 /* For anyone to insert markers. Remember trailing newline. */
83682 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83683 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83684 {
83685 }
83686
83687 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83688 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83689 {
83690 }
83691
83692 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83693 index ffe66e3..b310722 100644
83694 --- a/include/linux/mmzone.h
83695 +++ b/include/linux/mmzone.h
83696 @@ -527,7 +527,7 @@ struct zone {
83697
83698 ZONE_PADDING(_pad3_)
83699 /* Zone statistics */
83700 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83701 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83702 } ____cacheline_internodealigned_in_smp;
83703
83704 enum zone_flags {
83705 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83706 index 44eeef0..a92d3f9 100644
83707 --- a/include/linux/mod_devicetable.h
83708 +++ b/include/linux/mod_devicetable.h
83709 @@ -139,7 +139,7 @@ struct usb_device_id {
83710 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83711 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83712
83713 -#define HID_ANY_ID (~0)
83714 +#define HID_ANY_ID (~0U)
83715 #define HID_BUS_ANY 0xffff
83716 #define HID_GROUP_ANY 0x0000
83717
83718 @@ -475,7 +475,7 @@ struct dmi_system_id {
83719 const char *ident;
83720 struct dmi_strmatch matches[4];
83721 void *driver_data;
83722 -};
83723 +} __do_const;
83724 /*
83725 * struct dmi_device_id appears during expansion of
83726 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83727 diff --git a/include/linux/module.h b/include/linux/module.h
83728 index 71f282a..b2387e2 100644
83729 --- a/include/linux/module.h
83730 +++ b/include/linux/module.h
83731 @@ -17,9 +17,11 @@
83732 #include <linux/moduleparam.h>
83733 #include <linux/jump_label.h>
83734 #include <linux/export.h>
83735 +#include <linux/fs.h>
83736
83737 #include <linux/percpu.h>
83738 #include <asm/module.h>
83739 +#include <asm/pgtable.h>
83740
83741 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83742 #define MODULE_SIG_STRING "~Module signature appended~\n"
83743 @@ -42,7 +44,7 @@ struct module_kobject {
83744 struct kobject *drivers_dir;
83745 struct module_param_attrs *mp;
83746 struct completion *kobj_completion;
83747 -};
83748 +} __randomize_layout;
83749
83750 struct module_attribute {
83751 struct attribute attr;
83752 @@ -54,12 +56,13 @@ struct module_attribute {
83753 int (*test)(struct module *);
83754 void (*free)(struct module *);
83755 };
83756 +typedef struct module_attribute __no_const module_attribute_no_const;
83757
83758 struct module_version_attribute {
83759 struct module_attribute mattr;
83760 const char *module_name;
83761 const char *version;
83762 -} __attribute__ ((__aligned__(sizeof(void *))));
83763 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83764
83765 extern ssize_t __modver_version_show(struct module_attribute *,
83766 struct module_kobject *, char *);
83767 @@ -235,7 +238,7 @@ struct module {
83768
83769 /* Sysfs stuff. */
83770 struct module_kobject mkobj;
83771 - struct module_attribute *modinfo_attrs;
83772 + module_attribute_no_const *modinfo_attrs;
83773 const char *version;
83774 const char *srcversion;
83775 struct kobject *holders_dir;
83776 @@ -284,19 +287,16 @@ struct module {
83777 int (*init)(void);
83778
83779 /* If this is non-NULL, vfree after init() returns */
83780 - void *module_init;
83781 + void *module_init_rx, *module_init_rw;
83782
83783 /* Here is the actual code + data, vfree'd on unload. */
83784 - void *module_core;
83785 + void *module_core_rx, *module_core_rw;
83786
83787 /* Here are the sizes of the init and core sections */
83788 - unsigned int init_size, core_size;
83789 + unsigned int init_size_rw, core_size_rw;
83790
83791 /* The size of the executable code in each section. */
83792 - unsigned int init_text_size, core_text_size;
83793 -
83794 - /* Size of RO sections of the module (text+rodata) */
83795 - unsigned int init_ro_size, core_ro_size;
83796 + unsigned int init_size_rx, core_size_rx;
83797
83798 /* Arch-specific module values */
83799 struct mod_arch_specific arch;
83800 @@ -352,6 +352,10 @@ struct module {
83801 #ifdef CONFIG_EVENT_TRACING
83802 struct ftrace_event_call **trace_events;
83803 unsigned int num_trace_events;
83804 + struct file_operations trace_id;
83805 + struct file_operations trace_enable;
83806 + struct file_operations trace_format;
83807 + struct file_operations trace_filter;
83808 #endif
83809 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83810 unsigned int num_ftrace_callsites;
83811 @@ -375,7 +379,7 @@ struct module {
83812 ctor_fn_t *ctors;
83813 unsigned int num_ctors;
83814 #endif
83815 -};
83816 +} __randomize_layout;
83817 #ifndef MODULE_ARCH_INIT
83818 #define MODULE_ARCH_INIT {}
83819 #endif
83820 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83821 bool is_module_percpu_address(unsigned long addr);
83822 bool is_module_text_address(unsigned long addr);
83823
83824 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83825 +{
83826 +
83827 +#ifdef CONFIG_PAX_KERNEXEC
83828 + if (ktla_ktva(addr) >= (unsigned long)start &&
83829 + ktla_ktva(addr) < (unsigned long)start + size)
83830 + return 1;
83831 +#endif
83832 +
83833 + return ((void *)addr >= start && (void *)addr < start + size);
83834 +}
83835 +
83836 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83837 +{
83838 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83839 +}
83840 +
83841 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83842 +{
83843 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83844 +}
83845 +
83846 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83847 +{
83848 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83849 +}
83850 +
83851 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83852 +{
83853 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83854 +}
83855 +
83856 static inline bool within_module_core(unsigned long addr,
83857 const struct module *mod)
83858 {
83859 - return (unsigned long)mod->module_core <= addr &&
83860 - addr < (unsigned long)mod->module_core + mod->core_size;
83861 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83862 }
83863
83864 static inline bool within_module_init(unsigned long addr,
83865 const struct module *mod)
83866 {
83867 - return (unsigned long)mod->module_init <= addr &&
83868 - addr < (unsigned long)mod->module_init + mod->init_size;
83869 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83870 }
83871
83872 static inline bool within_module(unsigned long addr, const struct module *mod)
83873 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83874 index 7eeb9bb..68f37e0 100644
83875 --- a/include/linux/moduleloader.h
83876 +++ b/include/linux/moduleloader.h
83877 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83878 sections. Returns NULL on failure. */
83879 void *module_alloc(unsigned long size);
83880
83881 +#ifdef CONFIG_PAX_KERNEXEC
83882 +void *module_alloc_exec(unsigned long size);
83883 +#else
83884 +#define module_alloc_exec(x) module_alloc(x)
83885 +#endif
83886 +
83887 /* Free memory returned from module_alloc. */
83888 void module_free(struct module *mod, void *module_region);
83889
83890 +#ifdef CONFIG_PAX_KERNEXEC
83891 +void module_free_exec(struct module *mod, void *module_region);
83892 +#else
83893 +#define module_free_exec(x, y) module_free((x), (y))
83894 +#endif
83895 +
83896 /*
83897 * Apply the given relocation to the (simplified) ELF. Return -error
83898 * or 0.
83899 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83900 unsigned int relsec,
83901 struct module *me)
83902 {
83903 +#ifdef CONFIG_MODULES
83904 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83905 module_name(me));
83906 +#endif
83907 return -ENOEXEC;
83908 }
83909 #endif
83910 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83911 unsigned int relsec,
83912 struct module *me)
83913 {
83914 +#ifdef CONFIG_MODULES
83915 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83916 module_name(me));
83917 +#endif
83918 return -ENOEXEC;
83919 }
83920 #endif
83921 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83922 index 1c9effa..1160bdd 100644
83923 --- a/include/linux/moduleparam.h
83924 +++ b/include/linux/moduleparam.h
83925 @@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83926 * @len is usually just sizeof(string).
83927 */
83928 #define module_param_string(name, string, len, perm) \
83929 - static const struct kparam_string __param_string_##name \
83930 + static const struct kparam_string __param_string_##name __used \
83931 = { len, string }; \
83932 __module_param_call(MODULE_PARAM_PREFIX, name, \
83933 &param_ops_string, \
83934 @@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83935 */
83936 #define module_param_array_named(name, array, type, nump, perm) \
83937 param_check_##type(name, &(array)[0]); \
83938 - static const struct kparam_array __param_arr_##name \
83939 + static const struct kparam_array __param_arr_##name __used \
83940 = { .max = ARRAY_SIZE(array), .num = nump, \
83941 .ops = &param_ops_##type, \
83942 .elemsize = sizeof(array[0]), .elem = array }; \
83943 diff --git a/include/linux/mount.h b/include/linux/mount.h
83944 index c2c561d..a5f2a8c 100644
83945 --- a/include/linux/mount.h
83946 +++ b/include/linux/mount.h
83947 @@ -66,7 +66,7 @@ struct vfsmount {
83948 struct dentry *mnt_root; /* root of the mounted tree */
83949 struct super_block *mnt_sb; /* pointer to superblock */
83950 int mnt_flags;
83951 -};
83952 +} __randomize_layout;
83953
83954 struct file; /* forward dec */
83955 struct path;
83956 diff --git a/include/linux/namei.h b/include/linux/namei.h
83957 index 492de72..1bddcd4 100644
83958 --- a/include/linux/namei.h
83959 +++ b/include/linux/namei.h
83960 @@ -19,7 +19,7 @@ struct nameidata {
83961 unsigned seq, m_seq;
83962 int last_type;
83963 unsigned depth;
83964 - char *saved_names[MAX_NESTED_LINKS + 1];
83965 + const char *saved_names[MAX_NESTED_LINKS + 1];
83966 };
83967
83968 /*
83969 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83970
83971 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83972
83973 -static inline void nd_set_link(struct nameidata *nd, char *path)
83974 +static inline void nd_set_link(struct nameidata *nd, const char *path)
83975 {
83976 nd->saved_names[nd->depth] = path;
83977 }
83978
83979 -static inline char *nd_get_link(struct nameidata *nd)
83980 +static inline const char *nd_get_link(const struct nameidata *nd)
83981 {
83982 return nd->saved_names[nd->depth];
83983 }
83984 diff --git a/include/linux/net.h b/include/linux/net.h
83985 index 17d8339..81656c0 100644
83986 --- a/include/linux/net.h
83987 +++ b/include/linux/net.h
83988 @@ -192,7 +192,7 @@ struct net_proto_family {
83989 int (*create)(struct net *net, struct socket *sock,
83990 int protocol, int kern);
83991 struct module *owner;
83992 -};
83993 +} __do_const;
83994
83995 struct iovec;
83996 struct kvec;
83997 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83998 index 22339b4..4b4d5b3 100644
83999 --- a/include/linux/netdevice.h
84000 +++ b/include/linux/netdevice.h
84001 @@ -1160,6 +1160,7 @@ struct net_device_ops {
84002 struct net_device *dev,
84003 netdev_features_t features);
84004 };
84005 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84006
84007 /**
84008 * enum net_device_priv_flags - &struct net_device priv_flags
84009 @@ -1502,10 +1503,10 @@ struct net_device {
84010
84011 struct net_device_stats stats;
84012
84013 - atomic_long_t rx_dropped;
84014 - atomic_long_t tx_dropped;
84015 + atomic_long_unchecked_t rx_dropped;
84016 + atomic_long_unchecked_t tx_dropped;
84017
84018 - atomic_t carrier_changes;
84019 + atomic_unchecked_t carrier_changes;
84020
84021 #ifdef CONFIG_WIRELESS_EXT
84022 const struct iw_handler_def * wireless_handlers;
84023 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84024 index 2517ece..0bbfcfb 100644
84025 --- a/include/linux/netfilter.h
84026 +++ b/include/linux/netfilter.h
84027 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84028 #endif
84029 /* Use the module struct to lock set/get code in place */
84030 struct module *owner;
84031 -};
84032 +} __do_const;
84033
84034 /* Function to register/unregister hook points. */
84035 int nf_register_hook(struct nf_hook_ops *reg);
84036 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84037 index e955d47..04a5338 100644
84038 --- a/include/linux/netfilter/nfnetlink.h
84039 +++ b/include/linux/netfilter/nfnetlink.h
84040 @@ -19,7 +19,7 @@ struct nfnl_callback {
84041 const struct nlattr * const cda[]);
84042 const struct nla_policy *policy; /* netlink attribute policy */
84043 const u_int16_t attr_count; /* number of nlattr's */
84044 -};
84045 +} __do_const;
84046
84047 struct nfnetlink_subsystem {
84048 const char *name;
84049 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84050 new file mode 100644
84051 index 0000000..33f4af8
84052 --- /dev/null
84053 +++ b/include/linux/netfilter/xt_gradm.h
84054 @@ -0,0 +1,9 @@
84055 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84056 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84057 +
84058 +struct xt_gradm_mtinfo {
84059 + __u16 flags;
84060 + __u16 invflags;
84061 +};
84062 +
84063 +#endif
84064 diff --git a/include/linux/nls.h b/include/linux/nls.h
84065 index 520681b..2b7fabb 100644
84066 --- a/include/linux/nls.h
84067 +++ b/include/linux/nls.h
84068 @@ -31,7 +31,7 @@ struct nls_table {
84069 const unsigned char *charset2upper;
84070 struct module *owner;
84071 struct nls_table *next;
84072 -};
84073 +} __do_const;
84074
84075 /* this value hold the maximum octet of charset */
84076 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84077 @@ -46,7 +46,7 @@ enum utf16_endian {
84078 /* nls_base.c */
84079 extern int __register_nls(struct nls_table *, struct module *);
84080 extern int unregister_nls(struct nls_table *);
84081 -extern struct nls_table *load_nls(char *);
84082 +extern struct nls_table *load_nls(const char *);
84083 extern void unload_nls(struct nls_table *);
84084 extern struct nls_table *load_nls_default(void);
84085 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84086 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84087 index d14a4c3..a078786 100644
84088 --- a/include/linux/notifier.h
84089 +++ b/include/linux/notifier.h
84090 @@ -54,7 +54,8 @@ struct notifier_block {
84091 notifier_fn_t notifier_call;
84092 struct notifier_block __rcu *next;
84093 int priority;
84094 -};
84095 +} __do_const;
84096 +typedef struct notifier_block __no_const notifier_block_no_const;
84097
84098 struct atomic_notifier_head {
84099 spinlock_t lock;
84100 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84101 index b2a0f15..4d7da32 100644
84102 --- a/include/linux/oprofile.h
84103 +++ b/include/linux/oprofile.h
84104 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84105 int oprofilefs_create_ro_ulong(struct dentry * root,
84106 char const * name, ulong * val);
84107
84108 -/** Create a file for read-only access to an atomic_t. */
84109 +/** Create a file for read-only access to an atomic_unchecked_t. */
84110 int oprofilefs_create_ro_atomic(struct dentry * root,
84111 - char const * name, atomic_t * val);
84112 + char const * name, atomic_unchecked_t * val);
84113
84114 /** create a directory */
84115 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84116 diff --git a/include/linux/padata.h b/include/linux/padata.h
84117 index 4386946..f50c615 100644
84118 --- a/include/linux/padata.h
84119 +++ b/include/linux/padata.h
84120 @@ -129,7 +129,7 @@ struct parallel_data {
84121 struct padata_serial_queue __percpu *squeue;
84122 atomic_t reorder_objects;
84123 atomic_t refcnt;
84124 - atomic_t seq_nr;
84125 + atomic_unchecked_t seq_nr;
84126 struct padata_cpumask cpumask;
84127 spinlock_t lock ____cacheline_aligned;
84128 unsigned int processed;
84129 diff --git a/include/linux/path.h b/include/linux/path.h
84130 index d137218..be0c176 100644
84131 --- a/include/linux/path.h
84132 +++ b/include/linux/path.h
84133 @@ -1,13 +1,15 @@
84134 #ifndef _LINUX_PATH_H
84135 #define _LINUX_PATH_H
84136
84137 +#include <linux/compiler.h>
84138 +
84139 struct dentry;
84140 struct vfsmount;
84141
84142 struct path {
84143 struct vfsmount *mnt;
84144 struct dentry *dentry;
84145 -};
84146 +} __randomize_layout;
84147
84148 extern void path_get(const struct path *);
84149 extern void path_put(const struct path *);
84150 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84151 index 2706ee9..e691f7c 100644
84152 --- a/include/linux/pci_hotplug.h
84153 +++ b/include/linux/pci_hotplug.h
84154 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84155 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84156 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84157 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84158 -};
84159 +} __do_const;
84160 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84161
84162 /**
84163 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84164 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84165 index 893a0d0..d5f996e 100644
84166 --- a/include/linux/perf_event.h
84167 +++ b/include/linux/perf_event.h
84168 @@ -341,8 +341,8 @@ struct perf_event {
84169
84170 enum perf_event_active_state state;
84171 unsigned int attach_state;
84172 - local64_t count;
84173 - atomic64_t child_count;
84174 + local64_t count; /* PaX: fix it one day */
84175 + atomic64_unchecked_t child_count;
84176
84177 /*
84178 * These are the total time in nanoseconds that the event
84179 @@ -393,8 +393,8 @@ struct perf_event {
84180 * These accumulate total time (in nanoseconds) that children
84181 * events have been enabled and running, respectively.
84182 */
84183 - atomic64_t child_total_time_enabled;
84184 - atomic64_t child_total_time_running;
84185 + atomic64_unchecked_t child_total_time_enabled;
84186 + atomic64_unchecked_t child_total_time_running;
84187
84188 /*
84189 * Protect attach/detach and child_list:
84190 @@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84191 entry->ip[entry->nr++] = ip;
84192 }
84193
84194 -extern int sysctl_perf_event_paranoid;
84195 +extern int sysctl_perf_event_legitimately_concerned;
84196 extern int sysctl_perf_event_mlock;
84197 extern int sysctl_perf_event_sample_rate;
84198 extern int sysctl_perf_cpu_time_max_percent;
84199 @@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84200 loff_t *ppos);
84201
84202
84203 +static inline bool perf_paranoid_any(void)
84204 +{
84205 + return sysctl_perf_event_legitimately_concerned > 2;
84206 +}
84207 +
84208 static inline bool perf_paranoid_tracepoint_raw(void)
84209 {
84210 - return sysctl_perf_event_paranoid > -1;
84211 + return sysctl_perf_event_legitimately_concerned > -1;
84212 }
84213
84214 static inline bool perf_paranoid_cpu(void)
84215 {
84216 - return sysctl_perf_event_paranoid > 0;
84217 + return sysctl_perf_event_legitimately_concerned > 0;
84218 }
84219
84220 static inline bool perf_paranoid_kernel(void)
84221 {
84222 - return sysctl_perf_event_paranoid > 1;
84223 + return sysctl_perf_event_legitimately_concerned > 1;
84224 }
84225
84226 extern void perf_event_init(void);
84227 @@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
84228 struct device_attribute attr;
84229 u64 id;
84230 const char *event_str;
84231 -};
84232 +} __do_const;
84233
84234 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84235 static struct perf_pmu_events_attr _var = { \
84236 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84237 index 1997ffc..4f1f44d 100644
84238 --- a/include/linux/pid_namespace.h
84239 +++ b/include/linux/pid_namespace.h
84240 @@ -44,7 +44,7 @@ struct pid_namespace {
84241 int hide_pid;
84242 int reboot; /* group exit code if this pidns was rebooted */
84243 unsigned int proc_inum;
84244 -};
84245 +} __randomize_layout;
84246
84247 extern struct pid_namespace init_pid_ns;
84248
84249 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84250 index eb8b8ac..62649e1 100644
84251 --- a/include/linux/pipe_fs_i.h
84252 +++ b/include/linux/pipe_fs_i.h
84253 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84254 struct mutex mutex;
84255 wait_queue_head_t wait;
84256 unsigned int nrbufs, curbuf, buffers;
84257 - unsigned int readers;
84258 - unsigned int writers;
84259 - unsigned int files;
84260 - unsigned int waiting_writers;
84261 + atomic_t readers;
84262 + atomic_t writers;
84263 + atomic_t files;
84264 + atomic_t waiting_writers;
84265 unsigned int r_counter;
84266 unsigned int w_counter;
84267 struct page *tmp_page;
84268 diff --git a/include/linux/pm.h b/include/linux/pm.h
84269 index 383fd68..7a11504 100644
84270 --- a/include/linux/pm.h
84271 +++ b/include/linux/pm.h
84272 @@ -621,6 +621,7 @@ struct dev_pm_domain {
84273 struct dev_pm_ops ops;
84274 void (*detach)(struct device *dev, bool power_off);
84275 };
84276 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84277
84278 /*
84279 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84280 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84281 index 2e0e06d..824cc9b 100644
84282 --- a/include/linux/pm_domain.h
84283 +++ b/include/linux/pm_domain.h
84284 @@ -36,11 +36,11 @@ struct gpd_dev_ops {
84285 int (*save_state)(struct device *dev);
84286 int (*restore_state)(struct device *dev);
84287 bool (*active_wakeup)(struct device *dev);
84288 -};
84289 +} __no_const;
84290
84291 struct gpd_cpuidle_data {
84292 unsigned int saved_exit_latency;
84293 - struct cpuidle_state *idle_state;
84294 + cpuidle_state_no_const *idle_state;
84295 };
84296
84297 struct generic_pm_domain {
84298 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84299 index 367f49b..d2f5a14 100644
84300 --- a/include/linux/pm_runtime.h
84301 +++ b/include/linux/pm_runtime.h
84302 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84303
84304 static inline void pm_runtime_mark_last_busy(struct device *dev)
84305 {
84306 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84307 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84308 }
84309
84310 #else /* !CONFIG_PM_RUNTIME */
84311 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84312 index 195aafc..49a7bc2 100644
84313 --- a/include/linux/pnp.h
84314 +++ b/include/linux/pnp.h
84315 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84316 struct pnp_fixup {
84317 char id[7];
84318 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84319 -};
84320 +} __do_const;
84321
84322 /* config parameters */
84323 #define PNP_CONFIG_NORMAL 0x0001
84324 diff --git a/include/linux/poison.h b/include/linux/poison.h
84325 index 2110a81..13a11bb 100644
84326 --- a/include/linux/poison.h
84327 +++ b/include/linux/poison.h
84328 @@ -19,8 +19,8 @@
84329 * under normal circumstances, used to verify that nobody uses
84330 * non-initialized list entries.
84331 */
84332 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84333 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84334 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84335 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84336
84337 /********** include/linux/timer.h **********/
84338 /*
84339 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84340 index d8b187c3..9a9257a 100644
84341 --- a/include/linux/power/smartreflex.h
84342 +++ b/include/linux/power/smartreflex.h
84343 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84344 int (*notify)(struct omap_sr *sr, u32 status);
84345 u8 notify_flags;
84346 u8 class_type;
84347 -};
84348 +} __do_const;
84349
84350 /**
84351 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84352 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84353 index 4ea1d37..80f4b33 100644
84354 --- a/include/linux/ppp-comp.h
84355 +++ b/include/linux/ppp-comp.h
84356 @@ -84,7 +84,7 @@ struct compressor {
84357 struct module *owner;
84358 /* Extra skb space needed by the compressor algorithm */
84359 unsigned int comp_extra;
84360 -};
84361 +} __do_const;
84362
84363 /*
84364 * The return value from decompress routine is the length of the
84365 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84366 index de83b4e..c4b997d 100644
84367 --- a/include/linux/preempt.h
84368 +++ b/include/linux/preempt.h
84369 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84370 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84371 #endif
84372
84373 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84374 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84375 +
84376 #define __preempt_count_inc() __preempt_count_add(1)
84377 #define __preempt_count_dec() __preempt_count_sub(1)
84378
84379 #define preempt_count_inc() preempt_count_add(1)
84380 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84381 #define preempt_count_dec() preempt_count_sub(1)
84382 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84383
84384 #ifdef CONFIG_PREEMPT_COUNT
84385
84386 @@ -41,6 +46,12 @@ do { \
84387 barrier(); \
84388 } while (0)
84389
84390 +#define raw_preempt_disable() \
84391 +do { \
84392 + raw_preempt_count_inc(); \
84393 + barrier(); \
84394 +} while (0)
84395 +
84396 #define sched_preempt_enable_no_resched() \
84397 do { \
84398 barrier(); \
84399 @@ -49,6 +60,12 @@ do { \
84400
84401 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84402
84403 +#define raw_preempt_enable_no_resched() \
84404 +do { \
84405 + barrier(); \
84406 + raw_preempt_count_dec(); \
84407 +} while (0)
84408 +
84409 #ifdef CONFIG_PREEMPT
84410 #define preempt_enable() \
84411 do { \
84412 @@ -113,8 +130,10 @@ do { \
84413 * region.
84414 */
84415 #define preempt_disable() barrier()
84416 +#define raw_preempt_disable() barrier()
84417 #define sched_preempt_enable_no_resched() barrier()
84418 #define preempt_enable_no_resched() barrier()
84419 +#define raw_preempt_enable_no_resched() barrier()
84420 #define preempt_enable() barrier()
84421 #define preempt_check_resched() do { } while (0)
84422
84423 @@ -128,11 +147,13 @@ do { \
84424 /*
84425 * Modules have no business playing preemption tricks.
84426 */
84427 +#ifndef CONFIG_PAX_KERNEXEC
84428 #undef sched_preempt_enable_no_resched
84429 #undef preempt_enable_no_resched
84430 #undef preempt_enable_no_resched_notrace
84431 #undef preempt_check_resched
84432 #endif
84433 +#endif
84434
84435 #define preempt_set_need_resched() \
84436 do { \
84437 diff --git a/include/linux/printk.h b/include/linux/printk.h
84438 index d78125f..7f36596 100644
84439 --- a/include/linux/printk.h
84440 +++ b/include/linux/printk.h
84441 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84442 void early_printk(const char *s, ...) { }
84443 #endif
84444
84445 +extern int kptr_restrict;
84446 +
84447 #ifdef CONFIG_PRINTK
84448 asmlinkage __printf(5, 0)
84449 int vprintk_emit(int facility, int level,
84450 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84451
84452 extern int printk_delay_msec;
84453 extern int dmesg_restrict;
84454 -extern int kptr_restrict;
84455
84456 extern void wake_up_klogd(void);
84457
84458 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84459 index b97bf2e..f14c92d4 100644
84460 --- a/include/linux/proc_fs.h
84461 +++ b/include/linux/proc_fs.h
84462 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84463 extern struct proc_dir_entry *proc_symlink(const char *,
84464 struct proc_dir_entry *, const char *);
84465 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84466 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84467 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84468 struct proc_dir_entry *, void *);
84469 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84470 + struct proc_dir_entry *, void *);
84471 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84472 struct proc_dir_entry *);
84473
84474 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84475 return proc_create_data(name, mode, parent, proc_fops, NULL);
84476 }
84477
84478 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84479 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84480 +{
84481 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84482 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84483 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84484 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84485 +#else
84486 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84487 +#endif
84488 +}
84489 +
84490 +
84491 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84492 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84493 extern void *PDE_DATA(const struct inode *);
84494 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84495 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84496 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84497 struct proc_dir_entry *parent) {return NULL;}
84498 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84499 + struct proc_dir_entry *parent) { return NULL; }
84500 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84501 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84502 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84503 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84504 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84505 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84506 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84507 @@ -79,7 +99,7 @@ struct net;
84508 static inline struct proc_dir_entry *proc_net_mkdir(
84509 struct net *net, const char *name, struct proc_dir_entry *parent)
84510 {
84511 - return proc_mkdir_data(name, 0, parent, net);
84512 + return proc_mkdir_data_restrict(name, 0, parent, net);
84513 }
84514
84515 #endif /* _LINUX_PROC_FS_H */
84516 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84517 index 34a1e10..70f6bde 100644
84518 --- a/include/linux/proc_ns.h
84519 +++ b/include/linux/proc_ns.h
84520 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84521 void (*put)(void *ns);
84522 int (*install)(struct nsproxy *nsproxy, void *ns);
84523 unsigned int (*inum)(void *ns);
84524 -};
84525 +} __do_const __randomize_layout;
84526
84527 struct proc_ns {
84528 void *ns;
84529 diff --git a/include/linux/quota.h b/include/linux/quota.h
84530 index 80d345a..9e89a9a 100644
84531 --- a/include/linux/quota.h
84532 +++ b/include/linux/quota.h
84533 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84534
84535 extern bool qid_eq(struct kqid left, struct kqid right);
84536 extern bool qid_lt(struct kqid left, struct kqid right);
84537 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84538 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84539 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84540 extern bool qid_valid(struct kqid qid);
84541
84542 diff --git a/include/linux/random.h b/include/linux/random.h
84543 index b05856e..0a9f14e 100644
84544 --- a/include/linux/random.h
84545 +++ b/include/linux/random.h
84546 @@ -9,9 +9,19 @@
84547 #include <uapi/linux/random.h>
84548
84549 extern void add_device_randomness(const void *, unsigned int);
84550 +
84551 +static inline void add_latent_entropy(void)
84552 +{
84553 +
84554 +#ifdef LATENT_ENTROPY_PLUGIN
84555 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84556 +#endif
84557 +
84558 +}
84559 +
84560 extern void add_input_randomness(unsigned int type, unsigned int code,
84561 - unsigned int value);
84562 -extern void add_interrupt_randomness(int irq, int irq_flags);
84563 + unsigned int value) __latent_entropy;
84564 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84565
84566 extern void get_random_bytes(void *buf, int nbytes);
84567 extern void get_random_bytes_arch(void *buf, int nbytes);
84568 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84569 extern const struct file_operations random_fops, urandom_fops;
84570 #endif
84571
84572 -unsigned int get_random_int(void);
84573 +unsigned int __intentional_overflow(-1) get_random_int(void);
84574 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84575
84576 -u32 prandom_u32(void);
84577 +u32 prandom_u32(void) __intentional_overflow(-1);
84578 void prandom_bytes(void *buf, size_t nbytes);
84579 void prandom_seed(u32 seed);
84580 void prandom_reseed_late(void);
84581 @@ -37,6 +47,11 @@ struct rnd_state {
84582 u32 prandom_u32_state(struct rnd_state *state);
84583 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84584
84585 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84586 +{
84587 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84588 +}
84589 +
84590 /**
84591 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84592 * @ep_ro: right open interval endpoint
84593 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84594 *
84595 * Returns: pseudo-random number in interval [0, ep_ro)
84596 */
84597 -static inline u32 prandom_u32_max(u32 ep_ro)
84598 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84599 {
84600 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84601 }
84602 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84603 index 378c5ee..aa84a47 100644
84604 --- a/include/linux/rbtree_augmented.h
84605 +++ b/include/linux/rbtree_augmented.h
84606 @@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84607 old->rbaugmented = rbcompute(old); \
84608 } \
84609 rbstatic const struct rb_augment_callbacks rbname = { \
84610 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84611 + .propagate = rbname ## _propagate, \
84612 + .copy = rbname ## _copy, \
84613 + .rotate = rbname ## _rotate \
84614 };
84615
84616
84617 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84618 index 372ad5e..d4373f8 100644
84619 --- a/include/linux/rculist.h
84620 +++ b/include/linux/rculist.h
84621 @@ -29,8 +29,8 @@
84622 */
84623 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84624 {
84625 - ACCESS_ONCE(list->next) = list;
84626 - ACCESS_ONCE(list->prev) = list;
84627 + ACCESS_ONCE_RW(list->next) = list;
84628 + ACCESS_ONCE_RW(list->prev) = list;
84629 }
84630
84631 /*
84632 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84633 struct list_head *prev, struct list_head *next);
84634 #endif
84635
84636 +void __pax_list_add_rcu(struct list_head *new,
84637 + struct list_head *prev, struct list_head *next);
84638 +
84639 /**
84640 * list_add_rcu - add a new entry to rcu-protected list
84641 * @new: new entry to be added
84642 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84643 __list_add_rcu(new, head, head->next);
84644 }
84645
84646 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84647 +{
84648 + __pax_list_add_rcu(new, head, head->next);
84649 +}
84650 +
84651 /**
84652 * list_add_tail_rcu - add a new entry to rcu-protected list
84653 * @new: new entry to be added
84654 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84655 __list_add_rcu(new, head->prev, head);
84656 }
84657
84658 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84659 + struct list_head *head)
84660 +{
84661 + __pax_list_add_rcu(new, head->prev, head);
84662 +}
84663 +
84664 /**
84665 * list_del_rcu - deletes entry from list without re-initialization
84666 * @entry: the element to delete from the list.
84667 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84668 entry->prev = LIST_POISON2;
84669 }
84670
84671 +extern void pax_list_del_rcu(struct list_head *entry);
84672 +
84673 /**
84674 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84675 * @n: the element to delete from the hash list.
84676 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84677 index 53ff1a7..c40f0ab 100644
84678 --- a/include/linux/rcupdate.h
84679 +++ b/include/linux/rcupdate.h
84680 @@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84681 #define rcu_note_voluntary_context_switch(t) \
84682 do { \
84683 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84684 - ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84685 + ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84686 } while (0)
84687 #else /* #ifdef CONFIG_TASKS_RCU */
84688 #define TASKS_RCU(x) do { } while (0)
84689 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84690 index 67fc8fc..a90f7d8 100644
84691 --- a/include/linux/reboot.h
84692 +++ b/include/linux/reboot.h
84693 @@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84694 */
84695
84696 extern void migrate_to_reboot_cpu(void);
84697 -extern void machine_restart(char *cmd);
84698 -extern void machine_halt(void);
84699 -extern void machine_power_off(void);
84700 +extern void machine_restart(char *cmd) __noreturn;
84701 +extern void machine_halt(void) __noreturn;
84702 +extern void machine_power_off(void) __noreturn;
84703
84704 extern void machine_shutdown(void);
84705 struct pt_regs;
84706 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84707 */
84708
84709 extern void kernel_restart_prepare(char *cmd);
84710 -extern void kernel_restart(char *cmd);
84711 -extern void kernel_halt(void);
84712 -extern void kernel_power_off(void);
84713 +extern void kernel_restart(char *cmd) __noreturn;
84714 +extern void kernel_halt(void) __noreturn;
84715 +extern void kernel_power_off(void) __noreturn;
84716
84717 extern int C_A_D; /* for sysctl */
84718 void ctrl_alt_del(void);
84719 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84720 * Emergency restart, callable from an interrupt handler.
84721 */
84722
84723 -extern void emergency_restart(void);
84724 +extern void emergency_restart(void) __noreturn;
84725 #include <asm/emergency-restart.h>
84726
84727 #endif /* _LINUX_REBOOT_H */
84728 diff --git a/include/linux/regset.h b/include/linux/regset.h
84729 index 8e0c9fe..ac4d221 100644
84730 --- a/include/linux/regset.h
84731 +++ b/include/linux/regset.h
84732 @@ -161,7 +161,8 @@ struct user_regset {
84733 unsigned int align;
84734 unsigned int bias;
84735 unsigned int core_note_type;
84736 -};
84737 +} __do_const;
84738 +typedef struct user_regset __no_const user_regset_no_const;
84739
84740 /**
84741 * struct user_regset_view - available regsets
84742 diff --git a/include/linux/relay.h b/include/linux/relay.h
84743 index d7c8359..818daf5 100644
84744 --- a/include/linux/relay.h
84745 +++ b/include/linux/relay.h
84746 @@ -157,7 +157,7 @@ struct rchan_callbacks
84747 * The callback should return 0 if successful, negative if not.
84748 */
84749 int (*remove_buf_file)(struct dentry *dentry);
84750 -};
84751 +} __no_const;
84752
84753 /*
84754 * CONFIG_RELAY kernel API, kernel/relay.c
84755 diff --git a/include/linux/rio.h b/include/linux/rio.h
84756 index 6bda06f..bf39a9b 100644
84757 --- a/include/linux/rio.h
84758 +++ b/include/linux/rio.h
84759 @@ -358,7 +358,7 @@ struct rio_ops {
84760 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84761 u64 rstart, u32 size, u32 flags);
84762 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84763 -};
84764 +} __no_const;
84765
84766 #define RIO_RESOURCE_MEM 0x00000100
84767 #define RIO_RESOURCE_DOORBELL 0x00000200
84768 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84769 index c0c2bce..4813524 100644
84770 --- a/include/linux/rmap.h
84771 +++ b/include/linux/rmap.h
84772 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84773 void anon_vma_init(void); /* create anon_vma_cachep */
84774 int anon_vma_prepare(struct vm_area_struct *);
84775 void unlink_anon_vmas(struct vm_area_struct *);
84776 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84777 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84778 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84779 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84780
84781 static inline void anon_vma_merge(struct vm_area_struct *vma,
84782 struct vm_area_struct *next)
84783 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84784 index ed8f9e7..999bc96 100644
84785 --- a/include/linux/scatterlist.h
84786 +++ b/include/linux/scatterlist.h
84787 @@ -1,6 +1,7 @@
84788 #ifndef _LINUX_SCATTERLIST_H
84789 #define _LINUX_SCATTERLIST_H
84790
84791 +#include <linux/sched.h>
84792 #include <linux/string.h>
84793 #include <linux/bug.h>
84794 #include <linux/mm.h>
84795 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84796 #ifdef CONFIG_DEBUG_SG
84797 BUG_ON(!virt_addr_valid(buf));
84798 #endif
84799 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84800 + if (object_starts_on_stack(buf)) {
84801 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84802 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84803 + } else
84804 +#endif
84805 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84806 }
84807
84808 diff --git a/include/linux/sched.h b/include/linux/sched.h
84809 index 5e344bb..0743255 100644
84810 --- a/include/linux/sched.h
84811 +++ b/include/linux/sched.h
84812 @@ -133,6 +133,7 @@ struct fs_struct;
84813 struct perf_event_context;
84814 struct blk_plug;
84815 struct filename;
84816 +struct linux_binprm;
84817
84818 #define VMACACHE_BITS 2
84819 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84820 @@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84821 extern int in_sched_functions(unsigned long addr);
84822
84823 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84824 -extern signed long schedule_timeout(signed long timeout);
84825 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84826 extern signed long schedule_timeout_interruptible(signed long timeout);
84827 extern signed long schedule_timeout_killable(signed long timeout);
84828 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84829 @@ -387,6 +388,19 @@ struct nsproxy;
84830 struct user_namespace;
84831
84832 #ifdef CONFIG_MMU
84833 +
84834 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84835 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84836 +#else
84837 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84838 +{
84839 + return 0;
84840 +}
84841 +#endif
84842 +
84843 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84844 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84845 +
84846 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84847 extern unsigned long
84848 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84849 @@ -685,6 +699,17 @@ struct signal_struct {
84850 #ifdef CONFIG_TASKSTATS
84851 struct taskstats *stats;
84852 #endif
84853 +
84854 +#ifdef CONFIG_GRKERNSEC
84855 + u32 curr_ip;
84856 + u32 saved_ip;
84857 + u32 gr_saddr;
84858 + u32 gr_daddr;
84859 + u16 gr_sport;
84860 + u16 gr_dport;
84861 + u8 used_accept:1;
84862 +#endif
84863 +
84864 #ifdef CONFIG_AUDIT
84865 unsigned audit_tty;
84866 unsigned audit_tty_log_passwd;
84867 @@ -711,7 +736,7 @@ struct signal_struct {
84868 struct mutex cred_guard_mutex; /* guard against foreign influences on
84869 * credential calculations
84870 * (notably. ptrace) */
84871 -};
84872 +} __randomize_layout;
84873
84874 /*
84875 * Bits in flags field of signal_struct.
84876 @@ -764,6 +789,14 @@ struct user_struct {
84877 struct key *session_keyring; /* UID's default session keyring */
84878 #endif
84879
84880 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84881 + unsigned char kernel_banned;
84882 +#endif
84883 +#ifdef CONFIG_GRKERNSEC_BRUTE
84884 + unsigned char suid_banned;
84885 + unsigned long suid_ban_expires;
84886 +#endif
84887 +
84888 /* Hash table maintenance information */
84889 struct hlist_node uidhash_node;
84890 kuid_t uid;
84891 @@ -771,7 +804,7 @@ struct user_struct {
84892 #ifdef CONFIG_PERF_EVENTS
84893 atomic_long_t locked_vm;
84894 #endif
84895 -};
84896 +} __randomize_layout;
84897
84898 extern int uids_sysfs_init(void);
84899
84900 @@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84901 struct task_struct {
84902 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84903 void *stack;
84904 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84905 + void *lowmem_stack;
84906 +#endif
84907 atomic_t usage;
84908 unsigned int flags; /* per process flags, defined below */
84909 unsigned int ptrace;
84910 @@ -1362,8 +1398,8 @@ struct task_struct {
84911 struct list_head thread_node;
84912
84913 struct completion *vfork_done; /* for vfork() */
84914 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84915 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84916 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84917 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84918
84919 cputime_t utime, stime, utimescaled, stimescaled;
84920 cputime_t gtime;
84921 @@ -1388,11 +1424,6 @@ struct task_struct {
84922 struct task_cputime cputime_expires;
84923 struct list_head cpu_timers[3];
84924
84925 -/* process credentials */
84926 - const struct cred __rcu *real_cred; /* objective and real subjective task
84927 - * credentials (COW) */
84928 - const struct cred __rcu *cred; /* effective (overridable) subjective task
84929 - * credentials (COW) */
84930 char comm[TASK_COMM_LEN]; /* executable name excluding path
84931 - access with [gs]et_task_comm (which lock
84932 it with task_lock())
84933 @@ -1410,6 +1441,10 @@ struct task_struct {
84934 #endif
84935 /* CPU-specific state of this task */
84936 struct thread_struct thread;
84937 +/* thread_info moved to task_struct */
84938 +#ifdef CONFIG_X86
84939 + struct thread_info tinfo;
84940 +#endif
84941 /* filesystem information */
84942 struct fs_struct *fs;
84943 /* open file information */
84944 @@ -1484,6 +1519,10 @@ struct task_struct {
84945 gfp_t lockdep_reclaim_gfp;
84946 #endif
84947
84948 +/* process credentials */
84949 + const struct cred __rcu *real_cred; /* objective and real subjective task
84950 + * credentials (COW) */
84951 +
84952 /* journalling filesystem info */
84953 void *journal_info;
84954
84955 @@ -1522,6 +1561,10 @@ struct task_struct {
84956 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84957 struct list_head cg_list;
84958 #endif
84959 +
84960 + const struct cred __rcu *cred; /* effective (overridable) subjective task
84961 + * credentials (COW) */
84962 +
84963 #ifdef CONFIG_FUTEX
84964 struct robust_list_head __user *robust_list;
84965 #ifdef CONFIG_COMPAT
84966 @@ -1635,7 +1678,7 @@ struct task_struct {
84967 * Number of functions that haven't been traced
84968 * because of depth overrun.
84969 */
84970 - atomic_t trace_overrun;
84971 + atomic_unchecked_t trace_overrun;
84972 /* Pause for the tracing */
84973 atomic_t tracing_graph_pause;
84974 #endif
84975 @@ -1661,7 +1704,78 @@ struct task_struct {
84976 unsigned int sequential_io;
84977 unsigned int sequential_io_avg;
84978 #endif
84979 -};
84980 +
84981 +#ifdef CONFIG_GRKERNSEC
84982 + /* grsecurity */
84983 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84984 + u64 exec_id;
84985 +#endif
84986 +#ifdef CONFIG_GRKERNSEC_SETXID
84987 + const struct cred *delayed_cred;
84988 +#endif
84989 + struct dentry *gr_chroot_dentry;
84990 + struct acl_subject_label *acl;
84991 + struct acl_subject_label *tmpacl;
84992 + struct acl_role_label *role;
84993 + struct file *exec_file;
84994 + unsigned long brute_expires;
84995 + u16 acl_role_id;
84996 + u8 inherited;
84997 + /* is this the task that authenticated to the special role */
84998 + u8 acl_sp_role;
84999 + u8 is_writable;
85000 + u8 brute;
85001 + u8 gr_is_chrooted;
85002 +#endif
85003 +
85004 +} __randomize_layout;
85005 +
85006 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85007 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85008 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85009 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85010 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85011 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85012 +
85013 +#ifdef CONFIG_PAX_SOFTMODE
85014 +extern int pax_softmode;
85015 +#endif
85016 +
85017 +extern int pax_check_flags(unsigned long *);
85018 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85019 +
85020 +/* if tsk != current then task_lock must be held on it */
85021 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85022 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85023 +{
85024 + if (likely(tsk->mm))
85025 + return tsk->mm->pax_flags;
85026 + else
85027 + return 0UL;
85028 +}
85029 +
85030 +/* if tsk != current then task_lock must be held on it */
85031 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85032 +{
85033 + if (likely(tsk->mm)) {
85034 + tsk->mm->pax_flags = flags;
85035 + return 0;
85036 + }
85037 + return -EINVAL;
85038 +}
85039 +#endif
85040 +
85041 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85042 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85043 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85044 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85045 +#endif
85046 +
85047 +struct path;
85048 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85049 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85050 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85051 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85052
85053 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85054 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85055 @@ -1743,7 +1857,7 @@ struct pid_namespace;
85056 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85057 struct pid_namespace *ns);
85058
85059 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85060 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85061 {
85062 return tsk->pid;
85063 }
85064 @@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
85065
85066 extern void sched_clock_init(void);
85067
85068 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85069 +static inline void populate_stack(void)
85070 +{
85071 + struct task_struct *curtask = current;
85072 + int c;
85073 + int *ptr = curtask->stack;
85074 + int *end = curtask->stack + THREAD_SIZE;
85075 +
85076 + while (ptr < end) {
85077 + c = *(volatile int *)ptr;
85078 + ptr += PAGE_SIZE/sizeof(int);
85079 + }
85080 +}
85081 +#else
85082 +static inline void populate_stack(void)
85083 +{
85084 +}
85085 +#endif
85086 +
85087 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85088 static inline void sched_clock_tick(void)
85089 {
85090 @@ -2239,7 +2372,9 @@ void yield(void);
85091 extern struct exec_domain default_exec_domain;
85092
85093 union thread_union {
85094 +#ifndef CONFIG_X86
85095 struct thread_info thread_info;
85096 +#endif
85097 unsigned long stack[THREAD_SIZE/sizeof(long)];
85098 };
85099
85100 @@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
85101 */
85102
85103 extern struct task_struct *find_task_by_vpid(pid_t nr);
85104 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85105 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85106 struct pid_namespace *ns);
85107
85108 @@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85109 extern void exit_itimers(struct signal_struct *);
85110 extern void flush_itimer_signals(void);
85111
85112 -extern void do_group_exit(int);
85113 +extern __noreturn void do_group_exit(int);
85114
85115 extern int do_execve(struct filename *,
85116 const char __user * const __user *,
85117 @@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85118 #define task_stack_end_corrupted(task) \
85119 (*(end_of_stack(task)) != STACK_END_MAGIC)
85120
85121 -static inline int object_is_on_stack(void *obj)
85122 +static inline int object_starts_on_stack(const void *obj)
85123 {
85124 - void *stack = task_stack_page(current);
85125 + const void *stack = task_stack_page(current);
85126
85127 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85128 }
85129 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85130 index 596a0e0..bea77ec 100644
85131 --- a/include/linux/sched/sysctl.h
85132 +++ b/include/linux/sched/sysctl.h
85133 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85134 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85135
85136 extern int sysctl_max_map_count;
85137 +extern unsigned long sysctl_heap_stack_gap;
85138
85139 extern unsigned int sysctl_sched_latency;
85140 extern unsigned int sysctl_sched_min_granularity;
85141 diff --git a/include/linux/security.h b/include/linux/security.h
85142 index ba96471..74fb3f6 100644
85143 --- a/include/linux/security.h
85144 +++ b/include/linux/security.h
85145 @@ -27,6 +27,7 @@
85146 #include <linux/slab.h>
85147 #include <linux/err.h>
85148 #include <linux/string.h>
85149 +#include <linux/grsecurity.h>
85150
85151 struct linux_binprm;
85152 struct cred;
85153 @@ -116,8 +117,6 @@ struct seq_file;
85154
85155 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85156
85157 -void reset_security_ops(void);
85158 -
85159 #ifdef CONFIG_MMU
85160 extern unsigned long mmap_min_addr;
85161 extern unsigned long dac_mmap_min_addr;
85162 @@ -1729,7 +1728,7 @@ struct security_operations {
85163 struct audit_context *actx);
85164 void (*audit_rule_free) (void *lsmrule);
85165 #endif /* CONFIG_AUDIT */
85166 -};
85167 +} __randomize_layout;
85168
85169 /* prototypes */
85170 extern int security_init(void);
85171 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85172 index dc368b8..e895209 100644
85173 --- a/include/linux/semaphore.h
85174 +++ b/include/linux/semaphore.h
85175 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85176 }
85177
85178 extern void down(struct semaphore *sem);
85179 -extern int __must_check down_interruptible(struct semaphore *sem);
85180 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85181 extern int __must_check down_killable(struct semaphore *sem);
85182 extern int __must_check down_trylock(struct semaphore *sem);
85183 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85184 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85185 index 52e0097..383f21d 100644
85186 --- a/include/linux/seq_file.h
85187 +++ b/include/linux/seq_file.h
85188 @@ -27,6 +27,9 @@ struct seq_file {
85189 struct mutex lock;
85190 const struct seq_operations *op;
85191 int poll_event;
85192 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85193 + u64 exec_id;
85194 +#endif
85195 #ifdef CONFIG_USER_NS
85196 struct user_namespace *user_ns;
85197 #endif
85198 @@ -39,6 +42,7 @@ struct seq_operations {
85199 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85200 int (*show) (struct seq_file *m, void *v);
85201 };
85202 +typedef struct seq_operations __no_const seq_operations_no_const;
85203
85204 #define SEQ_SKIP 1
85205
85206 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85207
85208 char *mangle_path(char *s, const char *p, const char *esc);
85209 int seq_open(struct file *, const struct seq_operations *);
85210 +int seq_open_restrict(struct file *, const struct seq_operations *);
85211 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85212 loff_t seq_lseek(struct file *, loff_t, int);
85213 int seq_release(struct inode *, struct file *);
85214 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85215 }
85216
85217 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85218 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85219 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85220 int single_release(struct inode *, struct file *);
85221 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85222 diff --git a/include/linux/shm.h b/include/linux/shm.h
85223 index 6fb8016..ab4465e 100644
85224 --- a/include/linux/shm.h
85225 +++ b/include/linux/shm.h
85226 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85227 /* The task created the shm object. NULL if the task is dead. */
85228 struct task_struct *shm_creator;
85229 struct list_head shm_clist; /* list by creator */
85230 +#ifdef CONFIG_GRKERNSEC
85231 + u64 shm_createtime;
85232 + pid_t shm_lapid;
85233 +#endif
85234 };
85235
85236 /* shm_mode upper byte flags */
85237 diff --git a/include/linux/signal.h b/include/linux/signal.h
85238 index ab1e039..ad4229e 100644
85239 --- a/include/linux/signal.h
85240 +++ b/include/linux/signal.h
85241 @@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85242 * know it'll be handled, so that they don't get converted to
85243 * SIGKILL or just silently dropped.
85244 */
85245 - kernel_sigaction(sig, (__force __sighandler_t)2);
85246 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85247 }
85248
85249 static inline void disallow_signal(int sig)
85250 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85251 index 6c8b6f6..5a0f4bd 100644
85252 --- a/include/linux/skbuff.h
85253 +++ b/include/linux/skbuff.h
85254 @@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85255 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85256 int node);
85257 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85258 -static inline struct sk_buff *alloc_skb(unsigned int size,
85259 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85260 gfp_t priority)
85261 {
85262 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85263 @@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85264 return skb->inner_transport_header - skb->inner_network_header;
85265 }
85266
85267 -static inline int skb_network_offset(const struct sk_buff *skb)
85268 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85269 {
85270 return skb_network_header(skb) - skb->data;
85271 }
85272 @@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85273 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85274 */
85275 #ifndef NET_SKB_PAD
85276 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85277 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85278 #endif
85279
85280 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85281 @@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85282 int *err);
85283 unsigned int datagram_poll(struct file *file, struct socket *sock,
85284 struct poll_table_struct *wait);
85285 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85286 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85287 struct iovec *to, int size);
85288 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85289 struct iovec *iov);
85290 @@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85291 nf_bridge_put(skb->nf_bridge);
85292 skb->nf_bridge = NULL;
85293 #endif
85294 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85295 + skb->nf_trace = 0;
85296 +#endif
85297 }
85298
85299 static inline void nf_reset_trace(struct sk_buff *skb)
85300 diff --git a/include/linux/slab.h b/include/linux/slab.h
85301 index c265bec..4867d28 100644
85302 --- a/include/linux/slab.h
85303 +++ b/include/linux/slab.h
85304 @@ -14,15 +14,29 @@
85305 #include <linux/gfp.h>
85306 #include <linux/types.h>
85307 #include <linux/workqueue.h>
85308 -
85309 +#include <linux/err.h>
85310
85311 /*
85312 * Flags to pass to kmem_cache_create().
85313 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85314 */
85315 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85316 +
85317 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85318 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85319 +#else
85320 +#define SLAB_USERCOPY 0x00000000UL
85321 +#endif
85322 +
85323 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85324 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85325 +
85326 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85327 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85328 +#else
85329 +#define SLAB_NO_SANITIZE 0x00000000UL
85330 +#endif
85331 +
85332 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85333 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85334 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85335 @@ -98,10 +112,13 @@
85336 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85337 * Both make kfree a no-op.
85338 */
85339 -#define ZERO_SIZE_PTR ((void *)16)
85340 +#define ZERO_SIZE_PTR \
85341 +({ \
85342 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85343 + (void *)(-MAX_ERRNO-1L); \
85344 +})
85345
85346 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85347 - (unsigned long)ZERO_SIZE_PTR)
85348 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85349
85350 #include <linux/kmemleak.h>
85351
85352 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85353 void kfree(const void *);
85354 void kzfree(const void *);
85355 size_t ksize(const void *);
85356 +const char *check_heap_object(const void *ptr, unsigned long n);
85357 +bool is_usercopy_object(const void *ptr);
85358
85359 /*
85360 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85361 @@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85362 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85363 #endif
85364
85365 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85366 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85367 +#endif
85368 +
85369 /*
85370 * Figure out which kmalloc slab an allocation of a certain size
85371 * belongs to.
85372 @@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85373 * 2 = 120 .. 192 bytes
85374 * n = 2^(n-1) .. 2^n -1
85375 */
85376 -static __always_inline int kmalloc_index(size_t size)
85377 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85378 {
85379 if (!size)
85380 return 0;
85381 @@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85382 }
85383 #endif /* !CONFIG_SLOB */
85384
85385 -void *__kmalloc(size_t size, gfp_t flags);
85386 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85387 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85388
85389 #ifdef CONFIG_NUMA
85390 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85391 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85392 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85393 #else
85394 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85395 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85396 index b869d16..1453c73 100644
85397 --- a/include/linux/slab_def.h
85398 +++ b/include/linux/slab_def.h
85399 @@ -40,7 +40,7 @@ struct kmem_cache {
85400 /* 4) cache creation/removal */
85401 const char *name;
85402 struct list_head list;
85403 - int refcount;
85404 + atomic_t refcount;
85405 int object_size;
85406 int align;
85407
85408 @@ -56,10 +56,14 @@ struct kmem_cache {
85409 unsigned long node_allocs;
85410 unsigned long node_frees;
85411 unsigned long node_overflow;
85412 - atomic_t allochit;
85413 - atomic_t allocmiss;
85414 - atomic_t freehit;
85415 - atomic_t freemiss;
85416 + atomic_unchecked_t allochit;
85417 + atomic_unchecked_t allocmiss;
85418 + atomic_unchecked_t freehit;
85419 + atomic_unchecked_t freemiss;
85420 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85421 + atomic_unchecked_t sanitized;
85422 + atomic_unchecked_t not_sanitized;
85423 +#endif
85424
85425 /*
85426 * If debugging is enabled, then the allocator can add additional
85427 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85428 index d82abd4..408c3a0 100644
85429 --- a/include/linux/slub_def.h
85430 +++ b/include/linux/slub_def.h
85431 @@ -74,7 +74,7 @@ struct kmem_cache {
85432 struct kmem_cache_order_objects max;
85433 struct kmem_cache_order_objects min;
85434 gfp_t allocflags; /* gfp flags to use on each alloc */
85435 - int refcount; /* Refcount for slab cache destroy */
85436 + atomic_t refcount; /* Refcount for slab cache destroy */
85437 void (*ctor)(void *);
85438 int inuse; /* Offset to metadata */
85439 int align; /* Alignment */
85440 diff --git a/include/linux/smp.h b/include/linux/smp.h
85441 index 93dff5f..933c561 100644
85442 --- a/include/linux/smp.h
85443 +++ b/include/linux/smp.h
85444 @@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85445 #endif
85446
85447 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85448 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85449 #define put_cpu() preempt_enable()
85450 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85451
85452 /*
85453 * Callback to arch code if there's nosmp or maxcpus=0 on the
85454 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85455 index 46cca4c..3323536 100644
85456 --- a/include/linux/sock_diag.h
85457 +++ b/include/linux/sock_diag.h
85458 @@ -11,7 +11,7 @@ struct sock;
85459 struct sock_diag_handler {
85460 __u8 family;
85461 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85462 -};
85463 +} __do_const;
85464
85465 int sock_diag_register(const struct sock_diag_handler *h);
85466 void sock_diag_unregister(const struct sock_diag_handler *h);
85467 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85468 index 680f9a3..f13aeb0 100644
85469 --- a/include/linux/sonet.h
85470 +++ b/include/linux/sonet.h
85471 @@ -7,7 +7,7 @@
85472 #include <uapi/linux/sonet.h>
85473
85474 struct k_sonet_stats {
85475 -#define __HANDLE_ITEM(i) atomic_t i
85476 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85477 __SONET_ITEMS
85478 #undef __HANDLE_ITEM
85479 };
85480 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85481 index 07d8e53..dc934c9 100644
85482 --- a/include/linux/sunrpc/addr.h
85483 +++ b/include/linux/sunrpc/addr.h
85484 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85485 {
85486 switch (sap->sa_family) {
85487 case AF_INET:
85488 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85489 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85490 case AF_INET6:
85491 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85492 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85493 }
85494 return 0;
85495 }
85496 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85497 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85498 const struct sockaddr *src)
85499 {
85500 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85501 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85502 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85503
85504 dsin->sin_family = ssin->sin_family;
85505 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85506 if (sa->sa_family != AF_INET6)
85507 return 0;
85508
85509 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85510 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85511 }
85512
85513 #endif /* _LINUX_SUNRPC_ADDR_H */
85514 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85515 index 70736b9..37f33db 100644
85516 --- a/include/linux/sunrpc/clnt.h
85517 +++ b/include/linux/sunrpc/clnt.h
85518 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85519 unsigned int p_timer; /* Which RTT timer to use */
85520 u32 p_statidx; /* Which procedure to account */
85521 const char * p_name; /* name of procedure */
85522 -};
85523 +} __do_const;
85524
85525 #ifdef __KERNEL__
85526
85527 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85528 index 2167846..0648fc3 100644
85529 --- a/include/linux/sunrpc/svc.h
85530 +++ b/include/linux/sunrpc/svc.h
85531 @@ -416,7 +416,7 @@ struct svc_procedure {
85532 unsigned int pc_count; /* call count */
85533 unsigned int pc_cachetype; /* cache info (NFS) */
85534 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85535 -};
85536 +} __do_const;
85537
85538 /*
85539 * Function prototypes.
85540 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85541 index 975da75..318c083 100644
85542 --- a/include/linux/sunrpc/svc_rdma.h
85543 +++ b/include/linux/sunrpc/svc_rdma.h
85544 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85545 extern unsigned int svcrdma_max_requests;
85546 extern unsigned int svcrdma_max_req_size;
85547
85548 -extern atomic_t rdma_stat_recv;
85549 -extern atomic_t rdma_stat_read;
85550 -extern atomic_t rdma_stat_write;
85551 -extern atomic_t rdma_stat_sq_starve;
85552 -extern atomic_t rdma_stat_rq_starve;
85553 -extern atomic_t rdma_stat_rq_poll;
85554 -extern atomic_t rdma_stat_rq_prod;
85555 -extern atomic_t rdma_stat_sq_poll;
85556 -extern atomic_t rdma_stat_sq_prod;
85557 +extern atomic_unchecked_t rdma_stat_recv;
85558 +extern atomic_unchecked_t rdma_stat_read;
85559 +extern atomic_unchecked_t rdma_stat_write;
85560 +extern atomic_unchecked_t rdma_stat_sq_starve;
85561 +extern atomic_unchecked_t rdma_stat_rq_starve;
85562 +extern atomic_unchecked_t rdma_stat_rq_poll;
85563 +extern atomic_unchecked_t rdma_stat_rq_prod;
85564 +extern atomic_unchecked_t rdma_stat_sq_poll;
85565 +extern atomic_unchecked_t rdma_stat_sq_prod;
85566
85567 #define RPCRDMA_VERSION 1
85568
85569 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85570 index 8d71d65..f79586e 100644
85571 --- a/include/linux/sunrpc/svcauth.h
85572 +++ b/include/linux/sunrpc/svcauth.h
85573 @@ -120,7 +120,7 @@ struct auth_ops {
85574 int (*release)(struct svc_rqst *rq);
85575 void (*domain_release)(struct auth_domain *);
85576 int (*set_client)(struct svc_rqst *rq);
85577 -};
85578 +} __do_const;
85579
85580 #define SVC_GARBAGE 1
85581 #define SVC_SYSERR 2
85582 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85583 index e7a018e..49f8b17 100644
85584 --- a/include/linux/swiotlb.h
85585 +++ b/include/linux/swiotlb.h
85586 @@ -60,7 +60,8 @@ extern void
85587
85588 extern void
85589 swiotlb_free_coherent(struct device *hwdev, size_t size,
85590 - void *vaddr, dma_addr_t dma_handle);
85591 + void *vaddr, dma_addr_t dma_handle,
85592 + struct dma_attrs *attrs);
85593
85594 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85595 unsigned long offset, size_t size,
85596 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85597 index bda9b81..629e06e 100644
85598 --- a/include/linux/syscalls.h
85599 +++ b/include/linux/syscalls.h
85600 @@ -99,10 +99,16 @@ union bpf_attr;
85601 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85602
85603 #define __SC_DECL(t, a) t a
85604 +#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))
85605 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85606 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85607 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85608 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85609 +#define __SC_LONG(t, a) __typeof( \
85610 + __builtin_choose_expr( \
85611 + sizeof(t) > sizeof(int), \
85612 + (t) 0, \
85613 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85614 + )) a
85615 #define __SC_CAST(t, a) (t) a
85616 #define __SC_ARGS(t, a) a
85617 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85618 @@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85619 asmlinkage long sys_fsync(unsigned int fd);
85620 asmlinkage long sys_fdatasync(unsigned int fd);
85621 asmlinkage long sys_bdflush(int func, long data);
85622 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85623 - char __user *type, unsigned long flags,
85624 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85625 + const char __user *type, unsigned long flags,
85626 void __user *data);
85627 -asmlinkage long sys_umount(char __user *name, int flags);
85628 -asmlinkage long sys_oldumount(char __user *name);
85629 +asmlinkage long sys_umount(const char __user *name, int flags);
85630 +asmlinkage long sys_oldumount(const char __user *name);
85631 asmlinkage long sys_truncate(const char __user *path, long length);
85632 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85633 asmlinkage long sys_stat(const char __user *filename,
85634 @@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85635 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85636 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85637 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85638 - struct sockaddr __user *, int);
85639 + struct sockaddr __user *, int) __intentional_overflow(0);
85640 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85641 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85642 unsigned int vlen, unsigned flags);
85643 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85644 index 27b3b0b..e093dd9 100644
85645 --- a/include/linux/syscore_ops.h
85646 +++ b/include/linux/syscore_ops.h
85647 @@ -16,7 +16,7 @@ struct syscore_ops {
85648 int (*suspend)(void);
85649 void (*resume)(void);
85650 void (*shutdown)(void);
85651 -};
85652 +} __do_const;
85653
85654 extern void register_syscore_ops(struct syscore_ops *ops);
85655 extern void unregister_syscore_ops(struct syscore_ops *ops);
85656 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85657 index b7361f8..341a15a 100644
85658 --- a/include/linux/sysctl.h
85659 +++ b/include/linux/sysctl.h
85660 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85661
85662 extern int proc_dostring(struct ctl_table *, int,
85663 void __user *, size_t *, loff_t *);
85664 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85665 + void __user *, size_t *, loff_t *);
85666 extern int proc_dointvec(struct ctl_table *, int,
85667 void __user *, size_t *, loff_t *);
85668 extern int proc_dointvec_minmax(struct ctl_table *, int,
85669 @@ -113,7 +115,8 @@ struct ctl_table
85670 struct ctl_table_poll *poll;
85671 void *extra1;
85672 void *extra2;
85673 -};
85674 +} __do_const __randomize_layout;
85675 +typedef struct ctl_table __no_const ctl_table_no_const;
85676
85677 struct ctl_node {
85678 struct rb_node node;
85679 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85680 index f97d0db..c1187dc 100644
85681 --- a/include/linux/sysfs.h
85682 +++ b/include/linux/sysfs.h
85683 @@ -34,7 +34,8 @@ struct attribute {
85684 struct lock_class_key *key;
85685 struct lock_class_key skey;
85686 #endif
85687 -};
85688 +} __do_const;
85689 +typedef struct attribute __no_const attribute_no_const;
85690
85691 /**
85692 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85693 @@ -63,7 +64,8 @@ struct attribute_group {
85694 struct attribute *, int);
85695 struct attribute **attrs;
85696 struct bin_attribute **bin_attrs;
85697 -};
85698 +} __do_const;
85699 +typedef struct attribute_group __no_const attribute_group_no_const;
85700
85701 /**
85702 * Use these macros to make defining attributes easier. See include/linux/device.h
85703 @@ -128,7 +130,8 @@ struct bin_attribute {
85704 char *, loff_t, size_t);
85705 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85706 struct vm_area_struct *vma);
85707 -};
85708 +} __do_const;
85709 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85710
85711 /**
85712 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85713 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85714 index 387fa7d..3fcde6b 100644
85715 --- a/include/linux/sysrq.h
85716 +++ b/include/linux/sysrq.h
85717 @@ -16,6 +16,7 @@
85718
85719 #include <linux/errno.h>
85720 #include <linux/types.h>
85721 +#include <linux/compiler.h>
85722
85723 /* Possible values of bitmask for enabling sysrq functions */
85724 /* 0x0001 is reserved for enable everything */
85725 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85726 char *help_msg;
85727 char *action_msg;
85728 int enable_mask;
85729 -};
85730 +} __do_const;
85731
85732 #ifdef CONFIG_MAGIC_SYSRQ
85733
85734 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85735 index ff307b5..f1a4468 100644
85736 --- a/include/linux/thread_info.h
85737 +++ b/include/linux/thread_info.h
85738 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85739 #error "no set_restore_sigmask() provided and default one won't work"
85740 #endif
85741
85742 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85743 +
85744 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85745 +{
85746 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85747 +}
85748 +
85749 #endif /* __KERNEL__ */
85750
85751 #endif /* _LINUX_THREAD_INFO_H */
85752 diff --git a/include/linux/tty.h b/include/linux/tty.h
85753 index 5171ef8..1048d83e 100644
85754 --- a/include/linux/tty.h
85755 +++ b/include/linux/tty.h
85756 @@ -202,7 +202,7 @@ struct tty_port {
85757 const struct tty_port_operations *ops; /* Port operations */
85758 spinlock_t lock; /* Lock protecting tty field */
85759 int blocked_open; /* Waiting to open */
85760 - int count; /* Usage count */
85761 + atomic_t count; /* Usage count */
85762 wait_queue_head_t open_wait; /* Open waiters */
85763 wait_queue_head_t close_wait; /* Close waiters */
85764 wait_queue_head_t delta_msr_wait; /* Modem status change */
85765 @@ -290,7 +290,7 @@ struct tty_struct {
85766 /* If the tty has a pending do_SAK, queue it here - akpm */
85767 struct work_struct SAK_work;
85768 struct tty_port *port;
85769 -};
85770 +} __randomize_layout;
85771
85772 /* Each of a tty's open files has private_data pointing to tty_file_private */
85773 struct tty_file_private {
85774 @@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85775 struct tty_struct *tty, struct file *filp);
85776 static inline int tty_port_users(struct tty_port *port)
85777 {
85778 - return port->count + port->blocked_open;
85779 + return atomic_read(&port->count) + port->blocked_open;
85780 }
85781
85782 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85783 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85784 index 92e337c..f46757b 100644
85785 --- a/include/linux/tty_driver.h
85786 +++ b/include/linux/tty_driver.h
85787 @@ -291,7 +291,7 @@ struct tty_operations {
85788 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85789 #endif
85790 const struct file_operations *proc_fops;
85791 -};
85792 +} __do_const __randomize_layout;
85793
85794 struct tty_driver {
85795 int magic; /* magic number for this structure */
85796 @@ -325,7 +325,7 @@ struct tty_driver {
85797
85798 const struct tty_operations *ops;
85799 struct list_head tty_drivers;
85800 -};
85801 +} __randomize_layout;
85802
85803 extern struct list_head tty_drivers;
85804
85805 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85806 index 00c9d68..bc0188b 100644
85807 --- a/include/linux/tty_ldisc.h
85808 +++ b/include/linux/tty_ldisc.h
85809 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85810
85811 struct module *owner;
85812
85813 - int refcount;
85814 + atomic_t refcount;
85815 };
85816
85817 struct tty_ldisc {
85818 diff --git a/include/linux/types.h b/include/linux/types.h
85819 index a0bb704..f511c77 100644
85820 --- a/include/linux/types.h
85821 +++ b/include/linux/types.h
85822 @@ -177,10 +177,26 @@ typedef struct {
85823 int counter;
85824 } atomic_t;
85825
85826 +#ifdef CONFIG_PAX_REFCOUNT
85827 +typedef struct {
85828 + int counter;
85829 +} atomic_unchecked_t;
85830 +#else
85831 +typedef atomic_t atomic_unchecked_t;
85832 +#endif
85833 +
85834 #ifdef CONFIG_64BIT
85835 typedef struct {
85836 long counter;
85837 } atomic64_t;
85838 +
85839 +#ifdef CONFIG_PAX_REFCOUNT
85840 +typedef struct {
85841 + long counter;
85842 +} atomic64_unchecked_t;
85843 +#else
85844 +typedef atomic64_t atomic64_unchecked_t;
85845 +#endif
85846 #endif
85847
85848 struct list_head {
85849 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85850 index ecd3319..8a36ded 100644
85851 --- a/include/linux/uaccess.h
85852 +++ b/include/linux/uaccess.h
85853 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85854 long ret; \
85855 mm_segment_t old_fs = get_fs(); \
85856 \
85857 - set_fs(KERNEL_DS); \
85858 pagefault_disable(); \
85859 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85860 - pagefault_enable(); \
85861 + set_fs(KERNEL_DS); \
85862 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85863 set_fs(old_fs); \
85864 + pagefault_enable(); \
85865 ret; \
85866 })
85867
85868 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85869 index 2d1f9b6..d7a9fce 100644
85870 --- a/include/linux/uidgid.h
85871 +++ b/include/linux/uidgid.h
85872 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85873
85874 #endif /* CONFIG_USER_NS */
85875
85876 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85877 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85878 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85879 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85880 +
85881 #endif /* _LINUX_UIDGID_H */
85882 diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85883 index baa8171..9ca98ba 100644
85884 --- a/include/linux/uio_driver.h
85885 +++ b/include/linux/uio_driver.h
85886 @@ -67,7 +67,7 @@ struct uio_device {
85887 struct module *owner;
85888 struct device *dev;
85889 int minor;
85890 - atomic_t event;
85891 + atomic_unchecked_t event;
85892 struct fasync_struct *async_queue;
85893 wait_queue_head_t wait;
85894 struct uio_info *info;
85895 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85896 index 99c1b4d..562e6f3 100644
85897 --- a/include/linux/unaligned/access_ok.h
85898 +++ b/include/linux/unaligned/access_ok.h
85899 @@ -4,34 +4,34 @@
85900 #include <linux/kernel.h>
85901 #include <asm/byteorder.h>
85902
85903 -static inline u16 get_unaligned_le16(const void *p)
85904 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85905 {
85906 - return le16_to_cpup((__le16 *)p);
85907 + return le16_to_cpup((const __le16 *)p);
85908 }
85909
85910 -static inline u32 get_unaligned_le32(const void *p)
85911 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85912 {
85913 - return le32_to_cpup((__le32 *)p);
85914 + return le32_to_cpup((const __le32 *)p);
85915 }
85916
85917 -static inline u64 get_unaligned_le64(const void *p)
85918 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85919 {
85920 - return le64_to_cpup((__le64 *)p);
85921 + return le64_to_cpup((const __le64 *)p);
85922 }
85923
85924 -static inline u16 get_unaligned_be16(const void *p)
85925 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85926 {
85927 - return be16_to_cpup((__be16 *)p);
85928 + return be16_to_cpup((const __be16 *)p);
85929 }
85930
85931 -static inline u32 get_unaligned_be32(const void *p)
85932 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85933 {
85934 - return be32_to_cpup((__be32 *)p);
85935 + return be32_to_cpup((const __be32 *)p);
85936 }
85937
85938 -static inline u64 get_unaligned_be64(const void *p)
85939 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85940 {
85941 - return be64_to_cpup((__be64 *)p);
85942 + return be64_to_cpup((const __be64 *)p);
85943 }
85944
85945 static inline void put_unaligned_le16(u16 val, void *p)
85946 diff --git a/include/linux/usb.h b/include/linux/usb.h
85947 index 447a7e2..9cea7e9 100644
85948 --- a/include/linux/usb.h
85949 +++ b/include/linux/usb.h
85950 @@ -571,7 +571,7 @@ struct usb_device {
85951 int maxchild;
85952
85953 u32 quirks;
85954 - atomic_t urbnum;
85955 + atomic_unchecked_t urbnum;
85956
85957 unsigned long active_duration;
85958
85959 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85960
85961 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85962 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85963 - void *data, __u16 size, int timeout);
85964 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
85965 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85966 void *data, int len, int *actual_length, int timeout);
85967 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85968 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85969 index d5952bb..9a626d4 100644
85970 --- a/include/linux/usb/renesas_usbhs.h
85971 +++ b/include/linux/usb/renesas_usbhs.h
85972 @@ -39,7 +39,7 @@ enum {
85973 */
85974 struct renesas_usbhs_driver_callback {
85975 int (*notify_hotplug)(struct platform_device *pdev);
85976 -};
85977 +} __no_const;
85978
85979 /*
85980 * callback functions for platform
85981 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85982 index 9f3579f..3b2afa5 100644
85983 --- a/include/linux/user_namespace.h
85984 +++ b/include/linux/user_namespace.h
85985 @@ -38,7 +38,7 @@ struct user_namespace {
85986 struct key *persistent_keyring_register;
85987 struct rw_semaphore persistent_keyring_register_sem;
85988 #endif
85989 -};
85990 +} __randomize_layout;
85991
85992 extern struct user_namespace init_user_ns;
85993
85994 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85995 index 239e277..22a5cf5 100644
85996 --- a/include/linux/utsname.h
85997 +++ b/include/linux/utsname.h
85998 @@ -24,7 +24,7 @@ struct uts_namespace {
85999 struct new_utsname name;
86000 struct user_namespace *user_ns;
86001 unsigned int proc_inum;
86002 -};
86003 +} __randomize_layout;
86004 extern struct uts_namespace init_uts_ns;
86005
86006 #ifdef CONFIG_UTS_NS
86007 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86008 index 6f8fbcf..4efc177 100644
86009 --- a/include/linux/vermagic.h
86010 +++ b/include/linux/vermagic.h
86011 @@ -25,9 +25,42 @@
86012 #define MODULE_ARCH_VERMAGIC ""
86013 #endif
86014
86015 +#ifdef CONFIG_PAX_REFCOUNT
86016 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86017 +#else
86018 +#define MODULE_PAX_REFCOUNT ""
86019 +#endif
86020 +
86021 +#ifdef CONSTIFY_PLUGIN
86022 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86023 +#else
86024 +#define MODULE_CONSTIFY_PLUGIN ""
86025 +#endif
86026 +
86027 +#ifdef STACKLEAK_PLUGIN
86028 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86029 +#else
86030 +#define MODULE_STACKLEAK_PLUGIN ""
86031 +#endif
86032 +
86033 +#ifdef RANDSTRUCT_PLUGIN
86034 +#include <generated/randomize_layout_hash.h>
86035 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86036 +#else
86037 +#define MODULE_RANDSTRUCT_PLUGIN
86038 +#endif
86039 +
86040 +#ifdef CONFIG_GRKERNSEC
86041 +#define MODULE_GRSEC "GRSEC "
86042 +#else
86043 +#define MODULE_GRSEC ""
86044 +#endif
86045 +
86046 #define VERMAGIC_STRING \
86047 UTS_RELEASE " " \
86048 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86049 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86050 - MODULE_ARCH_VERMAGIC
86051 + MODULE_ARCH_VERMAGIC \
86052 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86053 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86054
86055 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86056 index b483abd..af305ad 100644
86057 --- a/include/linux/vga_switcheroo.h
86058 +++ b/include/linux/vga_switcheroo.h
86059 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86060
86061 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86062
86063 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86064 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86065 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86066 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86067 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86068 #else
86069
86070 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86071 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86072
86073 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86074
86075 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86076 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86077 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86078 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86079 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86080
86081 #endif
86082 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86083 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86084 index b87696f..1d11de7 100644
86085 --- a/include/linux/vmalloc.h
86086 +++ b/include/linux/vmalloc.h
86087 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86088 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86089 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86090 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86091 +
86092 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86093 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86094 +#endif
86095 +
86096 /* bits [20..32] reserved for arch specific ioremap internals */
86097
86098 /*
86099 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86100 unsigned long flags, pgprot_t prot);
86101 extern void vunmap(const void *addr);
86102
86103 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86104 +extern void unmap_process_stacks(struct task_struct *task);
86105 +#endif
86106 +
86107 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86108 unsigned long uaddr, void *kaddr,
86109 unsigned long size);
86110 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86111
86112 /* for /dev/kmem */
86113 extern long vread(char *buf, char *addr, unsigned long count);
86114 -extern long vwrite(char *buf, char *addr, unsigned long count);
86115 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86116
86117 /*
86118 * Internals. Dont't use..
86119 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86120 index 82e7db7..f8ce3d0 100644
86121 --- a/include/linux/vmstat.h
86122 +++ b/include/linux/vmstat.h
86123 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86124 /*
86125 * Zone based page accounting with per cpu differentials.
86126 */
86127 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86128 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86129
86130 static inline void zone_page_state_add(long x, struct zone *zone,
86131 enum zone_stat_item item)
86132 {
86133 - atomic_long_add(x, &zone->vm_stat[item]);
86134 - atomic_long_add(x, &vm_stat[item]);
86135 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86136 + atomic_long_add_unchecked(x, &vm_stat[item]);
86137 }
86138
86139 -static inline unsigned long global_page_state(enum zone_stat_item item)
86140 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86141 {
86142 - long x = atomic_long_read(&vm_stat[item]);
86143 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86144 #ifdef CONFIG_SMP
86145 if (x < 0)
86146 x = 0;
86147 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86148 return x;
86149 }
86150
86151 -static inline unsigned long zone_page_state(struct zone *zone,
86152 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86153 enum zone_stat_item item)
86154 {
86155 - long x = atomic_long_read(&zone->vm_stat[item]);
86156 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86157 #ifdef CONFIG_SMP
86158 if (x < 0)
86159 x = 0;
86160 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86161 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86162 enum zone_stat_item item)
86163 {
86164 - long x = atomic_long_read(&zone->vm_stat[item]);
86165 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86166
86167 #ifdef CONFIG_SMP
86168 int cpu;
86169 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86170
86171 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86172 {
86173 - atomic_long_inc(&zone->vm_stat[item]);
86174 - atomic_long_inc(&vm_stat[item]);
86175 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86176 + atomic_long_inc_unchecked(&vm_stat[item]);
86177 }
86178
86179 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86180 {
86181 - atomic_long_dec(&zone->vm_stat[item]);
86182 - atomic_long_dec(&vm_stat[item]);
86183 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86184 + atomic_long_dec_unchecked(&vm_stat[item]);
86185 }
86186
86187 static inline void __inc_zone_page_state(struct page *page,
86188 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86189 index 91b0a68..0e9adf6 100644
86190 --- a/include/linux/xattr.h
86191 +++ b/include/linux/xattr.h
86192 @@ -28,7 +28,7 @@ struct xattr_handler {
86193 size_t size, int handler_flags);
86194 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86195 size_t size, int flags, int handler_flags);
86196 -};
86197 +} __do_const;
86198
86199 struct xattr {
86200 const char *name;
86201 @@ -37,6 +37,9 @@ struct xattr {
86202 };
86203
86204 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86205 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86206 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86207 +#endif
86208 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86209 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86210 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86211 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86212 index 92dbbd3..13ab0b3 100644
86213 --- a/include/linux/zlib.h
86214 +++ b/include/linux/zlib.h
86215 @@ -31,6 +31,7 @@
86216 #define _ZLIB_H
86217
86218 #include <linux/zconf.h>
86219 +#include <linux/compiler.h>
86220
86221 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86222 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86223 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86224
86225 /* basic functions */
86226
86227 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86228 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86229 /*
86230 Returns the number of bytes that needs to be allocated for a per-
86231 stream workspace with the specified parameters. A pointer to this
86232 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86233 index eb76cfd..9fd0e7c 100644
86234 --- a/include/media/v4l2-dev.h
86235 +++ b/include/media/v4l2-dev.h
86236 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86237 int (*mmap) (struct file *, struct vm_area_struct *);
86238 int (*open) (struct file *);
86239 int (*release) (struct file *);
86240 -};
86241 +} __do_const;
86242
86243 /*
86244 * Newer version of video_device, handled by videodev2.c
86245 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86246 index ffb69da..040393e 100644
86247 --- a/include/media/v4l2-device.h
86248 +++ b/include/media/v4l2-device.h
86249 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86250 this function returns 0. If the name ends with a digit (e.g. cx18),
86251 then the name will be set to cx18-0 since cx180 looks really odd. */
86252 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86253 - atomic_t *instance);
86254 + atomic_unchecked_t *instance);
86255
86256 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86257 Since the parent disappears this ensures that v4l2_dev doesn't have an
86258 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86259 index 2a25dec..bf6dd8a 100644
86260 --- a/include/net/9p/transport.h
86261 +++ b/include/net/9p/transport.h
86262 @@ -62,7 +62,7 @@ struct p9_trans_module {
86263 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86264 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86265 char *, char *, int , int, int, int);
86266 -};
86267 +} __do_const;
86268
86269 void v9fs_register_trans(struct p9_trans_module *m);
86270 void v9fs_unregister_trans(struct p9_trans_module *m);
86271 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86272 index a175ba4..196eb8242 100644
86273 --- a/include/net/af_unix.h
86274 +++ b/include/net/af_unix.h
86275 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86276 u32 secid; /* Security ID */
86277 #endif
86278 u32 consumed;
86279 -};
86280 +} __randomize_layout;
86281
86282 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86283 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86284 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86285 index ead99f0..6263c4b 100644
86286 --- a/include/net/bluetooth/l2cap.h
86287 +++ b/include/net/bluetooth/l2cap.h
86288 @@ -608,7 +608,7 @@ struct l2cap_ops {
86289 unsigned char *kdata,
86290 struct iovec *iov,
86291 int len);
86292 -};
86293 +} __do_const;
86294
86295 struct l2cap_conn {
86296 struct hci_conn *hcon;
86297 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86298 index f2ae33d..c457cf0 100644
86299 --- a/include/net/caif/cfctrl.h
86300 +++ b/include/net/caif/cfctrl.h
86301 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86302 void (*radioset_rsp)(void);
86303 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86304 struct cflayer *client_layer);
86305 -};
86306 +} __no_const;
86307
86308 /* Link Setup Parameters for CAIF-Links. */
86309 struct cfctrl_link_param {
86310 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86311 struct cfctrl {
86312 struct cfsrvl serv;
86313 struct cfctrl_rsp res;
86314 - atomic_t req_seq_no;
86315 - atomic_t rsp_seq_no;
86316 + atomic_unchecked_t req_seq_no;
86317 + atomic_unchecked_t rsp_seq_no;
86318 struct list_head list;
86319 /* Protects from simultaneous access to first_req list */
86320 spinlock_t info_list_lock;
86321 diff --git a/include/net/flow.h b/include/net/flow.h
86322 index 8109a15..504466d 100644
86323 --- a/include/net/flow.h
86324 +++ b/include/net/flow.h
86325 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86326
86327 void flow_cache_flush(struct net *net);
86328 void flow_cache_flush_deferred(struct net *net);
86329 -extern atomic_t flow_cache_genid;
86330 +extern atomic_unchecked_t flow_cache_genid;
86331
86332 #endif
86333 diff --git a/include/net/flow_keys.h b/include/net/flow_keys.h
86334 index 7ee2df0..dc8fd81 100644
86335 --- a/include/net/flow_keys.h
86336 +++ b/include/net/flow_keys.h
86337 @@ -22,9 +22,9 @@ struct flow_keys {
86338 __be32 ports;
86339 __be16 port16[2];
86340 };
86341 - u16 thoff;
86342 - u16 n_proto;
86343 - u8 ip_proto;
86344 + u16 thoff;
86345 + __be16 n_proto;
86346 + u8 ip_proto;
86347 };
86348
86349 bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
86350 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86351 index af10c2c..a431cc5 100644
86352 --- a/include/net/genetlink.h
86353 +++ b/include/net/genetlink.h
86354 @@ -120,7 +120,7 @@ struct genl_ops {
86355 u8 cmd;
86356 u8 internal_flags;
86357 u8 flags;
86358 -};
86359 +} __do_const;
86360
86361 int __genl_register_family(struct genl_family *family);
86362
86363 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86364 index 734d9b5..48a9a4b 100644
86365 --- a/include/net/gro_cells.h
86366 +++ b/include/net/gro_cells.h
86367 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86368 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86369
86370 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86371 - atomic_long_inc(&dev->rx_dropped);
86372 + atomic_long_inc_unchecked(&dev->rx_dropped);
86373 kfree_skb(skb);
86374 return;
86375 }
86376 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86377 index 848e85c..051c7de 100644
86378 --- a/include/net/inet_connection_sock.h
86379 +++ b/include/net/inet_connection_sock.h
86380 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86381 int (*bind_conflict)(const struct sock *sk,
86382 const struct inet_bind_bucket *tb, bool relax);
86383 void (*mtu_reduced)(struct sock *sk);
86384 -};
86385 +} __do_const;
86386
86387 /** inet_connection_sock - INET connection oriented sock
86388 *
86389 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86390 index 80479ab..0c3f647 100644
86391 --- a/include/net/inetpeer.h
86392 +++ b/include/net/inetpeer.h
86393 @@ -47,7 +47,7 @@ struct inet_peer {
86394 */
86395 union {
86396 struct {
86397 - atomic_t rid; /* Frag reception counter */
86398 + atomic_unchecked_t rid; /* Frag reception counter */
86399 };
86400 struct rcu_head rcu;
86401 struct inet_peer *gc_next;
86402 diff --git a/include/net/ip.h b/include/net/ip.h
86403 index 0bb6207..1f38247 100644
86404 --- a/include/net/ip.h
86405 +++ b/include/net/ip.h
86406 @@ -39,11 +39,12 @@ struct inet_skb_parm {
86407 struct ip_options opt; /* Compiled IP options */
86408 unsigned char flags;
86409
86410 -#define IPSKB_FORWARDED 1
86411 -#define IPSKB_XFRM_TUNNEL_SIZE 2
86412 -#define IPSKB_XFRM_TRANSFORMED 4
86413 -#define IPSKB_FRAG_COMPLETE 8
86414 -#define IPSKB_REROUTED 16
86415 +#define IPSKB_FORWARDED BIT(0)
86416 +#define IPSKB_XFRM_TUNNEL_SIZE BIT(1)
86417 +#define IPSKB_XFRM_TRANSFORMED BIT(2)
86418 +#define IPSKB_FRAG_COMPLETE BIT(3)
86419 +#define IPSKB_REROUTED BIT(4)
86420 +#define IPSKB_DOREDIRECT BIT(5)
86421
86422 u16 frag_max_size;
86423 };
86424 @@ -316,7 +317,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86425 }
86426 }
86427
86428 -u32 ip_idents_reserve(u32 hash, int segs);
86429 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86430 void __ip_select_ident(struct iphdr *iph, int segs);
86431
86432 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86433 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86434 index dc9d2a2..d985691 100644
86435 --- a/include/net/ip_fib.h
86436 +++ b/include/net/ip_fib.h
86437 @@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86438
86439 #define FIB_RES_SADDR(net, res) \
86440 ((FIB_RES_NH(res).nh_saddr_genid == \
86441 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86442 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86443 FIB_RES_NH(res).nh_saddr : \
86444 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86445 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86446 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86447 index 615b20b..fd4cbd8 100644
86448 --- a/include/net/ip_vs.h
86449 +++ b/include/net/ip_vs.h
86450 @@ -534,7 +534,7 @@ struct ip_vs_conn {
86451 struct ip_vs_conn *control; /* Master control connection */
86452 atomic_t n_control; /* Number of controlled ones */
86453 struct ip_vs_dest *dest; /* real server */
86454 - atomic_t in_pkts; /* incoming packet counter */
86455 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86456
86457 /* Packet transmitter for different forwarding methods. If it
86458 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86459 @@ -682,7 +682,7 @@ struct ip_vs_dest {
86460 __be16 port; /* port number of the server */
86461 union nf_inet_addr addr; /* IP address of the server */
86462 volatile unsigned int flags; /* dest status flags */
86463 - atomic_t conn_flags; /* flags to copy to conn */
86464 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86465 atomic_t weight; /* server weight */
86466
86467 atomic_t refcnt; /* reference counter */
86468 @@ -928,11 +928,11 @@ struct netns_ipvs {
86469 /* ip_vs_lblc */
86470 int sysctl_lblc_expiration;
86471 struct ctl_table_header *lblc_ctl_header;
86472 - struct ctl_table *lblc_ctl_table;
86473 + ctl_table_no_const *lblc_ctl_table;
86474 /* ip_vs_lblcr */
86475 int sysctl_lblcr_expiration;
86476 struct ctl_table_header *lblcr_ctl_header;
86477 - struct ctl_table *lblcr_ctl_table;
86478 + ctl_table_no_const *lblcr_ctl_table;
86479 /* ip_vs_est */
86480 struct list_head est_list; /* estimator list */
86481 spinlock_t est_lock;
86482 diff --git a/include/net/ipv6.h b/include/net/ipv6.h
86483 index 4292929..7e21d2e 100644
86484 --- a/include/net/ipv6.h
86485 +++ b/include/net/ipv6.h
86486 @@ -708,7 +708,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86487 __be32 flowlabel, bool autolabel)
86488 {
86489 if (!flowlabel && (autolabel || net->ipv6.sysctl.auto_flowlabels)) {
86490 - __be32 hash;
86491 + u32 hash;
86492
86493 hash = skb_get_hash(skb);
86494
86495 @@ -718,7 +718,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86496 */
86497 hash ^= hash >> 12;
86498
86499 - flowlabel = hash & IPV6_FLOWLABEL_MASK;
86500 + flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
86501 }
86502
86503 return flowlabel;
86504 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86505 index 8d4f588..2e37ad2 100644
86506 --- a/include/net/irda/ircomm_tty.h
86507 +++ b/include/net/irda/ircomm_tty.h
86508 @@ -33,6 +33,7 @@
86509 #include <linux/termios.h>
86510 #include <linux/timer.h>
86511 #include <linux/tty.h> /* struct tty_struct */
86512 +#include <asm/local.h>
86513
86514 #include <net/irda/irias_object.h>
86515 #include <net/irda/ircomm_core.h>
86516 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86517 index 714cc9a..ea05f3e 100644
86518 --- a/include/net/iucv/af_iucv.h
86519 +++ b/include/net/iucv/af_iucv.h
86520 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86521 struct iucv_sock_list {
86522 struct hlist_head head;
86523 rwlock_t lock;
86524 - atomic_t autobind_name;
86525 + atomic_unchecked_t autobind_name;
86526 };
86527
86528 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86529 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86530 index f3be818..bf46196 100644
86531 --- a/include/net/llc_c_ac.h
86532 +++ b/include/net/llc_c_ac.h
86533 @@ -87,7 +87,7 @@
86534 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86535 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86536
86537 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86538 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86539
86540 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86541 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86542 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86543 index 3948cf1..83b28c4 100644
86544 --- a/include/net/llc_c_ev.h
86545 +++ b/include/net/llc_c_ev.h
86546 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86547 return (struct llc_conn_state_ev *)skb->cb;
86548 }
86549
86550 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86551 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86552 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86553 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86554
86555 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86556 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86557 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86558 index 0e79cfb..f46db31 100644
86559 --- a/include/net/llc_c_st.h
86560 +++ b/include/net/llc_c_st.h
86561 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86562 u8 next_state;
86563 llc_conn_ev_qfyr_t *ev_qualifiers;
86564 llc_conn_action_t *ev_actions;
86565 -};
86566 +} __do_const;
86567
86568 struct llc_conn_state {
86569 u8 current_state;
86570 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86571 index a61b98c..aade1eb 100644
86572 --- a/include/net/llc_s_ac.h
86573 +++ b/include/net/llc_s_ac.h
86574 @@ -23,7 +23,7 @@
86575 #define SAP_ACT_TEST_IND 9
86576
86577 /* All action functions must look like this */
86578 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86579 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86580
86581 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86582 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86583 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86584 index 567c681..cd73ac02 100644
86585 --- a/include/net/llc_s_st.h
86586 +++ b/include/net/llc_s_st.h
86587 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86588 llc_sap_ev_t ev;
86589 u8 next_state;
86590 llc_sap_action_t *ev_actions;
86591 -};
86592 +} __do_const;
86593
86594 struct llc_sap_state {
86595 u8 curr_state;
86596 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86597 index a9de1da..df72057 100644
86598 --- a/include/net/mac80211.h
86599 +++ b/include/net/mac80211.h
86600 @@ -4645,7 +4645,7 @@ struct rate_control_ops {
86601 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86602
86603 u32 (*get_expected_throughput)(void *priv_sta);
86604 -};
86605 +} __do_const;
86606
86607 static inline int rate_supported(struct ieee80211_sta *sta,
86608 enum ieee80211_band band,
86609 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86610 index f60558d..e5ed9bd 100644
86611 --- a/include/net/neighbour.h
86612 +++ b/include/net/neighbour.h
86613 @@ -163,7 +163,7 @@ struct neigh_ops {
86614 void (*error_report)(struct neighbour *, struct sk_buff *);
86615 int (*output)(struct neighbour *, struct sk_buff *);
86616 int (*connected_output)(struct neighbour *, struct sk_buff *);
86617 -};
86618 +} __do_const;
86619
86620 struct pneigh_entry {
86621 struct pneigh_entry *next;
86622 @@ -217,7 +217,7 @@ struct neigh_table {
86623 struct neigh_statistics __percpu *stats;
86624 struct neigh_hash_table __rcu *nht;
86625 struct pneigh_entry **phash_buckets;
86626 -};
86627 +} __randomize_layout;
86628
86629 static inline int neigh_parms_family(struct neigh_parms *p)
86630 {
86631 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86632 index e0d6466..e2f3003 100644
86633 --- a/include/net/net_namespace.h
86634 +++ b/include/net/net_namespace.h
86635 @@ -129,8 +129,8 @@ struct net {
86636 struct netns_ipvs *ipvs;
86637 #endif
86638 struct sock *diag_nlsk;
86639 - atomic_t fnhe_genid;
86640 -};
86641 + atomic_unchecked_t fnhe_genid;
86642 +} __randomize_layout;
86643
86644 #include <linux/seq_file_net.h>
86645
86646 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86647 #define __net_init __init
86648 #define __net_exit __exit_refok
86649 #define __net_initdata __initdata
86650 +#ifdef CONSTIFY_PLUGIN
86651 #define __net_initconst __initconst
86652 +#else
86653 +#define __net_initconst __initdata
86654 +#endif
86655 #endif
86656
86657 struct pernet_operations {
86658 @@ -296,7 +300,7 @@ struct pernet_operations {
86659 void (*exit_batch)(struct list_head *net_exit_list);
86660 int *id;
86661 size_t size;
86662 -};
86663 +} __do_const;
86664
86665 /*
86666 * Use these carefully. If you implement a network device and it
86667 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86668
86669 static inline int rt_genid_ipv4(struct net *net)
86670 {
86671 - return atomic_read(&net->ipv4.rt_genid);
86672 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86673 }
86674
86675 static inline void rt_genid_bump_ipv4(struct net *net)
86676 {
86677 - atomic_inc(&net->ipv4.rt_genid);
86678 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86679 }
86680
86681 extern void (*__fib6_flush_trees)(struct net *net);
86682 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86683
86684 static inline int fnhe_genid(struct net *net)
86685 {
86686 - return atomic_read(&net->fnhe_genid);
86687 + return atomic_read_unchecked(&net->fnhe_genid);
86688 }
86689
86690 static inline void fnhe_genid_bump(struct net *net)
86691 {
86692 - atomic_inc(&net->fnhe_genid);
86693 + atomic_inc_unchecked(&net->fnhe_genid);
86694 }
86695
86696 #endif /* __NET_NET_NAMESPACE_H */
86697 diff --git a/include/net/netlink.h b/include/net/netlink.h
86698 index 7b903e1..ad9ca4b 100644
86699 --- a/include/net/netlink.h
86700 +++ b/include/net/netlink.h
86701 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86702 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86703 {
86704 if (mark)
86705 - skb_trim(skb, (unsigned char *) mark - skb->data);
86706 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86707 }
86708
86709 /**
86710 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86711 index 29d6a94..235d3d84 100644
86712 --- a/include/net/netns/conntrack.h
86713 +++ b/include/net/netns/conntrack.h
86714 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86715 struct nf_proto_net {
86716 #ifdef CONFIG_SYSCTL
86717 struct ctl_table_header *ctl_table_header;
86718 - struct ctl_table *ctl_table;
86719 + ctl_table_no_const *ctl_table;
86720 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86721 struct ctl_table_header *ctl_compat_header;
86722 - struct ctl_table *ctl_compat_table;
86723 + ctl_table_no_const *ctl_compat_table;
86724 #endif
86725 #endif
86726 unsigned int users;
86727 @@ -60,7 +60,7 @@ struct nf_ip_net {
86728 struct nf_icmp_net icmpv6;
86729 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86730 struct ctl_table_header *ctl_table_header;
86731 - struct ctl_table *ctl_table;
86732 + ctl_table_no_const *ctl_table;
86733 #endif
86734 };
86735
86736 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86737 index 24945ce..f19e42f 100644
86738 --- a/include/net/netns/ipv4.h
86739 +++ b/include/net/netns/ipv4.h
86740 @@ -83,7 +83,7 @@ struct netns_ipv4 {
86741
86742 struct ping_group_range ping_group_range;
86743
86744 - atomic_t dev_addr_genid;
86745 + atomic_unchecked_t dev_addr_genid;
86746
86747 #ifdef CONFIG_SYSCTL
86748 unsigned long *sysctl_local_reserved_ports;
86749 @@ -97,6 +97,6 @@ struct netns_ipv4 {
86750 struct fib_rules_ops *mr_rules_ops;
86751 #endif
86752 #endif
86753 - atomic_t rt_genid;
86754 + atomic_unchecked_t rt_genid;
86755 };
86756 #endif
86757 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86758 index 69ae41f..4f94868 100644
86759 --- a/include/net/netns/ipv6.h
86760 +++ b/include/net/netns/ipv6.h
86761 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86762 struct fib_rules_ops *mr6_rules_ops;
86763 #endif
86764 #endif
86765 - atomic_t dev_addr_genid;
86766 - atomic_t fib6_sernum;
86767 + atomic_unchecked_t dev_addr_genid;
86768 + atomic_unchecked_t fib6_sernum;
86769 };
86770
86771 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86772 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86773 index 9da7982..099321b9 100644
86774 --- a/include/net/netns/xfrm.h
86775 +++ b/include/net/netns/xfrm.h
86776 @@ -78,7 +78,7 @@ struct netns_xfrm {
86777
86778 /* flow cache part */
86779 struct flow_cache flow_cache_global;
86780 - atomic_t flow_cache_genid;
86781 + atomic_unchecked_t flow_cache_genid;
86782 struct list_head flow_cache_gc_list;
86783 spinlock_t flow_cache_gc_lock;
86784 struct work_struct flow_cache_gc_work;
86785 diff --git a/include/net/ping.h b/include/net/ping.h
86786 index 026479b..d9b2829 100644
86787 --- a/include/net/ping.h
86788 +++ b/include/net/ping.h
86789 @@ -54,7 +54,7 @@ struct ping_iter_state {
86790
86791 extern struct proto ping_prot;
86792 #if IS_ENABLED(CONFIG_IPV6)
86793 -extern struct pingv6_ops pingv6_ops;
86794 +extern struct pingv6_ops *pingv6_ops;
86795 #endif
86796
86797 struct pingfakehdr {
86798 diff --git a/include/net/protocol.h b/include/net/protocol.h
86799 index d6fcc1f..ca277058 100644
86800 --- a/include/net/protocol.h
86801 +++ b/include/net/protocol.h
86802 @@ -49,7 +49,7 @@ struct net_protocol {
86803 * socket lookup?
86804 */
86805 icmp_strict_tag_validation:1;
86806 -};
86807 +} __do_const;
86808
86809 #if IS_ENABLED(CONFIG_IPV6)
86810 struct inet6_protocol {
86811 @@ -62,7 +62,7 @@ struct inet6_protocol {
86812 u8 type, u8 code, int offset,
86813 __be32 info);
86814 unsigned int flags; /* INET6_PROTO_xxx */
86815 -};
86816 +} __do_const;
86817
86818 #define INET6_PROTO_NOPOLICY 0x1
86819 #define INET6_PROTO_FINAL 0x2
86820 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86821 index e21b9f9..0191ef0 100644
86822 --- a/include/net/rtnetlink.h
86823 +++ b/include/net/rtnetlink.h
86824 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86825 int (*fill_slave_info)(struct sk_buff *skb,
86826 const struct net_device *dev,
86827 const struct net_device *slave_dev);
86828 -};
86829 +} __do_const;
86830
86831 int __rtnl_link_register(struct rtnl_link_ops *ops);
86832 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86833 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86834 index 4a5b9a3..ca27d73 100644
86835 --- a/include/net/sctp/checksum.h
86836 +++ b/include/net/sctp/checksum.h
86837 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86838 unsigned int offset)
86839 {
86840 struct sctphdr *sh = sctp_hdr(skb);
86841 - __le32 ret, old = sh->checksum;
86842 - const struct skb_checksum_ops ops = {
86843 + __le32 ret, old = sh->checksum;
86844 + static const struct skb_checksum_ops ops = {
86845 .update = sctp_csum_update,
86846 .combine = sctp_csum_combine,
86847 };
86848 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86849 index 72a31db..aaa63d9 100644
86850 --- a/include/net/sctp/sm.h
86851 +++ b/include/net/sctp/sm.h
86852 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86853 typedef struct {
86854 sctp_state_fn_t *fn;
86855 const char *name;
86856 -} sctp_sm_table_entry_t;
86857 +} __do_const sctp_sm_table_entry_t;
86858
86859 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86860 * currently in use.
86861 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86862 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86863
86864 /* Extern declarations for major data structures. */
86865 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86866 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86867
86868
86869 /* Get the size of a DATA chunk payload. */
86870 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86871 index 4ff3f67..89ae38e 100644
86872 --- a/include/net/sctp/structs.h
86873 +++ b/include/net/sctp/structs.h
86874 @@ -509,7 +509,7 @@ struct sctp_pf {
86875 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86876 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86877 struct sctp_af *af;
86878 -};
86879 +} __do_const;
86880
86881
86882 /* Structure to track chunk fragments that have been acked, but peer
86883 diff --git a/include/net/sock.h b/include/net/sock.h
86884 index 7db3db1..a915cca 100644
86885 --- a/include/net/sock.h
86886 +++ b/include/net/sock.h
86887 @@ -355,7 +355,7 @@ struct sock {
86888 unsigned int sk_napi_id;
86889 unsigned int sk_ll_usec;
86890 #endif
86891 - atomic_t sk_drops;
86892 + atomic_unchecked_t sk_drops;
86893 int sk_rcvbuf;
86894
86895 struct sk_filter __rcu *sk_filter;
86896 @@ -1048,7 +1048,7 @@ struct proto {
86897 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86898 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86899 #endif
86900 -};
86901 +} __randomize_layout;
86902
86903 /*
86904 * Bits in struct cg_proto.flags
86905 @@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86906 return ret >> PAGE_SHIFT;
86907 }
86908
86909 -static inline long
86910 +static inline long __intentional_overflow(-1)
86911 sk_memory_allocated(const struct sock *sk)
86912 {
86913 struct proto *prot = sk->sk_prot;
86914 @@ -1380,7 +1380,7 @@ struct sock_iocb {
86915 struct scm_cookie *scm;
86916 struct msghdr *msg, async_msg;
86917 struct kiocb *kiocb;
86918 -};
86919 +} __randomize_layout;
86920
86921 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86922 {
86923 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86924 }
86925
86926 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86927 - char __user *from, char *to,
86928 + char __user *from, unsigned char *to,
86929 int copy, int offset)
86930 {
86931 if (skb->ip_summed == CHECKSUM_NONE) {
86932 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86933 }
86934 }
86935
86936 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86937 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86938
86939 /**
86940 * sk_page_frag - return an appropriate page_frag
86941 diff --git a/include/net/tcp.h b/include/net/tcp.h
86942 index 4062b4f..9ff45e7 100644
86943 --- a/include/net/tcp.h
86944 +++ b/include/net/tcp.h
86945 @@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86946 void tcp_xmit_retransmit_queue(struct sock *);
86947 void tcp_simple_retransmit(struct sock *);
86948 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86949 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86950 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86951
86952 void tcp_send_probe0(struct sock *);
86953 void tcp_send_partial(struct sock *);
86954 @@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86955 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86956 */
86957 struct tcp_skb_cb {
86958 - __u32 seq; /* Starting sequence number */
86959 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86960 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
86961 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86962 union {
86963 /* Note : tcp_tw_isn is used in input path only
86964 * (isn chosen by tcp_timewait_state_process())
86965 @@ -718,7 +718,7 @@ struct tcp_skb_cb {
86966
86967 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86968 /* 1 byte hole */
86969 - __u32 ack_seq; /* Sequence number ACK'd */
86970 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86971 union {
86972 struct inet_skb_parm h4;
86973 #if IS_ENABLED(CONFIG_IPV6)
86974 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86975 index dc4865e..152ee4c 100644
86976 --- a/include/net/xfrm.h
86977 +++ b/include/net/xfrm.h
86978 @@ -285,7 +285,6 @@ struct xfrm_dst;
86979 struct xfrm_policy_afinfo {
86980 unsigned short family;
86981 struct dst_ops *dst_ops;
86982 - void (*garbage_collect)(struct net *net);
86983 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86984 const xfrm_address_t *saddr,
86985 const xfrm_address_t *daddr);
86986 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86987 struct net_device *dev,
86988 const struct flowi *fl);
86989 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86990 -};
86991 +} __do_const;
86992
86993 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86994 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86995 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86996 int (*transport_finish)(struct sk_buff *skb,
86997 int async);
86998 void (*local_error)(struct sk_buff *skb, u32 mtu);
86999 -};
87000 +} __do_const;
87001
87002 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87003 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87004 @@ -437,7 +436,7 @@ struct xfrm_mode {
87005 struct module *owner;
87006 unsigned int encap;
87007 int flags;
87008 -};
87009 +} __do_const;
87010
87011 /* Flags for xfrm_mode. */
87012 enum {
87013 @@ -534,7 +533,7 @@ struct xfrm_policy {
87014 struct timer_list timer;
87015
87016 struct flow_cache_object flo;
87017 - atomic_t genid;
87018 + atomic_unchecked_t genid;
87019 u32 priority;
87020 u32 index;
87021 struct xfrm_mark mark;
87022 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87023 }
87024
87025 void xfrm_garbage_collect(struct net *net);
87026 +void xfrm_garbage_collect_deferred(struct net *net);
87027
87028 #else
87029
87030 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87031 static inline void xfrm_garbage_collect(struct net *net)
87032 {
87033 }
87034 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87035 +{
87036 +}
87037 #endif
87038
87039 static __inline__
87040 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87041 index 1017e0b..227aa4d 100644
87042 --- a/include/rdma/iw_cm.h
87043 +++ b/include/rdma/iw_cm.h
87044 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87045 int backlog);
87046
87047 int (*destroy_listen)(struct iw_cm_id *cm_id);
87048 -};
87049 +} __no_const;
87050
87051 /**
87052 * iw_create_cm_id - Create an IW CM identifier.
87053 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87054 index 52beadf..598734c 100644
87055 --- a/include/scsi/libfc.h
87056 +++ b/include/scsi/libfc.h
87057 @@ -771,6 +771,7 @@ struct libfc_function_template {
87058 */
87059 void (*disc_stop_final) (struct fc_lport *);
87060 };
87061 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87062
87063 /**
87064 * struct fc_disc - Discovery context
87065 @@ -875,7 +876,7 @@ struct fc_lport {
87066 struct fc_vport *vport;
87067
87068 /* Operational Information */
87069 - struct libfc_function_template tt;
87070 + libfc_function_template_no_const tt;
87071 u8 link_up;
87072 u8 qfull;
87073 enum fc_lport_state state;
87074 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87075 index 27ecee7..5f42632 100644
87076 --- a/include/scsi/scsi_device.h
87077 +++ b/include/scsi/scsi_device.h
87078 @@ -186,9 +186,9 @@ struct scsi_device {
87079 unsigned int max_device_blocked; /* what device_blocked counts down from */
87080 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87081
87082 - atomic_t iorequest_cnt;
87083 - atomic_t iodone_cnt;
87084 - atomic_t ioerr_cnt;
87085 + atomic_unchecked_t iorequest_cnt;
87086 + atomic_unchecked_t iodone_cnt;
87087 + atomic_unchecked_t ioerr_cnt;
87088
87089 struct device sdev_gendev,
87090 sdev_dev;
87091 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87092 index 007a0bc..7188db8 100644
87093 --- a/include/scsi/scsi_transport_fc.h
87094 +++ b/include/scsi/scsi_transport_fc.h
87095 @@ -756,7 +756,8 @@ struct fc_function_template {
87096 unsigned long show_host_system_hostname:1;
87097
87098 unsigned long disable_target_scan:1;
87099 -};
87100 +} __do_const;
87101 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87102
87103
87104 /**
87105 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87106 index ae6c3b8..fd748ac 100644
87107 --- a/include/sound/compress_driver.h
87108 +++ b/include/sound/compress_driver.h
87109 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87110 struct snd_compr_caps *caps);
87111 int (*get_codec_caps) (struct snd_compr_stream *stream,
87112 struct snd_compr_codec_caps *codec);
87113 -};
87114 +} __no_const;
87115
87116 /**
87117 * struct snd_compr: Compressed device
87118 diff --git a/include/sound/soc.h b/include/sound/soc.h
87119 index 7ba7130..d46594d 100644
87120 --- a/include/sound/soc.h
87121 +++ b/include/sound/soc.h
87122 @@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
87123 enum snd_soc_dapm_type, int);
87124
87125 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
87126 -};
87127 +} __do_const;
87128
87129 /* SoC platform interface */
87130 struct snd_soc_platform_driver {
87131 @@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
87132 const struct snd_compr_ops *compr_ops;
87133
87134 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87135 -};
87136 +} __do_const;
87137
87138 struct snd_soc_dai_link_component {
87139 const char *name;
87140 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87141 index 23c518a..d6ef510 100644
87142 --- a/include/target/target_core_base.h
87143 +++ b/include/target/target_core_base.h
87144 @@ -764,7 +764,7 @@ struct se_device {
87145 atomic_long_t write_bytes;
87146 /* Active commands on this virtual SE device */
87147 atomic_t simple_cmds;
87148 - atomic_t dev_ordered_id;
87149 + atomic_unchecked_t dev_ordered_id;
87150 atomic_t dev_ordered_sync;
87151 atomic_t dev_qf_count;
87152 int export_count;
87153 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87154 new file mode 100644
87155 index 0000000..fb634b7
87156 --- /dev/null
87157 +++ b/include/trace/events/fs.h
87158 @@ -0,0 +1,53 @@
87159 +#undef TRACE_SYSTEM
87160 +#define TRACE_SYSTEM fs
87161 +
87162 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87163 +#define _TRACE_FS_H
87164 +
87165 +#include <linux/fs.h>
87166 +#include <linux/tracepoint.h>
87167 +
87168 +TRACE_EVENT(do_sys_open,
87169 +
87170 + TP_PROTO(const char *filename, int flags, int mode),
87171 +
87172 + TP_ARGS(filename, flags, mode),
87173 +
87174 + TP_STRUCT__entry(
87175 + __string( filename, filename )
87176 + __field( int, flags )
87177 + __field( int, mode )
87178 + ),
87179 +
87180 + TP_fast_assign(
87181 + __assign_str(filename, filename);
87182 + __entry->flags = flags;
87183 + __entry->mode = mode;
87184 + ),
87185 +
87186 + TP_printk("\"%s\" %x %o",
87187 + __get_str(filename), __entry->flags, __entry->mode)
87188 +);
87189 +
87190 +TRACE_EVENT(open_exec,
87191 +
87192 + TP_PROTO(const char *filename),
87193 +
87194 + TP_ARGS(filename),
87195 +
87196 + TP_STRUCT__entry(
87197 + __string( filename, filename )
87198 + ),
87199 +
87200 + TP_fast_assign(
87201 + __assign_str(filename, filename);
87202 + ),
87203 +
87204 + TP_printk("\"%s\"",
87205 + __get_str(filename))
87206 +);
87207 +
87208 +#endif /* _TRACE_FS_H */
87209 +
87210 +/* This part must be outside protection */
87211 +#include <trace/define_trace.h>
87212 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87213 index 3608beb..df39d8a 100644
87214 --- a/include/trace/events/irq.h
87215 +++ b/include/trace/events/irq.h
87216 @@ -36,7 +36,7 @@ struct softirq_action;
87217 */
87218 TRACE_EVENT(irq_handler_entry,
87219
87220 - TP_PROTO(int irq, struct irqaction *action),
87221 + TP_PROTO(int irq, const struct irqaction *action),
87222
87223 TP_ARGS(irq, action),
87224
87225 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87226 */
87227 TRACE_EVENT(irq_handler_exit,
87228
87229 - TP_PROTO(int irq, struct irqaction *action, int ret),
87230 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87231
87232 TP_ARGS(irq, action, ret),
87233
87234 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87235 index 7caf44c..23c6f27 100644
87236 --- a/include/uapi/linux/a.out.h
87237 +++ b/include/uapi/linux/a.out.h
87238 @@ -39,6 +39,14 @@ enum machine_type {
87239 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87240 };
87241
87242 +/* Constants for the N_FLAGS field */
87243 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87244 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87245 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87246 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87247 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87248 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87249 +
87250 #if !defined (N_MAGIC)
87251 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87252 #endif
87253 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87254 index 22b6ad3..aeba37e 100644
87255 --- a/include/uapi/linux/bcache.h
87256 +++ b/include/uapi/linux/bcache.h
87257 @@ -5,6 +5,7 @@
87258 * Bcache on disk data structures
87259 */
87260
87261 +#include <linux/compiler.h>
87262 #include <asm/types.h>
87263
87264 #define BITMASK(name, type, field, offset, size) \
87265 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87266 /* Btree keys - all units are in sectors */
87267
87268 struct bkey {
87269 - __u64 high;
87270 - __u64 low;
87271 + __u64 high __intentional_overflow(-1);
87272 + __u64 low __intentional_overflow(-1);
87273 __u64 ptr[];
87274 };
87275
87276 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87277 index d876736..ccce5c0 100644
87278 --- a/include/uapi/linux/byteorder/little_endian.h
87279 +++ b/include/uapi/linux/byteorder/little_endian.h
87280 @@ -42,51 +42,51 @@
87281
87282 static inline __le64 __cpu_to_le64p(const __u64 *p)
87283 {
87284 - return (__force __le64)*p;
87285 + return (__force const __le64)*p;
87286 }
87287 -static inline __u64 __le64_to_cpup(const __le64 *p)
87288 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87289 {
87290 - return (__force __u64)*p;
87291 + return (__force const __u64)*p;
87292 }
87293 static inline __le32 __cpu_to_le32p(const __u32 *p)
87294 {
87295 - return (__force __le32)*p;
87296 + return (__force const __le32)*p;
87297 }
87298 static inline __u32 __le32_to_cpup(const __le32 *p)
87299 {
87300 - return (__force __u32)*p;
87301 + return (__force const __u32)*p;
87302 }
87303 static inline __le16 __cpu_to_le16p(const __u16 *p)
87304 {
87305 - return (__force __le16)*p;
87306 + return (__force const __le16)*p;
87307 }
87308 static inline __u16 __le16_to_cpup(const __le16 *p)
87309 {
87310 - return (__force __u16)*p;
87311 + return (__force const __u16)*p;
87312 }
87313 static inline __be64 __cpu_to_be64p(const __u64 *p)
87314 {
87315 - return (__force __be64)__swab64p(p);
87316 + return (__force const __be64)__swab64p(p);
87317 }
87318 static inline __u64 __be64_to_cpup(const __be64 *p)
87319 {
87320 - return __swab64p((__u64 *)p);
87321 + return __swab64p((const __u64 *)p);
87322 }
87323 static inline __be32 __cpu_to_be32p(const __u32 *p)
87324 {
87325 - return (__force __be32)__swab32p(p);
87326 + return (__force const __be32)__swab32p(p);
87327 }
87328 -static inline __u32 __be32_to_cpup(const __be32 *p)
87329 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87330 {
87331 - return __swab32p((__u32 *)p);
87332 + return __swab32p((const __u32 *)p);
87333 }
87334 static inline __be16 __cpu_to_be16p(const __u16 *p)
87335 {
87336 - return (__force __be16)__swab16p(p);
87337 + return (__force const __be16)__swab16p(p);
87338 }
87339 static inline __u16 __be16_to_cpup(const __be16 *p)
87340 {
87341 - return __swab16p((__u16 *)p);
87342 + return __swab16p((const __u16 *)p);
87343 }
87344 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87345 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87346 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87347 index ea9bf25..5140c61 100644
87348 --- a/include/uapi/linux/elf.h
87349 +++ b/include/uapi/linux/elf.h
87350 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87351 #define PT_GNU_EH_FRAME 0x6474e550
87352
87353 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87354 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87355 +
87356 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87357 +
87358 +/* Constants for the e_flags field */
87359 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87360 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87361 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87362 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87363 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87364 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87365
87366 /*
87367 * Extended Numbering
87368 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87369 #define DT_DEBUG 21
87370 #define DT_TEXTREL 22
87371 #define DT_JMPREL 23
87372 +#define DT_FLAGS 30
87373 + #define DF_TEXTREL 0x00000004
87374 #define DT_ENCODING 32
87375 #define OLD_DT_LOOS 0x60000000
87376 #define DT_LOOS 0x6000000d
87377 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87378 #define PF_W 0x2
87379 #define PF_X 0x1
87380
87381 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87382 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87383 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87384 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87385 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87386 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87387 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87388 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87389 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87390 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87391 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87392 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87393 +
87394 typedef struct elf32_phdr{
87395 Elf32_Word p_type;
87396 Elf32_Off p_offset;
87397 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87398 #define EI_OSABI 7
87399 #define EI_PAD 8
87400
87401 +#define EI_PAX 14
87402 +
87403 #define ELFMAG0 0x7f /* EI_MAG */
87404 #define ELFMAG1 'E'
87405 #define ELFMAG2 'L'
87406 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87407 index aa169c4..6a2771d 100644
87408 --- a/include/uapi/linux/personality.h
87409 +++ b/include/uapi/linux/personality.h
87410 @@ -30,6 +30,7 @@ enum {
87411 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87412 ADDR_NO_RANDOMIZE | \
87413 ADDR_COMPAT_LAYOUT | \
87414 + ADDR_LIMIT_3GB | \
87415 MMAP_PAGE_ZERO)
87416
87417 /*
87418 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87419 index 7530e74..e714828 100644
87420 --- a/include/uapi/linux/screen_info.h
87421 +++ b/include/uapi/linux/screen_info.h
87422 @@ -43,7 +43,8 @@ struct screen_info {
87423 __u16 pages; /* 0x32 */
87424 __u16 vesa_attributes; /* 0x34 */
87425 __u32 capabilities; /* 0x36 */
87426 - __u8 _reserved[6]; /* 0x3a */
87427 + __u16 vesapm_size; /* 0x3a */
87428 + __u8 _reserved[4]; /* 0x3c */
87429 } __attribute__((packed));
87430
87431 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87432 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87433 index 0e011eb..82681b1 100644
87434 --- a/include/uapi/linux/swab.h
87435 +++ b/include/uapi/linux/swab.h
87436 @@ -43,7 +43,7 @@
87437 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87438 */
87439
87440 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87441 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87442 {
87443 #ifdef __HAVE_BUILTIN_BSWAP16__
87444 return __builtin_bswap16(val);
87445 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87446 #endif
87447 }
87448
87449 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87450 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87451 {
87452 #ifdef __HAVE_BUILTIN_BSWAP32__
87453 return __builtin_bswap32(val);
87454 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87455 #endif
87456 }
87457
87458 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87459 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87460 {
87461 #ifdef __HAVE_BUILTIN_BSWAP64__
87462 return __builtin_bswap64(val);
87463 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87464 index 43aaba1..1c30b48 100644
87465 --- a/include/uapi/linux/sysctl.h
87466 +++ b/include/uapi/linux/sysctl.h
87467 @@ -155,8 +155,6 @@ enum
87468 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87469 };
87470
87471 -
87472 -
87473 /* CTL_VM names: */
87474 enum
87475 {
87476 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87477 index 1590c49..5eab462 100644
87478 --- a/include/uapi/linux/xattr.h
87479 +++ b/include/uapi/linux/xattr.h
87480 @@ -73,5 +73,9 @@
87481 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87482 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87483
87484 +/* User namespace */
87485 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87486 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87487 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87488
87489 #endif /* _UAPI_LINUX_XATTR_H */
87490 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87491 index f9466fa..f4e2b81 100644
87492 --- a/include/video/udlfb.h
87493 +++ b/include/video/udlfb.h
87494 @@ -53,10 +53,10 @@ struct dlfb_data {
87495 u32 pseudo_palette[256];
87496 int blank_mode; /*one of FB_BLANK_ */
87497 /* blit-only rendering path metrics, exposed through sysfs */
87498 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87499 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87500 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87501 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87502 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87503 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87504 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87505 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87506 };
87507
87508 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87509 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87510 index 30f5362..8ed8ac9 100644
87511 --- a/include/video/uvesafb.h
87512 +++ b/include/video/uvesafb.h
87513 @@ -122,6 +122,7 @@ struct uvesafb_par {
87514 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87515 u8 pmi_setpal; /* PMI for palette changes */
87516 u16 *pmi_base; /* protected mode interface location */
87517 + u8 *pmi_code; /* protected mode code location */
87518 void *pmi_start;
87519 void *pmi_pal;
87520 u8 *vbe_state_orig; /*
87521 diff --git a/init/Kconfig b/init/Kconfig
87522 index 2081a4d..98d1149 100644
87523 --- a/init/Kconfig
87524 +++ b/init/Kconfig
87525 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87526
87527 config CHECKPOINT_RESTORE
87528 bool "Checkpoint/restore support" if EXPERT
87529 + depends on !GRKERNSEC
87530 default n
87531 help
87532 Enables additional kernel features in a sake of checkpoint/restore.
87533 @@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87534
87535 config COMPAT_BRK
87536 bool "Disable heap randomization"
87537 - default y
87538 + default n
87539 help
87540 Randomizing heap placement makes heap exploits harder, but it
87541 also breaks ancient binaries (including anything libc5 based).
87542 @@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87543 config STOP_MACHINE
87544 bool
87545 default y
87546 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87547 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87548 help
87549 Need stop_machine() primitive.
87550
87551 diff --git a/init/Makefile b/init/Makefile
87552 index 7bc47ee..6da2dc7 100644
87553 --- a/init/Makefile
87554 +++ b/init/Makefile
87555 @@ -2,6 +2,9 @@
87556 # Makefile for the linux kernel.
87557 #
87558
87559 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87560 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87561 +
87562 obj-y := main.o version.o mounts.o
87563 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87564 obj-y += noinitramfs.o
87565 diff --git a/init/do_mounts.c b/init/do_mounts.c
87566 index 9b3565c..3f90cf9 100644
87567 --- a/init/do_mounts.c
87568 +++ b/init/do_mounts.c
87569 @@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87570 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87571 {
87572 struct super_block *s;
87573 - int err = sys_mount(name, "/root", fs, flags, data);
87574 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87575 if (err)
87576 return err;
87577
87578 - sys_chdir("/root");
87579 + sys_chdir((const char __force_user *)"/root");
87580 s = current->fs->pwd.dentry->d_sb;
87581 ROOT_DEV = s->s_dev;
87582 printk(KERN_INFO
87583 @@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87584 va_start(args, fmt);
87585 vsprintf(buf, fmt, args);
87586 va_end(args);
87587 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87588 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87589 if (fd >= 0) {
87590 sys_ioctl(fd, FDEJECT, 0);
87591 sys_close(fd);
87592 }
87593 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87594 - fd = sys_open("/dev/console", O_RDWR, 0);
87595 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87596 if (fd >= 0) {
87597 sys_ioctl(fd, TCGETS, (long)&termios);
87598 termios.c_lflag &= ~ICANON;
87599 sys_ioctl(fd, TCSETSF, (long)&termios);
87600 - sys_read(fd, &c, 1);
87601 + sys_read(fd, (char __user *)&c, 1);
87602 termios.c_lflag |= ICANON;
87603 sys_ioctl(fd, TCSETSF, (long)&termios);
87604 sys_close(fd);
87605 @@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87606 mount_root();
87607 out:
87608 devtmpfs_mount("dev");
87609 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87610 - sys_chroot(".");
87611 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87612 + sys_chroot((const char __force_user *)".");
87613 }
87614
87615 static bool is_tmpfs;
87616 diff --git a/init/do_mounts.h b/init/do_mounts.h
87617 index f5b978a..69dbfe8 100644
87618 --- a/init/do_mounts.h
87619 +++ b/init/do_mounts.h
87620 @@ -15,15 +15,15 @@ extern int root_mountflags;
87621
87622 static inline int create_dev(char *name, dev_t dev)
87623 {
87624 - sys_unlink(name);
87625 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87626 + sys_unlink((char __force_user *)name);
87627 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87628 }
87629
87630 #if BITS_PER_LONG == 32
87631 static inline u32 bstat(char *name)
87632 {
87633 struct stat64 stat;
87634 - if (sys_stat64(name, &stat) != 0)
87635 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87636 return 0;
87637 if (!S_ISBLK(stat.st_mode))
87638 return 0;
87639 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87640 static inline u32 bstat(char *name)
87641 {
87642 struct stat stat;
87643 - if (sys_newstat(name, &stat) != 0)
87644 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87645 return 0;
87646 if (!S_ISBLK(stat.st_mode))
87647 return 0;
87648 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87649 index 3e0878e..8a9d7a0 100644
87650 --- a/init/do_mounts_initrd.c
87651 +++ b/init/do_mounts_initrd.c
87652 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87653 {
87654 sys_unshare(CLONE_FS | CLONE_FILES);
87655 /* stdin/stdout/stderr for /linuxrc */
87656 - sys_open("/dev/console", O_RDWR, 0);
87657 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87658 sys_dup(0);
87659 sys_dup(0);
87660 /* move initrd over / and chdir/chroot in initrd root */
87661 - sys_chdir("/root");
87662 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87663 - sys_chroot(".");
87664 + sys_chdir((const char __force_user *)"/root");
87665 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87666 + sys_chroot((const char __force_user *)".");
87667 sys_setsid();
87668 return 0;
87669 }
87670 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87671 create_dev("/dev/root.old", Root_RAM0);
87672 /* mount initrd on rootfs' /root */
87673 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87674 - sys_mkdir("/old", 0700);
87675 - sys_chdir("/old");
87676 + sys_mkdir((const char __force_user *)"/old", 0700);
87677 + sys_chdir((const char __force_user *)"/old");
87678
87679 /* try loading default modules from initrd */
87680 load_default_modules();
87681 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87682 current->flags &= ~PF_FREEZER_SKIP;
87683
87684 /* move initrd to rootfs' /old */
87685 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87686 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87687 /* switch root and cwd back to / of rootfs */
87688 - sys_chroot("..");
87689 + sys_chroot((const char __force_user *)"..");
87690
87691 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87692 - sys_chdir("/old");
87693 + sys_chdir((const char __force_user *)"/old");
87694 return;
87695 }
87696
87697 - sys_chdir("/");
87698 + sys_chdir((const char __force_user *)"/");
87699 ROOT_DEV = new_decode_dev(real_root_dev);
87700 mount_root();
87701
87702 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87703 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87704 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87705 if (!error)
87706 printk("okay\n");
87707 else {
87708 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87709 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87710 if (error == -ENOENT)
87711 printk("/initrd does not exist. Ignored.\n");
87712 else
87713 printk("failed\n");
87714 printk(KERN_NOTICE "Unmounting old root\n");
87715 - sys_umount("/old", MNT_DETACH);
87716 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87717 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87718 if (fd < 0) {
87719 error = fd;
87720 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87721 * mounted in the normal path.
87722 */
87723 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87724 - sys_unlink("/initrd.image");
87725 + sys_unlink((const char __force_user *)"/initrd.image");
87726 handle_initrd();
87727 return 1;
87728 }
87729 }
87730 - sys_unlink("/initrd.image");
87731 + sys_unlink((const char __force_user *)"/initrd.image");
87732 return 0;
87733 }
87734 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87735 index 8cb6db5..d729f50 100644
87736 --- a/init/do_mounts_md.c
87737 +++ b/init/do_mounts_md.c
87738 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87739 partitioned ? "_d" : "", minor,
87740 md_setup_args[ent].device_names);
87741
87742 - fd = sys_open(name, 0, 0);
87743 + fd = sys_open((char __force_user *)name, 0, 0);
87744 if (fd < 0) {
87745 printk(KERN_ERR "md: open failed - cannot start "
87746 "array %s\n", name);
87747 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87748 * array without it
87749 */
87750 sys_close(fd);
87751 - fd = sys_open(name, 0, 0);
87752 + fd = sys_open((char __force_user *)name, 0, 0);
87753 sys_ioctl(fd, BLKRRPART, 0);
87754 }
87755 sys_close(fd);
87756 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87757
87758 wait_for_device_probe();
87759
87760 - fd = sys_open("/dev/md0", 0, 0);
87761 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87762 if (fd >= 0) {
87763 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87764 sys_close(fd);
87765 diff --git a/init/init_task.c b/init/init_task.c
87766 index ba0a7f36..2bcf1d5 100644
87767 --- a/init/init_task.c
87768 +++ b/init/init_task.c
87769 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87770 * Initial thread structure. Alignment of this is handled by a special
87771 * linker map entry.
87772 */
87773 +#ifdef CONFIG_X86
87774 +union thread_union init_thread_union __init_task_data;
87775 +#else
87776 union thread_union init_thread_union __init_task_data =
87777 { INIT_THREAD_INFO(init_task) };
87778 +#endif
87779 diff --git a/init/initramfs.c b/init/initramfs.c
87780 index ad1bd77..dca2c1b 100644
87781 --- a/init/initramfs.c
87782 +++ b/init/initramfs.c
87783 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87784
87785 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87786 while (count) {
87787 - ssize_t rv = sys_write(fd, p, count);
87788 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87789
87790 if (rv < 0) {
87791 if (rv == -EINTR || rv == -EAGAIN)
87792 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87793 }
87794 }
87795
87796 -static long __init do_utime(char *filename, time_t mtime)
87797 +static long __init do_utime(char __force_user *filename, time_t mtime)
87798 {
87799 struct timespec t[2];
87800
87801 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87802 struct dir_entry *de, *tmp;
87803 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87804 list_del(&de->list);
87805 - do_utime(de->name, de->mtime);
87806 + do_utime((char __force_user *)de->name, de->mtime);
87807 kfree(de->name);
87808 kfree(de);
87809 }
87810 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87811 if (nlink >= 2) {
87812 char *old = find_link(major, minor, ino, mode, collected);
87813 if (old)
87814 - return (sys_link(old, collected) < 0) ? -1 : 1;
87815 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87816 }
87817 return 0;
87818 }
87819 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87820 {
87821 struct stat st;
87822
87823 - if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87824 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87825 if (S_ISDIR(st.st_mode))
87826 - sys_rmdir(path);
87827 + sys_rmdir((char __force_user *)path);
87828 else
87829 - sys_unlink(path);
87830 + sys_unlink((char __force_user *)path);
87831 }
87832 }
87833
87834 @@ -338,7 +338,7 @@ static int __init do_name(void)
87835 int openflags = O_WRONLY|O_CREAT;
87836 if (ml != 1)
87837 openflags |= O_TRUNC;
87838 - wfd = sys_open(collected, openflags, mode);
87839 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87840
87841 if (wfd >= 0) {
87842 sys_fchown(wfd, uid, gid);
87843 @@ -350,17 +350,17 @@ static int __init do_name(void)
87844 }
87845 }
87846 } else if (S_ISDIR(mode)) {
87847 - sys_mkdir(collected, mode);
87848 - sys_chown(collected, uid, gid);
87849 - sys_chmod(collected, mode);
87850 + sys_mkdir((char __force_user *)collected, mode);
87851 + sys_chown((char __force_user *)collected, uid, gid);
87852 + sys_chmod((char __force_user *)collected, mode);
87853 dir_add(collected, mtime);
87854 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87855 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87856 if (maybe_link() == 0) {
87857 - sys_mknod(collected, mode, rdev);
87858 - sys_chown(collected, uid, gid);
87859 - sys_chmod(collected, mode);
87860 - do_utime(collected, mtime);
87861 + sys_mknod((char __force_user *)collected, mode, rdev);
87862 + sys_chown((char __force_user *)collected, uid, gid);
87863 + sys_chmod((char __force_user *)collected, mode);
87864 + do_utime((char __force_user *)collected, mtime);
87865 }
87866 }
87867 return 0;
87868 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87869 if (xwrite(wfd, victim, body_len) != body_len)
87870 error("write error");
87871 sys_close(wfd);
87872 - do_utime(vcollected, mtime);
87873 + do_utime((char __force_user *)vcollected, mtime);
87874 kfree(vcollected);
87875 eat(body_len);
87876 state = SkipIt;
87877 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87878 {
87879 collected[N_ALIGN(name_len) + body_len] = '\0';
87880 clean_path(collected, 0);
87881 - sys_symlink(collected + N_ALIGN(name_len), collected);
87882 - sys_lchown(collected, uid, gid);
87883 - do_utime(collected, mtime);
87884 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87885 + sys_lchown((char __force_user *)collected, uid, gid);
87886 + do_utime((char __force_user *)collected, mtime);
87887 state = SkipIt;
87888 next_state = Reset;
87889 return 0;
87890 diff --git a/init/main.c b/init/main.c
87891 index 321d0ce..91b53e5 100644
87892 --- a/init/main.c
87893 +++ b/init/main.c
87894 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87895 static inline void mark_rodata_ro(void) { }
87896 #endif
87897
87898 +extern void grsecurity_init(void);
87899 +
87900 /*
87901 * Debug helper: via this flag we know that we are in 'early bootup code'
87902 * where only the boot processor is running with IRQ disabled. This means
87903 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87904
87905 __setup("reset_devices", set_reset_devices);
87906
87907 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87908 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87909 +static int __init setup_grsec_proc_gid(char *str)
87910 +{
87911 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87912 + return 1;
87913 +}
87914 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87915 +#endif
87916 +
87917 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87918 +unsigned long pax_user_shadow_base __read_only;
87919 +EXPORT_SYMBOL(pax_user_shadow_base);
87920 +extern char pax_enter_kernel_user[];
87921 +extern char pax_exit_kernel_user[];
87922 +#endif
87923 +
87924 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87925 +static int __init setup_pax_nouderef(char *str)
87926 +{
87927 +#ifdef CONFIG_X86_32
87928 + unsigned int cpu;
87929 + struct desc_struct *gdt;
87930 +
87931 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87932 + gdt = get_cpu_gdt_table(cpu);
87933 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87934 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87935 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87936 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87937 + }
87938 + loadsegment(ds, __KERNEL_DS);
87939 + loadsegment(es, __KERNEL_DS);
87940 + loadsegment(ss, __KERNEL_DS);
87941 +#else
87942 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87943 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87944 + clone_pgd_mask = ~(pgdval_t)0UL;
87945 + pax_user_shadow_base = 0UL;
87946 + setup_clear_cpu_cap(X86_FEATURE_PCID);
87947 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87948 +#endif
87949 +
87950 + return 0;
87951 +}
87952 +early_param("pax_nouderef", setup_pax_nouderef);
87953 +
87954 +#ifdef CONFIG_X86_64
87955 +static int __init setup_pax_weakuderef(char *str)
87956 +{
87957 + if (clone_pgd_mask != ~(pgdval_t)0UL)
87958 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87959 + return 1;
87960 +}
87961 +__setup("pax_weakuderef", setup_pax_weakuderef);
87962 +#endif
87963 +#endif
87964 +
87965 +#ifdef CONFIG_PAX_SOFTMODE
87966 +int pax_softmode;
87967 +
87968 +static int __init setup_pax_softmode(char *str)
87969 +{
87970 + get_option(&str, &pax_softmode);
87971 + return 1;
87972 +}
87973 +__setup("pax_softmode=", setup_pax_softmode);
87974 +#endif
87975 +
87976 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87977 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87978 static const char *panic_later, *panic_param;
87979 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87980 struct blacklist_entry *entry;
87981 char *fn_name;
87982
87983 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87984 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87985 if (!fn_name)
87986 return false;
87987
87988 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87989 {
87990 int count = preempt_count();
87991 int ret;
87992 - char msgbuf[64];
87993 + const char *msg1 = "", *msg2 = "";
87994
87995 if (initcall_blacklisted(fn))
87996 return -EPERM;
87997 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87998 else
87999 ret = fn();
88000
88001 - msgbuf[0] = 0;
88002 -
88003 if (preempt_count() != count) {
88004 - sprintf(msgbuf, "preemption imbalance ");
88005 + msg1 = " preemption imbalance";
88006 preempt_count_set(count);
88007 }
88008 if (irqs_disabled()) {
88009 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88010 + msg2 = " disabled interrupts";
88011 local_irq_enable();
88012 }
88013 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88014 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88015
88016 + add_latent_entropy();
88017 return ret;
88018 }
88019
88020 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
88021 {
88022 argv_init[0] = init_filename;
88023 return do_execve(getname_kernel(init_filename),
88024 - (const char __user *const __user *)argv_init,
88025 - (const char __user *const __user *)envp_init);
88026 + (const char __user *const __force_user *)argv_init,
88027 + (const char __user *const __force_user *)envp_init);
88028 }
88029
88030 static int try_to_run_init_process(const char *init_filename)
88031 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
88032 return ret;
88033 }
88034
88035 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88036 +extern int gr_init_ran;
88037 +#endif
88038 +
88039 static noinline void __init kernel_init_freeable(void);
88040
88041 static int __ref kernel_init(void *unused)
88042 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
88043 ramdisk_execute_command, ret);
88044 }
88045
88046 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88047 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88048 + gr_init_ran = 1;
88049 +#endif
88050 +
88051 /*
88052 * We try each of these until one succeeds.
88053 *
88054 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
88055 do_basic_setup();
88056
88057 /* Open the /dev/console on the rootfs, this should never fail */
88058 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88059 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88060 pr_err("Warning: unable to open an initial console.\n");
88061
88062 (void) sys_dup(0);
88063 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
88064 if (!ramdisk_execute_command)
88065 ramdisk_execute_command = "/init";
88066
88067 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88068 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88069 ramdisk_execute_command = NULL;
88070 prepare_namespace();
88071 }
88072
88073 + grsecurity_init();
88074 +
88075 /*
88076 * Ok, we have completed the initial bootup, and
88077 * we're essentially up and running. Get rid of the
88078 diff --git a/ipc/compat.c b/ipc/compat.c
88079 index 9b3c85f..1c4d897 100644
88080 --- a/ipc/compat.c
88081 +++ b/ipc/compat.c
88082 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88083 COMPAT_SHMLBA);
88084 if (err < 0)
88085 return err;
88086 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88087 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88088 }
88089 case SHMDT:
88090 return sys_shmdt(compat_ptr(ptr));
88091 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88092 index e8075b2..76f2c6a 100644
88093 --- a/ipc/ipc_sysctl.c
88094 +++ b/ipc/ipc_sysctl.c
88095 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88096 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88097 void __user *buffer, size_t *lenp, loff_t *ppos)
88098 {
88099 - struct ctl_table ipc_table;
88100 + ctl_table_no_const ipc_table;
88101
88102 memcpy(&ipc_table, table, sizeof(ipc_table));
88103 ipc_table.data = get_ipc(table);
88104 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88105 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88106 void __user *buffer, size_t *lenp, loff_t *ppos)
88107 {
88108 - struct ctl_table ipc_table;
88109 + ctl_table_no_const ipc_table;
88110
88111 memcpy(&ipc_table, table, sizeof(ipc_table));
88112 ipc_table.data = get_ipc(table);
88113 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88114 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88115 void __user *buffer, size_t *lenp, loff_t *ppos)
88116 {
88117 - struct ctl_table ipc_table;
88118 + ctl_table_no_const ipc_table;
88119 size_t lenp_bef = *lenp;
88120 int rc;
88121
88122 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88123 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88124 void __user *buffer, size_t *lenp, loff_t *ppos)
88125 {
88126 - struct ctl_table ipc_table;
88127 + ctl_table_no_const ipc_table;
88128 memcpy(&ipc_table, table, sizeof(ipc_table));
88129 ipc_table.data = get_ipc(table);
88130
88131 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88132 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88133 void __user *buffer, size_t *lenp, loff_t *ppos)
88134 {
88135 - struct ctl_table ipc_table;
88136 + ctl_table_no_const ipc_table;
88137 int oldval;
88138 int rc;
88139
88140 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88141 index 68d4e95..1477ded 100644
88142 --- a/ipc/mq_sysctl.c
88143 +++ b/ipc/mq_sysctl.c
88144 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88145 static int proc_mq_dointvec(struct ctl_table *table, int write,
88146 void __user *buffer, size_t *lenp, loff_t *ppos)
88147 {
88148 - struct ctl_table mq_table;
88149 + ctl_table_no_const mq_table;
88150 memcpy(&mq_table, table, sizeof(mq_table));
88151 mq_table.data = get_mq(table);
88152
88153 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88154 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88155 void __user *buffer, size_t *lenp, loff_t *ppos)
88156 {
88157 - struct ctl_table mq_table;
88158 + ctl_table_no_const mq_table;
88159 memcpy(&mq_table, table, sizeof(mq_table));
88160 mq_table.data = get_mq(table);
88161
88162 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88163 index 4fcf39a..d3cc2ec 100644
88164 --- a/ipc/mqueue.c
88165 +++ b/ipc/mqueue.c
88166 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88167 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88168 info->attr.mq_msgsize);
88169
88170 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88171 spin_lock(&mq_lock);
88172 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88173 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88174 diff --git a/ipc/shm.c b/ipc/shm.c
88175 index 0145479..3d27947 100644
88176 --- a/ipc/shm.c
88177 +++ b/ipc/shm.c
88178 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88179 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88180 #endif
88181
88182 +#ifdef CONFIG_GRKERNSEC
88183 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88184 + const u64 shm_createtime, const kuid_t cuid,
88185 + const int shmid);
88186 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88187 + const u64 shm_createtime);
88188 +#endif
88189 +
88190 void shm_init_ns(struct ipc_namespace *ns)
88191 {
88192 ns->shm_ctlmax = SHMMAX;
88193 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88194 shp->shm_lprid = 0;
88195 shp->shm_atim = shp->shm_dtim = 0;
88196 shp->shm_ctim = get_seconds();
88197 +#ifdef CONFIG_GRKERNSEC
88198 + shp->shm_createtime = ktime_get_ns();
88199 +#endif
88200 shp->shm_segsz = size;
88201 shp->shm_nattch = 0;
88202 shp->shm_file = file;
88203 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88204 f_mode = FMODE_READ | FMODE_WRITE;
88205 }
88206 if (shmflg & SHM_EXEC) {
88207 +
88208 +#ifdef CONFIG_PAX_MPROTECT
88209 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88210 + goto out;
88211 +#endif
88212 +
88213 prot |= PROT_EXEC;
88214 acc_mode |= S_IXUGO;
88215 }
88216 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88217 if (err)
88218 goto out_unlock;
88219
88220 +#ifdef CONFIG_GRKERNSEC
88221 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88222 + shp->shm_perm.cuid, shmid) ||
88223 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88224 + err = -EACCES;
88225 + goto out_unlock;
88226 + }
88227 +#endif
88228 +
88229 ipc_lock_object(&shp->shm_perm);
88230
88231 /* check if shm_destroy() is tearing down shp */
88232 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88233 path = shp->shm_file->f_path;
88234 path_get(&path);
88235 shp->shm_nattch++;
88236 +#ifdef CONFIG_GRKERNSEC
88237 + shp->shm_lapid = current->pid;
88238 +#endif
88239 size = i_size_read(path.dentry->d_inode);
88240 ipc_unlock_object(&shp->shm_perm);
88241 rcu_read_unlock();
88242 diff --git a/ipc/util.c b/ipc/util.c
88243 index 88adc32..3867c68 100644
88244 --- a/ipc/util.c
88245 +++ b/ipc/util.c
88246 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88247 int (*show)(struct seq_file *, void *);
88248 };
88249
88250 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88251 +
88252 static void ipc_memory_notifier(struct work_struct *work)
88253 {
88254 ipcns_notify(IPCNS_MEMCHANGED);
88255 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88256 granted_mode >>= 6;
88257 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88258 granted_mode >>= 3;
88259 +
88260 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88261 + return -1;
88262 +
88263 /* is there some bit set in requested_mode but not in granted_mode? */
88264 if ((requested_mode & ~granted_mode & 0007) &&
88265 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88266 diff --git a/kernel/audit.c b/kernel/audit.c
88267 index c6df990..fde80b4 100644
88268 --- a/kernel/audit.c
88269 +++ b/kernel/audit.c
88270 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88271 3) suppressed due to audit_rate_limit
88272 4) suppressed due to audit_backlog_limit
88273 */
88274 -static atomic_t audit_lost = ATOMIC_INIT(0);
88275 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88276
88277 /* The netlink socket. */
88278 static struct sock *audit_sock;
88279 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88280 unsigned long now;
88281 int print;
88282
88283 - atomic_inc(&audit_lost);
88284 + atomic_inc_unchecked(&audit_lost);
88285
88286 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88287
88288 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88289 if (print) {
88290 if (printk_ratelimit())
88291 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88292 - atomic_read(&audit_lost),
88293 + atomic_read_unchecked(&audit_lost),
88294 audit_rate_limit,
88295 audit_backlog_limit);
88296 audit_panic(message);
88297 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88298 s.pid = audit_pid;
88299 s.rate_limit = audit_rate_limit;
88300 s.backlog_limit = audit_backlog_limit;
88301 - s.lost = atomic_read(&audit_lost);
88302 + s.lost = atomic_read_unchecked(&audit_lost);
88303 s.backlog = skb_queue_len(&audit_skb_queue);
88304 s.version = AUDIT_VERSION_LATEST;
88305 s.backlog_wait_time = audit_backlog_wait_time;
88306 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88307 index e420a0c..38137fa 100644
88308 --- a/kernel/auditsc.c
88309 +++ b/kernel/auditsc.c
88310 @@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88311 }
88312
88313 /* global counter which is incremented every time something logs in */
88314 -static atomic_t session_id = ATOMIC_INIT(0);
88315 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88316
88317 static int audit_set_loginuid_perm(kuid_t loginuid)
88318 {
88319 @@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88320
88321 /* are we setting or clearing? */
88322 if (uid_valid(loginuid))
88323 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88324 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88325
88326 task->sessionid = sessionid;
88327 task->loginuid = loginuid;
88328 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88329 index d6594e4..597264b 100644
88330 --- a/kernel/bpf/core.c
88331 +++ b/kernel/bpf/core.c
88332 @@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88333 * random section of illegal instructions.
88334 */
88335 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88336 - hdr = module_alloc(size);
88337 + hdr = module_alloc_exec(size);
88338 if (hdr == NULL)
88339 return NULL;
88340
88341 /* Fill space with illegal/arch-dep instructions. */
88342 bpf_fill_ill_insns(hdr, size);
88343
88344 + pax_open_kernel();
88345 hdr->pages = size / PAGE_SIZE;
88346 + pax_close_kernel();
88347 +
88348 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88349 PAGE_SIZE - sizeof(*hdr));
88350 start = (prandom_u32() % hole) & ~(alignment - 1);
88351 @@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88352
88353 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88354 {
88355 - module_free(NULL, hdr);
88356 + module_free_exec(NULL, hdr);
88357 }
88358 #endif /* CONFIG_BPF_JIT */
88359
88360 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88361 index ba61c8c..c60c486 100644
88362 --- a/kernel/bpf/syscall.c
88363 +++ b/kernel/bpf/syscall.c
88364 @@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88365 int err;
88366
88367 /* the syscall is limited to root temporarily. This restriction will be
88368 - * lifted when security audit is clean. Note that eBPF+tracing must have
88369 - * this restriction, since it may pass kernel data to user space
88370 + * lifted by upstream when a half-assed security audit is clean. Note
88371 + * that eBPF+tracing must have this restriction, since it may pass
88372 + * kernel data to user space
88373 */
88374 if (!capable(CAP_SYS_ADMIN))
88375 return -EPERM;
88376 +#ifdef CONFIG_GRKERNSEC
88377 + return -EPERM;
88378 +#endif
88379
88380 if (!access_ok(VERIFY_READ, uattr, 1))
88381 return -EFAULT;
88382 diff --git a/kernel/capability.c b/kernel/capability.c
88383 index 989f5bf..d317ca0 100644
88384 --- a/kernel/capability.c
88385 +++ b/kernel/capability.c
88386 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88387 * before modification is attempted and the application
88388 * fails.
88389 */
88390 + if (tocopy > ARRAY_SIZE(kdata))
88391 + return -EFAULT;
88392 +
88393 if (copy_to_user(dataptr, kdata, tocopy
88394 * sizeof(struct __user_cap_data_struct))) {
88395 return -EFAULT;
88396 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88397 int ret;
88398
88399 rcu_read_lock();
88400 - ret = security_capable(__task_cred(t), ns, cap);
88401 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88402 + gr_task_is_capable(t, __task_cred(t), cap);
88403 rcu_read_unlock();
88404
88405 - return (ret == 0);
88406 + return ret;
88407 }
88408
88409 /**
88410 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88411 int ret;
88412
88413 rcu_read_lock();
88414 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88415 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88416 rcu_read_unlock();
88417
88418 - return (ret == 0);
88419 + return ret;
88420 }
88421
88422 /**
88423 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88424 BUG();
88425 }
88426
88427 - if (security_capable(current_cred(), ns, cap) == 0) {
88428 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88429 current->flags |= PF_SUPERPRIV;
88430 return true;
88431 }
88432 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88433 }
88434 EXPORT_SYMBOL(ns_capable);
88435
88436 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88437 +{
88438 + if (unlikely(!cap_valid(cap))) {
88439 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88440 + BUG();
88441 + }
88442 +
88443 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88444 + current->flags |= PF_SUPERPRIV;
88445 + return true;
88446 + }
88447 + return false;
88448 +}
88449 +EXPORT_SYMBOL(ns_capable_nolog);
88450 +
88451 /**
88452 * file_ns_capable - Determine if the file's opener had a capability in effect
88453 * @file: The file we want to check
88454 @@ -427,6 +446,12 @@ bool capable(int cap)
88455 }
88456 EXPORT_SYMBOL(capable);
88457
88458 +bool capable_nolog(int cap)
88459 +{
88460 + return ns_capable_nolog(&init_user_ns, cap);
88461 +}
88462 +EXPORT_SYMBOL(capable_nolog);
88463 +
88464 /**
88465 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88466 * @inode: The inode in question
88467 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88468 kgid_has_mapping(ns, inode->i_gid);
88469 }
88470 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88471 +
88472 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88473 +{
88474 + struct user_namespace *ns = current_user_ns();
88475 +
88476 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88477 + kgid_has_mapping(ns, inode->i_gid);
88478 +}
88479 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88480 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88481 index 136ecea..45157a6 100644
88482 --- a/kernel/cgroup.c
88483 +++ b/kernel/cgroup.c
88484 @@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88485 if (!pathbuf || !agentbuf)
88486 goto out;
88487
88488 + if (agentbuf[0] == '\0')
88489 + goto out;
88490 +
88491 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88492 if (!path)
88493 goto out;
88494 @@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88495 struct task_struct *task;
88496 int count = 0;
88497
88498 - seq_printf(seq, "css_set %p\n", cset);
88499 + seq_printf(seq, "css_set %pK\n", cset);
88500
88501 list_for_each_entry(task, &cset->tasks, cg_list) {
88502 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88503 diff --git a/kernel/compat.c b/kernel/compat.c
88504 index ebb3c36..1df606e 100644
88505 --- a/kernel/compat.c
88506 +++ b/kernel/compat.c
88507 @@ -13,6 +13,7 @@
88508
88509 #include <linux/linkage.h>
88510 #include <linux/compat.h>
88511 +#include <linux/module.h>
88512 #include <linux/errno.h>
88513 #include <linux/time.h>
88514 #include <linux/signal.h>
88515 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88516 mm_segment_t oldfs;
88517 long ret;
88518
88519 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88520 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88521 oldfs = get_fs();
88522 set_fs(KERNEL_DS);
88523 ret = hrtimer_nanosleep_restart(restart);
88524 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88525 oldfs = get_fs();
88526 set_fs(KERNEL_DS);
88527 ret = hrtimer_nanosleep(&tu,
88528 - rmtp ? (struct timespec __user *)&rmt : NULL,
88529 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88530 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88531 set_fs(oldfs);
88532
88533 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88534 mm_segment_t old_fs = get_fs();
88535
88536 set_fs(KERNEL_DS);
88537 - ret = sys_sigpending((old_sigset_t __user *) &s);
88538 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88539 set_fs(old_fs);
88540 if (ret == 0)
88541 ret = put_user(s, set);
88542 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88543 mm_segment_t old_fs = get_fs();
88544
88545 set_fs(KERNEL_DS);
88546 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88547 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88548 set_fs(old_fs);
88549
88550 if (!ret) {
88551 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88552 set_fs (KERNEL_DS);
88553 ret = sys_wait4(pid,
88554 (stat_addr ?
88555 - (unsigned int __user *) &status : NULL),
88556 - options, (struct rusage __user *) &r);
88557 + (unsigned int __force_user *) &status : NULL),
88558 + options, (struct rusage __force_user *) &r);
88559 set_fs (old_fs);
88560
88561 if (ret > 0) {
88562 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88563 memset(&info, 0, sizeof(info));
88564
88565 set_fs(KERNEL_DS);
88566 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88567 - uru ? (struct rusage __user *)&ru : NULL);
88568 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88569 + uru ? (struct rusage __force_user *)&ru : NULL);
88570 set_fs(old_fs);
88571
88572 if ((ret < 0) || (info.si_signo == 0))
88573 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88574 oldfs = get_fs();
88575 set_fs(KERNEL_DS);
88576 err = sys_timer_settime(timer_id, flags,
88577 - (struct itimerspec __user *) &newts,
88578 - (struct itimerspec __user *) &oldts);
88579 + (struct itimerspec __force_user *) &newts,
88580 + (struct itimerspec __force_user *) &oldts);
88581 set_fs(oldfs);
88582 if (!err && old && put_compat_itimerspec(old, &oldts))
88583 return -EFAULT;
88584 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88585 oldfs = get_fs();
88586 set_fs(KERNEL_DS);
88587 err = sys_timer_gettime(timer_id,
88588 - (struct itimerspec __user *) &ts);
88589 + (struct itimerspec __force_user *) &ts);
88590 set_fs(oldfs);
88591 if (!err && put_compat_itimerspec(setting, &ts))
88592 return -EFAULT;
88593 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88594 oldfs = get_fs();
88595 set_fs(KERNEL_DS);
88596 err = sys_clock_settime(which_clock,
88597 - (struct timespec __user *) &ts);
88598 + (struct timespec __force_user *) &ts);
88599 set_fs(oldfs);
88600 return err;
88601 }
88602 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88603 oldfs = get_fs();
88604 set_fs(KERNEL_DS);
88605 err = sys_clock_gettime(which_clock,
88606 - (struct timespec __user *) &ts);
88607 + (struct timespec __force_user *) &ts);
88608 set_fs(oldfs);
88609 if (!err && compat_put_timespec(&ts, tp))
88610 return -EFAULT;
88611 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88612
88613 oldfs = get_fs();
88614 set_fs(KERNEL_DS);
88615 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88616 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88617 set_fs(oldfs);
88618
88619 err = compat_put_timex(utp, &txc);
88620 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88621 oldfs = get_fs();
88622 set_fs(KERNEL_DS);
88623 err = sys_clock_getres(which_clock,
88624 - (struct timespec __user *) &ts);
88625 + (struct timespec __force_user *) &ts);
88626 set_fs(oldfs);
88627 if (!err && tp && compat_put_timespec(&ts, tp))
88628 return -EFAULT;
88629 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88630 struct timespec tu;
88631 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88632
88633 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88634 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88635 oldfs = get_fs();
88636 set_fs(KERNEL_DS);
88637 err = clock_nanosleep_restart(restart);
88638 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88639 oldfs = get_fs();
88640 set_fs(KERNEL_DS);
88641 err = sys_clock_nanosleep(which_clock, flags,
88642 - (struct timespec __user *) &in,
88643 - (struct timespec __user *) &out);
88644 + (struct timespec __force_user *) &in,
88645 + (struct timespec __force_user *) &out);
88646 set_fs(oldfs);
88647
88648 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88649 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88650 mm_segment_t old_fs = get_fs();
88651
88652 set_fs(KERNEL_DS);
88653 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88654 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88655 set_fs(old_fs);
88656 if (compat_put_timespec(&t, interval))
88657 return -EFAULT;
88658 diff --git a/kernel/configs.c b/kernel/configs.c
88659 index c18b1f1..b9a0132 100644
88660 --- a/kernel/configs.c
88661 +++ b/kernel/configs.c
88662 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88663 struct proc_dir_entry *entry;
88664
88665 /* create the current config file */
88666 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88667 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88668 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88669 + &ikconfig_file_ops);
88670 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88671 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88672 + &ikconfig_file_ops);
88673 +#endif
88674 +#else
88675 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88676 &ikconfig_file_ops);
88677 +#endif
88678 +
88679 if (!entry)
88680 return -ENOMEM;
88681
88682 diff --git a/kernel/cred.c b/kernel/cred.c
88683 index e0573a4..26c0fd3 100644
88684 --- a/kernel/cred.c
88685 +++ b/kernel/cred.c
88686 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88687 validate_creds(cred);
88688 alter_cred_subscribers(cred, -1);
88689 put_cred(cred);
88690 +
88691 +#ifdef CONFIG_GRKERNSEC_SETXID
88692 + cred = (struct cred *) tsk->delayed_cred;
88693 + if (cred != NULL) {
88694 + tsk->delayed_cred = NULL;
88695 + validate_creds(cred);
88696 + alter_cred_subscribers(cred, -1);
88697 + put_cred(cred);
88698 + }
88699 +#endif
88700 }
88701
88702 /**
88703 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88704 * Always returns 0 thus allowing this function to be tail-called at the end
88705 * of, say, sys_setgid().
88706 */
88707 -int commit_creds(struct cred *new)
88708 +static int __commit_creds(struct cred *new)
88709 {
88710 struct task_struct *task = current;
88711 const struct cred *old = task->real_cred;
88712 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88713
88714 get_cred(new); /* we will require a ref for the subj creds too */
88715
88716 + gr_set_role_label(task, new->uid, new->gid);
88717 +
88718 /* dumpability changes */
88719 if (!uid_eq(old->euid, new->euid) ||
88720 !gid_eq(old->egid, new->egid) ||
88721 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88722 put_cred(old);
88723 return 0;
88724 }
88725 +#ifdef CONFIG_GRKERNSEC_SETXID
88726 +extern int set_user(struct cred *new);
88727 +
88728 +void gr_delayed_cred_worker(void)
88729 +{
88730 + const struct cred *new = current->delayed_cred;
88731 + struct cred *ncred;
88732 +
88733 + current->delayed_cred = NULL;
88734 +
88735 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88736 + // from doing get_cred on it when queueing this
88737 + put_cred(new);
88738 + return;
88739 + } else if (new == NULL)
88740 + return;
88741 +
88742 + ncred = prepare_creds();
88743 + if (!ncred)
88744 + goto die;
88745 + // uids
88746 + ncred->uid = new->uid;
88747 + ncred->euid = new->euid;
88748 + ncred->suid = new->suid;
88749 + ncred->fsuid = new->fsuid;
88750 + // gids
88751 + ncred->gid = new->gid;
88752 + ncred->egid = new->egid;
88753 + ncred->sgid = new->sgid;
88754 + ncred->fsgid = new->fsgid;
88755 + // groups
88756 + set_groups(ncred, new->group_info);
88757 + // caps
88758 + ncred->securebits = new->securebits;
88759 + ncred->cap_inheritable = new->cap_inheritable;
88760 + ncred->cap_permitted = new->cap_permitted;
88761 + ncred->cap_effective = new->cap_effective;
88762 + ncred->cap_bset = new->cap_bset;
88763 +
88764 + if (set_user(ncred)) {
88765 + abort_creds(ncred);
88766 + goto die;
88767 + }
88768 +
88769 + // from doing get_cred on it when queueing this
88770 + put_cred(new);
88771 +
88772 + __commit_creds(ncred);
88773 + return;
88774 +die:
88775 + // from doing get_cred on it when queueing this
88776 + put_cred(new);
88777 + do_group_exit(SIGKILL);
88778 +}
88779 +#endif
88780 +
88781 +int commit_creds(struct cred *new)
88782 +{
88783 +#ifdef CONFIG_GRKERNSEC_SETXID
88784 + int ret;
88785 + int schedule_it = 0;
88786 + struct task_struct *t;
88787 + unsigned oldsecurebits = current_cred()->securebits;
88788 +
88789 + /* we won't get called with tasklist_lock held for writing
88790 + and interrupts disabled as the cred struct in that case is
88791 + init_cred
88792 + */
88793 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88794 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88795 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88796 + schedule_it = 1;
88797 + }
88798 + ret = __commit_creds(new);
88799 + if (schedule_it) {
88800 + rcu_read_lock();
88801 + read_lock(&tasklist_lock);
88802 + for (t = next_thread(current); t != current;
88803 + t = next_thread(t)) {
88804 + /* we'll check if the thread has uid 0 in
88805 + * the delayed worker routine
88806 + */
88807 + if (task_securebits(t) == oldsecurebits &&
88808 + t->delayed_cred == NULL) {
88809 + t->delayed_cred = get_cred(new);
88810 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88811 + set_tsk_need_resched(t);
88812 + }
88813 + }
88814 + read_unlock(&tasklist_lock);
88815 + rcu_read_unlock();
88816 + }
88817 +
88818 + return ret;
88819 +#else
88820 + return __commit_creds(new);
88821 +#endif
88822 +}
88823 +
88824 EXPORT_SYMBOL(commit_creds);
88825
88826 /**
88827 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88828 index 1adf62b..7736e06 100644
88829 --- a/kernel/debug/debug_core.c
88830 +++ b/kernel/debug/debug_core.c
88831 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88832 */
88833 static atomic_t masters_in_kgdb;
88834 static atomic_t slaves_in_kgdb;
88835 -static atomic_t kgdb_break_tasklet_var;
88836 +static atomic_unchecked_t kgdb_break_tasklet_var;
88837 atomic_t kgdb_setting_breakpoint;
88838
88839 struct task_struct *kgdb_usethread;
88840 @@ -134,7 +134,7 @@ int kgdb_single_step;
88841 static pid_t kgdb_sstep_pid;
88842
88843 /* to keep track of the CPU which is doing the single stepping*/
88844 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88845 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88846
88847 /*
88848 * If you are debugging a problem where roundup (the collection of
88849 @@ -549,7 +549,7 @@ return_normal:
88850 * kernel will only try for the value of sstep_tries before
88851 * giving up and continuing on.
88852 */
88853 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88854 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88855 (kgdb_info[cpu].task &&
88856 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88857 atomic_set(&kgdb_active, -1);
88858 @@ -647,8 +647,8 @@ cpu_master_loop:
88859 }
88860
88861 kgdb_restore:
88862 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88863 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88864 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88865 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88866 if (kgdb_info[sstep_cpu].task)
88867 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88868 else
88869 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88870 static void kgdb_tasklet_bpt(unsigned long ing)
88871 {
88872 kgdb_breakpoint();
88873 - atomic_set(&kgdb_break_tasklet_var, 0);
88874 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88875 }
88876
88877 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88878
88879 void kgdb_schedule_breakpoint(void)
88880 {
88881 - if (atomic_read(&kgdb_break_tasklet_var) ||
88882 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88883 atomic_read(&kgdb_active) != -1 ||
88884 atomic_read(&kgdb_setting_breakpoint))
88885 return;
88886 - atomic_inc(&kgdb_break_tasklet_var);
88887 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88888 tasklet_schedule(&kgdb_tasklet_breakpoint);
88889 }
88890 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88891 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88892 index 379650b..30c5180 100644
88893 --- a/kernel/debug/kdb/kdb_main.c
88894 +++ b/kernel/debug/kdb/kdb_main.c
88895 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88896 continue;
88897
88898 kdb_printf("%-20s%8u 0x%p ", mod->name,
88899 - mod->core_size, (void *)mod);
88900 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88901 #ifdef CONFIG_MODULE_UNLOAD
88902 kdb_printf("%4ld ", module_refcount(mod));
88903 #endif
88904 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88905 kdb_printf(" (Loading)");
88906 else
88907 kdb_printf(" (Live)");
88908 - kdb_printf(" 0x%p", mod->module_core);
88909 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88910
88911 #ifdef CONFIG_MODULE_UNLOAD
88912 {
88913 diff --git a/kernel/events/core.c b/kernel/events/core.c
88914 index 2ab0238..bf89262f5 100644
88915 --- a/kernel/events/core.c
88916 +++ b/kernel/events/core.c
88917 @@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88918 * 0 - disallow raw tracepoint access for unpriv
88919 * 1 - disallow cpu events for unpriv
88920 * 2 - disallow kernel profiling for unpriv
88921 + * 3 - disallow all unpriv perf event use
88922 */
88923 -int sysctl_perf_event_paranoid __read_mostly = 1;
88924 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88925 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88926 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88927 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88928 +#else
88929 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88930 +#endif
88931
88932 /* Minimum for 512 kiB + 1 user control page */
88933 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88934 @@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88935
88936 tmp *= sysctl_perf_cpu_time_max_percent;
88937 do_div(tmp, 100);
88938 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88939 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88940 }
88941
88942 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88943 @@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88944 }
88945 }
88946
88947 -static atomic64_t perf_event_id;
88948 +static atomic64_unchecked_t perf_event_id;
88949
88950 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88951 enum event_type_t event_type);
88952 @@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88953
88954 static inline u64 perf_event_count(struct perf_event *event)
88955 {
88956 - return local64_read(&event->count) + atomic64_read(&event->child_count);
88957 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88958 }
88959
88960 static u64 perf_event_read(struct perf_event *event)
88961 @@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88962 mutex_lock(&event->child_mutex);
88963 total += perf_event_read(event);
88964 *enabled += event->total_time_enabled +
88965 - atomic64_read(&event->child_total_time_enabled);
88966 + atomic64_read_unchecked(&event->child_total_time_enabled);
88967 *running += event->total_time_running +
88968 - atomic64_read(&event->child_total_time_running);
88969 + atomic64_read_unchecked(&event->child_total_time_running);
88970
88971 list_for_each_entry(child, &event->child_list, child_list) {
88972 total += perf_event_read(child);
88973 @@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88974 userpg->offset -= local64_read(&event->hw.prev_count);
88975
88976 userpg->time_enabled = enabled +
88977 - atomic64_read(&event->child_total_time_enabled);
88978 + atomic64_read_unchecked(&event->child_total_time_enabled);
88979
88980 userpg->time_running = running +
88981 - atomic64_read(&event->child_total_time_running);
88982 + atomic64_read_unchecked(&event->child_total_time_running);
88983
88984 arch_perf_update_userpage(userpg, now);
88985
88986 @@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88987
88988 /* Data. */
88989 sp = perf_user_stack_pointer(regs);
88990 - rem = __output_copy_user(handle, (void *) sp, dump_size);
88991 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88992 dyn_size = dump_size - rem;
88993
88994 perf_output_skip(handle, rem);
88995 @@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88996 values[n++] = perf_event_count(event);
88997 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88998 values[n++] = enabled +
88999 - atomic64_read(&event->child_total_time_enabled);
89000 + atomic64_read_unchecked(&event->child_total_time_enabled);
89001 }
89002 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89003 values[n++] = running +
89004 - atomic64_read(&event->child_total_time_running);
89005 + atomic64_read_unchecked(&event->child_total_time_running);
89006 }
89007 if (read_format & PERF_FORMAT_ID)
89008 values[n++] = primary_event_id(event);
89009 @@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89010 event->parent = parent_event;
89011
89012 event->ns = get_pid_ns(task_active_pid_ns(current));
89013 - event->id = atomic64_inc_return(&perf_event_id);
89014 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89015
89016 event->state = PERF_EVENT_STATE_INACTIVE;
89017
89018 @@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
89019 if (flags & ~PERF_FLAG_ALL)
89020 return -EINVAL;
89021
89022 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89023 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89024 + return -EACCES;
89025 +#endif
89026 +
89027 err = perf_copy_attr(attr_uptr, &attr);
89028 if (err)
89029 return err;
89030 @@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
89031 /*
89032 * Add back the child's count to the parent's count:
89033 */
89034 - atomic64_add(child_val, &parent_event->child_count);
89035 - atomic64_add(child_event->total_time_enabled,
89036 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89037 + atomic64_add_unchecked(child_event->total_time_enabled,
89038 &parent_event->child_total_time_enabled);
89039 - atomic64_add(child_event->total_time_running,
89040 + atomic64_add_unchecked(child_event->total_time_running,
89041 &parent_event->child_total_time_running);
89042
89043 /*
89044 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89045 index 569b2187..19940d9 100644
89046 --- a/kernel/events/internal.h
89047 +++ b/kernel/events/internal.h
89048 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89049 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89050 }
89051
89052 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89053 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89054 static inline unsigned long \
89055 func_name(struct perf_output_handle *handle, \
89056 - const void *buf, unsigned long len) \
89057 + const void user *buf, unsigned long len) \
89058 { \
89059 unsigned long size, written; \
89060 \
89061 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89062 return 0;
89063 }
89064
89065 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89066 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89067
89068 static inline unsigned long
89069 memcpy_skip(void *dst, const void *src, unsigned long n)
89070 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89071 return 0;
89072 }
89073
89074 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89075 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89076
89077 #ifndef arch_perf_out_copy_user
89078 #define arch_perf_out_copy_user arch_perf_out_copy_user
89079 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89080 }
89081 #endif
89082
89083 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89084 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89085
89086 /* Callchain handling */
89087 extern struct perf_callchain_entry *
89088 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89089 index ed8f2cd..fe8030c 100644
89090 --- a/kernel/events/uprobes.c
89091 +++ b/kernel/events/uprobes.c
89092 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89093 {
89094 struct page *page;
89095 uprobe_opcode_t opcode;
89096 - int result;
89097 + long result;
89098
89099 pagefault_disable();
89100 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89101 diff --git a/kernel/exit.c b/kernel/exit.c
89102 index 2116aac..d95df2a 100644
89103 --- a/kernel/exit.c
89104 +++ b/kernel/exit.c
89105 @@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
89106 struct task_struct *leader;
89107 int zap_leader;
89108 repeat:
89109 +#ifdef CONFIG_NET
89110 + gr_del_task_from_ip_table(p);
89111 +#endif
89112 +
89113 /* don't need to get the RCU readlock here - the process is dead and
89114 * can't be modifying its own credentials. But shut RCU-lockdep up */
89115 rcu_read_lock();
89116 @@ -670,6 +674,8 @@ void do_exit(long code)
89117 int group_dead;
89118 TASKS_RCU(int tasks_rcu_i);
89119
89120 + set_fs(USER_DS);
89121 +
89122 profile_task_exit(tsk);
89123
89124 WARN_ON(blk_needs_flush_plug(tsk));
89125 @@ -686,7 +692,6 @@ void do_exit(long code)
89126 * mm_release()->clear_child_tid() from writing to a user-controlled
89127 * kernel address.
89128 */
89129 - set_fs(USER_DS);
89130
89131 ptrace_event(PTRACE_EVENT_EXIT, code);
89132
89133 @@ -744,6 +749,9 @@ void do_exit(long code)
89134 tsk->exit_code = code;
89135 taskstats_exit(tsk, group_dead);
89136
89137 + gr_acl_handle_psacct(tsk, code);
89138 + gr_acl_handle_exit();
89139 +
89140 exit_mm(tsk);
89141
89142 if (group_dead)
89143 @@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89144 * Take down every thread in the group. This is called by fatal signals
89145 * as well as by sys_exit_group (below).
89146 */
89147 -void
89148 +__noreturn void
89149 do_group_exit(int exit_code)
89150 {
89151 struct signal_struct *sig = current->signal;
89152 diff --git a/kernel/fork.c b/kernel/fork.c
89153 index 9b7d746..5b898ab 100644
89154 --- a/kernel/fork.c
89155 +++ b/kernel/fork.c
89156 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89157 # endif
89158 #endif
89159
89160 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89161 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89162 + int node, void **lowmem_stack)
89163 +{
89164 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89165 + void *ret = NULL;
89166 + unsigned int i;
89167 +
89168 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89169 + if (*lowmem_stack == NULL)
89170 + goto out;
89171 +
89172 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89173 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89174 +
89175 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89176 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89177 + if (ret == NULL) {
89178 + free_thread_info(*lowmem_stack);
89179 + *lowmem_stack = NULL;
89180 + }
89181 +
89182 +out:
89183 + return ret;
89184 +}
89185 +
89186 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89187 +{
89188 + unmap_process_stacks(tsk);
89189 +}
89190 +#else
89191 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89192 + int node, void **lowmem_stack)
89193 +{
89194 + return alloc_thread_info_node(tsk, node);
89195 +}
89196 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89197 +{
89198 + free_thread_info(ti);
89199 +}
89200 +#endif
89201 +
89202 /* SLAB cache for signal_struct structures (tsk->signal) */
89203 static struct kmem_cache *signal_cachep;
89204
89205 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89206 /* SLAB cache for mm_struct structures (tsk->mm) */
89207 static struct kmem_cache *mm_cachep;
89208
89209 -static void account_kernel_stack(struct thread_info *ti, int account)
89210 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89211 {
89212 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89213 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89214 +#else
89215 struct zone *zone = page_zone(virt_to_page(ti));
89216 +#endif
89217
89218 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89219 }
89220
89221 void free_task(struct task_struct *tsk)
89222 {
89223 - account_kernel_stack(tsk->stack, -1);
89224 + account_kernel_stack(tsk, tsk->stack, -1);
89225 arch_release_thread_info(tsk->stack);
89226 - free_thread_info(tsk->stack);
89227 + gr_free_thread_info(tsk, tsk->stack);
89228 rt_mutex_debug_task_free(tsk);
89229 ftrace_graph_exit_task(tsk);
89230 put_seccomp_filter(tsk);
89231 @@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89232 {
89233 struct task_struct *tsk;
89234 struct thread_info *ti;
89235 + void *lowmem_stack;
89236 int node = tsk_fork_get_node(orig);
89237 int err;
89238
89239 @@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89240 if (!tsk)
89241 return NULL;
89242
89243 - ti = alloc_thread_info_node(tsk, node);
89244 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89245 if (!ti)
89246 goto free_tsk;
89247
89248 @@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89249 goto free_ti;
89250
89251 tsk->stack = ti;
89252 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89253 + tsk->lowmem_stack = lowmem_stack;
89254 +#endif
89255 #ifdef CONFIG_SECCOMP
89256 /*
89257 * We must handle setting up seccomp filters once we're under
89258 @@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89259 set_task_stack_end_magic(tsk);
89260
89261 #ifdef CONFIG_CC_STACKPROTECTOR
89262 - tsk->stack_canary = get_random_int();
89263 + tsk->stack_canary = pax_get_random_long();
89264 #endif
89265
89266 /*
89267 @@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89268 tsk->splice_pipe = NULL;
89269 tsk->task_frag.page = NULL;
89270
89271 - account_kernel_stack(ti, 1);
89272 + account_kernel_stack(tsk, ti, 1);
89273
89274 return tsk;
89275
89276 free_ti:
89277 - free_thread_info(ti);
89278 + gr_free_thread_info(tsk, ti);
89279 free_tsk:
89280 free_task_struct(tsk);
89281 return NULL;
89282 }
89283
89284 #ifdef CONFIG_MMU
89285 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89286 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89287 +{
89288 + struct vm_area_struct *tmp;
89289 + unsigned long charge;
89290 + struct file *file;
89291 + int retval;
89292 +
89293 + charge = 0;
89294 + if (mpnt->vm_flags & VM_ACCOUNT) {
89295 + unsigned long len = vma_pages(mpnt);
89296 +
89297 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89298 + goto fail_nomem;
89299 + charge = len;
89300 + }
89301 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89302 + if (!tmp)
89303 + goto fail_nomem;
89304 + *tmp = *mpnt;
89305 + tmp->vm_mm = mm;
89306 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89307 + retval = vma_dup_policy(mpnt, tmp);
89308 + if (retval)
89309 + goto fail_nomem_policy;
89310 + if (anon_vma_fork(tmp, mpnt))
89311 + goto fail_nomem_anon_vma_fork;
89312 + tmp->vm_flags &= ~VM_LOCKED;
89313 + tmp->vm_next = tmp->vm_prev = NULL;
89314 + tmp->vm_mirror = NULL;
89315 + file = tmp->vm_file;
89316 + if (file) {
89317 + struct inode *inode = file_inode(file);
89318 + struct address_space *mapping = file->f_mapping;
89319 +
89320 + get_file(file);
89321 + if (tmp->vm_flags & VM_DENYWRITE)
89322 + atomic_dec(&inode->i_writecount);
89323 + mutex_lock(&mapping->i_mmap_mutex);
89324 + if (tmp->vm_flags & VM_SHARED)
89325 + atomic_inc(&mapping->i_mmap_writable);
89326 + flush_dcache_mmap_lock(mapping);
89327 + /* insert tmp into the share list, just after mpnt */
89328 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89329 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89330 + else
89331 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89332 + flush_dcache_mmap_unlock(mapping);
89333 + mutex_unlock(&mapping->i_mmap_mutex);
89334 + }
89335 +
89336 + /*
89337 + * Clear hugetlb-related page reserves for children. This only
89338 + * affects MAP_PRIVATE mappings. Faults generated by the child
89339 + * are not guaranteed to succeed, even if read-only
89340 + */
89341 + if (is_vm_hugetlb_page(tmp))
89342 + reset_vma_resv_huge_pages(tmp);
89343 +
89344 + return tmp;
89345 +
89346 +fail_nomem_anon_vma_fork:
89347 + mpol_put(vma_policy(tmp));
89348 +fail_nomem_policy:
89349 + kmem_cache_free(vm_area_cachep, tmp);
89350 +fail_nomem:
89351 + vm_unacct_memory(charge);
89352 + return NULL;
89353 +}
89354 +
89355 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89356 {
89357 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89358 struct rb_node **rb_link, *rb_parent;
89359 int retval;
89360 - unsigned long charge;
89361
89362 uprobe_start_dup_mmap();
89363 down_write(&oldmm->mmap_sem);
89364 @@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89365
89366 prev = NULL;
89367 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89368 - struct file *file;
89369 -
89370 if (mpnt->vm_flags & VM_DONTCOPY) {
89371 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89372 -vma_pages(mpnt));
89373 continue;
89374 }
89375 - charge = 0;
89376 - if (mpnt->vm_flags & VM_ACCOUNT) {
89377 - unsigned long len = vma_pages(mpnt);
89378 -
89379 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89380 - goto fail_nomem;
89381 - charge = len;
89382 - }
89383 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89384 - if (!tmp)
89385 - goto fail_nomem;
89386 - *tmp = *mpnt;
89387 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89388 - retval = vma_dup_policy(mpnt, tmp);
89389 - if (retval)
89390 - goto fail_nomem_policy;
89391 - tmp->vm_mm = mm;
89392 - if (anon_vma_fork(tmp, mpnt))
89393 - goto fail_nomem_anon_vma_fork;
89394 - tmp->vm_flags &= ~VM_LOCKED;
89395 - tmp->vm_next = tmp->vm_prev = NULL;
89396 - file = tmp->vm_file;
89397 - if (file) {
89398 - struct inode *inode = file_inode(file);
89399 - struct address_space *mapping = file->f_mapping;
89400 -
89401 - get_file(file);
89402 - if (tmp->vm_flags & VM_DENYWRITE)
89403 - atomic_dec(&inode->i_writecount);
89404 - mutex_lock(&mapping->i_mmap_mutex);
89405 - if (tmp->vm_flags & VM_SHARED)
89406 - atomic_inc(&mapping->i_mmap_writable);
89407 - flush_dcache_mmap_lock(mapping);
89408 - /* insert tmp into the share list, just after mpnt */
89409 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89410 - vma_nonlinear_insert(tmp,
89411 - &mapping->i_mmap_nonlinear);
89412 - else
89413 - vma_interval_tree_insert_after(tmp, mpnt,
89414 - &mapping->i_mmap);
89415 - flush_dcache_mmap_unlock(mapping);
89416 - mutex_unlock(&mapping->i_mmap_mutex);
89417 + tmp = dup_vma(mm, oldmm, mpnt);
89418 + if (!tmp) {
89419 + retval = -ENOMEM;
89420 + goto out;
89421 }
89422
89423 /*
89424 @@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89425 if (retval)
89426 goto out;
89427 }
89428 +
89429 +#ifdef CONFIG_PAX_SEGMEXEC
89430 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89431 + struct vm_area_struct *mpnt_m;
89432 +
89433 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89434 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89435 +
89436 + if (!mpnt->vm_mirror)
89437 + continue;
89438 +
89439 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89440 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89441 + mpnt->vm_mirror = mpnt_m;
89442 + } else {
89443 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89444 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89445 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89446 + mpnt->vm_mirror->vm_mirror = mpnt;
89447 + }
89448 + }
89449 + BUG_ON(mpnt_m);
89450 + }
89451 +#endif
89452 +
89453 /* a new mm has just been created */
89454 arch_dup_mmap(oldmm, mm);
89455 retval = 0;
89456 @@ -486,14 +589,6 @@ out:
89457 up_write(&oldmm->mmap_sem);
89458 uprobe_end_dup_mmap();
89459 return retval;
89460 -fail_nomem_anon_vma_fork:
89461 - mpol_put(vma_policy(tmp));
89462 -fail_nomem_policy:
89463 - kmem_cache_free(vm_area_cachep, tmp);
89464 -fail_nomem:
89465 - retval = -ENOMEM;
89466 - vm_unacct_memory(charge);
89467 - goto out;
89468 }
89469
89470 static inline int mm_alloc_pgd(struct mm_struct *mm)
89471 @@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89472 return ERR_PTR(err);
89473
89474 mm = get_task_mm(task);
89475 - if (mm && mm != current->mm &&
89476 - !ptrace_may_access(task, mode)) {
89477 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89478 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89479 mmput(mm);
89480 mm = ERR_PTR(-EACCES);
89481 }
89482 @@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89483 spin_unlock(&fs->lock);
89484 return -EAGAIN;
89485 }
89486 - fs->users++;
89487 + atomic_inc(&fs->users);
89488 spin_unlock(&fs->lock);
89489 return 0;
89490 }
89491 tsk->fs = copy_fs_struct(fs);
89492 if (!tsk->fs)
89493 return -ENOMEM;
89494 + /* Carry through gr_chroot_dentry and is_chrooted instead
89495 + of recomputing it here. Already copied when the task struct
89496 + is duplicated. This allows pivot_root to not be treated as
89497 + a chroot
89498 + */
89499 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89500 +
89501 return 0;
89502 }
89503
89504 @@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89505 * parts of the process environment (as per the clone
89506 * flags). The actual kick-off is left to the caller.
89507 */
89508 -static struct task_struct *copy_process(unsigned long clone_flags,
89509 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89510 unsigned long stack_start,
89511 unsigned long stack_size,
89512 int __user *child_tidptr,
89513 @@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89514 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89515 #endif
89516 retval = -EAGAIN;
89517 +
89518 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89519 +
89520 if (atomic_read(&p->real_cred->user->processes) >=
89521 task_rlimit(p, RLIMIT_NPROC)) {
89522 if (p->real_cred->user != INIT_USER &&
89523 @@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89524 goto bad_fork_free_pid;
89525 }
89526
89527 + /* synchronizes with gr_set_acls()
89528 + we need to call this past the point of no return for fork()
89529 + */
89530 + gr_copy_label(p);
89531 +
89532 if (likely(p->pid)) {
89533 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89534
89535 @@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89536 bad_fork_free:
89537 free_task(p);
89538 fork_out:
89539 + gr_log_forkfail(retval);
89540 +
89541 return ERR_PTR(retval);
89542 }
89543
89544 @@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89545
89546 p = copy_process(clone_flags, stack_start, stack_size,
89547 child_tidptr, NULL, trace);
89548 + add_latent_entropy();
89549 /*
89550 * Do this prior waking up the new thread - the thread pointer
89551 * might get invalid after that point, if the thread exits quickly.
89552 @@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89553 if (clone_flags & CLONE_PARENT_SETTID)
89554 put_user(nr, parent_tidptr);
89555
89556 + gr_handle_brute_check();
89557 +
89558 if (clone_flags & CLONE_VFORK) {
89559 p->vfork_done = &vfork;
89560 init_completion(&vfork);
89561 @@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89562 mm_cachep = kmem_cache_create("mm_struct",
89563 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89564 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89565 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89566 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89567 mmap_init();
89568 nsproxy_cache_init();
89569 }
89570 @@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89571 return 0;
89572
89573 /* don't need lock here; in the worst case we'll do useless copy */
89574 - if (fs->users == 1)
89575 + if (atomic_read(&fs->users) == 1)
89576 return 0;
89577
89578 *new_fsp = copy_fs_struct(fs);
89579 @@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89580 fs = current->fs;
89581 spin_lock(&fs->lock);
89582 current->fs = new_fs;
89583 - if (--fs->users)
89584 + gr_set_chroot_entries(current, &current->fs->root);
89585 + if (atomic_dec_return(&fs->users))
89586 new_fs = NULL;
89587 else
89588 new_fs = fs;
89589 diff --git a/kernel/futex.c b/kernel/futex.c
89590 index 63678b5..512f9af 100644
89591 --- a/kernel/futex.c
89592 +++ b/kernel/futex.c
89593 @@ -201,7 +201,7 @@ struct futex_pi_state {
89594 atomic_t refcount;
89595
89596 union futex_key key;
89597 -};
89598 +} __randomize_layout;
89599
89600 /**
89601 * struct futex_q - The hashed futex queue entry, one per waiting task
89602 @@ -235,7 +235,7 @@ struct futex_q {
89603 struct rt_mutex_waiter *rt_waiter;
89604 union futex_key *requeue_pi_key;
89605 u32 bitset;
89606 -};
89607 +} __randomize_layout;
89608
89609 static const struct futex_q futex_q_init = {
89610 /* list gets initialized in queue_me()*/
89611 @@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89612 struct page *page, *page_head;
89613 int err, ro = 0;
89614
89615 +#ifdef CONFIG_PAX_SEGMEXEC
89616 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89617 + return -EFAULT;
89618 +#endif
89619 +
89620 /*
89621 * The futex address must be "naturally" aligned.
89622 */
89623 @@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89624
89625 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89626 {
89627 - int ret;
89628 + unsigned long ret;
89629
89630 pagefault_disable();
89631 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89632 @@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89633 {
89634 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89635 u32 curval;
89636 + mm_segment_t oldfs;
89637
89638 /*
89639 * This will fail and we want it. Some arch implementations do
89640 @@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89641 * implementation, the non-functional ones will return
89642 * -ENOSYS.
89643 */
89644 + oldfs = get_fs();
89645 + set_fs(USER_DS);
89646 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89647 futex_cmpxchg_enabled = 1;
89648 + set_fs(oldfs);
89649 #endif
89650 }
89651
89652 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89653 index 55c8c93..9ba7ad6 100644
89654 --- a/kernel/futex_compat.c
89655 +++ b/kernel/futex_compat.c
89656 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89657 return 0;
89658 }
89659
89660 -static void __user *futex_uaddr(struct robust_list __user *entry,
89661 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89662 compat_long_t futex_offset)
89663 {
89664 compat_uptr_t base = ptr_to_compat(entry);
89665 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89666 index b358a80..fc25240 100644
89667 --- a/kernel/gcov/base.c
89668 +++ b/kernel/gcov/base.c
89669 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89670 }
89671
89672 #ifdef CONFIG_MODULES
89673 -static inline int within(void *addr, void *start, unsigned long size)
89674 -{
89675 - return ((addr >= start) && (addr < start + size));
89676 -}
89677 -
89678 /* Update list and generate events when modules are unloaded. */
89679 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89680 void *data)
89681 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89682
89683 /* Remove entries located in module from linked list. */
89684 while ((info = gcov_info_next(info))) {
89685 - if (within(info, mod->module_core, mod->core_size)) {
89686 + if (within_module_core_rw((unsigned long)info, mod)) {
89687 gcov_info_unlink(prev, info);
89688 if (gcov_events_enabled)
89689 gcov_event(GCOV_REMOVE, info);
89690 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89691 index 9019f15..9a3c42e 100644
89692 --- a/kernel/jump_label.c
89693 +++ b/kernel/jump_label.c
89694 @@ -14,6 +14,7 @@
89695 #include <linux/err.h>
89696 #include <linux/static_key.h>
89697 #include <linux/jump_label_ratelimit.h>
89698 +#include <linux/mm.h>
89699
89700 #ifdef HAVE_JUMP_LABEL
89701
89702 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89703
89704 size = (((unsigned long)stop - (unsigned long)start)
89705 / sizeof(struct jump_entry));
89706 + pax_open_kernel();
89707 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89708 + pax_close_kernel();
89709 }
89710
89711 static void jump_label_update(struct static_key *key, int enable);
89712 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89713 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89714 struct jump_entry *iter;
89715
89716 + pax_open_kernel();
89717 for (iter = iter_start; iter < iter_stop; iter++) {
89718 if (within_module_init(iter->code, mod))
89719 iter->code = 0;
89720 }
89721 + pax_close_kernel();
89722 }
89723
89724 static int
89725 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89726 index 5c5987f..bc502b0 100644
89727 --- a/kernel/kallsyms.c
89728 +++ b/kernel/kallsyms.c
89729 @@ -11,6 +11,9 @@
89730 * Changed the compression method from stem compression to "table lookup"
89731 * compression (see scripts/kallsyms.c for a more complete description)
89732 */
89733 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89734 +#define __INCLUDED_BY_HIDESYM 1
89735 +#endif
89736 #include <linux/kallsyms.h>
89737 #include <linux/module.h>
89738 #include <linux/init.h>
89739 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89740
89741 static inline int is_kernel_inittext(unsigned long addr)
89742 {
89743 + if (system_state != SYSTEM_BOOTING)
89744 + return 0;
89745 +
89746 if (addr >= (unsigned long)_sinittext
89747 && addr <= (unsigned long)_einittext)
89748 return 1;
89749 return 0;
89750 }
89751
89752 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89753 +#ifdef CONFIG_MODULES
89754 +static inline int is_module_text(unsigned long addr)
89755 +{
89756 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89757 + return 1;
89758 +
89759 + addr = ktla_ktva(addr);
89760 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89761 +}
89762 +#else
89763 +static inline int is_module_text(unsigned long addr)
89764 +{
89765 + return 0;
89766 +}
89767 +#endif
89768 +#endif
89769 +
89770 static inline int is_kernel_text(unsigned long addr)
89771 {
89772 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89773 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89774
89775 static inline int is_kernel(unsigned long addr)
89776 {
89777 +
89778 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89779 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89780 + return 1;
89781 +
89782 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89783 +#else
89784 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89785 +#endif
89786 +
89787 return 1;
89788 return in_gate_area_no_mm(addr);
89789 }
89790
89791 static int is_ksym_addr(unsigned long addr)
89792 {
89793 +
89794 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89795 + if (is_module_text(addr))
89796 + return 0;
89797 +#endif
89798 +
89799 if (all_var)
89800 return is_kernel(addr);
89801
89802 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89803
89804 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89805 {
89806 - iter->name[0] = '\0';
89807 iter->nameoff = get_symbol_offset(new_pos);
89808 iter->pos = new_pos;
89809 }
89810 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89811 {
89812 struct kallsym_iter *iter = m->private;
89813
89814 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89815 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89816 + return 0;
89817 +#endif
89818 +
89819 /* Some debugging symbols have no name. Ignore them. */
89820 if (!iter->name[0])
89821 return 0;
89822 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89823 */
89824 type = iter->exported ? toupper(iter->type) :
89825 tolower(iter->type);
89826 +
89827 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89828 type, iter->name, iter->module_name);
89829 } else
89830 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89831 index 0aa69ea..a7fcafb 100644
89832 --- a/kernel/kcmp.c
89833 +++ b/kernel/kcmp.c
89834 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89835 struct task_struct *task1, *task2;
89836 int ret;
89837
89838 +#ifdef CONFIG_GRKERNSEC
89839 + return -ENOSYS;
89840 +#endif
89841 +
89842 rcu_read_lock();
89843
89844 /*
89845 diff --git a/kernel/kexec.c b/kernel/kexec.c
89846 index 2abf9f6..c40cf85 100644
89847 --- a/kernel/kexec.c
89848 +++ b/kernel/kexec.c
89849 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89850 compat_ulong_t, flags)
89851 {
89852 struct compat_kexec_segment in;
89853 - struct kexec_segment out, __user *ksegments;
89854 + struct kexec_segment out;
89855 + struct kexec_segment __user *ksegments;
89856 unsigned long i, result;
89857
89858 /* Don't allow clients that don't understand the native
89859 diff --git a/kernel/kmod.c b/kernel/kmod.c
89860 index 80f7a6d..3c476d3 100644
89861 --- a/kernel/kmod.c
89862 +++ b/kernel/kmod.c
89863 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89864 kfree(info->argv);
89865 }
89866
89867 -static int call_modprobe(char *module_name, int wait)
89868 +static int call_modprobe(char *module_name, char *module_param, int wait)
89869 {
89870 struct subprocess_info *info;
89871 static char *envp[] = {
89872 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89873 NULL
89874 };
89875
89876 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89877 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89878 if (!argv)
89879 goto out;
89880
89881 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89882 argv[1] = "-q";
89883 argv[2] = "--";
89884 argv[3] = module_name; /* check free_modprobe_argv() */
89885 - argv[4] = NULL;
89886 + argv[4] = module_param;
89887 + argv[5] = NULL;
89888
89889 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89890 NULL, free_modprobe_argv, NULL);
89891 @@ -129,9 +130,8 @@ out:
89892 * If module auto-loading support is disabled then this function
89893 * becomes a no-operation.
89894 */
89895 -int __request_module(bool wait, const char *fmt, ...)
89896 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89897 {
89898 - va_list args;
89899 char module_name[MODULE_NAME_LEN];
89900 unsigned int max_modprobes;
89901 int ret;
89902 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89903 if (!modprobe_path[0])
89904 return 0;
89905
89906 - va_start(args, fmt);
89907 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89908 - va_end(args);
89909 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89910 if (ret >= MODULE_NAME_LEN)
89911 return -ENAMETOOLONG;
89912
89913 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89914 if (ret)
89915 return ret;
89916
89917 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89918 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89919 + /* hack to workaround consolekit/udisks stupidity */
89920 + read_lock(&tasklist_lock);
89921 + if (!strcmp(current->comm, "mount") &&
89922 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89923 + read_unlock(&tasklist_lock);
89924 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89925 + return -EPERM;
89926 + }
89927 + read_unlock(&tasklist_lock);
89928 + }
89929 +#endif
89930 +
89931 /* If modprobe needs a service that is in a module, we get a recursive
89932 * loop. Limit the number of running kmod threads to max_threads/2 or
89933 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89934 @@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89935
89936 trace_module_request(module_name, wait, _RET_IP_);
89937
89938 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89939 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89940
89941 atomic_dec(&kmod_concurrent);
89942 return ret;
89943 }
89944 +
89945 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89946 +{
89947 + va_list args;
89948 + int ret;
89949 +
89950 + va_start(args, fmt);
89951 + ret = ____request_module(wait, module_param, fmt, args);
89952 + va_end(args);
89953 +
89954 + return ret;
89955 +}
89956 +
89957 +int __request_module(bool wait, const char *fmt, ...)
89958 +{
89959 + va_list args;
89960 + int ret;
89961 +
89962 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89963 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89964 + char module_param[MODULE_NAME_LEN];
89965 +
89966 + memset(module_param, 0, sizeof(module_param));
89967 +
89968 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89969 +
89970 + va_start(args, fmt);
89971 + ret = ____request_module(wait, module_param, fmt, args);
89972 + va_end(args);
89973 +
89974 + return ret;
89975 + }
89976 +#endif
89977 +
89978 + va_start(args, fmt);
89979 + ret = ____request_module(wait, NULL, fmt, args);
89980 + va_end(args);
89981 +
89982 + return ret;
89983 +}
89984 +
89985 EXPORT_SYMBOL(__request_module);
89986 #endif /* CONFIG_MODULES */
89987
89988 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89989 {
89990 +#ifdef CONFIG_GRKERNSEC
89991 + kfree(info->path);
89992 + info->path = info->origpath;
89993 +#endif
89994 if (info->cleanup)
89995 (*info->cleanup)(info);
89996 kfree(info);
89997 @@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89998 */
89999 set_user_nice(current, 0);
90000
90001 +#ifdef CONFIG_GRKERNSEC
90002 + /* this is race-free as far as userland is concerned as we copied
90003 + out the path to be used prior to this point and are now operating
90004 + on that copy
90005 + */
90006 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90007 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90008 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90009 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90010 + retval = -EPERM;
90011 + goto out;
90012 + }
90013 +#endif
90014 +
90015 retval = -ENOMEM;
90016 new = prepare_kernel_cred(current);
90017 if (!new)
90018 @@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
90019 commit_creds(new);
90020
90021 retval = do_execve(getname_kernel(sub_info->path),
90022 - (const char __user *const __user *)sub_info->argv,
90023 - (const char __user *const __user *)sub_info->envp);
90024 + (const char __user *const __force_user *)sub_info->argv,
90025 + (const char __user *const __force_user *)sub_info->envp);
90026 out:
90027 sub_info->retval = retval;
90028 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
90029 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
90030 *
90031 * Thus the __user pointer cast is valid here.
90032 */
90033 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90034 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90035
90036 /*
90037 * If ret is 0, either ____call_usermodehelper failed and the
90038 @@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90039 goto out;
90040
90041 INIT_WORK(&sub_info->work, __call_usermodehelper);
90042 +#ifdef CONFIG_GRKERNSEC
90043 + sub_info->origpath = path;
90044 + sub_info->path = kstrdup(path, gfp_mask);
90045 +#else
90046 sub_info->path = path;
90047 +#endif
90048 sub_info->argv = argv;
90049 sub_info->envp = envp;
90050
90051 @@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90052 static int proc_cap_handler(struct ctl_table *table, int write,
90053 void __user *buffer, size_t *lenp, loff_t *ppos)
90054 {
90055 - struct ctl_table t;
90056 + ctl_table_no_const t;
90057 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90058 kernel_cap_t new_cap;
90059 int err, i;
90060 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90061 index 3995f54..e247879 100644
90062 --- a/kernel/kprobes.c
90063 +++ b/kernel/kprobes.c
90064 @@ -31,6 +31,9 @@
90065 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90066 * <prasanna@in.ibm.com> added function-return probes.
90067 */
90068 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90069 +#define __INCLUDED_BY_HIDESYM 1
90070 +#endif
90071 #include <linux/kprobes.h>
90072 #include <linux/hash.h>
90073 #include <linux/init.h>
90074 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90075
90076 static void *alloc_insn_page(void)
90077 {
90078 - return module_alloc(PAGE_SIZE);
90079 + return module_alloc_exec(PAGE_SIZE);
90080 }
90081
90082 static void free_insn_page(void *page)
90083 {
90084 - module_free(NULL, page);
90085 + module_free_exec(NULL, page);
90086 }
90087
90088 struct kprobe_insn_cache kprobe_insn_slots = {
90089 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90090 kprobe_type = "k";
90091
90092 if (sym)
90093 - seq_printf(pi, "%p %s %s+0x%x %s ",
90094 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90095 p->addr, kprobe_type, sym, offset,
90096 (modname ? modname : " "));
90097 else
90098 - seq_printf(pi, "%p %s %p ",
90099 + seq_printf(pi, "%pK %s %pK ",
90100 p->addr, kprobe_type, p->addr);
90101
90102 if (!pp)
90103 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90104 index 6683cce..daf8999 100644
90105 --- a/kernel/ksysfs.c
90106 +++ b/kernel/ksysfs.c
90107 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90108 {
90109 if (count+1 > UEVENT_HELPER_PATH_LEN)
90110 return -ENOENT;
90111 + if (!capable(CAP_SYS_ADMIN))
90112 + return -EPERM;
90113 memcpy(uevent_helper, buf, count);
90114 uevent_helper[count] = '\0';
90115 if (count && uevent_helper[count-1] == '\n')
90116 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90117 return count;
90118 }
90119
90120 -static struct bin_attribute notes_attr = {
90121 +static bin_attribute_no_const notes_attr __read_only = {
90122 .attr = {
90123 .name = "notes",
90124 .mode = S_IRUGO,
90125 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90126 index 88d0d44..e9ce0ee 100644
90127 --- a/kernel/locking/lockdep.c
90128 +++ b/kernel/locking/lockdep.c
90129 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90130 end = (unsigned long) &_end,
90131 addr = (unsigned long) obj;
90132
90133 +#ifdef CONFIG_PAX_KERNEXEC
90134 + start = ktla_ktva(start);
90135 +#endif
90136 +
90137 /*
90138 * static variable?
90139 */
90140 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90141 if (!static_obj(lock->key)) {
90142 debug_locks_off();
90143 printk("INFO: trying to register non-static key.\n");
90144 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90145 printk("the code is fine but needs lockdep annotation.\n");
90146 printk("turning off the locking correctness validator.\n");
90147 dump_stack();
90148 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90149 if (!class)
90150 return 0;
90151 }
90152 - atomic_inc((atomic_t *)&class->ops);
90153 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90154 if (very_verbose(class)) {
90155 printk("\nacquire class [%p] %s", class->key, class->name);
90156 if (class->name_version > 1)
90157 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90158 index ef43ac4..2720dfa 100644
90159 --- a/kernel/locking/lockdep_proc.c
90160 +++ b/kernel/locking/lockdep_proc.c
90161 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90162 return 0;
90163 }
90164
90165 - seq_printf(m, "%p", class->key);
90166 + seq_printf(m, "%pK", class->key);
90167 #ifdef CONFIG_DEBUG_LOCKDEP
90168 seq_printf(m, " OPS:%8ld", class->ops);
90169 #endif
90170 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90171
90172 list_for_each_entry(entry, &class->locks_after, entry) {
90173 if (entry->distance == 1) {
90174 - seq_printf(m, " -> [%p] ", entry->class->key);
90175 + seq_printf(m, " -> [%pK] ", entry->class->key);
90176 print_name(m, entry->class);
90177 seq_puts(m, "\n");
90178 }
90179 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90180 if (!class->key)
90181 continue;
90182
90183 - seq_printf(m, "[%p] ", class->key);
90184 + seq_printf(m, "[%pK] ", class->key);
90185 print_name(m, class);
90186 seq_puts(m, "\n");
90187 }
90188 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90189 if (!i)
90190 seq_line(m, '-', 40-namelen, namelen);
90191
90192 - snprintf(ip, sizeof(ip), "[<%p>]",
90193 + snprintf(ip, sizeof(ip), "[<%pK>]",
90194 (void *)class->contention_point[i]);
90195 seq_printf(m, "%40s %14lu %29s %pS\n",
90196 name, stats->contention_point[i],
90197 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90198 if (!i)
90199 seq_line(m, '-', 40-namelen, namelen);
90200
90201 - snprintf(ip, sizeof(ip), "[<%p>]",
90202 + snprintf(ip, sizeof(ip), "[<%pK>]",
90203 (void *)class->contending_point[i]);
90204 seq_printf(m, "%40s %14lu %29s %pS\n",
90205 name, stats->contending_point[i],
90206 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90207 index 9887a90..0cd2b1d 100644
90208 --- a/kernel/locking/mcs_spinlock.c
90209 +++ b/kernel/locking/mcs_spinlock.c
90210 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90211
90212 prev = decode_cpu(old);
90213 node->prev = prev;
90214 - ACCESS_ONCE(prev->next) = node;
90215 + ACCESS_ONCE_RW(prev->next) = node;
90216
90217 /*
90218 * Normally @prev is untouchable after the above store; because at that
90219 @@ -172,8 +172,8 @@ unqueue:
90220 * it will wait in Step-A.
90221 */
90222
90223 - ACCESS_ONCE(next->prev) = prev;
90224 - ACCESS_ONCE(prev->next) = next;
90225 + ACCESS_ONCE_RW(next->prev) = prev;
90226 + ACCESS_ONCE_RW(prev->next) = next;
90227
90228 return false;
90229 }
90230 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90231 node = this_cpu_ptr(&osq_node);
90232 next = xchg(&node->next, NULL);
90233 if (next) {
90234 - ACCESS_ONCE(next->locked) = 1;
90235 + ACCESS_ONCE_RW(next->locked) = 1;
90236 return;
90237 }
90238
90239 next = osq_wait_next(lock, node, NULL);
90240 if (next)
90241 - ACCESS_ONCE(next->locked) = 1;
90242 + ACCESS_ONCE_RW(next->locked) = 1;
90243 }
90244
90245 #endif
90246 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90247 index 4d60986..5d351c1 100644
90248 --- a/kernel/locking/mcs_spinlock.h
90249 +++ b/kernel/locking/mcs_spinlock.h
90250 @@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90251 */
90252 return;
90253 }
90254 - ACCESS_ONCE(prev->next) = node;
90255 + ACCESS_ONCE_RW(prev->next) = node;
90256
90257 /* Wait until the lock holder passes the lock down. */
90258 arch_mcs_spin_lock_contended(&node->locked);
90259 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90260 index 5cf6731..ce3bc5a 100644
90261 --- a/kernel/locking/mutex-debug.c
90262 +++ b/kernel/locking/mutex-debug.c
90263 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90264 }
90265
90266 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90267 - struct thread_info *ti)
90268 + struct task_struct *task)
90269 {
90270 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90271
90272 /* Mark the current thread as blocked on the lock: */
90273 - ti->task->blocked_on = waiter;
90274 + task->blocked_on = waiter;
90275 }
90276
90277 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90278 - struct thread_info *ti)
90279 + struct task_struct *task)
90280 {
90281 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90282 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90283 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90284 - ti->task->blocked_on = NULL;
90285 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90286 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90287 + task->blocked_on = NULL;
90288
90289 list_del_init(&waiter->list);
90290 waiter->task = NULL;
90291 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90292 index 0799fd3..d06ae3b 100644
90293 --- a/kernel/locking/mutex-debug.h
90294 +++ b/kernel/locking/mutex-debug.h
90295 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90296 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90297 extern void debug_mutex_add_waiter(struct mutex *lock,
90298 struct mutex_waiter *waiter,
90299 - struct thread_info *ti);
90300 + struct task_struct *task);
90301 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90302 - struct thread_info *ti);
90303 + struct task_struct *task);
90304 extern void debug_mutex_unlock(struct mutex *lock);
90305 extern void debug_mutex_init(struct mutex *lock, const char *name,
90306 struct lock_class_key *key);
90307 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90308 index dadbf88..4500507 100644
90309 --- a/kernel/locking/mutex.c
90310 +++ b/kernel/locking/mutex.c
90311 @@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90312 goto skip_wait;
90313
90314 debug_mutex_lock_common(lock, &waiter);
90315 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90316 + debug_mutex_add_waiter(lock, &waiter, task);
90317
90318 /* add waiting tasks to the end of the waitqueue (FIFO): */
90319 list_add_tail(&waiter.list, &lock->wait_list);
90320 @@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90321 schedule_preempt_disabled();
90322 spin_lock_mutex(&lock->wait_lock, flags);
90323 }
90324 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90325 + mutex_remove_waiter(lock, &waiter, task);
90326 /* set it to 0 if there are no waiters left: */
90327 if (likely(list_empty(&lock->wait_list)))
90328 atomic_set(&lock->count, 0);
90329 @@ -600,7 +600,7 @@ skip_wait:
90330 return 0;
90331
90332 err:
90333 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90334 + mutex_remove_waiter(lock, &waiter, task);
90335 spin_unlock_mutex(&lock->wait_lock, flags);
90336 debug_mutex_free_waiter(&waiter);
90337 mutex_release(&lock->dep_map, 1, ip);
90338 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90339 index 1d96dd0..994ff19 100644
90340 --- a/kernel/locking/rtmutex-tester.c
90341 +++ b/kernel/locking/rtmutex-tester.c
90342 @@ -22,7 +22,7 @@
90343 #define MAX_RT_TEST_MUTEXES 8
90344
90345 static spinlock_t rttest_lock;
90346 -static atomic_t rttest_event;
90347 +static atomic_unchecked_t rttest_event;
90348
90349 struct test_thread_data {
90350 int opcode;
90351 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90352
90353 case RTTEST_LOCKCONT:
90354 td->mutexes[td->opdata] = 1;
90355 - td->event = atomic_add_return(1, &rttest_event);
90356 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90357 return 0;
90358
90359 case RTTEST_RESET:
90360 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90361 return 0;
90362
90363 case RTTEST_RESETEVENT:
90364 - atomic_set(&rttest_event, 0);
90365 + atomic_set_unchecked(&rttest_event, 0);
90366 return 0;
90367
90368 default:
90369 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90370 return ret;
90371
90372 td->mutexes[id] = 1;
90373 - td->event = atomic_add_return(1, &rttest_event);
90374 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90375 rt_mutex_lock(&mutexes[id]);
90376 - td->event = atomic_add_return(1, &rttest_event);
90377 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90378 td->mutexes[id] = 4;
90379 return 0;
90380
90381 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90382 return ret;
90383
90384 td->mutexes[id] = 1;
90385 - td->event = atomic_add_return(1, &rttest_event);
90386 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90387 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90388 - td->event = atomic_add_return(1, &rttest_event);
90389 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90390 td->mutexes[id] = ret ? 0 : 4;
90391 return ret ? -EINTR : 0;
90392
90393 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90394 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90395 return ret;
90396
90397 - td->event = atomic_add_return(1, &rttest_event);
90398 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90399 rt_mutex_unlock(&mutexes[id]);
90400 - td->event = atomic_add_return(1, &rttest_event);
90401 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90402 td->mutexes[id] = 0;
90403 return 0;
90404
90405 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90406 break;
90407
90408 td->mutexes[dat] = 2;
90409 - td->event = atomic_add_return(1, &rttest_event);
90410 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90411 break;
90412
90413 default:
90414 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90415 return;
90416
90417 td->mutexes[dat] = 3;
90418 - td->event = atomic_add_return(1, &rttest_event);
90419 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90420 break;
90421
90422 case RTTEST_LOCKNOWAIT:
90423 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90424 return;
90425
90426 td->mutexes[dat] = 1;
90427 - td->event = atomic_add_return(1, &rttest_event);
90428 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90429 return;
90430
90431 default:
90432 diff --git a/kernel/module.c b/kernel/module.c
90433 index 88cec1d..d097c28 100644
90434 --- a/kernel/module.c
90435 +++ b/kernel/module.c
90436 @@ -60,6 +60,7 @@
90437 #include <linux/jump_label.h>
90438 #include <linux/pfn.h>
90439 #include <linux/bsearch.h>
90440 +#include <linux/grsecurity.h>
90441 #include <uapi/linux/module.h>
90442 #include "module-internal.h"
90443
90444 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90445
90446 /* Bounds of module allocation, for speeding __module_address.
90447 * Protected by module_mutex. */
90448 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90449 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90450 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90451
90452 int register_module_notifier(struct notifier_block * nb)
90453 {
90454 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90455 return true;
90456
90457 list_for_each_entry_rcu(mod, &modules, list) {
90458 - struct symsearch arr[] = {
90459 + struct symsearch modarr[] = {
90460 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90461 NOT_GPL_ONLY, false },
90462 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90463 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90464 if (mod->state == MODULE_STATE_UNFORMED)
90465 continue;
90466
90467 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90468 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90469 return true;
90470 }
90471 return false;
90472 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90473 if (!pcpusec->sh_size)
90474 return 0;
90475
90476 - if (align > PAGE_SIZE) {
90477 + if (align-1 >= PAGE_SIZE) {
90478 pr_warn("%s: per-cpu alignment %li > %li\n",
90479 mod->name, align, PAGE_SIZE);
90480 align = PAGE_SIZE;
90481 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90482 static ssize_t show_coresize(struct module_attribute *mattr,
90483 struct module_kobject *mk, char *buffer)
90484 {
90485 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90486 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90487 }
90488
90489 static struct module_attribute modinfo_coresize =
90490 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90491 static ssize_t show_initsize(struct module_attribute *mattr,
90492 struct module_kobject *mk, char *buffer)
90493 {
90494 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90495 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90496 }
90497
90498 static struct module_attribute modinfo_initsize =
90499 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90500 goto bad_version;
90501 }
90502
90503 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90504 + /*
90505 + * avoid potentially printing jibberish on attempted load
90506 + * of a module randomized with a different seed
90507 + */
90508 + pr_warn("no symbol version for %s\n", symname);
90509 +#else
90510 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90511 +#endif
90512 return 0;
90513
90514 bad_version:
90515 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90516 + /*
90517 + * avoid potentially printing jibberish on attempted load
90518 + * of a module randomized with a different seed
90519 + */
90520 + printk("attempted module disagrees about version of symbol %s\n",
90521 + symname);
90522 +#else
90523 printk("%s: disagrees about version of symbol %s\n",
90524 mod->name, symname);
90525 +#endif
90526 return 0;
90527 }
90528
90529 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90530 */
90531 #ifdef CONFIG_SYSFS
90532
90533 -#ifdef CONFIG_KALLSYMS
90534 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90535 static inline bool sect_empty(const Elf_Shdr *sect)
90536 {
90537 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90538 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90539 {
90540 unsigned int notes, loaded, i;
90541 struct module_notes_attrs *notes_attrs;
90542 - struct bin_attribute *nattr;
90543 + bin_attribute_no_const *nattr;
90544
90545 /* failed to create section attributes, so can't create notes */
90546 if (!mod->sect_attrs)
90547 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90548 static int module_add_modinfo_attrs(struct module *mod)
90549 {
90550 struct module_attribute *attr;
90551 - struct module_attribute *temp_attr;
90552 + module_attribute_no_const *temp_attr;
90553 int error = 0;
90554 int i;
90555
90556 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90557
90558 static void unset_module_core_ro_nx(struct module *mod)
90559 {
90560 - set_page_attributes(mod->module_core + mod->core_text_size,
90561 - mod->module_core + mod->core_size,
90562 + set_page_attributes(mod->module_core_rw,
90563 + mod->module_core_rw + mod->core_size_rw,
90564 set_memory_x);
90565 - set_page_attributes(mod->module_core,
90566 - mod->module_core + mod->core_ro_size,
90567 + set_page_attributes(mod->module_core_rx,
90568 + mod->module_core_rx + mod->core_size_rx,
90569 set_memory_rw);
90570 }
90571
90572 static void unset_module_init_ro_nx(struct module *mod)
90573 {
90574 - set_page_attributes(mod->module_init + mod->init_text_size,
90575 - mod->module_init + mod->init_size,
90576 + set_page_attributes(mod->module_init_rw,
90577 + mod->module_init_rw + mod->init_size_rw,
90578 set_memory_x);
90579 - set_page_attributes(mod->module_init,
90580 - mod->module_init + mod->init_ro_size,
90581 + set_page_attributes(mod->module_init_rx,
90582 + mod->module_init_rx + mod->init_size_rx,
90583 set_memory_rw);
90584 }
90585
90586 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90587 list_for_each_entry_rcu(mod, &modules, list) {
90588 if (mod->state == MODULE_STATE_UNFORMED)
90589 continue;
90590 - if ((mod->module_core) && (mod->core_text_size)) {
90591 - set_page_attributes(mod->module_core,
90592 - mod->module_core + mod->core_text_size,
90593 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90594 + set_page_attributes(mod->module_core_rx,
90595 + mod->module_core_rx + mod->core_size_rx,
90596 set_memory_rw);
90597 }
90598 - if ((mod->module_init) && (mod->init_text_size)) {
90599 - set_page_attributes(mod->module_init,
90600 - mod->module_init + mod->init_text_size,
90601 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90602 + set_page_attributes(mod->module_init_rx,
90603 + mod->module_init_rx + mod->init_size_rx,
90604 set_memory_rw);
90605 }
90606 }
90607 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90608 list_for_each_entry_rcu(mod, &modules, list) {
90609 if (mod->state == MODULE_STATE_UNFORMED)
90610 continue;
90611 - if ((mod->module_core) && (mod->core_text_size)) {
90612 - set_page_attributes(mod->module_core,
90613 - mod->module_core + mod->core_text_size,
90614 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90615 + set_page_attributes(mod->module_core_rx,
90616 + mod->module_core_rx + mod->core_size_rx,
90617 set_memory_ro);
90618 }
90619 - if ((mod->module_init) && (mod->init_text_size)) {
90620 - set_page_attributes(mod->module_init,
90621 - mod->module_init + mod->init_text_size,
90622 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90623 + set_page_attributes(mod->module_init_rx,
90624 + mod->module_init_rx + mod->init_size_rx,
90625 set_memory_ro);
90626 }
90627 }
90628 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90629
90630 /* This may be NULL, but that's OK */
90631 unset_module_init_ro_nx(mod);
90632 - module_free(mod, mod->module_init);
90633 + module_free(mod, mod->module_init_rw);
90634 + module_free_exec(mod, mod->module_init_rx);
90635 kfree(mod->args);
90636 percpu_modfree(mod);
90637
90638 /* Free lock-classes: */
90639 - lockdep_free_key_range(mod->module_core, mod->core_size);
90640 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90641 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90642
90643 /* Finally, free the core (containing the module structure) */
90644 unset_module_core_ro_nx(mod);
90645 - module_free(mod, mod->module_core);
90646 + module_free_exec(mod, mod->module_core_rx);
90647 + module_free(mod, mod->module_core_rw);
90648
90649 #ifdef CONFIG_MPU
90650 update_protections(current->mm);
90651 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90652 int ret = 0;
90653 const struct kernel_symbol *ksym;
90654
90655 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90656 + int is_fs_load = 0;
90657 + int register_filesystem_found = 0;
90658 + char *p;
90659 +
90660 + p = strstr(mod->args, "grsec_modharden_fs");
90661 + if (p) {
90662 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90663 + /* copy \0 as well */
90664 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90665 + is_fs_load = 1;
90666 + }
90667 +#endif
90668 +
90669 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90670 const char *name = info->strtab + sym[i].st_name;
90671
90672 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90673 + /* it's a real shame this will never get ripped and copied
90674 + upstream! ;(
90675 + */
90676 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90677 + register_filesystem_found = 1;
90678 +#endif
90679 +
90680 switch (sym[i].st_shndx) {
90681 case SHN_COMMON:
90682 /* Ignore common symbols */
90683 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90684 ksym = resolve_symbol_wait(mod, info, name);
90685 /* Ok if resolved. */
90686 if (ksym && !IS_ERR(ksym)) {
90687 + pax_open_kernel();
90688 sym[i].st_value = ksym->value;
90689 + pax_close_kernel();
90690 break;
90691 }
90692
90693 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90694 secbase = (unsigned long)mod_percpu(mod);
90695 else
90696 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90697 + pax_open_kernel();
90698 sym[i].st_value += secbase;
90699 + pax_close_kernel();
90700 break;
90701 }
90702 }
90703
90704 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90705 + if (is_fs_load && !register_filesystem_found) {
90706 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90707 + ret = -EPERM;
90708 + }
90709 +#endif
90710 +
90711 return ret;
90712 }
90713
90714 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90715 || s->sh_entsize != ~0UL
90716 || strstarts(sname, ".init"))
90717 continue;
90718 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90719 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90720 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90721 + else
90722 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90723 pr_debug("\t%s\n", sname);
90724 }
90725 - switch (m) {
90726 - case 0: /* executable */
90727 - mod->core_size = debug_align(mod->core_size);
90728 - mod->core_text_size = mod->core_size;
90729 - break;
90730 - case 1: /* RO: text and ro-data */
90731 - mod->core_size = debug_align(mod->core_size);
90732 - mod->core_ro_size = mod->core_size;
90733 - break;
90734 - case 3: /* whole core */
90735 - mod->core_size = debug_align(mod->core_size);
90736 - break;
90737 - }
90738 }
90739
90740 pr_debug("Init section allocation order:\n");
90741 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90742 || s->sh_entsize != ~0UL
90743 || !strstarts(sname, ".init"))
90744 continue;
90745 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90746 - | INIT_OFFSET_MASK);
90747 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90748 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90749 + else
90750 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90751 + s->sh_entsize |= INIT_OFFSET_MASK;
90752 pr_debug("\t%s\n", sname);
90753 }
90754 - switch (m) {
90755 - case 0: /* executable */
90756 - mod->init_size = debug_align(mod->init_size);
90757 - mod->init_text_size = mod->init_size;
90758 - break;
90759 - case 1: /* RO: text and ro-data */
90760 - mod->init_size = debug_align(mod->init_size);
90761 - mod->init_ro_size = mod->init_size;
90762 - break;
90763 - case 3: /* whole init */
90764 - mod->init_size = debug_align(mod->init_size);
90765 - break;
90766 - }
90767 }
90768 }
90769
90770 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90771
90772 /* Put symbol section at end of init part of module. */
90773 symsect->sh_flags |= SHF_ALLOC;
90774 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90775 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90776 info->index.sym) | INIT_OFFSET_MASK;
90777 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90778
90779 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90780 }
90781
90782 /* Append room for core symbols at end of core part. */
90783 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90784 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90785 - mod->core_size += strtab_size;
90786 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90787 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90788 + mod->core_size_rx += strtab_size;
90789
90790 /* Put string table section at end of init part of module. */
90791 strsect->sh_flags |= SHF_ALLOC;
90792 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90793 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90794 info->index.str) | INIT_OFFSET_MASK;
90795 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90796 }
90797 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90798 /* Make sure we get permanent strtab: don't use info->strtab. */
90799 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90800
90801 + pax_open_kernel();
90802 +
90803 /* Set types up while we still have access to sections. */
90804 for (i = 0; i < mod->num_symtab; i++)
90805 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90806
90807 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90808 - mod->core_strtab = s = mod->module_core + info->stroffs;
90809 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90810 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90811 src = mod->symtab;
90812 for (ndst = i = 0; i < mod->num_symtab; i++) {
90813 if (i == 0 ||
90814 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90815 }
90816 }
90817 mod->core_num_syms = ndst;
90818 +
90819 + pax_close_kernel();
90820 }
90821 #else
90822 static inline void layout_symtab(struct module *mod, struct load_info *info)
90823 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90824 return vmalloc_exec(size);
90825 }
90826
90827 -static void *module_alloc_update_bounds(unsigned long size)
90828 +static void *module_alloc_update_bounds_rw(unsigned long size)
90829 {
90830 void *ret = module_alloc(size);
90831
90832 if (ret) {
90833 mutex_lock(&module_mutex);
90834 /* Update module bounds. */
90835 - if ((unsigned long)ret < module_addr_min)
90836 - module_addr_min = (unsigned long)ret;
90837 - if ((unsigned long)ret + size > module_addr_max)
90838 - module_addr_max = (unsigned long)ret + size;
90839 + if ((unsigned long)ret < module_addr_min_rw)
90840 + module_addr_min_rw = (unsigned long)ret;
90841 + if ((unsigned long)ret + size > module_addr_max_rw)
90842 + module_addr_max_rw = (unsigned long)ret + size;
90843 + mutex_unlock(&module_mutex);
90844 + }
90845 + return ret;
90846 +}
90847 +
90848 +static void *module_alloc_update_bounds_rx(unsigned long size)
90849 +{
90850 + void *ret = module_alloc_exec(size);
90851 +
90852 + if (ret) {
90853 + mutex_lock(&module_mutex);
90854 + /* Update module bounds. */
90855 + if ((unsigned long)ret < module_addr_min_rx)
90856 + module_addr_min_rx = (unsigned long)ret;
90857 + if ((unsigned long)ret + size > module_addr_max_rx)
90858 + module_addr_max_rx = (unsigned long)ret + size;
90859 mutex_unlock(&module_mutex);
90860 }
90861 return ret;
90862 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90863 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90864
90865 if (info->index.sym == 0) {
90866 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90867 + /*
90868 + * avoid potentially printing jibberish on attempted load
90869 + * of a module randomized with a different seed
90870 + */
90871 + pr_warn("module has no symbols (stripped?)\n");
90872 +#else
90873 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90874 +#endif
90875 return ERR_PTR(-ENOEXEC);
90876 }
90877
90878 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90879 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90880 {
90881 const char *modmagic = get_modinfo(info, "vermagic");
90882 + const char *license = get_modinfo(info, "license");
90883 int err;
90884
90885 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90886 + if (!license || !license_is_gpl_compatible(license))
90887 + return -ENOEXEC;
90888 +#endif
90889 +
90890 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90891 modmagic = NULL;
90892
90893 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90894 }
90895
90896 /* Set up license info based on the info section */
90897 - set_license(mod, get_modinfo(info, "license"));
90898 + set_license(mod, license);
90899
90900 return 0;
90901 }
90902 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90903 void *ptr;
90904
90905 /* Do the allocs. */
90906 - ptr = module_alloc_update_bounds(mod->core_size);
90907 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90908 /*
90909 * The pointer to this block is stored in the module structure
90910 * which is inside the block. Just mark it as not being a
90911 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90912 if (!ptr)
90913 return -ENOMEM;
90914
90915 - memset(ptr, 0, mod->core_size);
90916 - mod->module_core = ptr;
90917 + memset(ptr, 0, mod->core_size_rw);
90918 + mod->module_core_rw = ptr;
90919
90920 - if (mod->init_size) {
90921 - ptr = module_alloc_update_bounds(mod->init_size);
90922 + if (mod->init_size_rw) {
90923 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90924 /*
90925 * The pointer to this block is stored in the module structure
90926 * which is inside the block. This block doesn't need to be
90927 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90928 */
90929 kmemleak_ignore(ptr);
90930 if (!ptr) {
90931 - module_free(mod, mod->module_core);
90932 + module_free(mod, mod->module_core_rw);
90933 return -ENOMEM;
90934 }
90935 - memset(ptr, 0, mod->init_size);
90936 - mod->module_init = ptr;
90937 + memset(ptr, 0, mod->init_size_rw);
90938 + mod->module_init_rw = ptr;
90939 } else
90940 - mod->module_init = NULL;
90941 + mod->module_init_rw = NULL;
90942 +
90943 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90944 + kmemleak_not_leak(ptr);
90945 + if (!ptr) {
90946 + if (mod->module_init_rw)
90947 + module_free(mod, mod->module_init_rw);
90948 + module_free(mod, mod->module_core_rw);
90949 + return -ENOMEM;
90950 + }
90951 +
90952 + pax_open_kernel();
90953 + memset(ptr, 0, mod->core_size_rx);
90954 + pax_close_kernel();
90955 + mod->module_core_rx = ptr;
90956 +
90957 + if (mod->init_size_rx) {
90958 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90959 + kmemleak_ignore(ptr);
90960 + if (!ptr && mod->init_size_rx) {
90961 + module_free_exec(mod, mod->module_core_rx);
90962 + if (mod->module_init_rw)
90963 + module_free(mod, mod->module_init_rw);
90964 + module_free(mod, mod->module_core_rw);
90965 + return -ENOMEM;
90966 + }
90967 +
90968 + pax_open_kernel();
90969 + memset(ptr, 0, mod->init_size_rx);
90970 + pax_close_kernel();
90971 + mod->module_init_rx = ptr;
90972 + } else
90973 + mod->module_init_rx = NULL;
90974
90975 /* Transfer each section which specifies SHF_ALLOC */
90976 pr_debug("final section addresses:\n");
90977 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90978 if (!(shdr->sh_flags & SHF_ALLOC))
90979 continue;
90980
90981 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
90982 - dest = mod->module_init
90983 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90984 - else
90985 - dest = mod->module_core + shdr->sh_entsize;
90986 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90987 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90988 + dest = mod->module_init_rw
90989 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90990 + else
90991 + dest = mod->module_init_rx
90992 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90993 + } else {
90994 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90995 + dest = mod->module_core_rw + shdr->sh_entsize;
90996 + else
90997 + dest = mod->module_core_rx + shdr->sh_entsize;
90998 + }
90999 +
91000 + if (shdr->sh_type != SHT_NOBITS) {
91001 +
91002 +#ifdef CONFIG_PAX_KERNEXEC
91003 +#ifdef CONFIG_X86_64
91004 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91005 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91006 +#endif
91007 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91008 + pax_open_kernel();
91009 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91010 + pax_close_kernel();
91011 + } else
91012 +#endif
91013
91014 - if (shdr->sh_type != SHT_NOBITS)
91015 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91016 + }
91017 /* Update sh_addr to point to copy in image. */
91018 - shdr->sh_addr = (unsigned long)dest;
91019 +
91020 +#ifdef CONFIG_PAX_KERNEXEC
91021 + if (shdr->sh_flags & SHF_EXECINSTR)
91022 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91023 + else
91024 +#endif
91025 +
91026 + shdr->sh_addr = (unsigned long)dest;
91027 pr_debug("\t0x%lx %s\n",
91028 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91029 }
91030 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91031 * Do it before processing of module parameters, so the module
91032 * can provide parameter accessor functions of its own.
91033 */
91034 - if (mod->module_init)
91035 - flush_icache_range((unsigned long)mod->module_init,
91036 - (unsigned long)mod->module_init
91037 - + mod->init_size);
91038 - flush_icache_range((unsigned long)mod->module_core,
91039 - (unsigned long)mod->module_core + mod->core_size);
91040 + if (mod->module_init_rx)
91041 + flush_icache_range((unsigned long)mod->module_init_rx,
91042 + (unsigned long)mod->module_init_rx
91043 + + mod->init_size_rx);
91044 + flush_icache_range((unsigned long)mod->module_core_rx,
91045 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91046
91047 set_fs(old_fs);
91048 }
91049 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91050 static void module_deallocate(struct module *mod, struct load_info *info)
91051 {
91052 percpu_modfree(mod);
91053 - module_free(mod, mod->module_init);
91054 - module_free(mod, mod->module_core);
91055 + module_free_exec(mod, mod->module_init_rx);
91056 + module_free_exec(mod, mod->module_core_rx);
91057 + module_free(mod, mod->module_init_rw);
91058 + module_free(mod, mod->module_core_rw);
91059 }
91060
91061 int __weak module_finalize(const Elf_Ehdr *hdr,
91062 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91063 static int post_relocation(struct module *mod, const struct load_info *info)
91064 {
91065 /* Sort exception table now relocations are done. */
91066 + pax_open_kernel();
91067 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91068 + pax_close_kernel();
91069
91070 /* Copy relocated percpu area over. */
91071 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91072 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91073 mod->strtab = mod->core_strtab;
91074 #endif
91075 unset_module_init_ro_nx(mod);
91076 - module_free(mod, mod->module_init);
91077 - mod->module_init = NULL;
91078 - mod->init_size = 0;
91079 - mod->init_ro_size = 0;
91080 - mod->init_text_size = 0;
91081 + module_free(mod, mod->module_init_rw);
91082 + module_free_exec(mod, mod->module_init_rx);
91083 + mod->module_init_rw = NULL;
91084 + mod->module_init_rx = NULL;
91085 + mod->init_size_rw = 0;
91086 + mod->init_size_rx = 0;
91087 mutex_unlock(&module_mutex);
91088 wake_up_all(&module_wq);
91089
91090 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91091 module_bug_finalize(info->hdr, info->sechdrs, mod);
91092
91093 /* Set RO and NX regions for core */
91094 - set_section_ro_nx(mod->module_core,
91095 - mod->core_text_size,
91096 - mod->core_ro_size,
91097 - mod->core_size);
91098 + set_section_ro_nx(mod->module_core_rx,
91099 + mod->core_size_rx,
91100 + mod->core_size_rx,
91101 + mod->core_size_rx);
91102
91103 /* Set RO and NX regions for init */
91104 - set_section_ro_nx(mod->module_init,
91105 - mod->init_text_size,
91106 - mod->init_ro_size,
91107 - mod->init_size);
91108 + set_section_ro_nx(mod->module_init_rx,
91109 + mod->init_size_rx,
91110 + mod->init_size_rx,
91111 + mod->init_size_rx);
91112
91113 /* Mark state as coming so strong_try_module_get() ignores us,
91114 * but kallsyms etc. can see us. */
91115 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91116 if (err)
91117 goto free_unload;
91118
91119 + /* Now copy in args */
91120 + mod->args = strndup_user(uargs, ~0UL >> 1);
91121 + if (IS_ERR(mod->args)) {
91122 + err = PTR_ERR(mod->args);
91123 + goto free_unload;
91124 + }
91125 +
91126 /* Set up MODINFO_ATTR fields */
91127 setup_modinfo(mod, info);
91128
91129 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91130 + {
91131 + char *p, *p2;
91132 +
91133 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91134 + 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);
91135 + err = -EPERM;
91136 + goto free_modinfo;
91137 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91138 + p += sizeof("grsec_modharden_normal") - 1;
91139 + p2 = strstr(p, "_");
91140 + if (p2) {
91141 + *p2 = '\0';
91142 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91143 + *p2 = '_';
91144 + }
91145 + err = -EPERM;
91146 + goto free_modinfo;
91147 + }
91148 + }
91149 +#endif
91150 +
91151 /* Fix up syms, so that st_value is a pointer to location. */
91152 err = simplify_symbols(mod, info);
91153 if (err < 0)
91154 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91155
91156 flush_module_icache(mod);
91157
91158 - /* Now copy in args */
91159 - mod->args = strndup_user(uargs, ~0UL >> 1);
91160 - if (IS_ERR(mod->args)) {
91161 - err = PTR_ERR(mod->args);
91162 - goto free_arch_cleanup;
91163 - }
91164 -
91165 dynamic_debug_setup(info->debug, info->num_debug);
91166
91167 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91168 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91169 ddebug_cleanup:
91170 dynamic_debug_remove(info->debug);
91171 synchronize_sched();
91172 - kfree(mod->args);
91173 - free_arch_cleanup:
91174 module_arch_cleanup(mod);
91175 free_modinfo:
91176 free_modinfo(mod);
91177 + kfree(mod->args);
91178 free_unload:
91179 module_unload_free(mod);
91180 unlink_mod:
91181 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91182 unsigned long nextval;
91183
91184 /* At worse, next value is at end of module */
91185 - if (within_module_init(addr, mod))
91186 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91187 + if (within_module_init_rx(addr, mod))
91188 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91189 + else if (within_module_init_rw(addr, mod))
91190 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91191 + else if (within_module_core_rx(addr, mod))
91192 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91193 + else if (within_module_core_rw(addr, mod))
91194 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91195 else
91196 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91197 + return NULL;
91198
91199 /* Scan for closest preceding symbol, and next symbol. (ELF
91200 starts real symbols at 1). */
91201 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91202 return 0;
91203
91204 seq_printf(m, "%s %u",
91205 - mod->name, mod->init_size + mod->core_size);
91206 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91207 print_unload_info(m, mod);
91208
91209 /* Informative for users. */
91210 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91211 mod->state == MODULE_STATE_COMING ? "Loading":
91212 "Live");
91213 /* Used by oprofile and other similar tools. */
91214 - seq_printf(m, " 0x%pK", mod->module_core);
91215 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91216
91217 /* Taints info */
91218 if (mod->taints)
91219 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91220
91221 static int __init proc_modules_init(void)
91222 {
91223 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91224 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91225 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91226 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91227 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91228 +#else
91229 proc_create("modules", 0, NULL, &proc_modules_operations);
91230 +#endif
91231 +#else
91232 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91233 +#endif
91234 return 0;
91235 }
91236 module_init(proc_modules_init);
91237 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91238 {
91239 struct module *mod;
91240
91241 - if (addr < module_addr_min || addr > module_addr_max)
91242 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91243 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91244 return NULL;
91245
91246 list_for_each_entry_rcu(mod, &modules, list) {
91247 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91248 */
91249 struct module *__module_text_address(unsigned long addr)
91250 {
91251 - struct module *mod = __module_address(addr);
91252 + struct module *mod;
91253 +
91254 +#ifdef CONFIG_X86_32
91255 + addr = ktla_ktva(addr);
91256 +#endif
91257 +
91258 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91259 + return NULL;
91260 +
91261 + mod = __module_address(addr);
91262 +
91263 if (mod) {
91264 /* Make sure it's within the text section. */
91265 - if (!within(addr, mod->module_init, mod->init_text_size)
91266 - && !within(addr, mod->module_core, mod->core_text_size))
91267 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91268 mod = NULL;
91269 }
91270 return mod;
91271 diff --git a/kernel/notifier.c b/kernel/notifier.c
91272 index 4803da6..1c5eea6 100644
91273 --- a/kernel/notifier.c
91274 +++ b/kernel/notifier.c
91275 @@ -5,6 +5,7 @@
91276 #include <linux/rcupdate.h>
91277 #include <linux/vmalloc.h>
91278 #include <linux/reboot.h>
91279 +#include <linux/mm.h>
91280
91281 /*
91282 * Notifier list for kernel code which wants to be called
91283 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91284 while ((*nl) != NULL) {
91285 if (n->priority > (*nl)->priority)
91286 break;
91287 - nl = &((*nl)->next);
91288 + nl = (struct notifier_block **)&((*nl)->next);
91289 }
91290 - n->next = *nl;
91291 + pax_open_kernel();
91292 + *(const void **)&n->next = *nl;
91293 rcu_assign_pointer(*nl, n);
91294 + pax_close_kernel();
91295 return 0;
91296 }
91297
91298 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91299 return 0;
91300 if (n->priority > (*nl)->priority)
91301 break;
91302 - nl = &((*nl)->next);
91303 + nl = (struct notifier_block **)&((*nl)->next);
91304 }
91305 - n->next = *nl;
91306 + pax_open_kernel();
91307 + *(const void **)&n->next = *nl;
91308 rcu_assign_pointer(*nl, n);
91309 + pax_close_kernel();
91310 return 0;
91311 }
91312
91313 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91314 {
91315 while ((*nl) != NULL) {
91316 if ((*nl) == n) {
91317 + pax_open_kernel();
91318 rcu_assign_pointer(*nl, n->next);
91319 + pax_close_kernel();
91320 return 0;
91321 }
91322 - nl = &((*nl)->next);
91323 + nl = (struct notifier_block **)&((*nl)->next);
91324 }
91325 return -ENOENT;
91326 }
91327 diff --git a/kernel/padata.c b/kernel/padata.c
91328 index 161402f..598814c 100644
91329 --- a/kernel/padata.c
91330 +++ b/kernel/padata.c
91331 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91332 * seq_nr mod. number of cpus in use.
91333 */
91334
91335 - seq_nr = atomic_inc_return(&pd->seq_nr);
91336 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91337 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91338
91339 return padata_index_to_cpu(pd, cpu_index);
91340 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91341 padata_init_pqueues(pd);
91342 padata_init_squeues(pd);
91343 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91344 - atomic_set(&pd->seq_nr, -1);
91345 + atomic_set_unchecked(&pd->seq_nr, -1);
91346 atomic_set(&pd->reorder_objects, 0);
91347 atomic_set(&pd->refcnt, 0);
91348 pd->pinst = pinst;
91349 diff --git a/kernel/panic.c b/kernel/panic.c
91350 index cf80672..f6771b2 100644
91351 --- a/kernel/panic.c
91352 +++ b/kernel/panic.c
91353 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91354 /*
91355 * Stop ourself in panic -- architecture code may override this
91356 */
91357 -void __weak panic_smp_self_stop(void)
91358 +void __weak __noreturn panic_smp_self_stop(void)
91359 {
91360 while (1)
91361 cpu_relax();
91362 @@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91363 disable_trace_on_warning();
91364
91365 pr_warn("------------[ cut here ]------------\n");
91366 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91367 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91368 raw_smp_processor_id(), current->pid, file, line, caller);
91369
91370 if (args)
91371 @@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91372 */
91373 __visible void __stack_chk_fail(void)
91374 {
91375 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91376 + dump_stack();
91377 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91378 __builtin_return_address(0));
91379 }
91380 EXPORT_SYMBOL(__stack_chk_fail);
91381 diff --git a/kernel/pid.c b/kernel/pid.c
91382 index 82430c8..53d7793 100644
91383 --- a/kernel/pid.c
91384 +++ b/kernel/pid.c
91385 @@ -33,6 +33,7 @@
91386 #include <linux/rculist.h>
91387 #include <linux/bootmem.h>
91388 #include <linux/hash.h>
91389 +#include <linux/security.h>
91390 #include <linux/pid_namespace.h>
91391 #include <linux/init_task.h>
91392 #include <linux/syscalls.h>
91393 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91394
91395 int pid_max = PID_MAX_DEFAULT;
91396
91397 -#define RESERVED_PIDS 300
91398 +#define RESERVED_PIDS 500
91399
91400 int pid_max_min = RESERVED_PIDS + 1;
91401 int pid_max_max = PID_MAX_LIMIT;
91402 @@ -447,10 +448,18 @@ EXPORT_SYMBOL(pid_task);
91403 */
91404 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91405 {
91406 + struct task_struct *task;
91407 +
91408 rcu_lockdep_assert(rcu_read_lock_held(),
91409 "find_task_by_pid_ns() needs rcu_read_lock()"
91410 " protection");
91411 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91412 +
91413 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91414 +
91415 + if (gr_pid_is_chrooted(task))
91416 + return NULL;
91417 +
91418 + return task;
91419 }
91420
91421 struct task_struct *find_task_by_vpid(pid_t vnr)
91422 @@ -458,6 +467,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91423 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91424 }
91425
91426 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91427 +{
91428 + rcu_lockdep_assert(rcu_read_lock_held(),
91429 + "find_task_by_pid_ns() needs rcu_read_lock()"
91430 + " protection");
91431 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91432 +}
91433 +
91434 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91435 {
91436 struct pid *pid;
91437 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91438 index db95d8e..a0ca23f 100644
91439 --- a/kernel/pid_namespace.c
91440 +++ b/kernel/pid_namespace.c
91441 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91442 void __user *buffer, size_t *lenp, loff_t *ppos)
91443 {
91444 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91445 - struct ctl_table tmp = *table;
91446 + ctl_table_no_const tmp = *table;
91447
91448 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91449 return -EPERM;
91450 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91451 index bbef57f..5f94462 100644
91452 --- a/kernel/power/Kconfig
91453 +++ b/kernel/power/Kconfig
91454 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91455 config HIBERNATION
91456 bool "Hibernation (aka 'suspend to disk')"
91457 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91458 + depends on !GRKERNSEC_KMEM
91459 + depends on !PAX_MEMORY_SANITIZE
91460 select HIBERNATE_CALLBACKS
91461 select LZO_COMPRESS
91462 select LZO_DECOMPRESS
91463 diff --git a/kernel/power/process.c b/kernel/power/process.c
91464 index 5a6ec86..3a8c884 100644
91465 --- a/kernel/power/process.c
91466 +++ b/kernel/power/process.c
91467 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91468 unsigned int elapsed_msecs;
91469 bool wakeup = false;
91470 int sleep_usecs = USEC_PER_MSEC;
91471 + bool timedout = false;
91472
91473 do_gettimeofday(&start);
91474
91475 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91476
91477 while (true) {
91478 todo = 0;
91479 + if (time_after(jiffies, end_time))
91480 + timedout = true;
91481 read_lock(&tasklist_lock);
91482 for_each_process_thread(g, p) {
91483 if (p == current || !freeze_task(p))
91484 continue;
91485
91486 - if (!freezer_should_skip(p))
91487 + if (!freezer_should_skip(p)) {
91488 todo++;
91489 + if (timedout) {
91490 + printk(KERN_ERR "Task refusing to freeze:\n");
91491 + sched_show_task(p);
91492 + }
91493 + }
91494 }
91495 read_unlock(&tasklist_lock);
91496
91497 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91498 todo += wq_busy;
91499 }
91500
91501 - if (!todo || time_after(jiffies, end_time))
91502 + if (!todo || timedout)
91503 break;
91504
91505 if (pm_wakeup_pending()) {
91506 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91507 index ced2b84..ffc4791 100644
91508 --- a/kernel/printk/printk.c
91509 +++ b/kernel/printk/printk.c
91510 @@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91511 if (from_file && type != SYSLOG_ACTION_OPEN)
91512 return 0;
91513
91514 +#ifdef CONFIG_GRKERNSEC_DMESG
91515 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91516 + return -EPERM;
91517 +#endif
91518 +
91519 if (syslog_action_restricted(type)) {
91520 if (capable(CAP_SYSLOG))
91521 return 0;
91522 diff --git a/kernel/profile.c b/kernel/profile.c
91523 index 54bf5ba..df6e0a2 100644
91524 --- a/kernel/profile.c
91525 +++ b/kernel/profile.c
91526 @@ -37,7 +37,7 @@ struct profile_hit {
91527 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91528 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91529
91530 -static atomic_t *prof_buffer;
91531 +static atomic_unchecked_t *prof_buffer;
91532 static unsigned long prof_len, prof_shift;
91533
91534 int prof_on __read_mostly;
91535 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91536 hits[i].pc = 0;
91537 continue;
91538 }
91539 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91540 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91541 hits[i].hits = hits[i].pc = 0;
91542 }
91543 }
91544 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91545 * Add the current hit(s) and flush the write-queue out
91546 * to the global buffer:
91547 */
91548 - atomic_add(nr_hits, &prof_buffer[pc]);
91549 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91550 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91551 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91552 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91553 hits[i].pc = hits[i].hits = 0;
91554 }
91555 out:
91556 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91557 {
91558 unsigned long pc;
91559 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91560 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91561 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91562 }
91563 #endif /* !CONFIG_SMP */
91564
91565 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91566 return -EFAULT;
91567 buf++; p++; count--; read++;
91568 }
91569 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91570 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91571 if (copy_to_user(buf, (void *)pnt, count))
91572 return -EFAULT;
91573 read += count;
91574 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91575 }
91576 #endif
91577 profile_discard_flip_buffers();
91578 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91579 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91580 return count;
91581 }
91582
91583 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91584 index 54e7522..5b82dd6 100644
91585 --- a/kernel/ptrace.c
91586 +++ b/kernel/ptrace.c
91587 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91588 if (seize)
91589 flags |= PT_SEIZED;
91590 rcu_read_lock();
91591 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91592 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91593 flags |= PT_PTRACE_CAP;
91594 rcu_read_unlock();
91595 task->ptrace = flags;
91596 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91597 break;
91598 return -EIO;
91599 }
91600 - if (copy_to_user(dst, buf, retval))
91601 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91602 return -EFAULT;
91603 copied += retval;
91604 src += retval;
91605 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91606 bool seized = child->ptrace & PT_SEIZED;
91607 int ret = -EIO;
91608 siginfo_t siginfo, *si;
91609 - void __user *datavp = (void __user *) data;
91610 + void __user *datavp = (__force void __user *) data;
91611 unsigned long __user *datalp = datavp;
91612 unsigned long flags;
91613
91614 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91615 goto out;
91616 }
91617
91618 + if (gr_handle_ptrace(child, request)) {
91619 + ret = -EPERM;
91620 + goto out_put_task_struct;
91621 + }
91622 +
91623 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91624 ret = ptrace_attach(child, request, addr, data);
91625 /*
91626 * Some architectures need to do book-keeping after
91627 * a ptrace attach.
91628 */
91629 - if (!ret)
91630 + if (!ret) {
91631 arch_ptrace_attach(child);
91632 + gr_audit_ptrace(child);
91633 + }
91634 goto out_put_task_struct;
91635 }
91636
91637 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91638 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91639 if (copied != sizeof(tmp))
91640 return -EIO;
91641 - return put_user(tmp, (unsigned long __user *)data);
91642 + return put_user(tmp, (__force unsigned long __user *)data);
91643 }
91644
91645 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91646 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91647 }
91648
91649 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91650 - compat_long_t, addr, compat_long_t, data)
91651 + compat_ulong_t, addr, compat_ulong_t, data)
91652 {
91653 struct task_struct *child;
91654 long ret;
91655 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91656 goto out;
91657 }
91658
91659 + if (gr_handle_ptrace(child, request)) {
91660 + ret = -EPERM;
91661 + goto out_put_task_struct;
91662 + }
91663 +
91664 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91665 ret = ptrace_attach(child, request, addr, data);
91666 /*
91667 * Some architectures need to do book-keeping after
91668 * a ptrace attach.
91669 */
91670 - if (!ret)
91671 + if (!ret) {
91672 arch_ptrace_attach(child);
91673 + gr_audit_ptrace(child);
91674 + }
91675 goto out_put_task_struct;
91676 }
91677
91678 diff --git a/kernel/range.c b/kernel/range.c
91679 index 322ea8e..82cfc28 100644
91680 --- a/kernel/range.c
91681 +++ b/kernel/range.c
91682 @@ -113,12 +113,12 @@ static int cmp_range(const void *x1, const void *x2)
91683 {
91684 const struct range *r1 = x1;
91685 const struct range *r2 = x2;
91686 - s64 start1, start2;
91687
91688 - start1 = r1->start;
91689 - start2 = r2->start;
91690 -
91691 - return start1 - start2;
91692 + if (r1->start < r2->start)
91693 + return -1;
91694 + if (r1->start > r2->start)
91695 + return 1;
91696 + return 0;
91697 }
91698
91699 int clean_sort_range(struct range *range, int az)
91700 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91701 index 240fa90..5fa56bd 100644
91702 --- a/kernel/rcu/rcutorture.c
91703 +++ b/kernel/rcu/rcutorture.c
91704 @@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91705 rcu_torture_count) = { 0 };
91706 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91707 rcu_torture_batch) = { 0 };
91708 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91709 -static atomic_t n_rcu_torture_alloc;
91710 -static atomic_t n_rcu_torture_alloc_fail;
91711 -static atomic_t n_rcu_torture_free;
91712 -static atomic_t n_rcu_torture_mberror;
91713 -static atomic_t n_rcu_torture_error;
91714 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91715 +static atomic_unchecked_t n_rcu_torture_alloc;
91716 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91717 +static atomic_unchecked_t n_rcu_torture_free;
91718 +static atomic_unchecked_t n_rcu_torture_mberror;
91719 +static atomic_unchecked_t n_rcu_torture_error;
91720 static long n_rcu_torture_barrier_error;
91721 static long n_rcu_torture_boost_ktrerror;
91722 static long n_rcu_torture_boost_rterror;
91723 @@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91724 static long n_rcu_torture_timers;
91725 static long n_barrier_attempts;
91726 static long n_barrier_successes;
91727 -static atomic_long_t n_cbfloods;
91728 +static atomic_long_unchecked_t n_cbfloods;
91729 static struct list_head rcu_torture_removed;
91730
91731 static int rcu_torture_writer_state;
91732 @@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91733
91734 spin_lock_bh(&rcu_torture_lock);
91735 if (list_empty(&rcu_torture_freelist)) {
91736 - atomic_inc(&n_rcu_torture_alloc_fail);
91737 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91738 spin_unlock_bh(&rcu_torture_lock);
91739 return NULL;
91740 }
91741 - atomic_inc(&n_rcu_torture_alloc);
91742 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91743 p = rcu_torture_freelist.next;
91744 list_del_init(p);
91745 spin_unlock_bh(&rcu_torture_lock);
91746 @@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91747 static void
91748 rcu_torture_free(struct rcu_torture *p)
91749 {
91750 - atomic_inc(&n_rcu_torture_free);
91751 + atomic_inc_unchecked(&n_rcu_torture_free);
91752 spin_lock_bh(&rcu_torture_lock);
91753 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91754 spin_unlock_bh(&rcu_torture_lock);
91755 @@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91756 i = rp->rtort_pipe_count;
91757 if (i > RCU_TORTURE_PIPE_LEN)
91758 i = RCU_TORTURE_PIPE_LEN;
91759 - atomic_inc(&rcu_torture_wcount[i]);
91760 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91761 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91762 rp->rtort_mbtest = 0;
91763 return true;
91764 @@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91765 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91766 do {
91767 schedule_timeout_interruptible(cbflood_inter_holdoff);
91768 - atomic_long_inc(&n_cbfloods);
91769 + atomic_long_inc_unchecked(&n_cbfloods);
91770 WARN_ON(signal_pending(current));
91771 for (i = 0; i < cbflood_n_burst; i++) {
91772 for (j = 0; j < cbflood_n_per_burst; j++) {
91773 @@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91774 i = old_rp->rtort_pipe_count;
91775 if (i > RCU_TORTURE_PIPE_LEN)
91776 i = RCU_TORTURE_PIPE_LEN;
91777 - atomic_inc(&rcu_torture_wcount[i]);
91778 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91779 old_rp->rtort_pipe_count++;
91780 switch (synctype[torture_random(&rand) % nsynctypes]) {
91781 case RTWS_DEF_FREE:
91782 @@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91783 return;
91784 }
91785 if (p->rtort_mbtest == 0)
91786 - atomic_inc(&n_rcu_torture_mberror);
91787 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91788 spin_lock(&rand_lock);
91789 cur_ops->read_delay(&rand);
91790 n_rcu_torture_timers++;
91791 @@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91792 continue;
91793 }
91794 if (p->rtort_mbtest == 0)
91795 - atomic_inc(&n_rcu_torture_mberror);
91796 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91797 cur_ops->read_delay(&rand);
91798 preempt_disable();
91799 pipe_count = p->rtort_pipe_count;
91800 @@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91801 rcu_torture_current,
91802 rcu_torture_current_version,
91803 list_empty(&rcu_torture_freelist),
91804 - atomic_read(&n_rcu_torture_alloc),
91805 - atomic_read(&n_rcu_torture_alloc_fail),
91806 - atomic_read(&n_rcu_torture_free));
91807 + atomic_read_unchecked(&n_rcu_torture_alloc),
91808 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91809 + atomic_read_unchecked(&n_rcu_torture_free));
91810 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91811 - atomic_read(&n_rcu_torture_mberror),
91812 + atomic_read_unchecked(&n_rcu_torture_mberror),
91813 n_rcu_torture_boost_ktrerror,
91814 n_rcu_torture_boost_rterror);
91815 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91816 @@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91817 n_barrier_successes,
91818 n_barrier_attempts,
91819 n_rcu_torture_barrier_error);
91820 - pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91821 + pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91822
91823 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91824 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91825 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91826 n_rcu_torture_barrier_error != 0 ||
91827 n_rcu_torture_boost_ktrerror != 0 ||
91828 n_rcu_torture_boost_rterror != 0 ||
91829 n_rcu_torture_boost_failure != 0 ||
91830 i > 1) {
91831 pr_cont("%s", "!!! ");
91832 - atomic_inc(&n_rcu_torture_error);
91833 + atomic_inc_unchecked(&n_rcu_torture_error);
91834 WARN_ON_ONCE(1);
91835 }
91836 pr_cont("Reader Pipe: ");
91837 @@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91838 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91839 pr_cont("Free-Block Circulation: ");
91840 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91841 - pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91842 + pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91843 }
91844 pr_cont("\n");
91845
91846 @@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91847
91848 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91849
91850 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91851 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91852 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91853 else if (torture_onoff_failures())
91854 rcu_torture_print_module_parms(cur_ops,
91855 @@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91856
91857 rcu_torture_current = NULL;
91858 rcu_torture_current_version = 0;
91859 - atomic_set(&n_rcu_torture_alloc, 0);
91860 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91861 - atomic_set(&n_rcu_torture_free, 0);
91862 - atomic_set(&n_rcu_torture_mberror, 0);
91863 - atomic_set(&n_rcu_torture_error, 0);
91864 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91865 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91866 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91867 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91868 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91869 n_rcu_torture_barrier_error = 0;
91870 n_rcu_torture_boost_ktrerror = 0;
91871 n_rcu_torture_boost_rterror = 0;
91872 n_rcu_torture_boost_failure = 0;
91873 n_rcu_torture_boosts = 0;
91874 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91875 - atomic_set(&rcu_torture_wcount[i], 0);
91876 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91877 for_each_possible_cpu(cpu) {
91878 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91879 per_cpu(rcu_torture_count, cpu)[i] = 0;
91880 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91881 index c0623fc..329c091 100644
91882 --- a/kernel/rcu/tiny.c
91883 +++ b/kernel/rcu/tiny.c
91884 @@ -42,7 +42,7 @@
91885 /* Forward declarations for tiny_plugin.h. */
91886 struct rcu_ctrlblk;
91887 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91888 -static void rcu_process_callbacks(struct softirq_action *unused);
91889 +static void rcu_process_callbacks(void);
91890 static void __call_rcu(struct rcu_head *head,
91891 void (*func)(struct rcu_head *rcu),
91892 struct rcu_ctrlblk *rcp);
91893 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91894 false));
91895 }
91896
91897 -static void rcu_process_callbacks(struct softirq_action *unused)
91898 +static __latent_entropy void rcu_process_callbacks(void)
91899 {
91900 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91901 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91902 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91903 index 858c565..7efd915 100644
91904 --- a/kernel/rcu/tiny_plugin.h
91905 +++ b/kernel/rcu/tiny_plugin.h
91906 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91907 dump_stack();
91908 }
91909 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91910 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91911 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91912 3 * rcu_jiffies_till_stall_check() + 3;
91913 else if (ULONG_CMP_GE(j, js))
91914 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91915 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91916 }
91917
91918 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91919 {
91920 rcp->ticks_this_gp = 0;
91921 rcp->gp_start = jiffies;
91922 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91923 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91924 }
91925
91926 static void check_cpu_stalls(void)
91927 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91928 index 9815447..2cdf92a 100644
91929 --- a/kernel/rcu/tree.c
91930 +++ b/kernel/rcu/tree.c
91931 @@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91932 */
91933 rdtp = this_cpu_ptr(&rcu_dynticks);
91934 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91935 - atomic_add(2, &rdtp->dynticks); /* QS. */
91936 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91937 smp_mb__after_atomic(); /* Later stuff after QS. */
91938 break;
91939 }
91940 @@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91941 rcu_prepare_for_idle(smp_processor_id());
91942 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91943 smp_mb__before_atomic(); /* See above. */
91944 - atomic_inc(&rdtp->dynticks);
91945 + atomic_inc_unchecked(&rdtp->dynticks);
91946 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91947 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91948 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91949 rcu_dynticks_task_enter();
91950
91951 /*
91952 @@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91953 {
91954 rcu_dynticks_task_exit();
91955 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91956 - atomic_inc(&rdtp->dynticks);
91957 + atomic_inc_unchecked(&rdtp->dynticks);
91958 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91959 smp_mb__after_atomic(); /* See above. */
91960 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91961 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91962 rcu_cleanup_after_idle(smp_processor_id());
91963 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91964 if (!user && !is_idle_task(current)) {
91965 @@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91966 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91967
91968 if (rdtp->dynticks_nmi_nesting == 0 &&
91969 - (atomic_read(&rdtp->dynticks) & 0x1))
91970 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91971 return;
91972 rdtp->dynticks_nmi_nesting++;
91973 smp_mb__before_atomic(); /* Force delay from prior write. */
91974 - atomic_inc(&rdtp->dynticks);
91975 + atomic_inc_unchecked(&rdtp->dynticks);
91976 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91977 smp_mb__after_atomic(); /* See above. */
91978 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91979 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91980 }
91981
91982 /**
91983 @@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91984 return;
91985 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91986 smp_mb__before_atomic(); /* See above. */
91987 - atomic_inc(&rdtp->dynticks);
91988 + atomic_inc_unchecked(&rdtp->dynticks);
91989 smp_mb__after_atomic(); /* Force delay to next write. */
91990 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91991 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91992 }
91993
91994 /**
91995 @@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91996 */
91997 bool notrace __rcu_is_watching(void)
91998 {
91999 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92000 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92001 }
92002
92003 /**
92004 @@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92005 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92006 bool *isidle, unsigned long *maxj)
92007 {
92008 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92009 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92010 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92011 if ((rdp->dynticks_snap & 0x1) == 0) {
92012 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92013 @@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92014 int *rcrmp;
92015 unsigned int snap;
92016
92017 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92018 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92019 snap = (unsigned int)rdp->dynticks_snap;
92020
92021 /*
92022 @@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92023 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92024 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92025 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92026 - ACCESS_ONCE(rdp->cond_resched_completed) =
92027 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92028 ACCESS_ONCE(rdp->mynode->completed);
92029 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92030 - ACCESS_ONCE(*rcrmp) =
92031 + ACCESS_ONCE_RW(*rcrmp) =
92032 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92033 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92034 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92035 @@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92036 rsp->gp_start = j;
92037 smp_wmb(); /* Record start time before stall time. */
92038 j1 = rcu_jiffies_till_stall_check();
92039 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92040 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92041 rsp->jiffies_resched = j + j1 / 2;
92042 }
92043
92044 @@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92045 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92046 return;
92047 }
92048 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92049 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92050 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92051
92052 /*
92053 @@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92054
92055 raw_spin_lock_irqsave(&rnp->lock, flags);
92056 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92057 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92058 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92059 3 * rcu_jiffies_till_stall_check() + 3;
92060 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92061
92062 @@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
92063 struct rcu_state *rsp;
92064
92065 for_each_rcu_flavor(rsp)
92066 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92067 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92068 }
92069
92070 /*
92071 @@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92072 raw_spin_unlock_irq(&rnp->lock);
92073 return 0;
92074 }
92075 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92076 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92077
92078 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92079 /*
92080 @@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92081 rdp = this_cpu_ptr(rsp->rda);
92082 rcu_preempt_check_blocked_tasks(rnp);
92083 rnp->qsmask = rnp->qsmaskinit;
92084 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92085 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92086 WARN_ON_ONCE(rnp->completed != rsp->completed);
92087 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92088 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92089 if (rnp == rdp->mynode)
92090 (void)__note_gp_changes(rsp, rnp, rdp);
92091 rcu_preempt_boost_start_gp(rnp);
92092 @@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92093 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92094 raw_spin_lock_irq(&rnp->lock);
92095 smp_mb__after_unlock_lock();
92096 - ACCESS_ONCE(rsp->gp_flags) =
92097 + ACCESS_ONCE_RW(rsp->gp_flags) =
92098 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
92099 raw_spin_unlock_irq(&rnp->lock);
92100 }
92101 @@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92102 rcu_for_each_node_breadth_first(rsp, rnp) {
92103 raw_spin_lock_irq(&rnp->lock);
92104 smp_mb__after_unlock_lock();
92105 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92106 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92107 rdp = this_cpu_ptr(rsp->rda);
92108 if (rnp == rdp->mynode)
92109 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92110 @@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92111 rcu_nocb_gp_set(rnp, nocb);
92112
92113 /* Declare grace period done. */
92114 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92115 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92116 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92117 rsp->fqs_state = RCU_GP_IDLE;
92118 rdp = this_cpu_ptr(rsp->rda);
92119 /* Advance CBs to reduce false positives below. */
92120 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92121 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92122 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92123 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92124 trace_rcu_grace_period(rsp->name,
92125 ACCESS_ONCE(rsp->gpnum),
92126 TPS("newreq"));
92127 @@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92128 */
92129 return false;
92130 }
92131 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92132 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92133 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92134 TPS("newreq"));
92135
92136 @@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92137 rsp->qlen += rdp->qlen;
92138 rdp->n_cbs_orphaned += rdp->qlen;
92139 rdp->qlen_lazy = 0;
92140 - ACCESS_ONCE(rdp->qlen) = 0;
92141 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92142 }
92143
92144 /*
92145 @@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92146 }
92147 smp_mb(); /* List handling before counting for rcu_barrier(). */
92148 rdp->qlen_lazy -= count_lazy;
92149 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92150 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92151 rdp->n_cbs_invoked += count;
92152
92153 /* Reinstate batch limit if we have worked down the excess. */
92154 @@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92155 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92156 return; /* Someone beat us to it. */
92157 }
92158 - ACCESS_ONCE(rsp->gp_flags) =
92159 + ACCESS_ONCE_RW(rsp->gp_flags) =
92160 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
92161 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92162 rcu_gp_kthread_wake(rsp);
92163 @@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92164 /*
92165 * Do RCU core processing for the current CPU.
92166 */
92167 -static void rcu_process_callbacks(struct softirq_action *unused)
92168 +static void rcu_process_callbacks(void)
92169 {
92170 struct rcu_state *rsp;
92171
92172 @@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92173 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92174 if (debug_rcu_head_queue(head)) {
92175 /* Probable double call_rcu(), so leak the callback. */
92176 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92177 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92178 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92179 return;
92180 }
92181 @@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92182 local_irq_restore(flags);
92183 return;
92184 }
92185 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92186 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92187 if (lazy)
92188 rdp->qlen_lazy++;
92189 else
92190 @@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
92191 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92192 * course be required on a 64-bit system.
92193 */
92194 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92195 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92196 (ulong)atomic_long_read(&rsp->expedited_done) +
92197 ULONG_MAX / 8)) {
92198 synchronize_sched();
92199 - atomic_long_inc(&rsp->expedited_wrap);
92200 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92201 return;
92202 }
92203
92204 @@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
92205 * Take a ticket. Note that atomic_inc_return() implies a
92206 * full memory barrier.
92207 */
92208 - snap = atomic_long_inc_return(&rsp->expedited_start);
92209 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92210 firstsnap = snap;
92211 if (!try_get_online_cpus()) {
92212 /* CPU hotplug operation in flight, fall back to normal GP. */
92213 wait_rcu_gp(call_rcu_sched);
92214 - atomic_long_inc(&rsp->expedited_normal);
92215 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92216 return;
92217 }
92218 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92219 @@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
92220 synchronize_sched_expedited_cpu_stop,
92221 NULL) == -EAGAIN) {
92222 put_online_cpus();
92223 - atomic_long_inc(&rsp->expedited_tryfail);
92224 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92225
92226 /* Check to see if someone else did our work for us. */
92227 s = atomic_long_read(&rsp->expedited_done);
92228 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92229 /* ensure test happens before caller kfree */
92230 smp_mb__before_atomic(); /* ^^^ */
92231 - atomic_long_inc(&rsp->expedited_workdone1);
92232 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92233 return;
92234 }
92235
92236 @@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
92237 udelay(trycount * num_online_cpus());
92238 } else {
92239 wait_rcu_gp(call_rcu_sched);
92240 - atomic_long_inc(&rsp->expedited_normal);
92241 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92242 return;
92243 }
92244
92245 @@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
92246 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92247 /* ensure test happens before caller kfree */
92248 smp_mb__before_atomic(); /* ^^^ */
92249 - atomic_long_inc(&rsp->expedited_workdone2);
92250 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92251 return;
92252 }
92253
92254 @@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
92255 if (!try_get_online_cpus()) {
92256 /* CPU hotplug operation in flight, use normal GP. */
92257 wait_rcu_gp(call_rcu_sched);
92258 - atomic_long_inc(&rsp->expedited_normal);
92259 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92260 return;
92261 }
92262 - snap = atomic_long_read(&rsp->expedited_start);
92263 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92264 smp_mb(); /* ensure read is before try_stop_cpus(). */
92265 }
92266 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92267 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92268
92269 /*
92270 * Everyone up to our most recent fetch is covered by our grace
92271 @@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
92272 * than we did already did their update.
92273 */
92274 do {
92275 - atomic_long_inc(&rsp->expedited_done_tries);
92276 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92277 s = atomic_long_read(&rsp->expedited_done);
92278 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92279 /* ensure test happens before caller kfree */
92280 smp_mb__before_atomic(); /* ^^^ */
92281 - atomic_long_inc(&rsp->expedited_done_lost);
92282 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92283 break;
92284 }
92285 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92286 - atomic_long_inc(&rsp->expedited_done_exit);
92287 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92288
92289 put_online_cpus();
92290 }
92291 @@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92292 * ACCESS_ONCE() to prevent the compiler from speculating
92293 * the increment to precede the early-exit check.
92294 */
92295 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92296 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92297 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92298 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92299 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92300 @@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92301
92302 /* Increment ->n_barrier_done to prevent duplicate work. */
92303 smp_mb(); /* Keep increment after above mechanism. */
92304 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92305 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92306 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92307 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92308 smp_mb(); /* Keep increment before caller's subsequent code. */
92309 @@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92310 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92311 init_callback_list(rdp);
92312 rdp->qlen_lazy = 0;
92313 - ACCESS_ONCE(rdp->qlen) = 0;
92314 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92315 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92316 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92317 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92318 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92319 rdp->cpu = cpu;
92320 rdp->rsp = rsp;
92321 rcu_boot_init_nocb_percpu_data(rdp);
92322 @@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92323 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92324 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92325 rcu_sysidle_init_percpu_data(rdp->dynticks);
92326 - atomic_set(&rdp->dynticks->dynticks,
92327 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92328 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92329 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92330 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92331
92332 /* Add CPU to rcu_node bitmasks. */
92333 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92334 index bbdc45d..c882ccb 100644
92335 --- a/kernel/rcu/tree.h
92336 +++ b/kernel/rcu/tree.h
92337 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92338 long long dynticks_nesting; /* Track irq/process nesting level. */
92339 /* Process level is worth LLONG_MAX/2. */
92340 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92341 - atomic_t dynticks; /* Even value for idle, else odd. */
92342 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92343 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92344 long long dynticks_idle_nesting;
92345 /* irq/process nesting level from idle. */
92346 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92347 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92348 /* "Idle" excludes userspace execution. */
92349 unsigned long dynticks_idle_jiffies;
92350 /* End of last non-NMI non-idle period. */
92351 @@ -466,17 +466,17 @@ struct rcu_state {
92352 /* _rcu_barrier(). */
92353 /* End of fields guarded by barrier_mutex. */
92354
92355 - atomic_long_t expedited_start; /* Starting ticket. */
92356 - atomic_long_t expedited_done; /* Done ticket. */
92357 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92358 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92359 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92360 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92361 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92362 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92363 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92364 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92365 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92366 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92367 + atomic_long_t expedited_done; /* Done ticket. */
92368 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92369 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92370 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92371 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92372 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92373 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92374 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92375 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92376 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92377
92378 unsigned long jiffies_force_qs; /* Time at which to invoke */
92379 /* force_quiescent_state(). */
92380 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92381 index c1d7f27..a64bf49 100644
92382 --- a/kernel/rcu/tree_plugin.h
92383 +++ b/kernel/rcu/tree_plugin.h
92384 @@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92385 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92386 {
92387 return !rcu_preempted_readers_exp(rnp) &&
92388 - ACCESS_ONCE(rnp->expmask) == 0;
92389 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92390 }
92391
92392 /*
92393 @@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92394
92395 /* Clean up and exit. */
92396 smp_mb(); /* ensure expedited GP seen before counter increment. */
92397 - ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92398 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92399 sync_rcu_preempt_exp_count + 1;
92400 unlock_mb_ret:
92401 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92402 @@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92403 free_cpumask_var(cm);
92404 }
92405
92406 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92407 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92408 .store = &rcu_cpu_kthread_task,
92409 .thread_should_run = rcu_cpu_kthread_should_run,
92410 .thread_fn = rcu_cpu_kthread,
92411 @@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92412 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92413 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92414 cpu, ticks_value, ticks_title,
92415 - atomic_read(&rdtp->dynticks) & 0xfff,
92416 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92417 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92418 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92419 fast_no_hz);
92420 @@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92421 return;
92422 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92423 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92424 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92425 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92426 wake_up(&rdp_leader->nocb_wq);
92427 }
92428 }
92429 @@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92430
92431 /* Enqueue the callback on the nocb list and update counts. */
92432 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92433 - ACCESS_ONCE(*old_rhpp) = rhp;
92434 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92435 atomic_long_add(rhcount, &rdp->nocb_q_count);
92436 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92437 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92438 @@ -2286,7 +2286,7 @@ wait_again:
92439 continue; /* No CBs here, try next follower. */
92440
92441 /* Move callbacks to wait-for-GP list, which is empty. */
92442 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92443 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92444 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92445 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92446 rdp->nocb_gp_count_lazy =
92447 @@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92448 list = ACCESS_ONCE(rdp->nocb_follower_head);
92449 BUG_ON(!list);
92450 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92451 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92452 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92453 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92454 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92455 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92456 @@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92457 list = next;
92458 }
92459 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92460 - ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92461 - ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92462 + ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92463 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92464 rdp->nocb_p_count_lazy - cl;
92465 rdp->n_nocbs_invoked += c;
92466 }
92467 @@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92468 if (!rcu_nocb_need_deferred_wakeup(rdp))
92469 return;
92470 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92471 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92472 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92473 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92474 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92475 }
92476 @@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92477 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92478 "rcuo%c/%d", rsp->abbr, cpu);
92479 BUG_ON(IS_ERR(t));
92480 - ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92481 + ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92482 }
92483
92484 /*
92485 @@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92486
92487 /* Record start of fully idle period. */
92488 j = jiffies;
92489 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92490 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92491 smp_mb__before_atomic();
92492 - atomic_inc(&rdtp->dynticks_idle);
92493 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92494 smp_mb__after_atomic();
92495 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92496 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92497 }
92498
92499 /*
92500 @@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92501
92502 /* Record end of idle period. */
92503 smp_mb__before_atomic();
92504 - atomic_inc(&rdtp->dynticks_idle);
92505 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92506 smp_mb__after_atomic();
92507 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92508 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92509
92510 /*
92511 * If we are the timekeeping CPU, we are permitted to be non-idle
92512 @@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92513 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92514
92515 /* Pick up current idle and NMI-nesting counter and check. */
92516 - cur = atomic_read(&rdtp->dynticks_idle);
92517 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92518 if (cur & 0x1) {
92519 *isidle = false; /* We are not idle! */
92520 return;
92521 @@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92522 case RCU_SYSIDLE_NOT:
92523
92524 /* First time all are idle, so note a short idle period. */
92525 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92526 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92527 break;
92528
92529 case RCU_SYSIDLE_SHORT:
92530 @@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92531 {
92532 smp_mb();
92533 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92534 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92535 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92536 }
92537
92538 /*
92539 @@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92540 smp_mb(); /* grace period precedes setting inuse. */
92541
92542 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92543 - ACCESS_ONCE(rshp->inuse) = 0;
92544 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92545 }
92546
92547 /*
92548 @@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92549 static void rcu_dynticks_task_enter(void)
92550 {
92551 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92552 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92553 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92554 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92555 }
92556
92557 @@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92558 static void rcu_dynticks_task_exit(void)
92559 {
92560 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92561 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92562 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92563 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92564 }
92565 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92566 index 5cdc62e..cc52e88 100644
92567 --- a/kernel/rcu/tree_trace.c
92568 +++ b/kernel/rcu/tree_trace.c
92569 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92570 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92571 rdp->passed_quiesce, rdp->qs_pending);
92572 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92573 - atomic_read(&rdp->dynticks->dynticks),
92574 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92575 rdp->dynticks->dynticks_nesting,
92576 rdp->dynticks->dynticks_nmi_nesting,
92577 rdp->dynticks_fqs);
92578 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92579 struct rcu_state *rsp = (struct rcu_state *)m->private;
92580
92581 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",
92582 - atomic_long_read(&rsp->expedited_start),
92583 + atomic_long_read_unchecked(&rsp->expedited_start),
92584 atomic_long_read(&rsp->expedited_done),
92585 - atomic_long_read(&rsp->expedited_wrap),
92586 - atomic_long_read(&rsp->expedited_tryfail),
92587 - atomic_long_read(&rsp->expedited_workdone1),
92588 - atomic_long_read(&rsp->expedited_workdone2),
92589 - atomic_long_read(&rsp->expedited_normal),
92590 - atomic_long_read(&rsp->expedited_stoppedcpus),
92591 - atomic_long_read(&rsp->expedited_done_tries),
92592 - atomic_long_read(&rsp->expedited_done_lost),
92593 - atomic_long_read(&rsp->expedited_done_exit));
92594 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92595 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92596 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92597 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92598 + atomic_long_read_unchecked(&rsp->expedited_normal),
92599 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92600 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92601 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92602 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92603 return 0;
92604 }
92605
92606 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92607 index 3ef8ba5..8c5ebfb6 100644
92608 --- a/kernel/rcu/update.c
92609 +++ b/kernel/rcu/update.c
92610 @@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92611 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92612 */
92613 if (till_stall_check < 3) {
92614 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92615 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92616 till_stall_check = 3;
92617 } else if (till_stall_check > 300) {
92618 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92619 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92620 till_stall_check = 300;
92621 }
92622 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92623 @@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92624 !ACCESS_ONCE(t->on_rq) ||
92625 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92626 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92627 - ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92628 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92629 list_del_init(&t->rcu_tasks_holdout_list);
92630 put_task_struct(t);
92631 return;
92632 @@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92633 !is_idle_task(t)) {
92634 get_task_struct(t);
92635 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92636 - ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92637 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92638 list_add(&t->rcu_tasks_holdout_list,
92639 &rcu_tasks_holdouts);
92640 }
92641 @@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92642 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92643 BUG_ON(IS_ERR(t));
92644 smp_mb(); /* Ensure others see full kthread. */
92645 - ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92646 + ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92647 mutex_unlock(&rcu_tasks_kthread_mutex);
92648 }
92649
92650 diff --git a/kernel/resource.c b/kernel/resource.c
92651 index 0bcebff..e7cd5b2 100644
92652 --- a/kernel/resource.c
92653 +++ b/kernel/resource.c
92654 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92655
92656 static int __init ioresources_init(void)
92657 {
92658 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92659 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92660 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92661 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92662 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92663 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92664 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92665 +#endif
92666 +#else
92667 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92668 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92669 +#endif
92670 return 0;
92671 }
92672 __initcall(ioresources_init);
92673 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92674 index 8a2e230..6020954 100644
92675 --- a/kernel/sched/auto_group.c
92676 +++ b/kernel/sched/auto_group.c
92677 @@ -11,7 +11,7 @@
92678
92679 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92680 static struct autogroup autogroup_default;
92681 -static atomic_t autogroup_seq_nr;
92682 +static atomic_unchecked_t autogroup_seq_nr;
92683
92684 void __init autogroup_init(struct task_struct *init_task)
92685 {
92686 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92687
92688 kref_init(&ag->kref);
92689 init_rwsem(&ag->lock);
92690 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92691 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92692 ag->tg = tg;
92693 #ifdef CONFIG_RT_GROUP_SCHED
92694 /*
92695 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92696 index a63f4dc..349bbb0 100644
92697 --- a/kernel/sched/completion.c
92698 +++ b/kernel/sched/completion.c
92699 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92700 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92701 * or number of jiffies left till timeout) if completed.
92702 */
92703 -long __sched
92704 +long __sched __intentional_overflow(-1)
92705 wait_for_completion_interruptible_timeout(struct completion *x,
92706 unsigned long timeout)
92707 {
92708 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92709 *
92710 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92711 */
92712 -int __sched wait_for_completion_killable(struct completion *x)
92713 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92714 {
92715 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92716 if (t == -ERESTARTSYS)
92717 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92718 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92719 * or number of jiffies left till timeout) if completed.
92720 */
92721 -long __sched
92722 +long __sched __intentional_overflow(-1)
92723 wait_for_completion_killable_timeout(struct completion *x,
92724 unsigned long timeout)
92725 {
92726 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92727 index efdca2f..e361dfb 100644
92728 --- a/kernel/sched/core.c
92729 +++ b/kernel/sched/core.c
92730 @@ -1890,7 +1890,7 @@ void set_numabalancing_state(bool enabled)
92731 int sysctl_numa_balancing(struct ctl_table *table, int write,
92732 void __user *buffer, size_t *lenp, loff_t *ppos)
92733 {
92734 - struct ctl_table t;
92735 + ctl_table_no_const t;
92736 int err;
92737 int state = numabalancing_enabled;
92738
92739 @@ -2353,8 +2353,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92740 next->active_mm = oldmm;
92741 atomic_inc(&oldmm->mm_count);
92742 enter_lazy_tlb(oldmm, next);
92743 - } else
92744 + } else {
92745 switch_mm(oldmm, mm, next);
92746 + populate_stack();
92747 + }
92748
92749 if (!prev->mm) {
92750 prev->active_mm = NULL;
92751 @@ -3165,6 +3167,8 @@ int can_nice(const struct task_struct *p, const int nice)
92752 /* convert nice value [19,-20] to rlimit style value [1,40] */
92753 int nice_rlim = nice_to_rlimit(nice);
92754
92755 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92756 +
92757 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92758 capable(CAP_SYS_NICE));
92759 }
92760 @@ -3191,7 +3195,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92761 nice = task_nice(current) + increment;
92762
92763 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92764 - if (increment < 0 && !can_nice(current, nice))
92765 + if (increment < 0 && (!can_nice(current, nice) ||
92766 + gr_handle_chroot_nice()))
92767 return -EPERM;
92768
92769 retval = security_task_setnice(current, nice);
92770 @@ -3470,6 +3475,7 @@ recheck:
92771 if (policy != p->policy && !rlim_rtprio)
92772 return -EPERM;
92773
92774 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92775 /* can't increase priority */
92776 if (attr->sched_priority > p->rt_priority &&
92777 attr->sched_priority > rlim_rtprio)
92778 @@ -4890,6 +4896,7 @@ void idle_task_exit(void)
92779
92780 if (mm != &init_mm) {
92781 switch_mm(mm, &init_mm, current);
92782 + populate_stack();
92783 finish_arch_post_lock_switch();
92784 }
92785 mmdrop(mm);
92786 @@ -4985,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92787
92788 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92789
92790 -static struct ctl_table sd_ctl_dir[] = {
92791 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92792 {
92793 .procname = "sched_domain",
92794 .mode = 0555,
92795 @@ -5002,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
92796 {}
92797 };
92798
92799 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92800 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92801 {
92802 - struct ctl_table *entry =
92803 + ctl_table_no_const *entry =
92804 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92805
92806 return entry;
92807 }
92808
92809 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92810 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92811 {
92812 - struct ctl_table *entry;
92813 + ctl_table_no_const *entry;
92814
92815 /*
92816 * In the intermediate directories, both the child directory and
92817 @@ -5020,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92818 * will always be set. In the lowest directory the names are
92819 * static strings and all have proc handlers.
92820 */
92821 - for (entry = *tablep; entry->mode; entry++) {
92822 - if (entry->child)
92823 - sd_free_ctl_entry(&entry->child);
92824 + for (entry = tablep; entry->mode; entry++) {
92825 + if (entry->child) {
92826 + sd_free_ctl_entry(entry->child);
92827 + pax_open_kernel();
92828 + entry->child = NULL;
92829 + pax_close_kernel();
92830 + }
92831 if (entry->proc_handler == NULL)
92832 kfree(entry->procname);
92833 }
92834
92835 - kfree(*tablep);
92836 - *tablep = NULL;
92837 + kfree(tablep);
92838 }
92839
92840 static int min_load_idx = 0;
92841 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92842
92843 static void
92844 -set_table_entry(struct ctl_table *entry,
92845 +set_table_entry(ctl_table_no_const *entry,
92846 const char *procname, void *data, int maxlen,
92847 umode_t mode, proc_handler *proc_handler,
92848 bool load_idx)
92849 @@ -5055,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
92850 static struct ctl_table *
92851 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92852 {
92853 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92854 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92855
92856 if (table == NULL)
92857 return NULL;
92858 @@ -5093,9 +5103,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92859 return table;
92860 }
92861
92862 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92863 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92864 {
92865 - struct ctl_table *entry, *table;
92866 + ctl_table_no_const *entry, *table;
92867 struct sched_domain *sd;
92868 int domain_num = 0, i;
92869 char buf[32];
92870 @@ -5122,11 +5132,13 @@ static struct ctl_table_header *sd_sysctl_header;
92871 static void register_sched_domain_sysctl(void)
92872 {
92873 int i, cpu_num = num_possible_cpus();
92874 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92875 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92876 char buf[32];
92877
92878 WARN_ON(sd_ctl_dir[0].child);
92879 + pax_open_kernel();
92880 sd_ctl_dir[0].child = entry;
92881 + pax_close_kernel();
92882
92883 if (entry == NULL)
92884 return;
92885 @@ -5149,8 +5161,12 @@ static void unregister_sched_domain_sysctl(void)
92886 if (sd_sysctl_header)
92887 unregister_sysctl_table(sd_sysctl_header);
92888 sd_sysctl_header = NULL;
92889 - if (sd_ctl_dir[0].child)
92890 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
92891 + if (sd_ctl_dir[0].child) {
92892 + sd_free_ctl_entry(sd_ctl_dir[0].child);
92893 + pax_open_kernel();
92894 + sd_ctl_dir[0].child = NULL;
92895 + pax_close_kernel();
92896 + }
92897 }
92898 #else
92899 static void register_sched_domain_sysctl(void)
92900 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92901 index ef2b104..69961f6 100644
92902 --- a/kernel/sched/fair.c
92903 +++ b/kernel/sched/fair.c
92904 @@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92905
92906 static void reset_ptenuma_scan(struct task_struct *p)
92907 {
92908 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
92909 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92910 p->mm->numa_scan_offset = 0;
92911 }
92912
92913 @@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92914 * run_rebalance_domains is triggered when needed from the scheduler tick.
92915 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92916 */
92917 -static void run_rebalance_domains(struct softirq_action *h)
92918 +static __latent_entropy void run_rebalance_domains(void)
92919 {
92920 struct rq *this_rq = this_rq();
92921 enum cpu_idle_type idle = this_rq->idle_balance ?
92922 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92923 index 2df8ef0..aae070f 100644
92924 --- a/kernel/sched/sched.h
92925 +++ b/kernel/sched/sched.h
92926 @@ -1140,7 +1140,7 @@ struct sched_class {
92927 #ifdef CONFIG_FAIR_GROUP_SCHED
92928 void (*task_move_group) (struct task_struct *p, int on_rq);
92929 #endif
92930 -};
92931 +} __do_const;
92932
92933 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92934 {
92935 diff --git a/kernel/signal.c b/kernel/signal.c
92936 index 8f0876f..1153a5a 100644
92937 --- a/kernel/signal.c
92938 +++ b/kernel/signal.c
92939 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92940
92941 int print_fatal_signals __read_mostly;
92942
92943 -static void __user *sig_handler(struct task_struct *t, int sig)
92944 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
92945 {
92946 return t->sighand->action[sig - 1].sa.sa_handler;
92947 }
92948
92949 -static int sig_handler_ignored(void __user *handler, int sig)
92950 +static int sig_handler_ignored(__sighandler_t handler, int sig)
92951 {
92952 /* Is it explicitly or implicitly ignored? */
92953 return handler == SIG_IGN ||
92954 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92955
92956 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92957 {
92958 - void __user *handler;
92959 + __sighandler_t handler;
92960
92961 handler = sig_handler(t, sig);
92962
92963 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92964 atomic_inc(&user->sigpending);
92965 rcu_read_unlock();
92966
92967 + if (!override_rlimit)
92968 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92969 +
92970 if (override_rlimit ||
92971 atomic_read(&user->sigpending) <=
92972 task_rlimit(t, RLIMIT_SIGPENDING)) {
92973 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92974
92975 int unhandled_signal(struct task_struct *tsk, int sig)
92976 {
92977 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92978 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92979 if (is_global_init(tsk))
92980 return 1;
92981 if (handler != SIG_IGN && handler != SIG_DFL)
92982 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92983 }
92984 }
92985
92986 + /* allow glibc communication via tgkill to other threads in our
92987 + thread group */
92988 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92989 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92990 + && gr_handle_signal(t, sig))
92991 + return -EPERM;
92992 +
92993 return security_task_kill(t, info, sig, 0);
92994 }
92995
92996 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92997 return send_signal(sig, info, p, 1);
92998 }
92999
93000 -static int
93001 +int
93002 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93003 {
93004 return send_signal(sig, info, t, 0);
93005 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93006 unsigned long int flags;
93007 int ret, blocked, ignored;
93008 struct k_sigaction *action;
93009 + int is_unhandled = 0;
93010
93011 spin_lock_irqsave(&t->sighand->siglock, flags);
93012 action = &t->sighand->action[sig-1];
93013 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93014 }
93015 if (action->sa.sa_handler == SIG_DFL)
93016 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93017 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93018 + is_unhandled = 1;
93019 ret = specific_send_sig_info(sig, info, t);
93020 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93021
93022 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93023 + normal operation */
93024 + if (is_unhandled) {
93025 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93026 + gr_handle_crash(t, sig);
93027 + }
93028 +
93029 return ret;
93030 }
93031
93032 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93033 ret = check_kill_permission(sig, info, p);
93034 rcu_read_unlock();
93035
93036 - if (!ret && sig)
93037 + if (!ret && sig) {
93038 ret = do_send_sig_info(sig, info, p, true);
93039 + if (!ret)
93040 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93041 + }
93042
93043 return ret;
93044 }
93045 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93046 int error = -ESRCH;
93047
93048 rcu_read_lock();
93049 - p = find_task_by_vpid(pid);
93050 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93051 + /* allow glibc communication via tgkill to other threads in our
93052 + thread group */
93053 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93054 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93055 + p = find_task_by_vpid_unrestricted(pid);
93056 + else
93057 +#endif
93058 + p = find_task_by_vpid(pid);
93059 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93060 error = check_kill_permission(sig, info, p);
93061 /*
93062 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93063 }
93064 seg = get_fs();
93065 set_fs(KERNEL_DS);
93066 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93067 - (stack_t __force __user *) &uoss,
93068 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93069 + (stack_t __force_user *) &uoss,
93070 compat_user_stack_pointer());
93071 set_fs(seg);
93072 if (ret >= 0 && uoss_ptr) {
93073 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93074 index eb89e18..a4e6792 100644
93075 --- a/kernel/smpboot.c
93076 +++ b/kernel/smpboot.c
93077 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93078 }
93079 smpboot_unpark_thread(plug_thread, cpu);
93080 }
93081 - list_add(&plug_thread->list, &hotplug_threads);
93082 + pax_list_add(&plug_thread->list, &hotplug_threads);
93083 out:
93084 mutex_unlock(&smpboot_threads_lock);
93085 return ret;
93086 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93087 {
93088 get_online_cpus();
93089 mutex_lock(&smpboot_threads_lock);
93090 - list_del(&plug_thread->list);
93091 + pax_list_del(&plug_thread->list);
93092 smpboot_destroy_threads(plug_thread);
93093 mutex_unlock(&smpboot_threads_lock);
93094 put_online_cpus();
93095 diff --git a/kernel/softirq.c b/kernel/softirq.c
93096 index 0699add..d365ad8 100644
93097 --- a/kernel/softirq.c
93098 +++ b/kernel/softirq.c
93099 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93100 EXPORT_SYMBOL(irq_stat);
93101 #endif
93102
93103 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93104 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93105
93106 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93107
93108 @@ -266,7 +266,7 @@ restart:
93109 kstat_incr_softirqs_this_cpu(vec_nr);
93110
93111 trace_softirq_entry(vec_nr);
93112 - h->action(h);
93113 + h->action();
93114 trace_softirq_exit(vec_nr);
93115 if (unlikely(prev_count != preempt_count())) {
93116 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93117 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93118 or_softirq_pending(1UL << nr);
93119 }
93120
93121 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93122 +void __init open_softirq(int nr, void (*action)(void))
93123 {
93124 softirq_vec[nr].action = action;
93125 }
93126 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93127 }
93128 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93129
93130 -static void tasklet_action(struct softirq_action *a)
93131 +static void tasklet_action(void)
93132 {
93133 struct tasklet_struct *list;
93134
93135 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93136 }
93137 }
93138
93139 -static void tasklet_hi_action(struct softirq_action *a)
93140 +static __latent_entropy void tasklet_hi_action(void)
93141 {
93142 struct tasklet_struct *list;
93143
93144 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93145 .notifier_call = cpu_callback
93146 };
93147
93148 -static struct smp_hotplug_thread softirq_threads = {
93149 +static struct smp_hotplug_thread softirq_threads __read_only = {
93150 .store = &ksoftirqd,
93151 .thread_should_run = ksoftirqd_should_run,
93152 .thread_fn = run_ksoftirqd,
93153 diff --git a/kernel/sys.c b/kernel/sys.c
93154 index 1eaa2f0..d80d27c 100644
93155 --- a/kernel/sys.c
93156 +++ b/kernel/sys.c
93157 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93158 error = -EACCES;
93159 goto out;
93160 }
93161 +
93162 + if (gr_handle_chroot_setpriority(p, niceval)) {
93163 + error = -EACCES;
93164 + goto out;
93165 + }
93166 +
93167 no_nice = security_task_setnice(p, niceval);
93168 if (no_nice) {
93169 error = no_nice;
93170 @@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93171 goto error;
93172 }
93173
93174 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93175 + goto error;
93176 +
93177 + if (!gid_eq(new->gid, old->gid)) {
93178 + /* make sure we generate a learn log for what will
93179 + end up being a role transition after a full-learning
93180 + policy is generated
93181 + CAP_SETGID is required to perform a transition
93182 + we may not log a CAP_SETGID check above, e.g.
93183 + in the case where new rgid = old egid
93184 + */
93185 + gr_learn_cap(current, new, CAP_SETGID);
93186 + }
93187 +
93188 if (rgid != (gid_t) -1 ||
93189 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93190 new->sgid = new->egid;
93191 @@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93192 old = current_cred();
93193
93194 retval = -EPERM;
93195 +
93196 + if (gr_check_group_change(kgid, kgid, kgid))
93197 + goto error;
93198 +
93199 if (ns_capable(old->user_ns, CAP_SETGID))
93200 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93201 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93202 @@ -405,7 +429,7 @@ error:
93203 /*
93204 * change the user struct in a credentials set to match the new UID
93205 */
93206 -static int set_user(struct cred *new)
93207 +int set_user(struct cred *new)
93208 {
93209 struct user_struct *new_user;
93210
93211 @@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93212 goto error;
93213 }
93214
93215 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93216 + goto error;
93217 +
93218 if (!uid_eq(new->uid, old->uid)) {
93219 + /* make sure we generate a learn log for what will
93220 + end up being a role transition after a full-learning
93221 + policy is generated
93222 + CAP_SETUID is required to perform a transition
93223 + we may not log a CAP_SETUID check above, e.g.
93224 + in the case where new ruid = old euid
93225 + */
93226 + gr_learn_cap(current, new, CAP_SETUID);
93227 retval = set_user(new);
93228 if (retval < 0)
93229 goto error;
93230 @@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93231 old = current_cred();
93232
93233 retval = -EPERM;
93234 +
93235 + if (gr_check_crash_uid(kuid))
93236 + goto error;
93237 + if (gr_check_user_change(kuid, kuid, kuid))
93238 + goto error;
93239 +
93240 if (ns_capable(old->user_ns, CAP_SETUID)) {
93241 new->suid = new->uid = kuid;
93242 if (!uid_eq(kuid, old->uid)) {
93243 @@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93244 goto error;
93245 }
93246
93247 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93248 + goto error;
93249 +
93250 if (ruid != (uid_t) -1) {
93251 new->uid = kruid;
93252 if (!uid_eq(kruid, old->uid)) {
93253 @@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93254 goto error;
93255 }
93256
93257 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93258 + goto error;
93259 +
93260 if (rgid != (gid_t) -1)
93261 new->gid = krgid;
93262 if (egid != (gid_t) -1)
93263 @@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93264 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93265 ns_capable(old->user_ns, CAP_SETUID)) {
93266 if (!uid_eq(kuid, old->fsuid)) {
93267 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93268 + goto error;
93269 +
93270 new->fsuid = kuid;
93271 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93272 goto change_okay;
93273 }
93274 }
93275
93276 +error:
93277 abort_creds(new);
93278 return old_fsuid;
93279
93280 @@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93281 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93282 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93283 ns_capable(old->user_ns, CAP_SETGID)) {
93284 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93285 + goto error;
93286 +
93287 if (!gid_eq(kgid, old->fsgid)) {
93288 new->fsgid = kgid;
93289 goto change_okay;
93290 }
93291 }
93292
93293 +error:
93294 abort_creds(new);
93295 return old_fsgid;
93296
93297 @@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93298 return -EFAULT;
93299
93300 down_read(&uts_sem);
93301 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93302 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93303 __OLD_UTS_LEN);
93304 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93305 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93306 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93307 __OLD_UTS_LEN);
93308 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93309 - error |= __copy_to_user(&name->release, &utsname()->release,
93310 + error |= __copy_to_user(name->release, &utsname()->release,
93311 __OLD_UTS_LEN);
93312 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93313 - error |= __copy_to_user(&name->version, &utsname()->version,
93314 + error |= __copy_to_user(name->version, &utsname()->version,
93315 __OLD_UTS_LEN);
93316 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93317 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93318 + error |= __copy_to_user(name->machine, &utsname()->machine,
93319 __OLD_UTS_LEN);
93320 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93321 up_read(&uts_sem);
93322 @@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93323 */
93324 new_rlim->rlim_cur = 1;
93325 }
93326 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93327 + is changed to a lower value. Since tasks can be created by the same
93328 + user in between this limit change and an execve by this task, force
93329 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93330 + */
93331 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93332 + tsk->flags |= PF_NPROC_EXCEEDED;
93333 }
93334 if (!retval) {
93335 if (old_rlim)
93336 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93337 index 15f2511..181b356 100644
93338 --- a/kernel/sysctl.c
93339 +++ b/kernel/sysctl.c
93340 @@ -94,7 +94,6 @@
93341
93342
93343 #if defined(CONFIG_SYSCTL)
93344 -
93345 /* External variables not in a header file. */
93346 extern int max_threads;
93347 extern int suid_dumpable;
93348 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93349
93350 /* Constants used for minimum and maximum */
93351 #ifdef CONFIG_LOCKUP_DETECTOR
93352 -static int sixty = 60;
93353 +static int sixty __read_only = 60;
93354 #endif
93355
93356 -static int __maybe_unused neg_one = -1;
93357 +static int __maybe_unused neg_one __read_only = -1;
93358
93359 -static int zero;
93360 -static int __maybe_unused one = 1;
93361 -static int __maybe_unused two = 2;
93362 -static int __maybe_unused four = 4;
93363 -static unsigned long one_ul = 1;
93364 -static int one_hundred = 100;
93365 +static int zero __read_only = 0;
93366 +static int __maybe_unused one __read_only = 1;
93367 +static int __maybe_unused two __read_only = 2;
93368 +static int __maybe_unused three __read_only = 3;
93369 +static int __maybe_unused four __read_only = 4;
93370 +static unsigned long one_ul __read_only = 1;
93371 +static int one_hundred __read_only = 100;
93372 #ifdef CONFIG_PRINTK
93373 -static int ten_thousand = 10000;
93374 +static int ten_thousand __read_only = 10000;
93375 #endif
93376
93377 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93378 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93379 void __user *buffer, size_t *lenp, loff_t *ppos);
93380 #endif
93381
93382 -#ifdef CONFIG_PRINTK
93383 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93384 void __user *buffer, size_t *lenp, loff_t *ppos);
93385 -#endif
93386
93387 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93388 void __user *buffer, size_t *lenp, loff_t *ppos);
93389 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93390
93391 #endif
93392
93393 +extern struct ctl_table grsecurity_table[];
93394 +
93395 static struct ctl_table kern_table[];
93396 static struct ctl_table vm_table[];
93397 static struct ctl_table fs_table[];
93398 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93399 int sysctl_legacy_va_layout;
93400 #endif
93401
93402 +#ifdef CONFIG_PAX_SOFTMODE
93403 +static struct ctl_table pax_table[] = {
93404 + {
93405 + .procname = "softmode",
93406 + .data = &pax_softmode,
93407 + .maxlen = sizeof(unsigned int),
93408 + .mode = 0600,
93409 + .proc_handler = &proc_dointvec,
93410 + },
93411 +
93412 + { }
93413 +};
93414 +#endif
93415 +
93416 /* The default sysctl tables: */
93417
93418 static struct ctl_table sysctl_base_table[] = {
93419 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93420 #endif
93421
93422 static struct ctl_table kern_table[] = {
93423 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93424 + {
93425 + .procname = "grsecurity",
93426 + .mode = 0500,
93427 + .child = grsecurity_table,
93428 + },
93429 +#endif
93430 +
93431 +#ifdef CONFIG_PAX_SOFTMODE
93432 + {
93433 + .procname = "pax",
93434 + .mode = 0500,
93435 + .child = pax_table,
93436 + },
93437 +#endif
93438 +
93439 {
93440 .procname = "sched_child_runs_first",
93441 .data = &sysctl_sched_child_runs_first,
93442 @@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93443 .data = &modprobe_path,
93444 .maxlen = KMOD_PATH_LEN,
93445 .mode = 0644,
93446 - .proc_handler = proc_dostring,
93447 + .proc_handler = proc_dostring_modpriv,
93448 },
93449 {
93450 .procname = "modules_disabled",
93451 @@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93452 .extra1 = &zero,
93453 .extra2 = &one,
93454 },
93455 +#endif
93456 {
93457 .procname = "kptr_restrict",
93458 .data = &kptr_restrict,
93459 .maxlen = sizeof(int),
93460 .mode = 0644,
93461 .proc_handler = proc_dointvec_minmax_sysadmin,
93462 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93463 + .extra1 = &two,
93464 +#else
93465 .extra1 = &zero,
93466 +#endif
93467 .extra2 = &two,
93468 },
93469 -#endif
93470 {
93471 .procname = "ngroups_max",
93472 .data = &ngroups_max,
93473 @@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93474 */
93475 {
93476 .procname = "perf_event_paranoid",
93477 - .data = &sysctl_perf_event_paranoid,
93478 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93479 + .data = &sysctl_perf_event_legitimately_concerned,
93480 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93481 .mode = 0644,
93482 - .proc_handler = proc_dointvec,
93483 + /* go ahead, be a hero */
93484 + .proc_handler = proc_dointvec_minmax_sysadmin,
93485 + .extra1 = &neg_one,
93486 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93487 + .extra2 = &three,
93488 +#else
93489 + .extra2 = &two,
93490 +#endif
93491 },
93492 {
93493 .procname = "perf_event_mlock_kb",
93494 @@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93495 .proc_handler = proc_dointvec_minmax,
93496 .extra1 = &zero,
93497 },
93498 + {
93499 + .procname = "heap_stack_gap",
93500 + .data = &sysctl_heap_stack_gap,
93501 + .maxlen = sizeof(sysctl_heap_stack_gap),
93502 + .mode = 0644,
93503 + .proc_handler = proc_doulongvec_minmax,
93504 + },
93505 #else
93506 {
93507 .procname = "nr_trim_pages",
93508 @@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93509 (char __user *)buffer, lenp, ppos);
93510 }
93511
93512 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93513 + void __user *buffer, size_t *lenp, loff_t *ppos)
93514 +{
93515 + if (write && !capable(CAP_SYS_MODULE))
93516 + return -EPERM;
93517 +
93518 + return _proc_do_string(table->data, table->maxlen, write,
93519 + buffer, lenp, ppos);
93520 +}
93521 +
93522 static size_t proc_skip_spaces(char **buf)
93523 {
93524 size_t ret;
93525 @@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93526 len = strlen(tmp);
93527 if (len > *size)
93528 len = *size;
93529 + if (len > sizeof(tmp))
93530 + len = sizeof(tmp);
93531 if (copy_to_user(*buf, tmp, len))
93532 return -EFAULT;
93533 *size -= len;
93534 @@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93535 static int proc_taint(struct ctl_table *table, int write,
93536 void __user *buffer, size_t *lenp, loff_t *ppos)
93537 {
93538 - struct ctl_table t;
93539 + ctl_table_no_const t;
93540 unsigned long tmptaint = get_taint();
93541 int err;
93542
93543 @@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93544 return err;
93545 }
93546
93547 -#ifdef CONFIG_PRINTK
93548 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93549 void __user *buffer, size_t *lenp, loff_t *ppos)
93550 {
93551 @@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93552
93553 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93554 }
93555 -#endif
93556
93557 struct do_proc_dointvec_minmax_conv_param {
93558 int *min;
93559 @@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93560 return -ENOSYS;
93561 }
93562
93563 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93564 + void __user *buffer, size_t *lenp, loff_t *ppos)
93565 +{
93566 + return -ENOSYS;
93567 +}
93568 +
93569 int proc_dointvec(struct ctl_table *table, int write,
93570 void __user *buffer, size_t *lenp, loff_t *ppos)
93571 {
93572 @@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93573 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93574 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93575 EXPORT_SYMBOL(proc_dostring);
93576 +EXPORT_SYMBOL(proc_dostring_modpriv);
93577 EXPORT_SYMBOL(proc_doulongvec_minmax);
93578 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93579 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93580 index b312fcc7..753d72d 100644
93581 --- a/kernel/taskstats.c
93582 +++ b/kernel/taskstats.c
93583 @@ -28,9 +28,12 @@
93584 #include <linux/fs.h>
93585 #include <linux/file.h>
93586 #include <linux/pid_namespace.h>
93587 +#include <linux/grsecurity.h>
93588 #include <net/genetlink.h>
93589 #include <linux/atomic.h>
93590
93591 +extern int gr_is_taskstats_denied(int pid);
93592 +
93593 /*
93594 * Maximum length of a cpumask that can be specified in
93595 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93596 @@ -576,6 +579,9 @@ err:
93597
93598 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93599 {
93600 + if (gr_is_taskstats_denied(current->pid))
93601 + return -EACCES;
93602 +
93603 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93604 return cmd_attr_register_cpumask(info);
93605 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93606 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93607 index a7077d3..dd48a49 100644
93608 --- a/kernel/time/alarmtimer.c
93609 +++ b/kernel/time/alarmtimer.c
93610 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93611 struct platform_device *pdev;
93612 int error = 0;
93613 int i;
93614 - struct k_clock alarm_clock = {
93615 + static struct k_clock alarm_clock = {
93616 .clock_getres = alarm_clock_getres,
93617 .clock_get = alarm_clock_get,
93618 .timer_create = alarm_timer_create,
93619 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93620 index 37e50aa..57a9501 100644
93621 --- a/kernel/time/hrtimer.c
93622 +++ b/kernel/time/hrtimer.c
93623 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93624 local_irq_restore(flags);
93625 }
93626
93627 -static void run_hrtimer_softirq(struct softirq_action *h)
93628 +static __latent_entropy void run_hrtimer_softirq(void)
93629 {
93630 hrtimer_peek_ahead_timers();
93631 }
93632 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93633 index a16b678..8c5bd9d 100644
93634 --- a/kernel/time/posix-cpu-timers.c
93635 +++ b/kernel/time/posix-cpu-timers.c
93636 @@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93637
93638 static __init int init_posix_cpu_timers(void)
93639 {
93640 - struct k_clock process = {
93641 + static struct k_clock process = {
93642 .clock_getres = process_cpu_clock_getres,
93643 .clock_get = process_cpu_clock_get,
93644 .timer_create = process_cpu_timer_create,
93645 .nsleep = process_cpu_nsleep,
93646 .nsleep_restart = process_cpu_nsleep_restart,
93647 };
93648 - struct k_clock thread = {
93649 + static struct k_clock thread = {
93650 .clock_getres = thread_cpu_clock_getres,
93651 .clock_get = thread_cpu_clock_get,
93652 .timer_create = thread_cpu_timer_create,
93653 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93654 index 31ea01f..7fc61ef 100644
93655 --- a/kernel/time/posix-timers.c
93656 +++ b/kernel/time/posix-timers.c
93657 @@ -43,6 +43,7 @@
93658 #include <linux/hash.h>
93659 #include <linux/posix-clock.h>
93660 #include <linux/posix-timers.h>
93661 +#include <linux/grsecurity.h>
93662 #include <linux/syscalls.h>
93663 #include <linux/wait.h>
93664 #include <linux/workqueue.h>
93665 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93666 * which we beg off on and pass to do_sys_settimeofday().
93667 */
93668
93669 -static struct k_clock posix_clocks[MAX_CLOCKS];
93670 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93671
93672 /*
93673 * These ones are defined below.
93674 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93675 */
93676 static __init int init_posix_timers(void)
93677 {
93678 - struct k_clock clock_realtime = {
93679 + static struct k_clock clock_realtime = {
93680 .clock_getres = hrtimer_get_res,
93681 .clock_get = posix_clock_realtime_get,
93682 .clock_set = posix_clock_realtime_set,
93683 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93684 .timer_get = common_timer_get,
93685 .timer_del = common_timer_del,
93686 };
93687 - struct k_clock clock_monotonic = {
93688 + static struct k_clock clock_monotonic = {
93689 .clock_getres = hrtimer_get_res,
93690 .clock_get = posix_ktime_get_ts,
93691 .nsleep = common_nsleep,
93692 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93693 .timer_get = common_timer_get,
93694 .timer_del = common_timer_del,
93695 };
93696 - struct k_clock clock_monotonic_raw = {
93697 + static struct k_clock clock_monotonic_raw = {
93698 .clock_getres = hrtimer_get_res,
93699 .clock_get = posix_get_monotonic_raw,
93700 };
93701 - struct k_clock clock_realtime_coarse = {
93702 + static struct k_clock clock_realtime_coarse = {
93703 .clock_getres = posix_get_coarse_res,
93704 .clock_get = posix_get_realtime_coarse,
93705 };
93706 - struct k_clock clock_monotonic_coarse = {
93707 + static struct k_clock clock_monotonic_coarse = {
93708 .clock_getres = posix_get_coarse_res,
93709 .clock_get = posix_get_monotonic_coarse,
93710 };
93711 - struct k_clock clock_tai = {
93712 + static struct k_clock clock_tai = {
93713 .clock_getres = hrtimer_get_res,
93714 .clock_get = posix_get_tai,
93715 .nsleep = common_nsleep,
93716 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93717 .timer_get = common_timer_get,
93718 .timer_del = common_timer_del,
93719 };
93720 - struct k_clock clock_boottime = {
93721 + static struct k_clock clock_boottime = {
93722 .clock_getres = hrtimer_get_res,
93723 .clock_get = posix_get_boottime,
93724 .nsleep = common_nsleep,
93725 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93726 return;
93727 }
93728
93729 - posix_clocks[clock_id] = *new_clock;
93730 + posix_clocks[clock_id] = new_clock;
93731 }
93732 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93733
93734 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93735 return (id & CLOCKFD_MASK) == CLOCKFD ?
93736 &clock_posix_dynamic : &clock_posix_cpu;
93737
93738 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93739 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93740 return NULL;
93741 - return &posix_clocks[id];
93742 + return posix_clocks[id];
93743 }
93744
93745 static int common_timer_create(struct k_itimer *new_timer)
93746 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93747 struct k_clock *kc = clockid_to_kclock(which_clock);
93748 struct k_itimer *new_timer;
93749 int error, new_timer_id;
93750 - sigevent_t event;
93751 + sigevent_t event = { };
93752 int it_id_set = IT_ID_NOT_SET;
93753
93754 if (!kc)
93755 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93756 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93757 return -EFAULT;
93758
93759 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93760 + have their clock_set fptr set to a nosettime dummy function
93761 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93762 + call common_clock_set, which calls do_sys_settimeofday, which
93763 + we hook
93764 + */
93765 +
93766 return kc->clock_set(which_clock, &new_tp);
93767 }
93768
93769 diff --git a/kernel/time/time.c b/kernel/time/time.c
93770 index 22d5d3b..70caeb2 100644
93771 --- a/kernel/time/time.c
93772 +++ b/kernel/time/time.c
93773 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93774 return error;
93775
93776 if (tz) {
93777 + /* we log in do_settimeofday called below, so don't log twice
93778 + */
93779 + if (!tv)
93780 + gr_log_timechange();
93781 +
93782 sys_tz = *tz;
93783 update_vsyscall_tz();
93784 if (firsttime) {
93785 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93786 index ec1791f..6a086cd 100644
93787 --- a/kernel/time/timekeeping.c
93788 +++ b/kernel/time/timekeeping.c
93789 @@ -15,6 +15,7 @@
93790 #include <linux/init.h>
93791 #include <linux/mm.h>
93792 #include <linux/sched.h>
93793 +#include <linux/grsecurity.h>
93794 #include <linux/syscore_ops.h>
93795 #include <linux/clocksource.h>
93796 #include <linux/jiffies.h>
93797 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93798 if (!timespec_valid_strict(tv))
93799 return -EINVAL;
93800
93801 + gr_log_timechange();
93802 +
93803 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93804 write_seqcount_begin(&tk_core.seq);
93805
93806 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93807 index 3260ffd..c93cd5e 100644
93808 --- a/kernel/time/timer.c
93809 +++ b/kernel/time/timer.c
93810 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93811 /*
93812 * This function runs timers and the timer-tq in bottom half context.
93813 */
93814 -static void run_timer_softirq(struct softirq_action *h)
93815 +static __latent_entropy void run_timer_softirq(void)
93816 {
93817 struct tvec_base *base = __this_cpu_read(tvec_bases);
93818
93819 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93820 *
93821 * In all cases the return value is guaranteed to be non-negative.
93822 */
93823 -signed long __sched schedule_timeout(signed long timeout)
93824 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93825 {
93826 struct timer_list timer;
93827 unsigned long expire;
93828 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93829 index 61ed862..3b52c65 100644
93830 --- a/kernel/time/timer_list.c
93831 +++ b/kernel/time/timer_list.c
93832 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93833
93834 static void print_name_offset(struct seq_file *m, void *sym)
93835 {
93836 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93837 + SEQ_printf(m, "<%p>", NULL);
93838 +#else
93839 char symname[KSYM_NAME_LEN];
93840
93841 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93842 SEQ_printf(m, "<%pK>", sym);
93843 else
93844 SEQ_printf(m, "%s", symname);
93845 +#endif
93846 }
93847
93848 static void
93849 @@ -119,7 +123,11 @@ next_one:
93850 static void
93851 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93852 {
93853 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93854 + SEQ_printf(m, " .base: %p\n", NULL);
93855 +#else
93856 SEQ_printf(m, " .base: %pK\n", base);
93857 +#endif
93858 SEQ_printf(m, " .index: %d\n",
93859 base->index);
93860 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93861 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93862 {
93863 struct proc_dir_entry *pe;
93864
93865 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93866 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93867 +#else
93868 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93869 +#endif
93870 if (!pe)
93871 return -ENOMEM;
93872 return 0;
93873 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93874 index 1fb08f2..ca4bb1e 100644
93875 --- a/kernel/time/timer_stats.c
93876 +++ b/kernel/time/timer_stats.c
93877 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93878 static unsigned long nr_entries;
93879 static struct entry entries[MAX_ENTRIES];
93880
93881 -static atomic_t overflow_count;
93882 +static atomic_unchecked_t overflow_count;
93883
93884 /*
93885 * The entries are in a hash-table, for fast lookup:
93886 @@ -140,7 +140,7 @@ static void reset_entries(void)
93887 nr_entries = 0;
93888 memset(entries, 0, sizeof(entries));
93889 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93890 - atomic_set(&overflow_count, 0);
93891 + atomic_set_unchecked(&overflow_count, 0);
93892 }
93893
93894 static struct entry *alloc_entry(void)
93895 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93896 if (likely(entry))
93897 entry->count++;
93898 else
93899 - atomic_inc(&overflow_count);
93900 + atomic_inc_unchecked(&overflow_count);
93901
93902 out_unlock:
93903 raw_spin_unlock_irqrestore(lock, flags);
93904 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93905
93906 static void print_name_offset(struct seq_file *m, unsigned long addr)
93907 {
93908 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93909 + seq_printf(m, "<%p>", NULL);
93910 +#else
93911 char symname[KSYM_NAME_LEN];
93912
93913 if (lookup_symbol_name(addr, symname) < 0)
93914 - seq_printf(m, "<%p>", (void *)addr);
93915 + seq_printf(m, "<%pK>", (void *)addr);
93916 else
93917 seq_printf(m, "%s", symname);
93918 +#endif
93919 }
93920
93921 static int tstats_show(struct seq_file *m, void *v)
93922 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93923
93924 seq_puts(m, "Timer Stats Version: v0.3\n");
93925 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93926 - if (atomic_read(&overflow_count))
93927 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93928 + if (atomic_read_unchecked(&overflow_count))
93929 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93930 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93931
93932 for (i = 0; i < nr_entries; i++) {
93933 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93934 {
93935 struct proc_dir_entry *pe;
93936
93937 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93938 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93939 +#else
93940 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93941 +#endif
93942 if (!pe)
93943 return -ENOMEM;
93944 return 0;
93945 diff --git a/kernel/torture.c b/kernel/torture.c
93946 index dd70993..0bf694b 100644
93947 --- a/kernel/torture.c
93948 +++ b/kernel/torture.c
93949 @@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93950 mutex_lock(&fullstop_mutex);
93951 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93952 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93953 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93954 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93955 } else {
93956 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93957 }
93958 @@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93959 if (!torture_must_stop()) {
93960 if (stutter > 1) {
93961 schedule_timeout_interruptible(stutter - 1);
93962 - ACCESS_ONCE(stutter_pause_test) = 2;
93963 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
93964 }
93965 schedule_timeout_interruptible(1);
93966 - ACCESS_ONCE(stutter_pause_test) = 1;
93967 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
93968 }
93969 if (!torture_must_stop())
93970 schedule_timeout_interruptible(stutter);
93971 - ACCESS_ONCE(stutter_pause_test) = 0;
93972 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
93973 torture_shutdown_absorb("torture_stutter");
93974 } while (!torture_must_stop());
93975 torture_kthread_stopping("torture_stutter");
93976 @@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93977 schedule_timeout_uninterruptible(10);
93978 return true;
93979 }
93980 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93981 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93982 mutex_unlock(&fullstop_mutex);
93983 torture_shutdown_cleanup();
93984 torture_shuffle_cleanup();
93985 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93986 index c1bd4ad..4b861dc 100644
93987 --- a/kernel/trace/blktrace.c
93988 +++ b/kernel/trace/blktrace.c
93989 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93990 struct blk_trace *bt = filp->private_data;
93991 char buf[16];
93992
93993 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93994 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93995
93996 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93997 }
93998 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93999 return 1;
94000
94001 bt = buf->chan->private_data;
94002 - atomic_inc(&bt->dropped);
94003 + atomic_inc_unchecked(&bt->dropped);
94004 return 0;
94005 }
94006
94007 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94008
94009 bt->dir = dir;
94010 bt->dev = dev;
94011 - atomic_set(&bt->dropped, 0);
94012 + atomic_set_unchecked(&bt->dropped, 0);
94013 INIT_LIST_HEAD(&bt->running_list);
94014
94015 ret = -EIO;
94016 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94017 index 124e2c7..762ca29 100644
94018 --- a/kernel/trace/ftrace.c
94019 +++ b/kernel/trace/ftrace.c
94020 @@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94021 if (unlikely(ftrace_disabled))
94022 return 0;
94023
94024 + ret = ftrace_arch_code_modify_prepare();
94025 + FTRACE_WARN_ON(ret);
94026 + if (ret)
94027 + return 0;
94028 +
94029 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94030 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94031 if (ret) {
94032 ftrace_bug(ret, ip);
94033 - return 0;
94034 }
94035 - return 1;
94036 + return ret ? 0 : 1;
94037 }
94038
94039 /*
94040 @@ -4529,8 +4534,10 @@ static int ftrace_process_locs(struct module *mod,
94041 if (!count)
94042 return 0;
94043
94044 + pax_open_kernel();
94045 sort(start, count, sizeof(*start),
94046 ftrace_cmp_ips, ftrace_swap_ips);
94047 + pax_close_kernel();
94048
94049 start_pg = ftrace_allocate_pages(count);
94050 if (!start_pg)
94051 @@ -5377,7 +5384,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94052
94053 if (t->ret_stack == NULL) {
94054 atomic_set(&t->tracing_graph_pause, 0);
94055 - atomic_set(&t->trace_overrun, 0);
94056 + atomic_set_unchecked(&t->trace_overrun, 0);
94057 t->curr_ret_stack = -1;
94058 /* Make sure the tasks see the -1 first: */
94059 smp_wmb();
94060 @@ -5590,7 +5597,7 @@ static void
94061 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94062 {
94063 atomic_set(&t->tracing_graph_pause, 0);
94064 - atomic_set(&t->trace_overrun, 0);
94065 + atomic_set_unchecked(&t->trace_overrun, 0);
94066 t->ftrace_timestamp = 0;
94067 /* make curr_ret_stack visible before we add the ret_stack */
94068 smp_wmb();
94069 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94070 index a56e07c..d46f0ba 100644
94071 --- a/kernel/trace/ring_buffer.c
94072 +++ b/kernel/trace/ring_buffer.c
94073 @@ -352,9 +352,9 @@ struct buffer_data_page {
94074 */
94075 struct buffer_page {
94076 struct list_head list; /* list of buffer pages */
94077 - local_t write; /* index for next write */
94078 + local_unchecked_t write; /* index for next write */
94079 unsigned read; /* index for next read */
94080 - local_t entries; /* entries on this page */
94081 + local_unchecked_t entries; /* entries on this page */
94082 unsigned long real_end; /* real end of data */
94083 struct buffer_data_page *page; /* Actual data page */
94084 };
94085 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94086 unsigned long last_overrun;
94087 local_t entries_bytes;
94088 local_t entries;
94089 - local_t overrun;
94090 - local_t commit_overrun;
94091 + local_unchecked_t overrun;
94092 + local_unchecked_t commit_overrun;
94093 local_t dropped_events;
94094 local_t committing;
94095 local_t commits;
94096 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94097 *
94098 * We add a counter to the write field to denote this.
94099 */
94100 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94101 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94102 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94103 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94104
94105 /*
94106 * Just make sure we have seen our old_write and synchronize
94107 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94108 * cmpxchg to only update if an interrupt did not already
94109 * do it for us. If the cmpxchg fails, we don't care.
94110 */
94111 - (void)local_cmpxchg(&next_page->write, old_write, val);
94112 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94113 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94114 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94115
94116 /*
94117 * No need to worry about races with clearing out the commit.
94118 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94119
94120 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94121 {
94122 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94123 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94124 }
94125
94126 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94127 {
94128 - return local_read(&bpage->write) & RB_WRITE_MASK;
94129 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94130 }
94131
94132 static int
94133 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94134 * bytes consumed in ring buffer from here.
94135 * Increment overrun to account for the lost events.
94136 */
94137 - local_add(page_entries, &cpu_buffer->overrun);
94138 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94139 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94140 }
94141
94142 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94143 * it is our responsibility to update
94144 * the counters.
94145 */
94146 - local_add(entries, &cpu_buffer->overrun);
94147 + local_add_unchecked(entries, &cpu_buffer->overrun);
94148 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94149
94150 /*
94151 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94152 if (tail == BUF_PAGE_SIZE)
94153 tail_page->real_end = 0;
94154
94155 - local_sub(length, &tail_page->write);
94156 + local_sub_unchecked(length, &tail_page->write);
94157 return;
94158 }
94159
94160 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94161 rb_event_set_padding(event);
94162
94163 /* Set the write back to the previous setting */
94164 - local_sub(length, &tail_page->write);
94165 + local_sub_unchecked(length, &tail_page->write);
94166 return;
94167 }
94168
94169 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94170
94171 /* Set write to end of buffer */
94172 length = (tail + length) - BUF_PAGE_SIZE;
94173 - local_sub(length, &tail_page->write);
94174 + local_sub_unchecked(length, &tail_page->write);
94175 }
94176
94177 /*
94178 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94179 * about it.
94180 */
94181 if (unlikely(next_page == commit_page)) {
94182 - local_inc(&cpu_buffer->commit_overrun);
94183 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94184 goto out_reset;
94185 }
94186
94187 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94188 cpu_buffer->tail_page) &&
94189 (cpu_buffer->commit_page ==
94190 cpu_buffer->reader_page))) {
94191 - local_inc(&cpu_buffer->commit_overrun);
94192 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94193 goto out_reset;
94194 }
94195 }
94196 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94197 length += RB_LEN_TIME_EXTEND;
94198
94199 tail_page = cpu_buffer->tail_page;
94200 - write = local_add_return(length, &tail_page->write);
94201 + write = local_add_return_unchecked(length, &tail_page->write);
94202
94203 /* set write to only the index of the write */
94204 write &= RB_WRITE_MASK;
94205 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94206 kmemcheck_annotate_bitfield(event, bitfield);
94207 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94208
94209 - local_inc(&tail_page->entries);
94210 + local_inc_unchecked(&tail_page->entries);
94211
94212 /*
94213 * If this is the first commit on the page, then update
94214 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94215
94216 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94217 unsigned long write_mask =
94218 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94219 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94220 unsigned long event_length = rb_event_length(event);
94221 /*
94222 * This is on the tail page. It is possible that
94223 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94224 */
94225 old_index += write_mask;
94226 new_index += write_mask;
94227 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94228 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94229 if (index == old_index) {
94230 /* update counters */
94231 local_sub(event_length, &cpu_buffer->entries_bytes);
94232 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94233
94234 /* Do the likely case first */
94235 if (likely(bpage->page == (void *)addr)) {
94236 - local_dec(&bpage->entries);
94237 + local_dec_unchecked(&bpage->entries);
94238 return;
94239 }
94240
94241 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94242 start = bpage;
94243 do {
94244 if (bpage->page == (void *)addr) {
94245 - local_dec(&bpage->entries);
94246 + local_dec_unchecked(&bpage->entries);
94247 return;
94248 }
94249 rb_inc_page(cpu_buffer, &bpage);
94250 @@ -3173,7 +3173,7 @@ static inline unsigned long
94251 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94252 {
94253 return local_read(&cpu_buffer->entries) -
94254 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94255 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94256 }
94257
94258 /**
94259 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94260 return 0;
94261
94262 cpu_buffer = buffer->buffers[cpu];
94263 - ret = local_read(&cpu_buffer->overrun);
94264 + ret = local_read_unchecked(&cpu_buffer->overrun);
94265
94266 return ret;
94267 }
94268 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94269 return 0;
94270
94271 cpu_buffer = buffer->buffers[cpu];
94272 - ret = local_read(&cpu_buffer->commit_overrun);
94273 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94274
94275 return ret;
94276 }
94277 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94278 /* if you care about this being correct, lock the buffer */
94279 for_each_buffer_cpu(buffer, cpu) {
94280 cpu_buffer = buffer->buffers[cpu];
94281 - overruns += local_read(&cpu_buffer->overrun);
94282 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94283 }
94284
94285 return overruns;
94286 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94287 /*
94288 * Reset the reader page to size zero.
94289 */
94290 - local_set(&cpu_buffer->reader_page->write, 0);
94291 - local_set(&cpu_buffer->reader_page->entries, 0);
94292 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94293 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94294 local_set(&cpu_buffer->reader_page->page->commit, 0);
94295 cpu_buffer->reader_page->real_end = 0;
94296
94297 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94298 * want to compare with the last_overrun.
94299 */
94300 smp_mb();
94301 - overwrite = local_read(&(cpu_buffer->overrun));
94302 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94303
94304 /*
94305 * Here's the tricky part.
94306 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94307
94308 cpu_buffer->head_page
94309 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94310 - local_set(&cpu_buffer->head_page->write, 0);
94311 - local_set(&cpu_buffer->head_page->entries, 0);
94312 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94313 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94314 local_set(&cpu_buffer->head_page->page->commit, 0);
94315
94316 cpu_buffer->head_page->read = 0;
94317 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94318
94319 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94320 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94321 - local_set(&cpu_buffer->reader_page->write, 0);
94322 - local_set(&cpu_buffer->reader_page->entries, 0);
94323 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94324 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94325 local_set(&cpu_buffer->reader_page->page->commit, 0);
94326 cpu_buffer->reader_page->read = 0;
94327
94328 local_set(&cpu_buffer->entries_bytes, 0);
94329 - local_set(&cpu_buffer->overrun, 0);
94330 - local_set(&cpu_buffer->commit_overrun, 0);
94331 + local_set_unchecked(&cpu_buffer->overrun, 0);
94332 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94333 local_set(&cpu_buffer->dropped_events, 0);
94334 local_set(&cpu_buffer->entries, 0);
94335 local_set(&cpu_buffer->committing, 0);
94336 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94337 rb_init_page(bpage);
94338 bpage = reader->page;
94339 reader->page = *data_page;
94340 - local_set(&reader->write, 0);
94341 - local_set(&reader->entries, 0);
94342 + local_set_unchecked(&reader->write, 0);
94343 + local_set_unchecked(&reader->entries, 0);
94344 reader->read = 0;
94345 *data_page = bpage;
94346
94347 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94348 index 426962b..e8e2d9a 100644
94349 --- a/kernel/trace/trace.c
94350 +++ b/kernel/trace/trace.c
94351 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94352 return 0;
94353 }
94354
94355 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94356 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94357 {
94358 /* do nothing if flag is already set */
94359 if (!!(trace_flags & mask) == !!enabled)
94360 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94361 index 385391f..8d2250f 100644
94362 --- a/kernel/trace/trace.h
94363 +++ b/kernel/trace/trace.h
94364 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94365 void trace_printk_init_buffers(void);
94366 void trace_printk_start_comm(void);
94367 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94368 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94369 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94370
94371 /*
94372 * Normal trace_printk() and friends allocates special buffers
94373 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94374 index 57b67b1..66082a9 100644
94375 --- a/kernel/trace/trace_clock.c
94376 +++ b/kernel/trace/trace_clock.c
94377 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94378 return now;
94379 }
94380
94381 -static atomic64_t trace_counter;
94382 +static atomic64_unchecked_t trace_counter;
94383
94384 /*
94385 * trace_clock_counter(): simply an atomic counter.
94386 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94387 */
94388 u64 notrace trace_clock_counter(void)
94389 {
94390 - return atomic64_add_return(1, &trace_counter);
94391 + return atomic64_inc_return_unchecked(&trace_counter);
94392 }
94393 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94394 index 1b0df1e..4ebb965 100644
94395 --- a/kernel/trace/trace_events.c
94396 +++ b/kernel/trace/trace_events.c
94397 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94398 return 0;
94399 }
94400
94401 -struct ftrace_module_file_ops;
94402 static void __add_event_to_tracers(struct ftrace_event_call *call);
94403
94404 /* Add an additional event_call dynamically */
94405 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94406 index f0a0c98..3692dc8 100644
94407 --- a/kernel/trace/trace_functions_graph.c
94408 +++ b/kernel/trace/trace_functions_graph.c
94409 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94410
94411 /* The return trace stack is full */
94412 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94413 - atomic_inc(&current->trace_overrun);
94414 + atomic_inc_unchecked(&current->trace_overrun);
94415 return -EBUSY;
94416 }
94417
94418 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94419 *ret = current->ret_stack[index].ret;
94420 trace->func = current->ret_stack[index].func;
94421 trace->calltime = current->ret_stack[index].calltime;
94422 - trace->overrun = atomic_read(&current->trace_overrun);
94423 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94424 trace->depth = index;
94425 }
94426
94427 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94428 index 0abd9b8..6a663a2 100644
94429 --- a/kernel/trace/trace_mmiotrace.c
94430 +++ b/kernel/trace/trace_mmiotrace.c
94431 @@ -24,7 +24,7 @@ struct header_iter {
94432 static struct trace_array *mmio_trace_array;
94433 static bool overrun_detected;
94434 static unsigned long prev_overruns;
94435 -static atomic_t dropped_count;
94436 +static atomic_unchecked_t dropped_count;
94437
94438 static void mmio_reset_data(struct trace_array *tr)
94439 {
94440 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94441
94442 static unsigned long count_overruns(struct trace_iterator *iter)
94443 {
94444 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94445 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94446 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94447
94448 if (over > prev_overruns)
94449 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94450 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94451 sizeof(*entry), 0, pc);
94452 if (!event) {
94453 - atomic_inc(&dropped_count);
94454 + atomic_inc_unchecked(&dropped_count);
94455 return;
94456 }
94457 entry = ring_buffer_event_data(event);
94458 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94459 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94460 sizeof(*entry), 0, pc);
94461 if (!event) {
94462 - atomic_inc(&dropped_count);
94463 + atomic_inc_unchecked(&dropped_count);
94464 return;
94465 }
94466 entry = ring_buffer_event_data(event);
94467 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94468 index c6977d5..d243785 100644
94469 --- a/kernel/trace/trace_output.c
94470 +++ b/kernel/trace/trace_output.c
94471 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94472 goto out;
94473 }
94474
94475 + pax_open_kernel();
94476 if (event->funcs->trace == NULL)
94477 - event->funcs->trace = trace_nop_print;
94478 + *(void **)&event->funcs->trace = trace_nop_print;
94479 if (event->funcs->raw == NULL)
94480 - event->funcs->raw = trace_nop_print;
94481 + *(void **)&event->funcs->raw = trace_nop_print;
94482 if (event->funcs->hex == NULL)
94483 - event->funcs->hex = trace_nop_print;
94484 + *(void **)&event->funcs->hex = trace_nop_print;
94485 if (event->funcs->binary == NULL)
94486 - event->funcs->binary = trace_nop_print;
94487 + *(void **)&event->funcs->binary = trace_nop_print;
94488 + pax_close_kernel();
94489
94490 key = event->type & (EVENT_HASHSIZE - 1);
94491
94492 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94493 index 1f24ed9..10407ec 100644
94494 --- a/kernel/trace/trace_seq.c
94495 +++ b/kernel/trace/trace_seq.c
94496 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94497
94498 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94499 if (!IS_ERR(p)) {
94500 - p = mangle_path(s->buffer + s->len, p, "\n");
94501 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94502 if (p) {
94503 s->len = p - s->buffer;
94504 return 1;
94505 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94506 index 16eddb3..758b308 100644
94507 --- a/kernel/trace/trace_stack.c
94508 +++ b/kernel/trace/trace_stack.c
94509 @@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94510 return;
94511
94512 /* we do not handle interrupt stacks yet */
94513 - if (!object_is_on_stack(stack))
94514 + if (!object_starts_on_stack(stack))
94515 return;
94516
94517 local_irq_save(flags);
94518 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94519 index 29228c4..301bc8c 100644
94520 --- a/kernel/trace/trace_syscalls.c
94521 +++ b/kernel/trace/trace_syscalls.c
94522 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94523 int num;
94524
94525 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94526 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94527 + return -EINVAL;
94528
94529 mutex_lock(&syscall_trace_lock);
94530 if (!sys_perf_refcount_enter)
94531 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94532 int num;
94533
94534 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94535 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94536 + return;
94537
94538 mutex_lock(&syscall_trace_lock);
94539 sys_perf_refcount_enter--;
94540 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94541 int num;
94542
94543 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94544 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94545 + return -EINVAL;
94546
94547 mutex_lock(&syscall_trace_lock);
94548 if (!sys_perf_refcount_exit)
94549 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94550 int num;
94551
94552 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94553 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94554 + return;
94555
94556 mutex_lock(&syscall_trace_lock);
94557 sys_perf_refcount_exit--;
94558 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94559 index a2e37c5..4fa859b 100644
94560 --- a/kernel/user_namespace.c
94561 +++ b/kernel/user_namespace.c
94562 @@ -83,6 +83,21 @@ int create_user_ns(struct cred *new)
94563 !kgid_has_mapping(parent_ns, group))
94564 return -EPERM;
94565
94566 +#ifdef CONFIG_GRKERNSEC
94567 + /*
94568 + * This doesn't really inspire confidence:
94569 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94570 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94571 + * Increases kernel attack surface in areas developers
94572 + * previously cared little about ("low importance due
94573 + * to requiring "root" capability")
94574 + * To be removed when this code receives *proper* review
94575 + */
94576 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94577 + !capable(CAP_SETGID))
94578 + return -EPERM;
94579 +#endif
94580 +
94581 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94582 if (!ns)
94583 return -ENOMEM;
94584 @@ -974,7 +989,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94585 if (atomic_read(&current->mm->mm_users) > 1)
94586 return -EINVAL;
94587
94588 - if (current->fs->users != 1)
94589 + if (atomic_read(&current->fs->users) != 1)
94590 return -EINVAL;
94591
94592 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94593 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94594 index c8eac43..4b5f08f 100644
94595 --- a/kernel/utsname_sysctl.c
94596 +++ b/kernel/utsname_sysctl.c
94597 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94598 static int proc_do_uts_string(struct ctl_table *table, int write,
94599 void __user *buffer, size_t *lenp, loff_t *ppos)
94600 {
94601 - struct ctl_table uts_table;
94602 + ctl_table_no_const uts_table;
94603 int r;
94604 memcpy(&uts_table, table, sizeof(uts_table));
94605 uts_table.data = get_uts(table, write);
94606 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94607 index 70bf118..4be3c37 100644
94608 --- a/kernel/watchdog.c
94609 +++ b/kernel/watchdog.c
94610 @@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94611 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94612 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94613
94614 -static struct smp_hotplug_thread watchdog_threads = {
94615 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94616 .store = &softlockup_watchdog,
94617 .thread_should_run = watchdog_should_run,
94618 .thread_fn = watchdog,
94619 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94620 index 66940a5..a44fed0 100644
94621 --- a/kernel/workqueue.c
94622 +++ b/kernel/workqueue.c
94623 @@ -4499,7 +4499,7 @@ static void rebind_workers(struct worker_pool *pool)
94624 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94625 worker_flags |= WORKER_REBOUND;
94626 worker_flags &= ~WORKER_UNBOUND;
94627 - ACCESS_ONCE(worker->flags) = worker_flags;
94628 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94629 }
94630
94631 spin_unlock_irq(&pool->lock);
94632 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94633 index 4e35a5d..8a1f3f0 100644
94634 --- a/lib/Kconfig.debug
94635 +++ b/lib/Kconfig.debug
94636 @@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94637
94638 config DEBUG_WW_MUTEX_SLOWPATH
94639 bool "Wait/wound mutex debugging: Slowpath testing"
94640 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94641 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94642 select DEBUG_LOCK_ALLOC
94643 select DEBUG_SPINLOCK
94644 select DEBUG_MUTEXES
94645 @@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94646
94647 config DEBUG_LOCK_ALLOC
94648 bool "Lock debugging: detect incorrect freeing of live locks"
94649 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94650 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94651 select DEBUG_SPINLOCK
94652 select DEBUG_MUTEXES
94653 select LOCKDEP
94654 @@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94655
94656 config PROVE_LOCKING
94657 bool "Lock debugging: prove locking correctness"
94658 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94659 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94660 select LOCKDEP
94661 select DEBUG_SPINLOCK
94662 select DEBUG_MUTEXES
94663 @@ -976,7 +976,7 @@ config LOCKDEP
94664
94665 config LOCK_STAT
94666 bool "Lock usage statistics"
94667 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94668 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94669 select LOCKDEP
94670 select DEBUG_SPINLOCK
94671 select DEBUG_MUTEXES
94672 @@ -1449,6 +1449,7 @@ config LATENCYTOP
94673 depends on DEBUG_KERNEL
94674 depends on STACKTRACE_SUPPORT
94675 depends on PROC_FS
94676 + depends on !GRKERNSEC_HIDESYM
94677 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94678 select KALLSYMS
94679 select KALLSYMS_ALL
94680 @@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94681 config DEBUG_STRICT_USER_COPY_CHECKS
94682 bool "Strict user copy size checks"
94683 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94684 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94685 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94686 help
94687 Enabling this option turns a certain set of sanity checks for user
94688 copy operations into compile time failures.
94689 @@ -1593,7 +1594,7 @@ endmenu # runtime tests
94690
94691 config PROVIDE_OHCI1394_DMA_INIT
94692 bool "Remote debugging over FireWire early on boot"
94693 - depends on PCI && X86
94694 + depends on PCI && X86 && !GRKERNSEC
94695 help
94696 If you want to debug problems which hang or crash the kernel early
94697 on boot and the crashing machine has a FireWire port, you can use
94698 diff --git a/lib/Makefile b/lib/Makefile
94699 index 0211d2b..93f5cc3 100644
94700 --- a/lib/Makefile
94701 +++ b/lib/Makefile
94702 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94703 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94704 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94705 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94706 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94707 +obj-y += list_debug.o
94708 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94709
94710 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94711 diff --git a/lib/average.c b/lib/average.c
94712 index 114d1be..ab0350c 100644
94713 --- a/lib/average.c
94714 +++ b/lib/average.c
94715 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94716 {
94717 unsigned long internal = ACCESS_ONCE(avg->internal);
94718
94719 - ACCESS_ONCE(avg->internal) = internal ?
94720 + ACCESS_ONCE_RW(avg->internal) = internal ?
94721 (((internal << avg->weight) - internal) +
94722 (val << avg->factor)) >> avg->weight :
94723 (val << avg->factor);
94724 diff --git a/lib/bitmap.c b/lib/bitmap.c
94725 index b499ab6..fbdb76c 100644
94726 --- a/lib/bitmap.c
94727 +++ b/lib/bitmap.c
94728 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94729 {
94730 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94731 u32 chunk;
94732 - const char __user __force *ubuf = (const char __user __force *)buf;
94733 + const char __user *ubuf = (const char __force_user *)buf;
94734
94735 bitmap_zero(maskp, nmaskbits);
94736
94737 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94738 {
94739 if (!access_ok(VERIFY_READ, ubuf, ulen))
94740 return -EFAULT;
94741 - return __bitmap_parse((const char __force *)ubuf,
94742 + return __bitmap_parse((const char __force_kernel *)ubuf,
94743 ulen, 1, maskp, nmaskbits);
94744
94745 }
94746 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94747 {
94748 unsigned a, b;
94749 int c, old_c, totaldigits;
94750 - const char __user __force *ubuf = (const char __user __force *)buf;
94751 + const char __user *ubuf = (const char __force_user *)buf;
94752 int exp_digit, in_range;
94753
94754 totaldigits = c = 0;
94755 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94756 {
94757 if (!access_ok(VERIFY_READ, ubuf, ulen))
94758 return -EFAULT;
94759 - return __bitmap_parselist((const char __force *)ubuf,
94760 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94761 ulen, 1, maskp, nmaskbits);
94762 }
94763 EXPORT_SYMBOL(bitmap_parselist_user);
94764 diff --git a/lib/bug.c b/lib/bug.c
94765 index d1d7c78..b354235 100644
94766 --- a/lib/bug.c
94767 +++ b/lib/bug.c
94768 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94769 return BUG_TRAP_TYPE_NONE;
94770
94771 bug = find_bug(bugaddr);
94772 + if (!bug)
94773 + return BUG_TRAP_TYPE_NONE;
94774
94775 file = NULL;
94776 line = 0;
94777 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94778 index 547f7f9..a6d4ba0 100644
94779 --- a/lib/debugobjects.c
94780 +++ b/lib/debugobjects.c
94781 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94782 if (limit > 4)
94783 return;
94784
94785 - is_on_stack = object_is_on_stack(addr);
94786 + is_on_stack = object_starts_on_stack(addr);
94787 if (is_on_stack == onstack)
94788 return;
94789
94790 diff --git a/lib/div64.c b/lib/div64.c
94791 index 4382ad7..08aa558 100644
94792 --- a/lib/div64.c
94793 +++ b/lib/div64.c
94794 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94795 EXPORT_SYMBOL(__div64_32);
94796
94797 #ifndef div_s64_rem
94798 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94799 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94800 {
94801 u64 quotient;
94802
94803 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94804 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94805 */
94806 #ifndef div64_u64
94807 -u64 div64_u64(u64 dividend, u64 divisor)
94808 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94809 {
94810 u32 high = divisor >> 32;
94811 u64 quot;
94812 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94813 index add80cc..0d27550 100644
94814 --- a/lib/dma-debug.c
94815 +++ b/lib/dma-debug.c
94816 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94817
94818 void dma_debug_add_bus(struct bus_type *bus)
94819 {
94820 - struct notifier_block *nb;
94821 + notifier_block_no_const *nb;
94822
94823 if (global_disable)
94824 return;
94825 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94826
94827 static void check_for_stack(struct device *dev, void *addr)
94828 {
94829 - if (object_is_on_stack(addr))
94830 + if (object_starts_on_stack(addr))
94831 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94832 "stack [addr=%p]\n", addr);
94833 }
94834 diff --git a/lib/hash.c b/lib/hash.c
94835 index fea973f..386626f 100644
94836 --- a/lib/hash.c
94837 +++ b/lib/hash.c
94838 @@ -14,7 +14,7 @@
94839 #include <linux/hash.h>
94840 #include <linux/cache.h>
94841
94842 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94843 +static struct fast_hash_ops arch_hash_ops __read_only = {
94844 .hash = jhash,
94845 .hash2 = jhash2,
94846 };
94847 diff --git a/lib/inflate.c b/lib/inflate.c
94848 index 013a761..c28f3fc 100644
94849 --- a/lib/inflate.c
94850 +++ b/lib/inflate.c
94851 @@ -269,7 +269,7 @@ static void free(void *where)
94852 malloc_ptr = free_mem_ptr;
94853 }
94854 #else
94855 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94856 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94857 #define free(a) kfree(a)
94858 #endif
94859
94860 diff --git a/lib/ioremap.c b/lib/ioremap.c
94861 index 0c9216c..863bd89 100644
94862 --- a/lib/ioremap.c
94863 +++ b/lib/ioremap.c
94864 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94865 unsigned long next;
94866
94867 phys_addr -= addr;
94868 - pmd = pmd_alloc(&init_mm, pud, addr);
94869 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94870 if (!pmd)
94871 return -ENOMEM;
94872 do {
94873 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94874 unsigned long next;
94875
94876 phys_addr -= addr;
94877 - pud = pud_alloc(&init_mm, pgd, addr);
94878 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94879 if (!pud)
94880 return -ENOMEM;
94881 do {
94882 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94883 index bd2bea9..6b3c95e 100644
94884 --- a/lib/is_single_threaded.c
94885 +++ b/lib/is_single_threaded.c
94886 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94887 struct task_struct *p, *t;
94888 bool ret;
94889
94890 + if (!mm)
94891 + return true;
94892 +
94893 if (atomic_read(&task->signal->live) != 1)
94894 return false;
94895
94896 diff --git a/lib/kobject.c b/lib/kobject.c
94897 index 58751bb..93a1853 100644
94898 --- a/lib/kobject.c
94899 +++ b/lib/kobject.c
94900 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94901
94902
94903 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94904 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94905 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94906
94907 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94908 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94909 {
94910 enum kobj_ns_type type = ops->type;
94911 int error;
94912 diff --git a/lib/list_debug.c b/lib/list_debug.c
94913 index c24c2f7..f0296f4 100644
94914 --- a/lib/list_debug.c
94915 +++ b/lib/list_debug.c
94916 @@ -11,7 +11,9 @@
94917 #include <linux/bug.h>
94918 #include <linux/kernel.h>
94919 #include <linux/rculist.h>
94920 +#include <linux/mm.h>
94921
94922 +#ifdef CONFIG_DEBUG_LIST
94923 /*
94924 * Insert a new entry between two known consecutive entries.
94925 *
94926 @@ -19,21 +21,40 @@
94927 * the prev/next entries already!
94928 */
94929
94930 +static bool __list_add_debug(struct list_head *new,
94931 + struct list_head *prev,
94932 + struct list_head *next)
94933 +{
94934 + if (unlikely(next->prev != prev)) {
94935 + printk(KERN_ERR "list_add corruption. next->prev should be "
94936 + "prev (%p), but was %p. (next=%p).\n",
94937 + prev, next->prev, next);
94938 + BUG();
94939 + return false;
94940 + }
94941 + if (unlikely(prev->next != next)) {
94942 + printk(KERN_ERR "list_add corruption. prev->next should be "
94943 + "next (%p), but was %p. (prev=%p).\n",
94944 + next, prev->next, prev);
94945 + BUG();
94946 + return false;
94947 + }
94948 + if (unlikely(new == prev || new == next)) {
94949 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94950 + new, prev, next);
94951 + BUG();
94952 + return false;
94953 + }
94954 + return true;
94955 +}
94956 +
94957 void __list_add(struct list_head *new,
94958 - struct list_head *prev,
94959 - struct list_head *next)
94960 + struct list_head *prev,
94961 + struct list_head *next)
94962 {
94963 - WARN(next->prev != prev,
94964 - "list_add corruption. next->prev should be "
94965 - "prev (%p), but was %p. (next=%p).\n",
94966 - prev, next->prev, next);
94967 - WARN(prev->next != next,
94968 - "list_add corruption. prev->next should be "
94969 - "next (%p), but was %p. (prev=%p).\n",
94970 - next, prev->next, prev);
94971 - WARN(new == prev || new == next,
94972 - "list_add double add: new=%p, prev=%p, next=%p.\n",
94973 - new, prev, next);
94974 + if (!__list_add_debug(new, prev, next))
94975 + return;
94976 +
94977 next->prev = new;
94978 new->next = next;
94979 new->prev = prev;
94980 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94981 }
94982 EXPORT_SYMBOL(__list_add);
94983
94984 -void __list_del_entry(struct list_head *entry)
94985 +static bool __list_del_entry_debug(struct list_head *entry)
94986 {
94987 struct list_head *prev, *next;
94988
94989 prev = entry->prev;
94990 next = entry->next;
94991
94992 - if (WARN(next == LIST_POISON1,
94993 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94994 - entry, LIST_POISON1) ||
94995 - WARN(prev == LIST_POISON2,
94996 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94997 - entry, LIST_POISON2) ||
94998 - WARN(prev->next != entry,
94999 - "list_del corruption. prev->next should be %p, "
95000 - "but was %p\n", entry, prev->next) ||
95001 - WARN(next->prev != entry,
95002 - "list_del corruption. next->prev should be %p, "
95003 - "but was %p\n", entry, next->prev))
95004 + if (unlikely(next == LIST_POISON1)) {
95005 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95006 + entry, LIST_POISON1);
95007 + BUG();
95008 + return false;
95009 + }
95010 + if (unlikely(prev == LIST_POISON2)) {
95011 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95012 + entry, LIST_POISON2);
95013 + BUG();
95014 + return false;
95015 + }
95016 + if (unlikely(entry->prev->next != entry)) {
95017 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95018 + "but was %p\n", entry, prev->next);
95019 + BUG();
95020 + return false;
95021 + }
95022 + if (unlikely(entry->next->prev != entry)) {
95023 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95024 + "but was %p\n", entry, next->prev);
95025 + BUG();
95026 + return false;
95027 + }
95028 + return true;
95029 +}
95030 +
95031 +void __list_del_entry(struct list_head *entry)
95032 +{
95033 + if (!__list_del_entry_debug(entry))
95034 return;
95035
95036 - __list_del(prev, next);
95037 + __list_del(entry->prev, entry->next);
95038 }
95039 EXPORT_SYMBOL(__list_del_entry);
95040
95041 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95042 void __list_add_rcu(struct list_head *new,
95043 struct list_head *prev, struct list_head *next)
95044 {
95045 - WARN(next->prev != prev,
95046 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95047 - prev, next->prev, next);
95048 - WARN(prev->next != next,
95049 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95050 - next, prev->next, prev);
95051 + if (!__list_add_debug(new, prev, next))
95052 + return;
95053 +
95054 new->next = next;
95055 new->prev = prev;
95056 rcu_assign_pointer(list_next_rcu(prev), new);
95057 next->prev = new;
95058 }
95059 EXPORT_SYMBOL(__list_add_rcu);
95060 +#endif
95061 +
95062 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95063 +{
95064 +#ifdef CONFIG_DEBUG_LIST
95065 + if (!__list_add_debug(new, prev, next))
95066 + return;
95067 +#endif
95068 +
95069 + pax_open_kernel();
95070 + next->prev = new;
95071 + new->next = next;
95072 + new->prev = prev;
95073 + prev->next = new;
95074 + pax_close_kernel();
95075 +}
95076 +EXPORT_SYMBOL(__pax_list_add);
95077 +
95078 +void pax_list_del(struct list_head *entry)
95079 +{
95080 +#ifdef CONFIG_DEBUG_LIST
95081 + if (!__list_del_entry_debug(entry))
95082 + return;
95083 +#endif
95084 +
95085 + pax_open_kernel();
95086 + __list_del(entry->prev, entry->next);
95087 + entry->next = LIST_POISON1;
95088 + entry->prev = LIST_POISON2;
95089 + pax_close_kernel();
95090 +}
95091 +EXPORT_SYMBOL(pax_list_del);
95092 +
95093 +void pax_list_del_init(struct list_head *entry)
95094 +{
95095 + pax_open_kernel();
95096 + __list_del(entry->prev, entry->next);
95097 + INIT_LIST_HEAD(entry);
95098 + pax_close_kernel();
95099 +}
95100 +EXPORT_SYMBOL(pax_list_del_init);
95101 +
95102 +void __pax_list_add_rcu(struct list_head *new,
95103 + struct list_head *prev, struct list_head *next)
95104 +{
95105 +#ifdef CONFIG_DEBUG_LIST
95106 + if (!__list_add_debug(new, prev, next))
95107 + return;
95108 +#endif
95109 +
95110 + pax_open_kernel();
95111 + new->next = next;
95112 + new->prev = prev;
95113 + rcu_assign_pointer(list_next_rcu(prev), new);
95114 + next->prev = new;
95115 + pax_close_kernel();
95116 +}
95117 +EXPORT_SYMBOL(__pax_list_add_rcu);
95118 +
95119 +void pax_list_del_rcu(struct list_head *entry)
95120 +{
95121 +#ifdef CONFIG_DEBUG_LIST
95122 + if (!__list_del_entry_debug(entry))
95123 + return;
95124 +#endif
95125 +
95126 + pax_open_kernel();
95127 + __list_del(entry->prev, entry->next);
95128 + entry->next = LIST_POISON1;
95129 + entry->prev = LIST_POISON2;
95130 + pax_close_kernel();
95131 +}
95132 +EXPORT_SYMBOL(pax_list_del_rcu);
95133 diff --git a/lib/lockref.c b/lib/lockref.c
95134 index d2233de..fa1a2f6 100644
95135 --- a/lib/lockref.c
95136 +++ b/lib/lockref.c
95137 @@ -48,13 +48,13 @@
95138 void lockref_get(struct lockref *lockref)
95139 {
95140 CMPXCHG_LOOP(
95141 - new.count++;
95142 + __lockref_inc(&new);
95143 ,
95144 return;
95145 );
95146
95147 spin_lock(&lockref->lock);
95148 - lockref->count++;
95149 + __lockref_inc(lockref);
95150 spin_unlock(&lockref->lock);
95151 }
95152 EXPORT_SYMBOL(lockref_get);
95153 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95154 int retval;
95155
95156 CMPXCHG_LOOP(
95157 - new.count++;
95158 + __lockref_inc(&new);
95159 if (!old.count)
95160 return 0;
95161 ,
95162 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95163 spin_lock(&lockref->lock);
95164 retval = 0;
95165 if (lockref->count) {
95166 - lockref->count++;
95167 + __lockref_inc(lockref);
95168 retval = 1;
95169 }
95170 spin_unlock(&lockref->lock);
95171 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95172 int lockref_get_or_lock(struct lockref *lockref)
95173 {
95174 CMPXCHG_LOOP(
95175 - new.count++;
95176 + __lockref_inc(&new);
95177 if (!old.count)
95178 break;
95179 ,
95180 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95181 spin_lock(&lockref->lock);
95182 if (!lockref->count)
95183 return 0;
95184 - lockref->count++;
95185 + __lockref_inc(lockref);
95186 spin_unlock(&lockref->lock);
95187 return 1;
95188 }
95189 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95190 int lockref_put_or_lock(struct lockref *lockref)
95191 {
95192 CMPXCHG_LOOP(
95193 - new.count--;
95194 + __lockref_dec(&new);
95195 if (old.count <= 1)
95196 break;
95197 ,
95198 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95199 spin_lock(&lockref->lock);
95200 if (lockref->count <= 1)
95201 return 0;
95202 - lockref->count--;
95203 + __lockref_dec(lockref);
95204 spin_unlock(&lockref->lock);
95205 return 1;
95206 }
95207 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95208 int retval;
95209
95210 CMPXCHG_LOOP(
95211 - new.count++;
95212 + __lockref_inc(&new);
95213 if ((int)old.count < 0)
95214 return 0;
95215 ,
95216 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95217 spin_lock(&lockref->lock);
95218 retval = 0;
95219 if ((int) lockref->count >= 0) {
95220 - lockref->count++;
95221 + __lockref_inc(lockref);
95222 retval = 1;
95223 }
95224 spin_unlock(&lockref->lock);
95225 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95226 index 6111bcb..02e816b 100644
95227 --- a/lib/percpu-refcount.c
95228 +++ b/lib/percpu-refcount.c
95229 @@ -31,7 +31,7 @@
95230 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
95231 */
95232
95233 -#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
95234 +#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
95235
95236 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
95237
95238 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95239 index 3291a8e..346a91e 100644
95240 --- a/lib/radix-tree.c
95241 +++ b/lib/radix-tree.c
95242 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95243 int nr;
95244 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95245 };
95246 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95247 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95248
95249 static inline void *ptr_to_indirect(void *ptr)
95250 {
95251 diff --git a/lib/random32.c b/lib/random32.c
95252 index 0bee183..526f12f 100644
95253 --- a/lib/random32.c
95254 +++ b/lib/random32.c
95255 @@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
95256 }
95257 #endif
95258
95259 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95260 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95261
95262 /**
95263 * prandom_u32_state - seeded pseudo-random number generator.
95264 diff --git a/lib/rbtree.c b/lib/rbtree.c
95265 index c16c81a..4dcbda1 100644
95266 --- a/lib/rbtree.c
95267 +++ b/lib/rbtree.c
95268 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95269 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95270
95271 static const struct rb_augment_callbacks dummy_callbacks = {
95272 - dummy_propagate, dummy_copy, dummy_rotate
95273 + .propagate = dummy_propagate,
95274 + .copy = dummy_copy,
95275 + .rotate = dummy_rotate
95276 };
95277
95278 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95279 diff --git a/lib/show_mem.c b/lib/show_mem.c
95280 index 5e25627..3ed9d7f 100644
95281 --- a/lib/show_mem.c
95282 +++ b/lib/show_mem.c
95283 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95284 quicklist_total_size());
95285 #endif
95286 #ifdef CONFIG_MEMORY_FAILURE
95287 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95288 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95289 #endif
95290 }
95291 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95292 index bb2b201..46abaf9 100644
95293 --- a/lib/strncpy_from_user.c
95294 +++ b/lib/strncpy_from_user.c
95295 @@ -21,7 +21,7 @@
95296 */
95297 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95298 {
95299 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95300 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95301 long res = 0;
95302
95303 /*
95304 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95305 index a28df52..3d55877 100644
95306 --- a/lib/strnlen_user.c
95307 +++ b/lib/strnlen_user.c
95308 @@ -26,7 +26,7 @@
95309 */
95310 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95311 {
95312 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95313 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95314 long align, res = 0;
95315 unsigned long c;
95316
95317 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95318 index 4abda07..b9d3765 100644
95319 --- a/lib/swiotlb.c
95320 +++ b/lib/swiotlb.c
95321 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95322
95323 void
95324 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95325 - dma_addr_t dev_addr)
95326 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95327 {
95328 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95329
95330 diff --git a/lib/usercopy.c b/lib/usercopy.c
95331 index 4f5b1dd..7cab418 100644
95332 --- a/lib/usercopy.c
95333 +++ b/lib/usercopy.c
95334 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95335 WARN(1, "Buffer overflow detected!\n");
95336 }
95337 EXPORT_SYMBOL(copy_from_user_overflow);
95338 +
95339 +void copy_to_user_overflow(void)
95340 +{
95341 + WARN(1, "Buffer overflow detected!\n");
95342 +}
95343 +EXPORT_SYMBOL(copy_to_user_overflow);
95344 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95345 index ec337f6..8484eb2 100644
95346 --- a/lib/vsprintf.c
95347 +++ b/lib/vsprintf.c
95348 @@ -16,6 +16,9 @@
95349 * - scnprintf and vscnprintf
95350 */
95351
95352 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95353 +#define __INCLUDED_BY_HIDESYM 1
95354 +#endif
95355 #include <stdarg.h>
95356 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95357 #include <linux/types.h>
95358 @@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95359 #ifdef CONFIG_KALLSYMS
95360 if (*fmt == 'B')
95361 sprint_backtrace(sym, value);
95362 - else if (*fmt != 'f' && *fmt != 's')
95363 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95364 sprint_symbol(sym, value);
95365 else
95366 sprint_symbol_no_offset(sym, value);
95367 @@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95368 return number(buf, end, num, spec);
95369 }
95370
95371 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95372 +int kptr_restrict __read_mostly = 2;
95373 +#else
95374 int kptr_restrict __read_mostly;
95375 +#endif
95376
95377 /*
95378 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95379 @@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95380 *
95381 * - 'F' For symbolic function descriptor pointers with offset
95382 * - 'f' For simple symbolic function names without offset
95383 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95384 * - 'S' For symbolic direct pointers with offset
95385 * - 's' For symbolic direct pointers without offset
95386 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95387 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95388 * - 'B' For backtraced symbolic direct pointers with offset
95389 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95390 @@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95391
95392 if (!ptr && *fmt != 'K') {
95393 /*
95394 - * Print (null) with the same width as a pointer so it makes
95395 + * Print (nil) with the same width as a pointer so it makes
95396 * tabular output look nice.
95397 */
95398 if (spec.field_width == -1)
95399 spec.field_width = default_width;
95400 - return string(buf, end, "(null)", spec);
95401 + return string(buf, end, "(nil)", spec);
95402 }
95403
95404 switch (*fmt) {
95405 @@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95406 /* Fallthrough */
95407 case 'S':
95408 case 's':
95409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95410 + break;
95411 +#else
95412 + return symbol_string(buf, end, ptr, spec, fmt);
95413 +#endif
95414 + case 'X':
95415 + ptr = dereference_function_descriptor(ptr);
95416 + case 'A':
95417 case 'B':
95418 return symbol_string(buf, end, ptr, spec, fmt);
95419 case 'R':
95420 @@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95421 va_end(va);
95422 return buf;
95423 }
95424 + case 'P':
95425 + break;
95426 case 'K':
95427 /*
95428 * %pK cannot be used in IRQ context because its test
95429 @@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95430 ((const struct file *)ptr)->f_path.dentry,
95431 spec, fmt);
95432 }
95433 +
95434 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95435 + /* 'P' = approved pointers to copy to userland,
95436 + as in the /proc/kallsyms case, as we make it display nothing
95437 + for non-root users, and the real contents for root users
95438 + 'X' = approved simple symbols
95439 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95440 + above
95441 + */
95442 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95443 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95444 + dump_stack();
95445 + ptr = NULL;
95446 + }
95447 +#endif
95448 +
95449 spec.flags |= SMALL;
95450 if (spec.field_width == -1) {
95451 spec.field_width = default_width;
95452 @@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95453 typeof(type) value; \
95454 if (sizeof(type) == 8) { \
95455 args = PTR_ALIGN(args, sizeof(u32)); \
95456 - *(u32 *)&value = *(u32 *)args; \
95457 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95458 + *(u32 *)&value = *(const u32 *)args; \
95459 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95460 } else { \
95461 args = PTR_ALIGN(args, sizeof(type)); \
95462 - value = *(typeof(type) *)args; \
95463 + value = *(const typeof(type) *)args; \
95464 } \
95465 args += sizeof(type); \
95466 value; \
95467 @@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95468 case FORMAT_TYPE_STR: {
95469 const char *str_arg = args;
95470 args += strlen(str_arg) + 1;
95471 - str = string(str, end, (char *)str_arg, spec);
95472 + str = string(str, end, str_arg, spec);
95473 break;
95474 }
95475
95476 diff --git a/localversion-grsec b/localversion-grsec
95477 new file mode 100644
95478 index 0000000..7cd6065
95479 --- /dev/null
95480 +++ b/localversion-grsec
95481 @@ -0,0 +1 @@
95482 +-grsec
95483 diff --git a/mm/Kconfig b/mm/Kconfig
95484 index 1d1ae6b..0f05885 100644
95485 --- a/mm/Kconfig
95486 +++ b/mm/Kconfig
95487 @@ -341,10 +341,11 @@ config KSM
95488 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95489
95490 config DEFAULT_MMAP_MIN_ADDR
95491 - int "Low address space to protect from user allocation"
95492 + int "Low address space to protect from user allocation"
95493 depends on MMU
95494 - default 4096
95495 - help
95496 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95497 + default 65536
95498 + help
95499 This is the portion of low virtual memory which should be protected
95500 from userspace allocation. Keeping a user from writing to low pages
95501 can help reduce the impact of kernel NULL pointer bugs.
95502 @@ -375,7 +376,7 @@ config MEMORY_FAILURE
95503
95504 config HWPOISON_INJECT
95505 tristate "HWPoison pages injector"
95506 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95507 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95508 select PROC_PAGE_MONITOR
95509
95510 config NOMMU_INITIAL_TRIM_EXCESS
95511 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95512 index 0ae0df5..82ac56b 100644
95513 --- a/mm/backing-dev.c
95514 +++ b/mm/backing-dev.c
95515 @@ -12,7 +12,7 @@
95516 #include <linux/device.h>
95517 #include <trace/events/writeback.h>
95518
95519 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95520 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95521
95522 struct backing_dev_info default_backing_dev_info = {
95523 .name = "default",
95524 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95525 return err;
95526
95527 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95528 - atomic_long_inc_return(&bdi_seq));
95529 + atomic_long_inc_return_unchecked(&bdi_seq));
95530 if (err) {
95531 bdi_destroy(bdi);
95532 return err;
95533 diff --git a/mm/filemap.c b/mm/filemap.c
95534 index 37beab9..2c55a85 100644
95535 --- a/mm/filemap.c
95536 +++ b/mm/filemap.c
95537 @@ -2097,7 +2097,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95538 struct address_space *mapping = file->f_mapping;
95539
95540 if (!mapping->a_ops->readpage)
95541 - return -ENOEXEC;
95542 + return -ENODEV;
95543 file_accessed(file);
95544 vma->vm_ops = &generic_file_vm_ops;
95545 return 0;
95546 @@ -2275,6 +2275,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95547 *pos = i_size_read(inode);
95548
95549 if (limit != RLIM_INFINITY) {
95550 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95551 if (*pos >= limit) {
95552 send_sig(SIGXFSZ, current, 0);
95553 return -EFBIG;
95554 diff --git a/mm/fremap.c b/mm/fremap.c
95555 index 72b8fa3..c5b39f1 100644
95556 --- a/mm/fremap.c
95557 +++ b/mm/fremap.c
95558 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95559 retry:
95560 vma = find_vma(mm, start);
95561
95562 +#ifdef CONFIG_PAX_SEGMEXEC
95563 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95564 + goto out;
95565 +#endif
95566 +
95567 /*
95568 * Make sure the vma is shared, that it supports prefaulting,
95569 * and that the remapped range is valid and fully within
95570 diff --git a/mm/gup.c b/mm/gup.c
95571 index cd62c8c..3bb2053 100644
95572 --- a/mm/gup.c
95573 +++ b/mm/gup.c
95574 @@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95575 unsigned int fault_flags = 0;
95576 int ret;
95577
95578 - /* For mlock, just skip the stack guard page. */
95579 - if ((*flags & FOLL_MLOCK) &&
95580 - (stack_guard_page_start(vma, address) ||
95581 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95582 - return -ENOENT;
95583 if (*flags & FOLL_WRITE)
95584 fault_flags |= FAULT_FLAG_WRITE;
95585 if (nonblocking)
95586 @@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95587 if (!(gup_flags & FOLL_FORCE))
95588 gup_flags |= FOLL_NUMA;
95589
95590 - do {
95591 + while (nr_pages) {
95592 struct page *page;
95593 unsigned int foll_flags = gup_flags;
95594 unsigned int page_increm;
95595
95596 /* first iteration or cross vma bound */
95597 if (!vma || start >= vma->vm_end) {
95598 - vma = find_extend_vma(mm, start);
95599 + vma = find_vma(mm, start);
95600 if (!vma && in_gate_area(mm, start)) {
95601 int ret;
95602 ret = get_gate_page(mm, start & PAGE_MASK,
95603 @@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95604 goto next_page;
95605 }
95606
95607 - if (!vma || check_vma_flags(vma, gup_flags))
95608 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95609 return i ? : -EFAULT;
95610 if (is_vm_hugetlb_page(vma)) {
95611 i = follow_hugetlb_page(mm, vma, pages, vmas,
95612 @@ -518,7 +513,7 @@ next_page:
95613 i += page_increm;
95614 start += page_increm * PAGE_SIZE;
95615 nr_pages -= page_increm;
95616 - } while (nr_pages);
95617 + }
95618 return i;
95619 }
95620 EXPORT_SYMBOL(__get_user_pages);
95621 diff --git a/mm/highmem.c b/mm/highmem.c
95622 index 123bcd3..0de52ba 100644
95623 --- a/mm/highmem.c
95624 +++ b/mm/highmem.c
95625 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95626 * So no dangers, even with speculative execution.
95627 */
95628 page = pte_page(pkmap_page_table[i]);
95629 + pax_open_kernel();
95630 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95631 -
95632 + pax_close_kernel();
95633 set_page_address(page, NULL);
95634 need_flush = 1;
95635 }
95636 @@ -259,9 +260,11 @@ start:
95637 }
95638 }
95639 vaddr = PKMAP_ADDR(last_pkmap_nr);
95640 +
95641 + pax_open_kernel();
95642 set_pte_at(&init_mm, vaddr,
95643 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95644 -
95645 + pax_close_kernel();
95646 pkmap_count[last_pkmap_nr] = 1;
95647 set_page_address(page, (void *)vaddr);
95648
95649 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95650 index 9fd7227..5628939 100644
95651 --- a/mm/hugetlb.c
95652 +++ b/mm/hugetlb.c
95653 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95654 struct ctl_table *table, int write,
95655 void __user *buffer, size_t *length, loff_t *ppos)
95656 {
95657 + ctl_table_no_const t;
95658 struct hstate *h = &default_hstate;
95659 unsigned long tmp = h->max_huge_pages;
95660 int ret;
95661 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95662 if (!hugepages_supported())
95663 return -ENOTSUPP;
95664
95665 - table->data = &tmp;
95666 - table->maxlen = sizeof(unsigned long);
95667 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95668 + t = *table;
95669 + t.data = &tmp;
95670 + t.maxlen = sizeof(unsigned long);
95671 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95672 if (ret)
95673 goto out;
95674
95675 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95676 struct hstate *h = &default_hstate;
95677 unsigned long tmp;
95678 int ret;
95679 + ctl_table_no_const hugetlb_table;
95680
95681 if (!hugepages_supported())
95682 return -ENOTSUPP;
95683 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95684 if (write && hstate_is_gigantic(h))
95685 return -EINVAL;
95686
95687 - table->data = &tmp;
95688 - table->maxlen = sizeof(unsigned long);
95689 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95690 + hugetlb_table = *table;
95691 + hugetlb_table.data = &tmp;
95692 + hugetlb_table.maxlen = sizeof(unsigned long);
95693 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95694 if (ret)
95695 goto out;
95696
95697 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95698 mutex_unlock(&mapping->i_mmap_mutex);
95699 }
95700
95701 +#ifdef CONFIG_PAX_SEGMEXEC
95702 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95703 +{
95704 + struct mm_struct *mm = vma->vm_mm;
95705 + struct vm_area_struct *vma_m;
95706 + unsigned long address_m;
95707 + pte_t *ptep_m;
95708 +
95709 + vma_m = pax_find_mirror_vma(vma);
95710 + if (!vma_m)
95711 + return;
95712 +
95713 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95714 + address_m = address + SEGMEXEC_TASK_SIZE;
95715 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95716 + get_page(page_m);
95717 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95718 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95719 +}
95720 +#endif
95721 +
95722 /*
95723 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95724 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95725 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95726 make_huge_pte(vma, new_page, 1));
95727 page_remove_rmap(old_page);
95728 hugepage_add_new_anon_rmap(new_page, vma, address);
95729 +
95730 +#ifdef CONFIG_PAX_SEGMEXEC
95731 + pax_mirror_huge_pte(vma, address, new_page);
95732 +#endif
95733 +
95734 /* Make the old page be freed below */
95735 new_page = old_page;
95736 }
95737 @@ -3063,6 +3093,10 @@ retry:
95738 && (vma->vm_flags & VM_SHARED)));
95739 set_huge_pte_at(mm, address, ptep, new_pte);
95740
95741 +#ifdef CONFIG_PAX_SEGMEXEC
95742 + pax_mirror_huge_pte(vma, address, page);
95743 +#endif
95744 +
95745 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95746 /* Optimization, do the COW without a second fault */
95747 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95748 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95749 struct hstate *h = hstate_vma(vma);
95750 struct address_space *mapping;
95751
95752 +#ifdef CONFIG_PAX_SEGMEXEC
95753 + struct vm_area_struct *vma_m;
95754 +#endif
95755 +
95756 address &= huge_page_mask(h);
95757
95758 ptep = huge_pte_offset(mm, address);
95759 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95760 VM_FAULT_SET_HINDEX(hstate_index(h));
95761 }
95762
95763 +#ifdef CONFIG_PAX_SEGMEXEC
95764 + vma_m = pax_find_mirror_vma(vma);
95765 + if (vma_m) {
95766 + unsigned long address_m;
95767 +
95768 + if (vma->vm_start > vma_m->vm_start) {
95769 + address_m = address;
95770 + address -= SEGMEXEC_TASK_SIZE;
95771 + vma = vma_m;
95772 + h = hstate_vma(vma);
95773 + } else
95774 + address_m = address + SEGMEXEC_TASK_SIZE;
95775 +
95776 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95777 + return VM_FAULT_OOM;
95778 + address_m &= HPAGE_MASK;
95779 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95780 + }
95781 +#endif
95782 +
95783 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95784 if (!ptep)
95785 return VM_FAULT_OOM;
95786 diff --git a/mm/internal.h b/mm/internal.h
95787 index a4f90ba..fbdc32b 100644
95788 --- a/mm/internal.h
95789 +++ b/mm/internal.h
95790 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95791
95792 extern int __isolate_free_page(struct page *page, unsigned int order);
95793 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95794 +extern void free_compound_page(struct page *page);
95795 extern void prep_compound_page(struct page *page, unsigned long order);
95796 #ifdef CONFIG_MEMORY_FAILURE
95797 extern bool is_free_buddy_page(struct page *page);
95798 @@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95799
95800 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95801 unsigned long, unsigned long,
95802 - unsigned long, unsigned long);
95803 + unsigned long, unsigned long) __intentional_overflow(-1);
95804
95805 extern void set_pageblock_order(void);
95806 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95807 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95808 index e34a3cb..a810efe 100644
95809 --- a/mm/iov_iter.c
95810 +++ b/mm/iov_iter.c
95811 @@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95812
95813 while (bytes) {
95814 char __user *buf = iov->iov_base + base;
95815 - int copy = min(bytes, iov->iov_len - base);
95816 + size_t copy = min(bytes, iov->iov_len - base);
95817
95818 base = 0;
95819 left = __copy_from_user_inatomic(vaddr, buf, copy);
95820 @@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95821
95822 kaddr = kmap_atomic(page);
95823 if (likely(i->nr_segs == 1)) {
95824 - int left;
95825 + size_t left;
95826 char __user *buf = i->iov->iov_base + i->iov_offset;
95827 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95828 copied = bytes - left;
95829 @@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95830 * zero-length segments (without overruning the iovec).
95831 */
95832 while (bytes || unlikely(i->count && !iov->iov_len)) {
95833 - int copy;
95834 + size_t copy;
95835
95836 copy = min(bytes, iov->iov_len - base);
95837 BUG_ON(!i->count || i->count < copy);
95838 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95839 index 3cda50c..032ba634 100644
95840 --- a/mm/kmemleak.c
95841 +++ b/mm/kmemleak.c
95842 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95843
95844 for (i = 0; i < object->trace_len; i++) {
95845 void *ptr = (void *)object->trace[i];
95846 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95847 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95848 }
95849 }
95850
95851 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95852 return -ENOMEM;
95853 }
95854
95855 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95856 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95857 &kmemleak_fops);
95858 if (!dentry)
95859 pr_warning("Failed to create the debugfs kmemleak file\n");
95860 diff --git a/mm/maccess.c b/mm/maccess.c
95861 index d53adf9..03a24bf 100644
95862 --- a/mm/maccess.c
95863 +++ b/mm/maccess.c
95864 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95865 set_fs(KERNEL_DS);
95866 pagefault_disable();
95867 ret = __copy_from_user_inatomic(dst,
95868 - (__force const void __user *)src, size);
95869 + (const void __force_user *)src, size);
95870 pagefault_enable();
95871 set_fs(old_fs);
95872
95873 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95874
95875 set_fs(KERNEL_DS);
95876 pagefault_disable();
95877 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95878 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95879 pagefault_enable();
95880 set_fs(old_fs);
95881
95882 diff --git a/mm/madvise.c b/mm/madvise.c
95883 index 0938b30..199abe8 100644
95884 --- a/mm/madvise.c
95885 +++ b/mm/madvise.c
95886 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95887 pgoff_t pgoff;
95888 unsigned long new_flags = vma->vm_flags;
95889
95890 +#ifdef CONFIG_PAX_SEGMEXEC
95891 + struct vm_area_struct *vma_m;
95892 +#endif
95893 +
95894 switch (behavior) {
95895 case MADV_NORMAL:
95896 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95897 @@ -126,6 +130,13 @@ success:
95898 /*
95899 * vm_flags is protected by the mmap_sem held in write mode.
95900 */
95901 +
95902 +#ifdef CONFIG_PAX_SEGMEXEC
95903 + vma_m = pax_find_mirror_vma(vma);
95904 + if (vma_m)
95905 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95906 +#endif
95907 +
95908 vma->vm_flags = new_flags;
95909
95910 out:
95911 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95912 struct vm_area_struct **prev,
95913 unsigned long start, unsigned long end)
95914 {
95915 +
95916 +#ifdef CONFIG_PAX_SEGMEXEC
95917 + struct vm_area_struct *vma_m;
95918 +#endif
95919 +
95920 *prev = vma;
95921 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95922 return -EINVAL;
95923 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95924 zap_page_range(vma, start, end - start, &details);
95925 } else
95926 zap_page_range(vma, start, end - start, NULL);
95927 +
95928 +#ifdef CONFIG_PAX_SEGMEXEC
95929 + vma_m = pax_find_mirror_vma(vma);
95930 + if (vma_m) {
95931 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95932 + struct zap_details details = {
95933 + .nonlinear_vma = vma_m,
95934 + .last_index = ULONG_MAX,
95935 + };
95936 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95937 + } else
95938 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95939 + }
95940 +#endif
95941 +
95942 return 0;
95943 }
95944
95945 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95946 if (end < start)
95947 return error;
95948
95949 +#ifdef CONFIG_PAX_SEGMEXEC
95950 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95951 + if (end > SEGMEXEC_TASK_SIZE)
95952 + return error;
95953 + } else
95954 +#endif
95955 +
95956 + if (end > TASK_SIZE)
95957 + return error;
95958 +
95959 error = 0;
95960 if (end == start)
95961 return error;
95962 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95963 index 8639f6b..b623882a 100644
95964 --- a/mm/memory-failure.c
95965 +++ b/mm/memory-failure.c
95966 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95967
95968 int sysctl_memory_failure_recovery __read_mostly = 1;
95969
95970 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95971 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95972
95973 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95974
95975 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95976 pfn, t->comm, t->pid);
95977 si.si_signo = SIGBUS;
95978 si.si_errno = 0;
95979 - si.si_addr = (void *)addr;
95980 + si.si_addr = (void __user *)addr;
95981 #ifdef __ARCH_SI_TRAPNO
95982 si.si_trapno = trapno;
95983 #endif
95984 @@ -791,7 +791,7 @@ static struct page_state {
95985 unsigned long res;
95986 char *msg;
95987 int (*action)(struct page *p, unsigned long pfn);
95988 -} error_states[] = {
95989 +} __do_const error_states[] = {
95990 { reserved, reserved, "reserved kernel", me_kernel },
95991 /*
95992 * free pages are specially detected outside this table:
95993 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95994 nr_pages = 1 << compound_order(hpage);
95995 else /* normal page or thp */
95996 nr_pages = 1;
95997 - atomic_long_add(nr_pages, &num_poisoned_pages);
95998 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95999
96000 /*
96001 * We need/can do nothing about count=0 pages.
96002 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96003 if (PageHWPoison(hpage)) {
96004 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96005 || (p != hpage && TestSetPageHWPoison(hpage))) {
96006 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96007 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96008 unlock_page(hpage);
96009 return 0;
96010 }
96011 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96012 */
96013 if (!PageHWPoison(p)) {
96014 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96015 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96016 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96017 put_page(hpage);
96018 res = 0;
96019 goto out;
96020 }
96021 if (hwpoison_filter(p)) {
96022 if (TestClearPageHWPoison(p))
96023 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96024 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96025 unlock_page(hpage);
96026 put_page(hpage);
96027 return 0;
96028 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96029 return 0;
96030 }
96031 if (TestClearPageHWPoison(p))
96032 - atomic_long_dec(&num_poisoned_pages);
96033 + atomic_long_dec_unchecked(&num_poisoned_pages);
96034 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96035 return 0;
96036 }
96037 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96038 */
96039 if (TestClearPageHWPoison(page)) {
96040 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96041 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96042 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96043 freeit = 1;
96044 if (PageHuge(page))
96045 clear_page_hwpoison_huge_page(page);
96046 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96047 if (PageHuge(page)) {
96048 set_page_hwpoison_huge_page(hpage);
96049 dequeue_hwpoisoned_huge_page(hpage);
96050 - atomic_long_add(1 << compound_order(hpage),
96051 + atomic_long_add_unchecked(1 << compound_order(hpage),
96052 &num_poisoned_pages);
96053 } else {
96054 SetPageHWPoison(page);
96055 - atomic_long_inc(&num_poisoned_pages);
96056 + atomic_long_inc_unchecked(&num_poisoned_pages);
96057 }
96058 }
96059 return ret;
96060 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96061 put_page(page);
96062 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96063 SetPageHWPoison(page);
96064 - atomic_long_inc(&num_poisoned_pages);
96065 + atomic_long_inc_unchecked(&num_poisoned_pages);
96066 return 0;
96067 }
96068
96069 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96070 if (!is_free_buddy_page(page))
96071 pr_info("soft offline: %#lx: page leaked\n",
96072 pfn);
96073 - atomic_long_inc(&num_poisoned_pages);
96074 + atomic_long_inc_unchecked(&num_poisoned_pages);
96075 }
96076 } else {
96077 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96078 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96079 if (PageHuge(page)) {
96080 set_page_hwpoison_huge_page(hpage);
96081 dequeue_hwpoisoned_huge_page(hpage);
96082 - atomic_long_add(1 << compound_order(hpage),
96083 + atomic_long_add_unchecked(1 << compound_order(hpage),
96084 &num_poisoned_pages);
96085 } else {
96086 SetPageHWPoison(page);
96087 - atomic_long_inc(&num_poisoned_pages);
96088 + atomic_long_inc_unchecked(&num_poisoned_pages);
96089 }
96090 }
96091 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96092 diff --git a/mm/memory.c b/mm/memory.c
96093 index 7f86cf6..0600e22 100644
96094 --- a/mm/memory.c
96095 +++ b/mm/memory.c
96096 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96097 free_pte_range(tlb, pmd, addr);
96098 } while (pmd++, addr = next, addr != end);
96099
96100 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96101 start &= PUD_MASK;
96102 if (start < floor)
96103 return;
96104 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96105 pmd = pmd_offset(pud, start);
96106 pud_clear(pud);
96107 pmd_free_tlb(tlb, pmd, start);
96108 +#endif
96109 +
96110 }
96111
96112 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96113 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96114 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96115 } while (pud++, addr = next, addr != end);
96116
96117 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96118 start &= PGDIR_MASK;
96119 if (start < floor)
96120 return;
96121 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96122 pud = pud_offset(pgd, start);
96123 pgd_clear(pgd);
96124 pud_free_tlb(tlb, pud, start);
96125 +#endif
96126 +
96127 }
96128
96129 /*
96130 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96131 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96132 */
96133 if (vma->vm_ops)
96134 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96135 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96136 vma->vm_ops->fault);
96137 if (vma->vm_file)
96138 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96139 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96140 vma->vm_file->f_op->mmap);
96141 dump_stack();
96142 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96143 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96144 page_add_file_rmap(page);
96145 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96146
96147 +#ifdef CONFIG_PAX_SEGMEXEC
96148 + pax_mirror_file_pte(vma, addr, page, ptl);
96149 +#endif
96150 +
96151 retval = 0;
96152 pte_unmap_unlock(pte, ptl);
96153 return retval;
96154 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96155 if (!page_count(page))
96156 return -EINVAL;
96157 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96158 +
96159 +#ifdef CONFIG_PAX_SEGMEXEC
96160 + struct vm_area_struct *vma_m;
96161 +#endif
96162 +
96163 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96164 BUG_ON(vma->vm_flags & VM_PFNMAP);
96165 vma->vm_flags |= VM_MIXEDMAP;
96166 +
96167 +#ifdef CONFIG_PAX_SEGMEXEC
96168 + vma_m = pax_find_mirror_vma(vma);
96169 + if (vma_m)
96170 + vma_m->vm_flags |= VM_MIXEDMAP;
96171 +#endif
96172 +
96173 }
96174 return insert_page(vma, addr, page, vma->vm_page_prot);
96175 }
96176 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96177 unsigned long pfn)
96178 {
96179 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96180 + BUG_ON(vma->vm_mirror);
96181
96182 if (addr < vma->vm_start || addr >= vma->vm_end)
96183 return -EFAULT;
96184 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96185
96186 BUG_ON(pud_huge(*pud));
96187
96188 - pmd = pmd_alloc(mm, pud, addr);
96189 + pmd = (mm == &init_mm) ?
96190 + pmd_alloc_kernel(mm, pud, addr) :
96191 + pmd_alloc(mm, pud, addr);
96192 if (!pmd)
96193 return -ENOMEM;
96194 do {
96195 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96196 unsigned long next;
96197 int err;
96198
96199 - pud = pud_alloc(mm, pgd, addr);
96200 + pud = (mm == &init_mm) ?
96201 + pud_alloc_kernel(mm, pgd, addr) :
96202 + pud_alloc(mm, pgd, addr);
96203 if (!pud)
96204 return -ENOMEM;
96205 do {
96206 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96207 return ret;
96208 }
96209
96210 +#ifdef CONFIG_PAX_SEGMEXEC
96211 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96212 +{
96213 + struct mm_struct *mm = vma->vm_mm;
96214 + spinlock_t *ptl;
96215 + pte_t *pte, entry;
96216 +
96217 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96218 + entry = *pte;
96219 + if (!pte_present(entry)) {
96220 + if (!pte_none(entry)) {
96221 + BUG_ON(pte_file(entry));
96222 + free_swap_and_cache(pte_to_swp_entry(entry));
96223 + pte_clear_not_present_full(mm, address, pte, 0);
96224 + }
96225 + } else {
96226 + struct page *page;
96227 +
96228 + flush_cache_page(vma, address, pte_pfn(entry));
96229 + entry = ptep_clear_flush(vma, address, pte);
96230 + BUG_ON(pte_dirty(entry));
96231 + page = vm_normal_page(vma, address, entry);
96232 + if (page) {
96233 + update_hiwater_rss(mm);
96234 + if (PageAnon(page))
96235 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96236 + else
96237 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96238 + page_remove_rmap(page);
96239 + page_cache_release(page);
96240 + }
96241 + }
96242 + pte_unmap_unlock(pte, ptl);
96243 +}
96244 +
96245 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96246 + *
96247 + * the ptl of the lower mapped page is held on entry and is not released on exit
96248 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96249 + */
96250 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96251 +{
96252 + struct mm_struct *mm = vma->vm_mm;
96253 + unsigned long address_m;
96254 + spinlock_t *ptl_m;
96255 + struct vm_area_struct *vma_m;
96256 + pmd_t *pmd_m;
96257 + pte_t *pte_m, entry_m;
96258 +
96259 + BUG_ON(!page_m || !PageAnon(page_m));
96260 +
96261 + vma_m = pax_find_mirror_vma(vma);
96262 + if (!vma_m)
96263 + return;
96264 +
96265 + BUG_ON(!PageLocked(page_m));
96266 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96267 + address_m = address + SEGMEXEC_TASK_SIZE;
96268 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96269 + pte_m = pte_offset_map(pmd_m, address_m);
96270 + ptl_m = pte_lockptr(mm, pmd_m);
96271 + if (ptl != ptl_m) {
96272 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96273 + if (!pte_none(*pte_m))
96274 + goto out;
96275 + }
96276 +
96277 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96278 + page_cache_get(page_m);
96279 + page_add_anon_rmap(page_m, vma_m, address_m);
96280 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96281 + set_pte_at(mm, address_m, pte_m, entry_m);
96282 + update_mmu_cache(vma_m, address_m, pte_m);
96283 +out:
96284 + if (ptl != ptl_m)
96285 + spin_unlock(ptl_m);
96286 + pte_unmap(pte_m);
96287 + unlock_page(page_m);
96288 +}
96289 +
96290 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96291 +{
96292 + struct mm_struct *mm = vma->vm_mm;
96293 + unsigned long address_m;
96294 + spinlock_t *ptl_m;
96295 + struct vm_area_struct *vma_m;
96296 + pmd_t *pmd_m;
96297 + pte_t *pte_m, entry_m;
96298 +
96299 + BUG_ON(!page_m || PageAnon(page_m));
96300 +
96301 + vma_m = pax_find_mirror_vma(vma);
96302 + if (!vma_m)
96303 + return;
96304 +
96305 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96306 + address_m = address + SEGMEXEC_TASK_SIZE;
96307 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96308 + pte_m = pte_offset_map(pmd_m, address_m);
96309 + ptl_m = pte_lockptr(mm, pmd_m);
96310 + if (ptl != ptl_m) {
96311 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96312 + if (!pte_none(*pte_m))
96313 + goto out;
96314 + }
96315 +
96316 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96317 + page_cache_get(page_m);
96318 + page_add_file_rmap(page_m);
96319 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96320 + set_pte_at(mm, address_m, pte_m, entry_m);
96321 + update_mmu_cache(vma_m, address_m, pte_m);
96322 +out:
96323 + if (ptl != ptl_m)
96324 + spin_unlock(ptl_m);
96325 + pte_unmap(pte_m);
96326 +}
96327 +
96328 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96329 +{
96330 + struct mm_struct *mm = vma->vm_mm;
96331 + unsigned long address_m;
96332 + spinlock_t *ptl_m;
96333 + struct vm_area_struct *vma_m;
96334 + pmd_t *pmd_m;
96335 + pte_t *pte_m, entry_m;
96336 +
96337 + vma_m = pax_find_mirror_vma(vma);
96338 + if (!vma_m)
96339 + return;
96340 +
96341 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96342 + address_m = address + SEGMEXEC_TASK_SIZE;
96343 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96344 + pte_m = pte_offset_map(pmd_m, address_m);
96345 + ptl_m = pte_lockptr(mm, pmd_m);
96346 + if (ptl != ptl_m) {
96347 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96348 + if (!pte_none(*pte_m))
96349 + goto out;
96350 + }
96351 +
96352 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96353 + set_pte_at(mm, address_m, pte_m, entry_m);
96354 +out:
96355 + if (ptl != ptl_m)
96356 + spin_unlock(ptl_m);
96357 + pte_unmap(pte_m);
96358 +}
96359 +
96360 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96361 +{
96362 + struct page *page_m;
96363 + pte_t entry;
96364 +
96365 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96366 + goto out;
96367 +
96368 + entry = *pte;
96369 + page_m = vm_normal_page(vma, address, entry);
96370 + if (!page_m)
96371 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96372 + else if (PageAnon(page_m)) {
96373 + if (pax_find_mirror_vma(vma)) {
96374 + pte_unmap_unlock(pte, ptl);
96375 + lock_page(page_m);
96376 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96377 + if (pte_same(entry, *pte))
96378 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96379 + else
96380 + unlock_page(page_m);
96381 + }
96382 + } else
96383 + pax_mirror_file_pte(vma, address, page_m, ptl);
96384 +
96385 +out:
96386 + pte_unmap_unlock(pte, ptl);
96387 +}
96388 +#endif
96389 +
96390 /*
96391 * This routine handles present pages, when users try to write
96392 * to a shared page. It is done by copying the page to a new address
96393 @@ -2225,6 +2432,12 @@ gotten:
96394 */
96395 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96396 if (likely(pte_same(*page_table, orig_pte))) {
96397 +
96398 +#ifdef CONFIG_PAX_SEGMEXEC
96399 + if (pax_find_mirror_vma(vma))
96400 + BUG_ON(!trylock_page(new_page));
96401 +#endif
96402 +
96403 if (old_page) {
96404 if (!PageAnon(old_page)) {
96405 dec_mm_counter_fast(mm, MM_FILEPAGES);
96406 @@ -2278,6 +2491,10 @@ gotten:
96407 page_remove_rmap(old_page);
96408 }
96409
96410 +#ifdef CONFIG_PAX_SEGMEXEC
96411 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96412 +#endif
96413 +
96414 /* Free the old page.. */
96415 new_page = old_page;
96416 ret |= VM_FAULT_WRITE;
96417 @@ -2552,6 +2769,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96418 swap_free(entry);
96419 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96420 try_to_free_swap(page);
96421 +
96422 +#ifdef CONFIG_PAX_SEGMEXEC
96423 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96424 +#endif
96425 +
96426 unlock_page(page);
96427 if (page != swapcache) {
96428 /*
96429 @@ -2575,6 +2797,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96430
96431 /* No need to invalidate - it was non-present before */
96432 update_mmu_cache(vma, address, page_table);
96433 +
96434 +#ifdef CONFIG_PAX_SEGMEXEC
96435 + pax_mirror_anon_pte(vma, address, page, ptl);
96436 +#endif
96437 +
96438 unlock:
96439 pte_unmap_unlock(page_table, ptl);
96440 out:
96441 @@ -2594,40 +2821,6 @@ out_release:
96442 }
96443
96444 /*
96445 - * This is like a special single-page "expand_{down|up}wards()",
96446 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96447 - * doesn't hit another vma.
96448 - */
96449 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96450 -{
96451 - address &= PAGE_MASK;
96452 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96453 - struct vm_area_struct *prev = vma->vm_prev;
96454 -
96455 - /*
96456 - * Is there a mapping abutting this one below?
96457 - *
96458 - * That's only ok if it's the same stack mapping
96459 - * that has gotten split..
96460 - */
96461 - if (prev && prev->vm_end == address)
96462 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96463 -
96464 - return expand_downwards(vma, address - PAGE_SIZE);
96465 - }
96466 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96467 - struct vm_area_struct *next = vma->vm_next;
96468 -
96469 - /* As VM_GROWSDOWN but s/below/above/ */
96470 - if (next && next->vm_start == address + PAGE_SIZE)
96471 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96472 -
96473 - return expand_upwards(vma, address + PAGE_SIZE);
96474 - }
96475 - return 0;
96476 -}
96477 -
96478 -/*
96479 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96480 * but allow concurrent faults), and pte mapped but not yet locked.
96481 * We return with mmap_sem still held, but pte unmapped and unlocked.
96482 @@ -2637,27 +2830,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96483 unsigned int flags)
96484 {
96485 struct mem_cgroup *memcg;
96486 - struct page *page;
96487 + struct page *page = NULL;
96488 spinlock_t *ptl;
96489 pte_t entry;
96490
96491 - pte_unmap(page_table);
96492 -
96493 - /* Check if we need to add a guard page to the stack */
96494 - if (check_stack_guard_page(vma, address) < 0)
96495 - return VM_FAULT_SIGBUS;
96496 -
96497 - /* Use the zero-page for reads */
96498 if (!(flags & FAULT_FLAG_WRITE)) {
96499 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96500 vma->vm_page_prot));
96501 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96502 + ptl = pte_lockptr(mm, pmd);
96503 + spin_lock(ptl);
96504 if (!pte_none(*page_table))
96505 goto unlock;
96506 goto setpte;
96507 }
96508
96509 /* Allocate our own private page. */
96510 + pte_unmap(page_table);
96511 +
96512 if (unlikely(anon_vma_prepare(vma)))
96513 goto oom;
96514 page = alloc_zeroed_user_highpage_movable(vma, address);
96515 @@ -2681,6 +2870,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96516 if (!pte_none(*page_table))
96517 goto release;
96518
96519 +#ifdef CONFIG_PAX_SEGMEXEC
96520 + if (pax_find_mirror_vma(vma))
96521 + BUG_ON(!trylock_page(page));
96522 +#endif
96523 +
96524 inc_mm_counter_fast(mm, MM_ANONPAGES);
96525 page_add_new_anon_rmap(page, vma, address);
96526 mem_cgroup_commit_charge(page, memcg, false);
96527 @@ -2690,6 +2884,12 @@ setpte:
96528
96529 /* No need to invalidate - it was non-present before */
96530 update_mmu_cache(vma, address, page_table);
96531 +
96532 +#ifdef CONFIG_PAX_SEGMEXEC
96533 + if (page)
96534 + pax_mirror_anon_pte(vma, address, page, ptl);
96535 +#endif
96536 +
96537 unlock:
96538 pte_unmap_unlock(page_table, ptl);
96539 return 0;
96540 @@ -2920,6 +3120,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96541 return ret;
96542 }
96543 do_set_pte(vma, address, fault_page, pte, false, false);
96544 +
96545 +#ifdef CONFIG_PAX_SEGMEXEC
96546 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96547 +#endif
96548 +
96549 unlock_page(fault_page);
96550 unlock_out:
96551 pte_unmap_unlock(pte, ptl);
96552 @@ -2962,7 +3167,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96553 page_cache_release(fault_page);
96554 goto uncharge_out;
96555 }
96556 +
96557 +#ifdef CONFIG_PAX_SEGMEXEC
96558 + if (pax_find_mirror_vma(vma))
96559 + BUG_ON(!trylock_page(new_page));
96560 +#endif
96561 +
96562 do_set_pte(vma, address, new_page, pte, true, true);
96563 +
96564 +#ifdef CONFIG_PAX_SEGMEXEC
96565 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96566 +#endif
96567 +
96568 mem_cgroup_commit_charge(new_page, memcg, false);
96569 lru_cache_add_active_or_unevictable(new_page, vma);
96570 pte_unmap_unlock(pte, ptl);
96571 @@ -3012,6 +3228,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96572 return ret;
96573 }
96574 do_set_pte(vma, address, fault_page, pte, true, false);
96575 +
96576 +#ifdef CONFIG_PAX_SEGMEXEC
96577 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96578 +#endif
96579 +
96580 pte_unmap_unlock(pte, ptl);
96581
96582 if (set_page_dirty(fault_page))
96583 @@ -3253,6 +3474,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96584 if (flags & FAULT_FLAG_WRITE)
96585 flush_tlb_fix_spurious_fault(vma, address);
96586 }
96587 +
96588 +#ifdef CONFIG_PAX_SEGMEXEC
96589 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96590 + return 0;
96591 +#endif
96592 +
96593 unlock:
96594 pte_unmap_unlock(pte, ptl);
96595 return 0;
96596 @@ -3272,9 +3499,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96597 pmd_t *pmd;
96598 pte_t *pte;
96599
96600 +#ifdef CONFIG_PAX_SEGMEXEC
96601 + struct vm_area_struct *vma_m;
96602 +#endif
96603 +
96604 if (unlikely(is_vm_hugetlb_page(vma)))
96605 return hugetlb_fault(mm, vma, address, flags);
96606
96607 +#ifdef CONFIG_PAX_SEGMEXEC
96608 + vma_m = pax_find_mirror_vma(vma);
96609 + if (vma_m) {
96610 + unsigned long address_m;
96611 + pgd_t *pgd_m;
96612 + pud_t *pud_m;
96613 + pmd_t *pmd_m;
96614 +
96615 + if (vma->vm_start > vma_m->vm_start) {
96616 + address_m = address;
96617 + address -= SEGMEXEC_TASK_SIZE;
96618 + vma = vma_m;
96619 + } else
96620 + address_m = address + SEGMEXEC_TASK_SIZE;
96621 +
96622 + pgd_m = pgd_offset(mm, address_m);
96623 + pud_m = pud_alloc(mm, pgd_m, address_m);
96624 + if (!pud_m)
96625 + return VM_FAULT_OOM;
96626 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96627 + if (!pmd_m)
96628 + return VM_FAULT_OOM;
96629 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96630 + return VM_FAULT_OOM;
96631 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96632 + }
96633 +#endif
96634 +
96635 pgd = pgd_offset(mm, address);
96636 pud = pud_alloc(mm, pgd, address);
96637 if (!pud)
96638 @@ -3408,6 +3667,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96639 spin_unlock(&mm->page_table_lock);
96640 return 0;
96641 }
96642 +
96643 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96644 +{
96645 + pud_t *new = pud_alloc_one(mm, address);
96646 + if (!new)
96647 + return -ENOMEM;
96648 +
96649 + smp_wmb(); /* See comment in __pte_alloc */
96650 +
96651 + spin_lock(&mm->page_table_lock);
96652 + if (pgd_present(*pgd)) /* Another has populated it */
96653 + pud_free(mm, new);
96654 + else
96655 + pgd_populate_kernel(mm, pgd, new);
96656 + spin_unlock(&mm->page_table_lock);
96657 + return 0;
96658 +}
96659 #endif /* __PAGETABLE_PUD_FOLDED */
96660
96661 #ifndef __PAGETABLE_PMD_FOLDED
96662 @@ -3438,6 +3714,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96663 spin_unlock(&mm->page_table_lock);
96664 return 0;
96665 }
96666 +
96667 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96668 +{
96669 + pmd_t *new = pmd_alloc_one(mm, address);
96670 + if (!new)
96671 + return -ENOMEM;
96672 +
96673 + smp_wmb(); /* See comment in __pte_alloc */
96674 +
96675 + spin_lock(&mm->page_table_lock);
96676 +#ifndef __ARCH_HAS_4LEVEL_HACK
96677 + if (pud_present(*pud)) /* Another has populated it */
96678 + pmd_free(mm, new);
96679 + else
96680 + pud_populate_kernel(mm, pud, new);
96681 +#else
96682 + if (pgd_present(*pud)) /* Another has populated it */
96683 + pmd_free(mm, new);
96684 + else
96685 + pgd_populate_kernel(mm, pud, new);
96686 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96687 + spin_unlock(&mm->page_table_lock);
96688 + return 0;
96689 +}
96690 #endif /* __PAGETABLE_PMD_FOLDED */
96691
96692 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96693 @@ -3547,8 +3847,8 @@ out:
96694 return ret;
96695 }
96696
96697 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96698 - void *buf, int len, int write)
96699 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96700 + void *buf, size_t len, int write)
96701 {
96702 resource_size_t phys_addr;
96703 unsigned long prot = 0;
96704 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96705 * Access another process' address space as given in mm. If non-NULL, use the
96706 * given task for page fault accounting.
96707 */
96708 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96709 - unsigned long addr, void *buf, int len, int write)
96710 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96711 + unsigned long addr, void *buf, size_t len, int write)
96712 {
96713 struct vm_area_struct *vma;
96714 void *old_buf = buf;
96715 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96716 down_read(&mm->mmap_sem);
96717 /* ignore errors, just check how much was successfully transferred */
96718 while (len) {
96719 - int bytes, ret, offset;
96720 + ssize_t bytes, ret, offset;
96721 void *maddr;
96722 struct page *page = NULL;
96723
96724 @@ -3644,8 +3944,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96725 *
96726 * The caller must hold a reference on @mm.
96727 */
96728 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96729 - void *buf, int len, int write)
96730 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96731 + void *buf, size_t len, int write)
96732 {
96733 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96734 }
96735 @@ -3655,11 +3955,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96736 * Source/target buffer must be kernel space,
96737 * Do not walk the page table directly, use get_user_pages
96738 */
96739 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96740 - void *buf, int len, int write)
96741 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96742 + void *buf, size_t len, int write)
96743 {
96744 struct mm_struct *mm;
96745 - int ret;
96746 + ssize_t ret;
96747
96748 mm = get_task_mm(tsk);
96749 if (!mm)
96750 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96751 index e58725a..e0be017 100644
96752 --- a/mm/mempolicy.c
96753 +++ b/mm/mempolicy.c
96754 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96755 unsigned long vmstart;
96756 unsigned long vmend;
96757
96758 +#ifdef CONFIG_PAX_SEGMEXEC
96759 + struct vm_area_struct *vma_m;
96760 +#endif
96761 +
96762 vma = find_vma(mm, start);
96763 if (!vma || vma->vm_start > start)
96764 return -EFAULT;
96765 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96766 err = vma_replace_policy(vma, new_pol);
96767 if (err)
96768 goto out;
96769 +
96770 +#ifdef CONFIG_PAX_SEGMEXEC
96771 + vma_m = pax_find_mirror_vma(vma);
96772 + if (vma_m) {
96773 + err = vma_replace_policy(vma_m, new_pol);
96774 + if (err)
96775 + goto out;
96776 + }
96777 +#endif
96778 +
96779 }
96780
96781 out:
96782 @@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96783
96784 if (end < start)
96785 return -EINVAL;
96786 +
96787 +#ifdef CONFIG_PAX_SEGMEXEC
96788 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96789 + if (end > SEGMEXEC_TASK_SIZE)
96790 + return -EINVAL;
96791 + } else
96792 +#endif
96793 +
96794 + if (end > TASK_SIZE)
96795 + return -EINVAL;
96796 +
96797 if (end == start)
96798 return 0;
96799
96800 @@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96801 */
96802 tcred = __task_cred(task);
96803 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96804 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96805 - !capable(CAP_SYS_NICE)) {
96806 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96807 rcu_read_unlock();
96808 err = -EPERM;
96809 goto out_put;
96810 @@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96811 goto out;
96812 }
96813
96814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96815 + if (mm != current->mm &&
96816 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96817 + mmput(mm);
96818 + err = -EPERM;
96819 + goto out;
96820 + }
96821 +#endif
96822 +
96823 err = do_migrate_pages(mm, old, new,
96824 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96825
96826 diff --git a/mm/migrate.c b/mm/migrate.c
96827 index 0143995..b294728 100644
96828 --- a/mm/migrate.c
96829 +++ b/mm/migrate.c
96830 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96831 */
96832 tcred = __task_cred(task);
96833 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96834 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96835 - !capable(CAP_SYS_NICE)) {
96836 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96837 rcu_read_unlock();
96838 err = -EPERM;
96839 goto out;
96840 diff --git a/mm/mlock.c b/mm/mlock.c
96841 index 73cf098..ab547c7 100644
96842 --- a/mm/mlock.c
96843 +++ b/mm/mlock.c
96844 @@ -14,6 +14,7 @@
96845 #include <linux/pagevec.h>
96846 #include <linux/mempolicy.h>
96847 #include <linux/syscalls.h>
96848 +#include <linux/security.h>
96849 #include <linux/sched.h>
96850 #include <linux/export.h>
96851 #include <linux/rmap.h>
96852 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96853 {
96854 unsigned long nstart, end, tmp;
96855 struct vm_area_struct * vma, * prev;
96856 - int error;
96857 + int error = 0;
96858
96859 VM_BUG_ON(start & ~PAGE_MASK);
96860 VM_BUG_ON(len != PAGE_ALIGN(len));
96861 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96862 return -EINVAL;
96863 if (end == start)
96864 return 0;
96865 + if (end > TASK_SIZE)
96866 + return -EINVAL;
96867 +
96868 vma = find_vma(current->mm, start);
96869 if (!vma || vma->vm_start > start)
96870 return -ENOMEM;
96871 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96872 for (nstart = start ; ; ) {
96873 vm_flags_t newflags;
96874
96875 +#ifdef CONFIG_PAX_SEGMEXEC
96876 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96877 + break;
96878 +#endif
96879 +
96880 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96881
96882 newflags = vma->vm_flags & ~VM_LOCKED;
96883 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96884 locked += current->mm->locked_vm;
96885
96886 /* check against resource limits */
96887 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96888 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96889 error = do_mlock(start, len, 1);
96890
96891 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96892 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96893 vm_flags_t newflags;
96894
96895 +#ifdef CONFIG_PAX_SEGMEXEC
96896 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96897 + break;
96898 +#endif
96899 +
96900 newflags = vma->vm_flags & ~VM_LOCKED;
96901 if (flags & MCL_CURRENT)
96902 newflags |= VM_LOCKED;
96903 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96904 lock_limit >>= PAGE_SHIFT;
96905
96906 ret = -ENOMEM;
96907 +
96908 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96909 +
96910 down_write(&current->mm->mmap_sem);
96911 -
96912 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96913 capable(CAP_IPC_LOCK))
96914 ret = do_mlockall(flags);
96915 diff --git a/mm/mmap.c b/mm/mmap.c
96916 index 1620adb..348da48 100644
96917 --- a/mm/mmap.c
96918 +++ b/mm/mmap.c
96919 @@ -41,6 +41,7 @@
96920 #include <linux/notifier.h>
96921 #include <linux/memory.h>
96922 #include <linux/printk.h>
96923 +#include <linux/random.h>
96924
96925 #include <asm/uaccess.h>
96926 #include <asm/cacheflush.h>
96927 @@ -57,6 +58,16 @@
96928 #define arch_rebalance_pgtables(addr, len) (addr)
96929 #endif
96930
96931 +static inline void verify_mm_writelocked(struct mm_struct *mm)
96932 +{
96933 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96934 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96935 + up_read(&mm->mmap_sem);
96936 + BUG();
96937 + }
96938 +#endif
96939 +}
96940 +
96941 static void unmap_region(struct mm_struct *mm,
96942 struct vm_area_struct *vma, struct vm_area_struct *prev,
96943 unsigned long start, unsigned long end);
96944 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96945 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96946 *
96947 */
96948 -pgprot_t protection_map[16] = {
96949 +pgprot_t protection_map[16] __read_only = {
96950 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96951 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96952 };
96953
96954 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
96955 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96956 {
96957 - return __pgprot(pgprot_val(protection_map[vm_flags &
96958 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96959 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96960 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96961 +
96962 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96963 + if (!(__supported_pte_mask & _PAGE_NX) &&
96964 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96965 + (vm_flags & (VM_READ | VM_WRITE)))
96966 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96967 +#endif
96968 +
96969 + return prot;
96970 }
96971 EXPORT_SYMBOL(vm_get_page_prot);
96972
96973 @@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96974 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96975 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96976 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96977 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96978 /*
96979 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96980 * other variables. It can be updated by several CPUs frequently.
96981 @@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96982 struct vm_area_struct *next = vma->vm_next;
96983
96984 might_sleep();
96985 + BUG_ON(vma->vm_mirror);
96986 if (vma->vm_ops && vma->vm_ops->close)
96987 vma->vm_ops->close(vma);
96988 if (vma->vm_file)
96989 @@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
96990
96991 SYSCALL_DEFINE1(brk, unsigned long, brk)
96992 {
96993 + unsigned long rlim;
96994 unsigned long retval;
96995 unsigned long newbrk, oldbrk;
96996 struct mm_struct *mm = current->mm;
96997 @@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96998 * segment grow beyond its set limit the in case where the limit is
96999 * not page aligned -Ram Gupta
97000 */
97001 - if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
97002 + rlim = rlimit(RLIMIT_DATA);
97003 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97004 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97005 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97006 + rlim = 4096 * PAGE_SIZE;
97007 +#endif
97008 + if (check_data_rlimit(rlim, brk, mm->start_brk,
97009 mm->end_data, mm->start_data))
97010 goto out;
97011
97012 @@ -976,6 +1005,12 @@ static int
97013 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97014 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97015 {
97016 +
97017 +#ifdef CONFIG_PAX_SEGMEXEC
97018 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97019 + return 0;
97020 +#endif
97021 +
97022 if (is_mergeable_vma(vma, file, vm_flags) &&
97023 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97024 if (vma->vm_pgoff == vm_pgoff)
97025 @@ -995,6 +1030,12 @@ static int
97026 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97027 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97028 {
97029 +
97030 +#ifdef CONFIG_PAX_SEGMEXEC
97031 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97032 + return 0;
97033 +#endif
97034 +
97035 if (is_mergeable_vma(vma, file, vm_flags) &&
97036 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97037 pgoff_t vm_pglen;
97038 @@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97039 struct vm_area_struct *area, *next;
97040 int err;
97041
97042 +#ifdef CONFIG_PAX_SEGMEXEC
97043 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97044 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97045 +
97046 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97047 +#endif
97048 +
97049 /*
97050 * We later require that vma->vm_flags == vm_flags,
97051 * so this tests vma->vm_flags & VM_SPECIAL, too.
97052 @@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97053 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97054 next = next->vm_next;
97055
97056 +#ifdef CONFIG_PAX_SEGMEXEC
97057 + if (prev)
97058 + prev_m = pax_find_mirror_vma(prev);
97059 + if (area)
97060 + area_m = pax_find_mirror_vma(area);
97061 + if (next)
97062 + next_m = pax_find_mirror_vma(next);
97063 +#endif
97064 +
97065 /*
97066 * Can it merge with the predecessor?
97067 */
97068 @@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97069 /* cases 1, 6 */
97070 err = vma_adjust(prev, prev->vm_start,
97071 next->vm_end, prev->vm_pgoff, NULL);
97072 - } else /* cases 2, 5, 7 */
97073 +
97074 +#ifdef CONFIG_PAX_SEGMEXEC
97075 + if (!err && prev_m)
97076 + err = vma_adjust(prev_m, prev_m->vm_start,
97077 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97078 +#endif
97079 +
97080 + } else { /* cases 2, 5, 7 */
97081 err = vma_adjust(prev, prev->vm_start,
97082 end, prev->vm_pgoff, NULL);
97083 +
97084 +#ifdef CONFIG_PAX_SEGMEXEC
97085 + if (!err && prev_m)
97086 + err = vma_adjust(prev_m, prev_m->vm_start,
97087 + end_m, prev_m->vm_pgoff, NULL);
97088 +#endif
97089 +
97090 + }
97091 if (err)
97092 return NULL;
97093 khugepaged_enter_vma_merge(prev, vm_flags);
97094 @@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97095 mpol_equal(policy, vma_policy(next)) &&
97096 can_vma_merge_before(next, vm_flags,
97097 anon_vma, file, pgoff+pglen)) {
97098 - if (prev && addr < prev->vm_end) /* case 4 */
97099 + if (prev && addr < prev->vm_end) { /* case 4 */
97100 err = vma_adjust(prev, prev->vm_start,
97101 addr, prev->vm_pgoff, NULL);
97102 - else /* cases 3, 8 */
97103 +
97104 +#ifdef CONFIG_PAX_SEGMEXEC
97105 + if (!err && prev_m)
97106 + err = vma_adjust(prev_m, prev_m->vm_start,
97107 + addr_m, prev_m->vm_pgoff, NULL);
97108 +#endif
97109 +
97110 + } else { /* cases 3, 8 */
97111 err = vma_adjust(area, addr, next->vm_end,
97112 next->vm_pgoff - pglen, NULL);
97113 +
97114 +#ifdef CONFIG_PAX_SEGMEXEC
97115 + if (!err && area_m)
97116 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97117 + next_m->vm_pgoff - pglen, NULL);
97118 +#endif
97119 +
97120 + }
97121 if (err)
97122 return NULL;
97123 khugepaged_enter_vma_merge(area, vm_flags);
97124 @@ -1208,8 +1295,10 @@ none:
97125 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97126 struct file *file, long pages)
97127 {
97128 - const unsigned long stack_flags
97129 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97130 +
97131 +#ifdef CONFIG_PAX_RANDMMAP
97132 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97133 +#endif
97134
97135 mm->total_vm += pages;
97136
97137 @@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97138 mm->shared_vm += pages;
97139 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97140 mm->exec_vm += pages;
97141 - } else if (flags & stack_flags)
97142 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97143 mm->stack_vm += pages;
97144 }
97145 #endif /* CONFIG_PROC_FS */
97146 @@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97147 locked += mm->locked_vm;
97148 lock_limit = rlimit(RLIMIT_MEMLOCK);
97149 lock_limit >>= PAGE_SHIFT;
97150 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97151 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97152 return -EAGAIN;
97153 }
97154 @@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97155 * (the exception is when the underlying filesystem is noexec
97156 * mounted, in which case we dont add PROT_EXEC.)
97157 */
97158 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97159 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97160 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97161 prot |= PROT_EXEC;
97162
97163 @@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97164 /* Obtain the address to map to. we verify (or select) it and ensure
97165 * that it represents a valid section of the address space.
97166 */
97167 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97168 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97169 if (addr & ~PAGE_MASK)
97170 return addr;
97171
97172 @@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97173 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97174 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97175
97176 +#ifdef CONFIG_PAX_MPROTECT
97177 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97178 +
97179 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97180 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97181 + mm->binfmt->handle_mmap)
97182 + mm->binfmt->handle_mmap(file);
97183 +#endif
97184 +
97185 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97186 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97187 + gr_log_rwxmmap(file);
97188 +
97189 +#ifdef CONFIG_PAX_EMUPLT
97190 + vm_flags &= ~VM_EXEC;
97191 +#else
97192 + return -EPERM;
97193 +#endif
97194 +
97195 + }
97196 +
97197 + if (!(vm_flags & VM_EXEC))
97198 + vm_flags &= ~VM_MAYEXEC;
97199 +#else
97200 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97201 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97202 +#endif
97203 + else
97204 + vm_flags &= ~VM_MAYWRITE;
97205 + }
97206 +#endif
97207 +
97208 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97209 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97210 + vm_flags &= ~VM_PAGEEXEC;
97211 +#endif
97212 +
97213 if (flags & MAP_LOCKED)
97214 if (!can_do_mlock())
97215 return -EPERM;
97216 @@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97217 vm_flags |= VM_NORESERVE;
97218 }
97219
97220 + if (!gr_acl_handle_mmap(file, prot))
97221 + return -EACCES;
97222 +
97223 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97224 if (!IS_ERR_VALUE(addr) &&
97225 ((vm_flags & VM_LOCKED) ||
97226 @@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97227 vm_flags_t vm_flags = vma->vm_flags;
97228
97229 /* If it was private or non-writable, the write bit is already clear */
97230 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97231 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97232 return 0;
97233
97234 /* The backer wishes to know when pages are first written to? */
97235 @@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97236 struct rb_node **rb_link, *rb_parent;
97237 unsigned long charged = 0;
97238
97239 +#ifdef CONFIG_PAX_SEGMEXEC
97240 + struct vm_area_struct *vma_m = NULL;
97241 +#endif
97242 +
97243 + /*
97244 + * mm->mmap_sem is required to protect against another thread
97245 + * changing the mappings in case we sleep.
97246 + */
97247 + verify_mm_writelocked(mm);
97248 +
97249 /* Check against address space limit. */
97250 +
97251 +#ifdef CONFIG_PAX_RANDMMAP
97252 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97253 +#endif
97254 +
97255 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97256 unsigned long nr_pages;
97257
97258 @@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97259
97260 /* Clear old maps */
97261 error = -ENOMEM;
97262 -munmap_back:
97263 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97264 if (do_munmap(mm, addr, len))
97265 return -ENOMEM;
97266 - goto munmap_back;
97267 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97268 }
97269
97270 /*
97271 @@ -1595,6 +1739,16 @@ munmap_back:
97272 goto unacct_error;
97273 }
97274
97275 +#ifdef CONFIG_PAX_SEGMEXEC
97276 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97277 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97278 + if (!vma_m) {
97279 + error = -ENOMEM;
97280 + goto free_vma;
97281 + }
97282 + }
97283 +#endif
97284 +
97285 vma->vm_mm = mm;
97286 vma->vm_start = addr;
97287 vma->vm_end = addr + len;
97288 @@ -1625,6 +1779,13 @@ munmap_back:
97289 if (error)
97290 goto unmap_and_free_vma;
97291
97292 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97293 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97294 + vma->vm_flags |= VM_PAGEEXEC;
97295 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97296 + }
97297 +#endif
97298 +
97299 /* Can addr have changed??
97300 *
97301 * Answer: Yes, several device drivers can do it in their
97302 @@ -1643,6 +1804,12 @@ munmap_back:
97303 }
97304
97305 vma_link(mm, vma, prev, rb_link, rb_parent);
97306 +
97307 +#ifdef CONFIG_PAX_SEGMEXEC
97308 + if (vma_m)
97309 + BUG_ON(pax_mirror_vma(vma_m, vma));
97310 +#endif
97311 +
97312 /* Once vma denies write, undo our temporary denial count */
97313 if (file) {
97314 if (vm_flags & VM_SHARED)
97315 @@ -1655,6 +1822,7 @@ out:
97316 perf_event_mmap(vma);
97317
97318 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97319 + track_exec_limit(mm, addr, addr + len, vm_flags);
97320 if (vm_flags & VM_LOCKED) {
97321 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97322 vma == get_gate_vma(current->mm)))
97323 @@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97324 if (vm_flags & VM_DENYWRITE)
97325 allow_write_access(file);
97326 free_vma:
97327 +
97328 +#ifdef CONFIG_PAX_SEGMEXEC
97329 + if (vma_m)
97330 + kmem_cache_free(vm_area_cachep, vma_m);
97331 +#endif
97332 +
97333 kmem_cache_free(vm_area_cachep, vma);
97334 unacct_error:
97335 if (charged)
97336 @@ -1699,7 +1873,63 @@ unacct_error:
97337 return error;
97338 }
97339
97340 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97341 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97342 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97343 +{
97344 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97345 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97346 +
97347 + return 0;
97348 +}
97349 +#endif
97350 +
97351 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97352 +{
97353 + if (!vma) {
97354 +#ifdef CONFIG_STACK_GROWSUP
97355 + if (addr > sysctl_heap_stack_gap)
97356 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97357 + else
97358 + vma = find_vma(current->mm, 0);
97359 + if (vma && (vma->vm_flags & VM_GROWSUP))
97360 + return false;
97361 +#endif
97362 + return true;
97363 + }
97364 +
97365 + if (addr + len > vma->vm_start)
97366 + return false;
97367 +
97368 + if (vma->vm_flags & VM_GROWSDOWN)
97369 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97370 +#ifdef CONFIG_STACK_GROWSUP
97371 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97372 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97373 +#endif
97374 + else if (offset)
97375 + return offset <= vma->vm_start - addr - len;
97376 +
97377 + return true;
97378 +}
97379 +
97380 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97381 +{
97382 + if (vma->vm_start < len)
97383 + return -ENOMEM;
97384 +
97385 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97386 + if (offset <= vma->vm_start - len)
97387 + return vma->vm_start - len - offset;
97388 + else
97389 + return -ENOMEM;
97390 + }
97391 +
97392 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97393 + return vma->vm_start - len - sysctl_heap_stack_gap;
97394 + return -ENOMEM;
97395 +}
97396 +
97397 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97398 {
97399 /*
97400 * We implement the search by looking for an rbtree node that
97401 @@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97402 }
97403 }
97404
97405 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97406 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97407 check_current:
97408 /* Check if current node has a suitable gap */
97409 if (gap_start > high_limit)
97410 return -ENOMEM;
97411 +
97412 + if (gap_end - gap_start > info->threadstack_offset)
97413 + gap_start += info->threadstack_offset;
97414 + else
97415 + gap_start = gap_end;
97416 +
97417 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97418 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97419 + gap_start += sysctl_heap_stack_gap;
97420 + else
97421 + gap_start = gap_end;
97422 + }
97423 + if (vma->vm_flags & VM_GROWSDOWN) {
97424 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97425 + gap_end -= sysctl_heap_stack_gap;
97426 + else
97427 + gap_end = gap_start;
97428 + }
97429 if (gap_end >= low_limit && gap_end - gap_start >= length)
97430 goto found;
97431
97432 @@ -1801,7 +2049,7 @@ found:
97433 return gap_start;
97434 }
97435
97436 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97437 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97438 {
97439 struct mm_struct *mm = current->mm;
97440 struct vm_area_struct *vma;
97441 @@ -1855,6 +2103,24 @@ check_current:
97442 gap_end = vma->vm_start;
97443 if (gap_end < low_limit)
97444 return -ENOMEM;
97445 +
97446 + if (gap_end - gap_start > info->threadstack_offset)
97447 + gap_end -= info->threadstack_offset;
97448 + else
97449 + gap_end = gap_start;
97450 +
97451 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97452 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97453 + gap_start += sysctl_heap_stack_gap;
97454 + else
97455 + gap_start = gap_end;
97456 + }
97457 + if (vma->vm_flags & VM_GROWSDOWN) {
97458 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97459 + gap_end -= sysctl_heap_stack_gap;
97460 + else
97461 + gap_end = gap_start;
97462 + }
97463 if (gap_start <= high_limit && gap_end - gap_start >= length)
97464 goto found;
97465
97466 @@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97467 struct mm_struct *mm = current->mm;
97468 struct vm_area_struct *vma;
97469 struct vm_unmapped_area_info info;
97470 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97471
97472 if (len > TASK_SIZE - mmap_min_addr)
97473 return -ENOMEM;
97474 @@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97475 if (flags & MAP_FIXED)
97476 return addr;
97477
97478 +#ifdef CONFIG_PAX_RANDMMAP
97479 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97480 +#endif
97481 +
97482 if (addr) {
97483 addr = PAGE_ALIGN(addr);
97484 vma = find_vma(mm, addr);
97485 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97486 - (!vma || addr + len <= vma->vm_start))
97487 + check_heap_stack_gap(vma, addr, len, offset))
97488 return addr;
97489 }
97490
97491 @@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97492 info.low_limit = mm->mmap_base;
97493 info.high_limit = TASK_SIZE;
97494 info.align_mask = 0;
97495 + info.threadstack_offset = offset;
97496 return vm_unmapped_area(&info);
97497 }
97498 #endif
97499 @@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97500 struct mm_struct *mm = current->mm;
97501 unsigned long addr = addr0;
97502 struct vm_unmapped_area_info info;
97503 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97504
97505 /* requested length too big for entire address space */
97506 if (len > TASK_SIZE - mmap_min_addr)
97507 @@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97508 if (flags & MAP_FIXED)
97509 return addr;
97510
97511 +#ifdef CONFIG_PAX_RANDMMAP
97512 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97513 +#endif
97514 +
97515 /* requesting a specific address */
97516 if (addr) {
97517 addr = PAGE_ALIGN(addr);
97518 vma = find_vma(mm, addr);
97519 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97520 - (!vma || addr + len <= vma->vm_start))
97521 + check_heap_stack_gap(vma, addr, len, offset))
97522 return addr;
97523 }
97524
97525 @@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97526 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97527 info.high_limit = mm->mmap_base;
97528 info.align_mask = 0;
97529 + info.threadstack_offset = offset;
97530 addr = vm_unmapped_area(&info);
97531
97532 /*
97533 @@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97534 VM_BUG_ON(addr != -ENOMEM);
97535 info.flags = 0;
97536 info.low_limit = TASK_UNMAPPED_BASE;
97537 +
97538 +#ifdef CONFIG_PAX_RANDMMAP
97539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97540 + info.low_limit += mm->delta_mmap;
97541 +#endif
97542 +
97543 info.high_limit = TASK_SIZE;
97544 addr = vm_unmapped_area(&info);
97545 }
97546 @@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97547 return vma;
97548 }
97549
97550 +#ifdef CONFIG_PAX_SEGMEXEC
97551 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97552 +{
97553 + struct vm_area_struct *vma_m;
97554 +
97555 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97556 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97557 + BUG_ON(vma->vm_mirror);
97558 + return NULL;
97559 + }
97560 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97561 + vma_m = vma->vm_mirror;
97562 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97563 + BUG_ON(vma->vm_file != vma_m->vm_file);
97564 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97565 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97566 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97567 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97568 + return vma_m;
97569 +}
97570 +#endif
97571 +
97572 /*
97573 * Verify that the stack growth is acceptable and
97574 * update accounting. This is shared with both the
97575 @@ -2107,8 +2413,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97576
97577 /* Stack limit test */
97578 actual_size = size;
97579 - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
97580 - actual_size -= PAGE_SIZE;
97581 + gr_learn_resource(current, RLIMIT_STACK, actual_size, 1);
97582 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97583 return -ENOMEM;
97584
97585 @@ -2119,6 +2424,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97586 locked = mm->locked_vm + grow;
97587 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97588 limit >>= PAGE_SHIFT;
97589 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97590 if (locked > limit && !capable(CAP_IPC_LOCK))
97591 return -ENOMEM;
97592 }
97593 @@ -2148,37 +2454,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97594 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97595 * vma is the last one with address > vma->vm_end. Have to extend vma.
97596 */
97597 +#ifndef CONFIG_IA64
97598 +static
97599 +#endif
97600 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97601 {
97602 int error;
97603 + bool locknext;
97604
97605 if (!(vma->vm_flags & VM_GROWSUP))
97606 return -EFAULT;
97607
97608 + /* Also guard against wrapping around to address 0. */
97609 + if (address < PAGE_ALIGN(address+1))
97610 + address = PAGE_ALIGN(address+1);
97611 + else
97612 + return -ENOMEM;
97613 +
97614 /*
97615 * We must make sure the anon_vma is allocated
97616 * so that the anon_vma locking is not a noop.
97617 */
97618 if (unlikely(anon_vma_prepare(vma)))
97619 return -ENOMEM;
97620 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97621 + if (locknext && anon_vma_prepare(vma->vm_next))
97622 + return -ENOMEM;
97623 vma_lock_anon_vma(vma);
97624 + if (locknext)
97625 + vma_lock_anon_vma(vma->vm_next);
97626
97627 /*
97628 * vma->vm_start/vm_end cannot change under us because the caller
97629 * is required to hold the mmap_sem in read mode. We need the
97630 - * anon_vma lock to serialize against concurrent expand_stacks.
97631 - * Also guard against wrapping around to address 0.
97632 + * anon_vma locks to serialize against concurrent expand_stacks
97633 + * and expand_upwards.
97634 */
97635 - if (address < PAGE_ALIGN(address+4))
97636 - address = PAGE_ALIGN(address+4);
97637 - else {
97638 - vma_unlock_anon_vma(vma);
97639 - return -ENOMEM;
97640 - }
97641 error = 0;
97642
97643 /* Somebody else might have raced and expanded it already */
97644 - if (address > vma->vm_end) {
97645 + 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)
97646 + error = -ENOMEM;
97647 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97648 unsigned long size, grow;
97649
97650 size = address - vma->vm_start;
97651 @@ -2213,6 +2530,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97652 }
97653 }
97654 }
97655 + if (locknext)
97656 + vma_unlock_anon_vma(vma->vm_next);
97657 vma_unlock_anon_vma(vma);
97658 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97659 validate_mm(vma->vm_mm);
97660 @@ -2227,6 +2546,8 @@ int expand_downwards(struct vm_area_struct *vma,
97661 unsigned long address)
97662 {
97663 int error;
97664 + bool lockprev = false;
97665 + struct vm_area_struct *prev;
97666
97667 /*
97668 * We must make sure the anon_vma is allocated
97669 @@ -2240,6 +2561,15 @@ int expand_downwards(struct vm_area_struct *vma,
97670 if (error)
97671 return error;
97672
97673 + prev = vma->vm_prev;
97674 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97675 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97676 +#endif
97677 + if (lockprev && anon_vma_prepare(prev))
97678 + return -ENOMEM;
97679 + if (lockprev)
97680 + vma_lock_anon_vma(prev);
97681 +
97682 vma_lock_anon_vma(vma);
97683
97684 /*
97685 @@ -2249,9 +2579,17 @@ int expand_downwards(struct vm_area_struct *vma,
97686 */
97687
97688 /* Somebody else might have raced and expanded it already */
97689 - if (address < vma->vm_start) {
97690 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97691 + error = -ENOMEM;
97692 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97693 unsigned long size, grow;
97694
97695 +#ifdef CONFIG_PAX_SEGMEXEC
97696 + struct vm_area_struct *vma_m;
97697 +
97698 + vma_m = pax_find_mirror_vma(vma);
97699 +#endif
97700 +
97701 size = vma->vm_end - address;
97702 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97703
97704 @@ -2276,13 +2614,27 @@ int expand_downwards(struct vm_area_struct *vma,
97705 vma->vm_pgoff -= grow;
97706 anon_vma_interval_tree_post_update_vma(vma);
97707 vma_gap_update(vma);
97708 +
97709 +#ifdef CONFIG_PAX_SEGMEXEC
97710 + if (vma_m) {
97711 + anon_vma_interval_tree_pre_update_vma(vma_m);
97712 + vma_m->vm_start -= grow << PAGE_SHIFT;
97713 + vma_m->vm_pgoff -= grow;
97714 + anon_vma_interval_tree_post_update_vma(vma_m);
97715 + vma_gap_update(vma_m);
97716 + }
97717 +#endif
97718 +
97719 spin_unlock(&vma->vm_mm->page_table_lock);
97720
97721 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97722 perf_event_mmap(vma);
97723 }
97724 }
97725 }
97726 vma_unlock_anon_vma(vma);
97727 + if (lockprev)
97728 + vma_unlock_anon_vma(prev);
97729 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97730 validate_mm(vma->vm_mm);
97731 return error;
97732 @@ -2380,6 +2732,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97733 do {
97734 long nrpages = vma_pages(vma);
97735
97736 +#ifdef CONFIG_PAX_SEGMEXEC
97737 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97738 + vma = remove_vma(vma);
97739 + continue;
97740 + }
97741 +#endif
97742 +
97743 if (vma->vm_flags & VM_ACCOUNT)
97744 nr_accounted += nrpages;
97745 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97746 @@ -2424,6 +2783,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97747 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97748 vma->vm_prev = NULL;
97749 do {
97750 +
97751 +#ifdef CONFIG_PAX_SEGMEXEC
97752 + if (vma->vm_mirror) {
97753 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97754 + vma->vm_mirror->vm_mirror = NULL;
97755 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97756 + vma->vm_mirror = NULL;
97757 + }
97758 +#endif
97759 +
97760 vma_rb_erase(vma, &mm->mm_rb);
97761 mm->map_count--;
97762 tail_vma = vma;
97763 @@ -2451,14 +2820,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97764 struct vm_area_struct *new;
97765 int err = -ENOMEM;
97766
97767 +#ifdef CONFIG_PAX_SEGMEXEC
97768 + struct vm_area_struct *vma_m, *new_m = NULL;
97769 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97770 +#endif
97771 +
97772 if (is_vm_hugetlb_page(vma) && (addr &
97773 ~(huge_page_mask(hstate_vma(vma)))))
97774 return -EINVAL;
97775
97776 +#ifdef CONFIG_PAX_SEGMEXEC
97777 + vma_m = pax_find_mirror_vma(vma);
97778 +#endif
97779 +
97780 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97781 if (!new)
97782 goto out_err;
97783
97784 +#ifdef CONFIG_PAX_SEGMEXEC
97785 + if (vma_m) {
97786 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97787 + if (!new_m) {
97788 + kmem_cache_free(vm_area_cachep, new);
97789 + goto out_err;
97790 + }
97791 + }
97792 +#endif
97793 +
97794 /* most fields are the same, copy all, and then fixup */
97795 *new = *vma;
97796
97797 @@ -2471,6 +2859,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97798 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97799 }
97800
97801 +#ifdef CONFIG_PAX_SEGMEXEC
97802 + if (vma_m) {
97803 + *new_m = *vma_m;
97804 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97805 + new_m->vm_mirror = new;
97806 + new->vm_mirror = new_m;
97807 +
97808 + if (new_below)
97809 + new_m->vm_end = addr_m;
97810 + else {
97811 + new_m->vm_start = addr_m;
97812 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97813 + }
97814 + }
97815 +#endif
97816 +
97817 err = vma_dup_policy(vma, new);
97818 if (err)
97819 goto out_free_vma;
97820 @@ -2491,6 +2895,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97821 else
97822 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97823
97824 +#ifdef CONFIG_PAX_SEGMEXEC
97825 + if (!err && vma_m) {
97826 + struct mempolicy *pol = vma_policy(new);
97827 +
97828 + if (anon_vma_clone(new_m, vma_m))
97829 + goto out_free_mpol;
97830 +
97831 + mpol_get(pol);
97832 + set_vma_policy(new_m, pol);
97833 +
97834 + if (new_m->vm_file)
97835 + get_file(new_m->vm_file);
97836 +
97837 + if (new_m->vm_ops && new_m->vm_ops->open)
97838 + new_m->vm_ops->open(new_m);
97839 +
97840 + if (new_below)
97841 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97842 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97843 + else
97844 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97845 +
97846 + if (err) {
97847 + if (new_m->vm_ops && new_m->vm_ops->close)
97848 + new_m->vm_ops->close(new_m);
97849 + if (new_m->vm_file)
97850 + fput(new_m->vm_file);
97851 + mpol_put(pol);
97852 + }
97853 + }
97854 +#endif
97855 +
97856 /* Success. */
97857 if (!err)
97858 return 0;
97859 @@ -2500,10 +2936,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97860 new->vm_ops->close(new);
97861 if (new->vm_file)
97862 fput(new->vm_file);
97863 - unlink_anon_vmas(new);
97864 out_free_mpol:
97865 mpol_put(vma_policy(new));
97866 out_free_vma:
97867 +
97868 +#ifdef CONFIG_PAX_SEGMEXEC
97869 + if (new_m) {
97870 + unlink_anon_vmas(new_m);
97871 + kmem_cache_free(vm_area_cachep, new_m);
97872 + }
97873 +#endif
97874 +
97875 + unlink_anon_vmas(new);
97876 kmem_cache_free(vm_area_cachep, new);
97877 out_err:
97878 return err;
97879 @@ -2516,6 +2960,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97880 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97881 unsigned long addr, int new_below)
97882 {
97883 +
97884 +#ifdef CONFIG_PAX_SEGMEXEC
97885 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97886 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97887 + if (mm->map_count >= sysctl_max_map_count-1)
97888 + return -ENOMEM;
97889 + } else
97890 +#endif
97891 +
97892 if (mm->map_count >= sysctl_max_map_count)
97893 return -ENOMEM;
97894
97895 @@ -2527,11 +2980,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97896 * work. This now handles partial unmappings.
97897 * Jeremy Fitzhardinge <jeremy@goop.org>
97898 */
97899 +#ifdef CONFIG_PAX_SEGMEXEC
97900 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97901 {
97902 + int ret = __do_munmap(mm, start, len);
97903 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97904 + return ret;
97905 +
97906 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97907 +}
97908 +
97909 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97910 +#else
97911 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97912 +#endif
97913 +{
97914 unsigned long end;
97915 struct vm_area_struct *vma, *prev, *last;
97916
97917 + /*
97918 + * mm->mmap_sem is required to protect against another thread
97919 + * changing the mappings in case we sleep.
97920 + */
97921 + verify_mm_writelocked(mm);
97922 +
97923 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97924 return -EINVAL;
97925
97926 @@ -2607,6 +3079,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97927 /* Fix up all other VM information */
97928 remove_vma_list(mm, vma);
97929
97930 + track_exec_limit(mm, start, end, 0UL);
97931 +
97932 return 0;
97933 }
97934
97935 @@ -2615,6 +3089,13 @@ int vm_munmap(unsigned long start, size_t len)
97936 int ret;
97937 struct mm_struct *mm = current->mm;
97938
97939 +
97940 +#ifdef CONFIG_PAX_SEGMEXEC
97941 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97942 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97943 + return -EINVAL;
97944 +#endif
97945 +
97946 down_write(&mm->mmap_sem);
97947 ret = do_munmap(mm, start, len);
97948 up_write(&mm->mmap_sem);
97949 @@ -2628,16 +3109,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97950 return vm_munmap(addr, len);
97951 }
97952
97953 -static inline void verify_mm_writelocked(struct mm_struct *mm)
97954 -{
97955 -#ifdef CONFIG_DEBUG_VM
97956 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97957 - WARN_ON(1);
97958 - up_read(&mm->mmap_sem);
97959 - }
97960 -#endif
97961 -}
97962 -
97963 /*
97964 * this is really a simplified "do_mmap". it only handles
97965 * anonymous maps. eventually we may be able to do some
97966 @@ -2651,6 +3122,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97967 struct rb_node **rb_link, *rb_parent;
97968 pgoff_t pgoff = addr >> PAGE_SHIFT;
97969 int error;
97970 + unsigned long charged;
97971
97972 len = PAGE_ALIGN(len);
97973 if (!len)
97974 @@ -2658,10 +3130,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97975
97976 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97977
97978 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97979 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97980 + flags &= ~VM_EXEC;
97981 +
97982 +#ifdef CONFIG_PAX_MPROTECT
97983 + if (mm->pax_flags & MF_PAX_MPROTECT)
97984 + flags &= ~VM_MAYEXEC;
97985 +#endif
97986 +
97987 + }
97988 +#endif
97989 +
97990 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97991 if (error & ~PAGE_MASK)
97992 return error;
97993
97994 + charged = len >> PAGE_SHIFT;
97995 +
97996 error = mlock_future_check(mm, mm->def_flags, len);
97997 if (error)
97998 return error;
97999 @@ -2675,21 +3161,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98000 /*
98001 * Clear old maps. this also does some error checking for us
98002 */
98003 - munmap_back:
98004 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98005 if (do_munmap(mm, addr, len))
98006 return -ENOMEM;
98007 - goto munmap_back;
98008 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98009 }
98010
98011 /* Check against address space limits *after* clearing old maps... */
98012 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98013 + if (!may_expand_vm(mm, charged))
98014 return -ENOMEM;
98015
98016 if (mm->map_count > sysctl_max_map_count)
98017 return -ENOMEM;
98018
98019 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98020 + if (security_vm_enough_memory_mm(mm, charged))
98021 return -ENOMEM;
98022
98023 /* Can we just expand an old private anonymous mapping? */
98024 @@ -2703,7 +3188,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98025 */
98026 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98027 if (!vma) {
98028 - vm_unacct_memory(len >> PAGE_SHIFT);
98029 + vm_unacct_memory(charged);
98030 return -ENOMEM;
98031 }
98032
98033 @@ -2717,10 +3202,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98034 vma_link(mm, vma, prev, rb_link, rb_parent);
98035 out:
98036 perf_event_mmap(vma);
98037 - mm->total_vm += len >> PAGE_SHIFT;
98038 + mm->total_vm += charged;
98039 if (flags & VM_LOCKED)
98040 - mm->locked_vm += (len >> PAGE_SHIFT);
98041 + mm->locked_vm += charged;
98042 vma->vm_flags |= VM_SOFTDIRTY;
98043 + track_exec_limit(mm, addr, addr + len, flags);
98044 return addr;
98045 }
98046
98047 @@ -2782,6 +3268,7 @@ void exit_mmap(struct mm_struct *mm)
98048 while (vma) {
98049 if (vma->vm_flags & VM_ACCOUNT)
98050 nr_accounted += vma_pages(vma);
98051 + vma->vm_mirror = NULL;
98052 vma = remove_vma(vma);
98053 }
98054 vm_unacct_memory(nr_accounted);
98055 @@ -2799,6 +3286,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98056 struct vm_area_struct *prev;
98057 struct rb_node **rb_link, *rb_parent;
98058
98059 +#ifdef CONFIG_PAX_SEGMEXEC
98060 + struct vm_area_struct *vma_m = NULL;
98061 +#endif
98062 +
98063 + if (security_mmap_addr(vma->vm_start))
98064 + return -EPERM;
98065 +
98066 /*
98067 * The vm_pgoff of a purely anonymous vma should be irrelevant
98068 * until its first write fault, when page's anon_vma and index
98069 @@ -2822,7 +3316,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98070 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98071 return -ENOMEM;
98072
98073 +#ifdef CONFIG_PAX_SEGMEXEC
98074 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98075 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98076 + if (!vma_m)
98077 + return -ENOMEM;
98078 + }
98079 +#endif
98080 +
98081 vma_link(mm, vma, prev, rb_link, rb_parent);
98082 +
98083 +#ifdef CONFIG_PAX_SEGMEXEC
98084 + if (vma_m)
98085 + BUG_ON(pax_mirror_vma(vma_m, vma));
98086 +#endif
98087 +
98088 return 0;
98089 }
98090
98091 @@ -2841,6 +3349,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98092 struct rb_node **rb_link, *rb_parent;
98093 bool faulted_in_anon_vma = true;
98094
98095 + BUG_ON(vma->vm_mirror);
98096 +
98097 /*
98098 * If anonymous vma has not yet been faulted, update new pgoff
98099 * to match new location, to increase its chance of merging.
98100 @@ -2905,6 +3415,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98101 return NULL;
98102 }
98103
98104 +#ifdef CONFIG_PAX_SEGMEXEC
98105 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98106 +{
98107 + struct vm_area_struct *prev_m;
98108 + struct rb_node **rb_link_m, *rb_parent_m;
98109 + struct mempolicy *pol_m;
98110 +
98111 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98112 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98113 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98114 + *vma_m = *vma;
98115 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98116 + if (anon_vma_clone(vma_m, vma))
98117 + return -ENOMEM;
98118 + pol_m = vma_policy(vma_m);
98119 + mpol_get(pol_m);
98120 + set_vma_policy(vma_m, pol_m);
98121 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98122 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98123 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98124 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98125 + if (vma_m->vm_file)
98126 + get_file(vma_m->vm_file);
98127 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98128 + vma_m->vm_ops->open(vma_m);
98129 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98130 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98131 + vma_m->vm_mirror = vma;
98132 + vma->vm_mirror = vma_m;
98133 + return 0;
98134 +}
98135 +#endif
98136 +
98137 /*
98138 * Return true if the calling process may expand its vm space by the passed
98139 * number of pages
98140 @@ -2916,6 +3459,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98141
98142 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98143
98144 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98145 if (cur + npages > lim)
98146 return 0;
98147 return 1;
98148 @@ -2998,6 +3542,22 @@ static struct vm_area_struct *__install_special_mapping(
98149 vma->vm_start = addr;
98150 vma->vm_end = addr + len;
98151
98152 +#ifdef CONFIG_PAX_MPROTECT
98153 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98154 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98155 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98156 + return ERR_PTR(-EPERM);
98157 + if (!(vm_flags & VM_EXEC))
98158 + vm_flags &= ~VM_MAYEXEC;
98159 +#else
98160 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98161 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98162 +#endif
98163 + else
98164 + vm_flags &= ~VM_MAYWRITE;
98165 + }
98166 +#endif
98167 +
98168 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98169 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98170
98171 diff --git a/mm/mprotect.c b/mm/mprotect.c
98172 index ace9345..63320dc 100644
98173 --- a/mm/mprotect.c
98174 +++ b/mm/mprotect.c
98175 @@ -24,10 +24,18 @@
98176 #include <linux/migrate.h>
98177 #include <linux/perf_event.h>
98178 #include <linux/ksm.h>
98179 +#include <linux/sched/sysctl.h>
98180 +
98181 +#ifdef CONFIG_PAX_MPROTECT
98182 +#include <linux/elf.h>
98183 +#include <linux/binfmts.h>
98184 +#endif
98185 +
98186 #include <asm/uaccess.h>
98187 #include <asm/pgtable.h>
98188 #include <asm/cacheflush.h>
98189 #include <asm/tlbflush.h>
98190 +#include <asm/mmu_context.h>
98191
98192 /*
98193 * For a prot_numa update we only hold mmap_sem for read so there is a
98194 @@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98195 return pages;
98196 }
98197
98198 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98199 +/* called while holding the mmap semaphor for writing except stack expansion */
98200 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98201 +{
98202 + unsigned long oldlimit, newlimit = 0UL;
98203 +
98204 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98205 + return;
98206 +
98207 + spin_lock(&mm->page_table_lock);
98208 + oldlimit = mm->context.user_cs_limit;
98209 + if ((prot & VM_EXEC) && oldlimit < end)
98210 + /* USER_CS limit moved up */
98211 + newlimit = end;
98212 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98213 + /* USER_CS limit moved down */
98214 + newlimit = start;
98215 +
98216 + if (newlimit) {
98217 + mm->context.user_cs_limit = newlimit;
98218 +
98219 +#ifdef CONFIG_SMP
98220 + wmb();
98221 + cpus_clear(mm->context.cpu_user_cs_mask);
98222 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98223 +#endif
98224 +
98225 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98226 + }
98227 + spin_unlock(&mm->page_table_lock);
98228 + if (newlimit == end) {
98229 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98230 +
98231 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98232 + if (is_vm_hugetlb_page(vma))
98233 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98234 + else
98235 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98236 + }
98237 +}
98238 +#endif
98239 +
98240 int
98241 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98242 unsigned long start, unsigned long end, unsigned long newflags)
98243 @@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98244 int error;
98245 int dirty_accountable = 0;
98246
98247 +#ifdef CONFIG_PAX_SEGMEXEC
98248 + struct vm_area_struct *vma_m = NULL;
98249 + unsigned long start_m, end_m;
98250 +
98251 + start_m = start + SEGMEXEC_TASK_SIZE;
98252 + end_m = end + SEGMEXEC_TASK_SIZE;
98253 +#endif
98254 +
98255 if (newflags == oldflags) {
98256 *pprev = vma;
98257 return 0;
98258 }
98259
98260 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98261 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98262 +
98263 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98264 + return -ENOMEM;
98265 +
98266 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98267 + return -ENOMEM;
98268 + }
98269 +
98270 /*
98271 * If we make a private mapping writable we increase our commit;
98272 * but (without finer accounting) cannot reduce our commit if we
98273 @@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98274 }
98275 }
98276
98277 +#ifdef CONFIG_PAX_SEGMEXEC
98278 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98279 + if (start != vma->vm_start) {
98280 + error = split_vma(mm, vma, start, 1);
98281 + if (error)
98282 + goto fail;
98283 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98284 + *pprev = (*pprev)->vm_next;
98285 + }
98286 +
98287 + if (end != vma->vm_end) {
98288 + error = split_vma(mm, vma, end, 0);
98289 + if (error)
98290 + goto fail;
98291 + }
98292 +
98293 + if (pax_find_mirror_vma(vma)) {
98294 + error = __do_munmap(mm, start_m, end_m - start_m);
98295 + if (error)
98296 + goto fail;
98297 + } else {
98298 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98299 + if (!vma_m) {
98300 + error = -ENOMEM;
98301 + goto fail;
98302 + }
98303 + vma->vm_flags = newflags;
98304 + error = pax_mirror_vma(vma_m, vma);
98305 + if (error) {
98306 + vma->vm_flags = oldflags;
98307 + goto fail;
98308 + }
98309 + }
98310 + }
98311 +#endif
98312 +
98313 /*
98314 * First try to merge with previous and/or next vma.
98315 */
98316 @@ -314,7 +418,19 @@ success:
98317 * vm_flags and vm_page_prot are protected by the mmap_sem
98318 * held in write mode.
98319 */
98320 +
98321 +#ifdef CONFIG_PAX_SEGMEXEC
98322 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98323 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98324 +#endif
98325 +
98326 vma->vm_flags = newflags;
98327 +
98328 +#ifdef CONFIG_PAX_MPROTECT
98329 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98330 + mm->binfmt->handle_mprotect(vma, newflags);
98331 +#endif
98332 +
98333 dirty_accountable = vma_wants_writenotify(vma);
98334 vma_set_page_prot(vma);
98335
98336 @@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98337 end = start + len;
98338 if (end <= start)
98339 return -ENOMEM;
98340 +
98341 +#ifdef CONFIG_PAX_SEGMEXEC
98342 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98343 + if (end > SEGMEXEC_TASK_SIZE)
98344 + return -EINVAL;
98345 + } else
98346 +#endif
98347 +
98348 + if (end > TASK_SIZE)
98349 + return -EINVAL;
98350 +
98351 if (!arch_validate_prot(prot))
98352 return -EINVAL;
98353
98354 @@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98355 /*
98356 * Does the application expect PROT_READ to imply PROT_EXEC:
98357 */
98358 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98359 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98360 prot |= PROT_EXEC;
98361
98362 vm_flags = calc_vm_prot_bits(prot);
98363 @@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98364 if (start > vma->vm_start)
98365 prev = vma;
98366
98367 +#ifdef CONFIG_PAX_MPROTECT
98368 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98369 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98370 +#endif
98371 +
98372 for (nstart = start ; ; ) {
98373 unsigned long newflags;
98374
98375 @@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98376
98377 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98378 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98379 + if (prot & (PROT_WRITE | PROT_EXEC))
98380 + gr_log_rwxmprotect(vma);
98381 +
98382 + error = -EACCES;
98383 + goto out;
98384 + }
98385 +
98386 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98387 error = -EACCES;
98388 goto out;
98389 }
98390 @@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98391 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98392 if (error)
98393 goto out;
98394 +
98395 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98396 +
98397 nstart = tmp;
98398
98399 if (nstart < prev->vm_end)
98400 diff --git a/mm/mremap.c b/mm/mremap.c
98401 index b147f66..98a695ab 100644
98402 --- a/mm/mremap.c
98403 +++ b/mm/mremap.c
98404 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98405 continue;
98406 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98407 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98408 +
98409 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98410 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98411 + pte = pte_exprotect(pte);
98412 +#endif
98413 +
98414 pte = move_soft_dirty_pte(pte);
98415 set_pte_at(mm, new_addr, new_pte, pte);
98416 }
98417 @@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98418 if (is_vm_hugetlb_page(vma))
98419 goto Einval;
98420
98421 +#ifdef CONFIG_PAX_SEGMEXEC
98422 + if (pax_find_mirror_vma(vma))
98423 + goto Einval;
98424 +#endif
98425 +
98426 /* We can't remap across vm area boundaries */
98427 if (old_len > vma->vm_end - addr)
98428 goto Efault;
98429 @@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98430 unsigned long ret = -EINVAL;
98431 unsigned long charged = 0;
98432 unsigned long map_flags;
98433 + unsigned long pax_task_size = TASK_SIZE;
98434
98435 if (new_addr & ~PAGE_MASK)
98436 goto out;
98437
98438 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98439 +#ifdef CONFIG_PAX_SEGMEXEC
98440 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98441 + pax_task_size = SEGMEXEC_TASK_SIZE;
98442 +#endif
98443 +
98444 + pax_task_size -= PAGE_SIZE;
98445 +
98446 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98447 goto out;
98448
98449 /* Check if the location we're moving into overlaps the
98450 * old location at all, and fail if it does.
98451 */
98452 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98453 - goto out;
98454 -
98455 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98456 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98457 goto out;
98458
98459 ret = do_munmap(mm, new_addr, new_len);
98460 @@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98461 unsigned long ret = -EINVAL;
98462 unsigned long charged = 0;
98463 bool locked = false;
98464 + unsigned long pax_task_size = TASK_SIZE;
98465
98466 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98467 return ret;
98468 @@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98469 if (!new_len)
98470 return ret;
98471
98472 +#ifdef CONFIG_PAX_SEGMEXEC
98473 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98474 + pax_task_size = SEGMEXEC_TASK_SIZE;
98475 +#endif
98476 +
98477 + pax_task_size -= PAGE_SIZE;
98478 +
98479 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98480 + old_len > pax_task_size || addr > pax_task_size-old_len)
98481 + return ret;
98482 +
98483 down_write(&current->mm->mmap_sem);
98484
98485 if (flags & MREMAP_FIXED) {
98486 @@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98487 new_addr = addr;
98488 }
98489 ret = addr;
98490 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98491 goto out;
98492 }
98493 }
98494 @@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98495 goto out;
98496 }
98497
98498 + map_flags = vma->vm_flags;
98499 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98500 + if (!(ret & ~PAGE_MASK)) {
98501 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98502 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98503 + }
98504 }
98505 out:
98506 if (ret & ~PAGE_MASK)
98507 diff --git a/mm/nommu.c b/mm/nommu.c
98508 index bd1808e..b63d87c 100644
98509 --- a/mm/nommu.c
98510 +++ b/mm/nommu.c
98511 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98512 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98513 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98514 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98515 -int heap_stack_gap = 0;
98516
98517 atomic_long_t mmap_pages_allocated;
98518
98519 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98520 EXPORT_SYMBOL(find_vma);
98521
98522 /*
98523 - * find a VMA
98524 - * - we don't extend stack VMAs under NOMMU conditions
98525 - */
98526 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98527 -{
98528 - return find_vma(mm, addr);
98529 -}
98530 -
98531 -/*
98532 * expand a stack to a given address
98533 * - not supported under NOMMU conditions
98534 */
98535 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98536
98537 /* most fields are the same, copy all, and then fixup */
98538 *new = *vma;
98539 + INIT_LIST_HEAD(&new->anon_vma_chain);
98540 *region = *vma->vm_region;
98541 new->vm_region = region;
98542
98543 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98544 }
98545 EXPORT_SYMBOL(generic_file_remap_pages);
98546
98547 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98548 - unsigned long addr, void *buf, int len, int write)
98549 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98550 + unsigned long addr, void *buf, size_t len, int write)
98551 {
98552 struct vm_area_struct *vma;
98553
98554 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98555 *
98556 * The caller must hold a reference on @mm.
98557 */
98558 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98559 - void *buf, int len, int write)
98560 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98561 + void *buf, size_t len, int write)
98562 {
98563 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98564 }
98565 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98566 * Access another process' address space.
98567 * - source/target buffer must be kernel space
98568 */
98569 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98570 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98571 {
98572 struct mm_struct *mm;
98573
98574 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98575 index 437174a..8b86707 100644
98576 --- a/mm/page-writeback.c
98577 +++ b/mm/page-writeback.c
98578 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98579 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98580 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98581 */
98582 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98583 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98584 unsigned long thresh,
98585 unsigned long bg_thresh,
98586 unsigned long dirty,
98587 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98588 index 616a2c9..0e755f6 100644
98589 --- a/mm/page_alloc.c
98590 +++ b/mm/page_alloc.c
98591 @@ -59,6 +59,7 @@
98592 #include <linux/page-debug-flags.h>
98593 #include <linux/hugetlb.h>
98594 #include <linux/sched/rt.h>
98595 +#include <linux/random.h>
98596
98597 #include <asm/sections.h>
98598 #include <asm/tlbflush.h>
98599 @@ -356,7 +357,7 @@ out:
98600 * This usage means that zero-order pages may not be compound.
98601 */
98602
98603 -static void free_compound_page(struct page *page)
98604 +void free_compound_page(struct page *page)
98605 {
98606 __free_pages_ok(page, compound_order(page));
98607 }
98608 @@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98609 int i;
98610 int bad = 0;
98611
98612 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98613 + unsigned long index = 1UL << order;
98614 +#endif
98615 +
98616 trace_mm_page_free(page, order);
98617 kmemcheck_free_shadow(page, order);
98618
98619 @@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98620 debug_check_no_obj_freed(page_address(page),
98621 PAGE_SIZE << order);
98622 }
98623 +
98624 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98625 + for (; index; --index)
98626 + sanitize_highpage(page + index - 1);
98627 +#endif
98628 +
98629 arch_free_page(page, order);
98630 kernel_map_pages(page, 1 << order, 0);
98631
98632 @@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98633 local_irq_restore(flags);
98634 }
98635
98636 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98637 +bool __meminitdata extra_latent_entropy;
98638 +
98639 +static int __init setup_pax_extra_latent_entropy(char *str)
98640 +{
98641 + extra_latent_entropy = true;
98642 + return 0;
98643 +}
98644 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98645 +
98646 +volatile u64 latent_entropy __latent_entropy;
98647 +EXPORT_SYMBOL(latent_entropy);
98648 +#endif
98649 +
98650 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98651 {
98652 unsigned int nr_pages = 1 << order;
98653 @@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98654 __ClearPageReserved(p);
98655 set_page_count(p, 0);
98656
98657 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98658 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98659 + u64 hash = 0;
98660 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98661 + const u64 *data = lowmem_page_address(page);
98662 +
98663 + for (index = 0; index < end; index++)
98664 + hash ^= hash + data[index];
98665 + latent_entropy ^= hash;
98666 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98667 + }
98668 +#endif
98669 +
98670 page_zone(page)->managed_pages += nr_pages;
98671 set_page_refcounted(page);
98672 __free_pages(page, order);
98673 @@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98674 arch_alloc_page(page, order);
98675 kernel_map_pages(page, 1 << order, 1);
98676
98677 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98678 if (gfp_flags & __GFP_ZERO)
98679 prep_zero_page(page, order, gfp_flags);
98680 +#endif
98681
98682 if (order && (gfp_flags & __GFP_COMP))
98683 prep_compound_page(page, order);
98684 @@ -1602,7 +1642,7 @@ again:
98685 }
98686
98687 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98688 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98689 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98690 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98691 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98692
98693 @@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98694 do {
98695 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98696 high_wmark_pages(zone) - low_wmark_pages(zone) -
98697 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98698 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98699 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98700 } while (zone++ != preferred_zone);
98701 }
98702 @@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98703
98704 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98705 high_wmark_pages(zone) - low_wmark_pages(zone) -
98706 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98707 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98708
98709 setup_zone_migrate_reserve(zone);
98710 spin_unlock_irqrestore(&zone->lock, flags);
98711 diff --git a/mm/percpu.c b/mm/percpu.c
98712 index 014bab6..db5a76f 100644
98713 --- a/mm/percpu.c
98714 +++ b/mm/percpu.c
98715 @@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98716 static unsigned int pcpu_high_unit_cpu __read_mostly;
98717
98718 /* the address of the first chunk which starts with the kernel static area */
98719 -void *pcpu_base_addr __read_mostly;
98720 +void *pcpu_base_addr __read_only;
98721 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98722
98723 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98724 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98725 index 5077afc..846c9ef 100644
98726 --- a/mm/process_vm_access.c
98727 +++ b/mm/process_vm_access.c
98728 @@ -13,6 +13,7 @@
98729 #include <linux/uio.h>
98730 #include <linux/sched.h>
98731 #include <linux/highmem.h>
98732 +#include <linux/security.h>
98733 #include <linux/ptrace.h>
98734 #include <linux/slab.h>
98735 #include <linux/syscalls.h>
98736 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98737 ssize_t iov_len;
98738 size_t total_len = iov_iter_count(iter);
98739
98740 + return -ENOSYS; // PaX: until properly audited
98741 +
98742 /*
98743 * Work out how many pages of struct pages we're going to need
98744 * when eventually calling get_user_pages
98745 */
98746 for (i = 0; i < riovcnt; i++) {
98747 iov_len = rvec[i].iov_len;
98748 - if (iov_len > 0) {
98749 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98750 - + iov_len)
98751 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98752 - / PAGE_SIZE + 1;
98753 - nr_pages = max(nr_pages, nr_pages_iov);
98754 - }
98755 + if (iov_len <= 0)
98756 + continue;
98757 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98758 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98759 + nr_pages = max(nr_pages, nr_pages_iov);
98760 }
98761
98762 if (nr_pages == 0)
98763 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98764 goto free_proc_pages;
98765 }
98766
98767 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98768 + rc = -EPERM;
98769 + goto put_task_struct;
98770 + }
98771 +
98772 mm = mm_access(task, PTRACE_MODE_ATTACH);
98773 if (!mm || IS_ERR(mm)) {
98774 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98775 diff --git a/mm/rmap.c b/mm/rmap.c
98776 index 3e4c721..a5e3e39 100644
98777 --- a/mm/rmap.c
98778 +++ b/mm/rmap.c
98779 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98780 struct anon_vma *anon_vma = vma->anon_vma;
98781 struct anon_vma_chain *avc;
98782
98783 +#ifdef CONFIG_PAX_SEGMEXEC
98784 + struct anon_vma_chain *avc_m = NULL;
98785 +#endif
98786 +
98787 might_sleep();
98788 if (unlikely(!anon_vma)) {
98789 struct mm_struct *mm = vma->vm_mm;
98790 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98791 if (!avc)
98792 goto out_enomem;
98793
98794 +#ifdef CONFIG_PAX_SEGMEXEC
98795 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98796 + if (!avc_m)
98797 + goto out_enomem_free_avc;
98798 +#endif
98799 +
98800 anon_vma = find_mergeable_anon_vma(vma);
98801 allocated = NULL;
98802 if (!anon_vma) {
98803 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98804 /* page_table_lock to protect against threads */
98805 spin_lock(&mm->page_table_lock);
98806 if (likely(!vma->anon_vma)) {
98807 +
98808 +#ifdef CONFIG_PAX_SEGMEXEC
98809 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98810 +
98811 + if (vma_m) {
98812 + BUG_ON(vma_m->anon_vma);
98813 + vma_m->anon_vma = anon_vma;
98814 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98815 + avc_m = NULL;
98816 + }
98817 +#endif
98818 +
98819 vma->anon_vma = anon_vma;
98820 anon_vma_chain_link(vma, avc, anon_vma);
98821 allocated = NULL;
98822 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98823
98824 if (unlikely(allocated))
98825 put_anon_vma(allocated);
98826 +
98827 +#ifdef CONFIG_PAX_SEGMEXEC
98828 + if (unlikely(avc_m))
98829 + anon_vma_chain_free(avc_m);
98830 +#endif
98831 +
98832 if (unlikely(avc))
98833 anon_vma_chain_free(avc);
98834 }
98835 return 0;
98836
98837 out_enomem_free_avc:
98838 +
98839 +#ifdef CONFIG_PAX_SEGMEXEC
98840 + if (avc_m)
98841 + anon_vma_chain_free(avc_m);
98842 +#endif
98843 +
98844 anon_vma_chain_free(avc);
98845 out_enomem:
98846 return -ENOMEM;
98847 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98848 * Attach the anon_vmas from src to dst.
98849 * Returns 0 on success, -ENOMEM on failure.
98850 */
98851 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98852 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98853 {
98854 struct anon_vma_chain *avc, *pavc;
98855 struct anon_vma *root = NULL;
98856 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98857 * the corresponding VMA in the parent process is attached to.
98858 * Returns 0 on success, non-zero on failure.
98859 */
98860 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98861 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98862 {
98863 struct anon_vma_chain *avc;
98864 struct anon_vma *anon_vma;
98865 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98866 void __init anon_vma_init(void)
98867 {
98868 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98869 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98870 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98871 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98872 + anon_vma_ctor);
98873 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98874 + SLAB_PANIC|SLAB_NO_SANITIZE);
98875 }
98876
98877 /*
98878 diff --git a/mm/shmem.c b/mm/shmem.c
98879 index 185836b..d7255a1 100644
98880 --- a/mm/shmem.c
98881 +++ b/mm/shmem.c
98882 @@ -33,7 +33,7 @@
98883 #include <linux/swap.h>
98884 #include <linux/aio.h>
98885
98886 -static struct vfsmount *shm_mnt;
98887 +struct vfsmount *shm_mnt;
98888
98889 #ifdef CONFIG_SHMEM
98890 /*
98891 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98892 #define BOGO_DIRENT_SIZE 20
98893
98894 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98895 -#define SHORT_SYMLINK_LEN 128
98896 +#define SHORT_SYMLINK_LEN 64
98897
98898 /*
98899 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98900 @@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98901 static int shmem_xattr_validate(const char *name)
98902 {
98903 struct { const char *prefix; size_t len; } arr[] = {
98904 +
98905 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98906 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98907 +#endif
98908 +
98909 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98910 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98911 };
98912 @@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98913 if (err)
98914 return err;
98915
98916 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98917 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98918 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98919 + return -EOPNOTSUPP;
98920 + if (size > 8)
98921 + return -EINVAL;
98922 + }
98923 +#endif
98924 +
98925 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98926 }
98927
98928 @@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98929 int err = -ENOMEM;
98930
98931 /* Round up to L1_CACHE_BYTES to resist false sharing */
98932 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98933 - L1_CACHE_BYTES), GFP_KERNEL);
98934 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98935 if (!sbinfo)
98936 return -ENOMEM;
98937
98938 diff --git a/mm/slab.c b/mm/slab.c
98939 index f34e053..78a3839 100644
98940 --- a/mm/slab.c
98941 +++ b/mm/slab.c
98942 @@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98943 if ((x)->max_freeable < i) \
98944 (x)->max_freeable = i; \
98945 } while (0)
98946 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98947 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98948 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98949 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98950 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98951 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98952 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98953 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98954 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98955 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98956 #else
98957 #define STATS_INC_ACTIVE(x) do { } while (0)
98958 #define STATS_DEC_ACTIVE(x) do { } while (0)
98959 @@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98960 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98961 #define STATS_INC_FREEHIT(x) do { } while (0)
98962 #define STATS_INC_FREEMISS(x) do { } while (0)
98963 +#define STATS_INC_SANITIZED(x) do { } while (0)
98964 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98965 #endif
98966
98967 #if DEBUG
98968 @@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98969 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98970 */
98971 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98972 - const struct page *page, void *obj)
98973 + const struct page *page, const void *obj)
98974 {
98975 u32 offset = (obj - page->s_mem);
98976 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98977 @@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
98978 * structures first. Without this, further allocations will bug.
98979 */
98980 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
98981 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98982 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98983 slab_state = PARTIAL_NODE;
98984
98985 slab_early_init = 0;
98986 @@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98987
98988 cachep = find_mergeable(size, align, flags, name, ctor);
98989 if (cachep) {
98990 - cachep->refcount++;
98991 + atomic_inc(&cachep->refcount);
98992
98993 /*
98994 * Adjust the object sizes so that we clear
98995 @@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98996 struct array_cache *ac = cpu_cache_get(cachep);
98997
98998 check_irq_off();
98999 +
99000 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99001 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99002 + STATS_INC_NOT_SANITIZED(cachep);
99003 + else {
99004 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99005 +
99006 + if (cachep->ctor)
99007 + cachep->ctor(objp);
99008 +
99009 + STATS_INC_SANITIZED(cachep);
99010 + }
99011 +#endif
99012 +
99013 kmemleak_free_recursive(objp, cachep->flags);
99014 objp = cache_free_debugcheck(cachep, objp, caller);
99015
99016 @@ -3557,6 +3575,7 @@ void kfree(const void *objp)
99017
99018 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99019 return;
99020 + VM_BUG_ON(!virt_addr_valid(objp));
99021 local_irq_save(flags);
99022 kfree_debugcheck(objp);
99023 c = virt_to_cache(objp);
99024 @@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99025 }
99026 /* cpu stats */
99027 {
99028 - unsigned long allochit = atomic_read(&cachep->allochit);
99029 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99030 - unsigned long freehit = atomic_read(&cachep->freehit);
99031 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99032 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99033 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99034 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99035 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99036
99037 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99038 allochit, allocmiss, freehit, freemiss);
99039 }
99040 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99041 + {
99042 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99043 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99044 +
99045 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99046 + }
99047 +#endif
99048 #endif
99049 }
99050
99051 @@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
99052 static int __init slab_proc_init(void)
99053 {
99054 #ifdef CONFIG_DEBUG_SLAB_LEAK
99055 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99056 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99057 #endif
99058 return 0;
99059 }
99060 module_init(slab_proc_init);
99061 #endif
99062
99063 +bool is_usercopy_object(const void *ptr)
99064 +{
99065 + struct page *page;
99066 + struct kmem_cache *cachep;
99067 +
99068 + if (ZERO_OR_NULL_PTR(ptr))
99069 + return false;
99070 +
99071 + if (!slab_is_available())
99072 + return false;
99073 +
99074 + if (!virt_addr_valid(ptr))
99075 + return false;
99076 +
99077 + page = virt_to_head_page(ptr);
99078 +
99079 + if (!PageSlab(page))
99080 + return false;
99081 +
99082 + cachep = page->slab_cache;
99083 + return cachep->flags & SLAB_USERCOPY;
99084 +}
99085 +
99086 +#ifdef CONFIG_PAX_USERCOPY
99087 +const char *check_heap_object(const void *ptr, unsigned long n)
99088 +{
99089 + struct page *page;
99090 + struct kmem_cache *cachep;
99091 + unsigned int objnr;
99092 + unsigned long offset;
99093 +
99094 + if (ZERO_OR_NULL_PTR(ptr))
99095 + return "<null>";
99096 +
99097 + if (!virt_addr_valid(ptr))
99098 + return NULL;
99099 +
99100 + page = virt_to_head_page(ptr);
99101 +
99102 + if (!PageSlab(page))
99103 + return NULL;
99104 +
99105 + cachep = page->slab_cache;
99106 + if (!(cachep->flags & SLAB_USERCOPY))
99107 + return cachep->name;
99108 +
99109 + objnr = obj_to_index(cachep, page, ptr);
99110 + BUG_ON(objnr >= cachep->num);
99111 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99112 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99113 + return NULL;
99114 +
99115 + return cachep->name;
99116 +}
99117 +#endif
99118 +
99119 /**
99120 * ksize - get the actual amount of memory allocated for a given object
99121 * @objp: Pointer to the object
99122 diff --git a/mm/slab.h b/mm/slab.h
99123 index ab019e6..fbcac34 100644
99124 --- a/mm/slab.h
99125 +++ b/mm/slab.h
99126 @@ -22,7 +22,7 @@ struct kmem_cache {
99127 unsigned int align; /* Alignment as calculated */
99128 unsigned long flags; /* Active flags on the slab */
99129 const char *name; /* Slab name for sysfs */
99130 - int refcount; /* Use counter */
99131 + atomic_t refcount; /* Use counter */
99132 void (*ctor)(void *); /* Called on object slot creation */
99133 struct list_head list; /* List of all slab caches on the system */
99134 };
99135 @@ -66,6 +66,20 @@ extern struct list_head slab_caches;
99136 /* The slab cache that manages slab cache information */
99137 extern struct kmem_cache *kmem_cache;
99138
99139 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99140 +#ifdef CONFIG_X86_64
99141 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99142 +#else
99143 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99144 +#endif
99145 +enum pax_sanitize_mode {
99146 + PAX_SANITIZE_SLAB_OFF = 0,
99147 + PAX_SANITIZE_SLAB_FAST,
99148 + PAX_SANITIZE_SLAB_FULL,
99149 +};
99150 +extern enum pax_sanitize_mode pax_sanitize_slab;
99151 +#endif
99152 +
99153 unsigned long calculate_alignment(unsigned long flags,
99154 unsigned long align, unsigned long size);
99155
99156 @@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
99157
99158 /* Legal flag mask for kmem_cache_create(), for various configurations */
99159 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99160 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99161 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99162 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99163
99164 #if defined(CONFIG_DEBUG_SLAB)
99165 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99166 @@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99167 return s;
99168
99169 page = virt_to_head_page(x);
99170 +
99171 + BUG_ON(!PageSlab(page));
99172 +
99173 cachep = page->slab_cache;
99174 if (slab_equal_or_root(cachep, s))
99175 return cachep;
99176 diff --git a/mm/slab_common.c b/mm/slab_common.c
99177 index dcdab81..3576646 100644
99178 --- a/mm/slab_common.c
99179 +++ b/mm/slab_common.c
99180 @@ -25,11 +25,35 @@
99181
99182 #include "slab.h"
99183
99184 -enum slab_state slab_state;
99185 +enum slab_state slab_state __read_only;
99186 LIST_HEAD(slab_caches);
99187 DEFINE_MUTEX(slab_mutex);
99188 struct kmem_cache *kmem_cache;
99189
99190 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99191 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99192 +static int __init pax_sanitize_slab_setup(char *str)
99193 +{
99194 + if (!str)
99195 + return 0;
99196 +
99197 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99198 + pr_info("PaX slab sanitization: %s\n", "disabled");
99199 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99200 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99201 + pr_info("PaX slab sanitization: %s\n", "fast");
99202 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99203 + } else if (!strcmp(str, "full")) {
99204 + pr_info("PaX slab sanitization: %s\n", "full");
99205 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99206 + } else
99207 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99208 +
99209 + return 0;
99210 +}
99211 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99212 +#endif
99213 +
99214 /*
99215 * Set of flags that will prevent slab merging
99216 */
99217 @@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
99218 * Merge control. If this is set then no merging of slab caches will occur.
99219 * (Could be removed. This was introduced to pacify the merge skeptics.)
99220 */
99221 -static int slab_nomerge;
99222 +static int slab_nomerge = 1;
99223
99224 static int __init setup_slab_nomerge(char *str)
99225 {
99226 @@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
99227 /*
99228 * We may have set a slab to be unmergeable during bootstrap.
99229 */
99230 - if (s->refcount < 0)
99231 + if (atomic_read(&s->refcount) < 0)
99232 return 1;
99233
99234 return 0;
99235 @@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99236 if (err)
99237 goto out_free_cache;
99238
99239 - s->refcount = 1;
99240 + atomic_set(&s->refcount, 1);
99241 list_add(&s->list, &slab_caches);
99242 out:
99243 if (err)
99244 @@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99245 */
99246 flags &= CACHE_CREATE_MASK;
99247
99248 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99249 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99250 + flags |= SLAB_NO_SANITIZE;
99251 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99252 + flags &= ~SLAB_NO_SANITIZE;
99253 +#endif
99254 +
99255 s = __kmem_cache_alias(name, size, align, flags, ctor);
99256 if (s)
99257 goto out_unlock;
99258 @@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99259
99260 mutex_lock(&slab_mutex);
99261
99262 - s->refcount--;
99263 - if (s->refcount)
99264 + if (!atomic_dec_and_test(&s->refcount))
99265 goto out_unlock;
99266
99267 if (memcg_cleanup_cache_params(s) != 0)
99268 @@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99269 rcu_barrier();
99270
99271 memcg_free_cache_params(s);
99272 -#ifdef SLAB_SUPPORTS_SYSFS
99273 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99274 sysfs_slab_remove(s);
99275 #else
99276 slab_kmem_cache_release(s);
99277 @@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99278 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99279 name, size, err);
99280
99281 - s->refcount = -1; /* Exempt from merging for now */
99282 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99283 }
99284
99285 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99286 @@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99287
99288 create_boot_cache(s, name, size, flags);
99289 list_add(&s->list, &slab_caches);
99290 - s->refcount = 1;
99291 + atomic_set(&s->refcount, 1);
99292 return s;
99293 }
99294
99295 @@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99296 EXPORT_SYMBOL(kmalloc_dma_caches);
99297 #endif
99298
99299 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99300 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99301 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99302 +#endif
99303 +
99304 /*
99305 * Conversion table for small slabs sizes / 8 to the index in the
99306 * kmalloc array. This is necessary for slabs < 192 since we have non power
99307 @@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99308 return kmalloc_dma_caches[index];
99309
99310 #endif
99311 +
99312 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99313 + if (unlikely((flags & GFP_USERCOPY)))
99314 + return kmalloc_usercopy_caches[index];
99315 +
99316 +#endif
99317 +
99318 return kmalloc_caches[index];
99319 }
99320
99321 @@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99322 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99323 if (!kmalloc_caches[i]) {
99324 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99325 - 1 << i, flags);
99326 + 1 << i, SLAB_USERCOPY | flags);
99327 }
99328
99329 /*
99330 @@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99331 * earlier power of two caches
99332 */
99333 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99334 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99335 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99336
99337 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99338 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99339 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99340 }
99341
99342 /* Kmalloc array is now usable */
99343 @@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99344 }
99345 }
99346 #endif
99347 +
99348 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99349 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99350 + struct kmem_cache *s = kmalloc_caches[i];
99351 +
99352 + if (s) {
99353 + int size = kmalloc_size(i);
99354 + char *n = kasprintf(GFP_NOWAIT,
99355 + "usercopy-kmalloc-%d", size);
99356 +
99357 + BUG_ON(!n);
99358 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99359 + size, SLAB_USERCOPY | flags);
99360 + }
99361 + }
99362 +#endif
99363 +
99364 }
99365 #endif /* !CONFIG_SLOB */
99366
99367 @@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99368 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99369 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99370 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99371 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99372 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99373 +#endif
99374 #endif
99375 seq_putc(m, '\n');
99376 }
99377 diff --git a/mm/slob.c b/mm/slob.c
99378 index 96a8620..3e7e663 100644
99379 --- a/mm/slob.c
99380 +++ b/mm/slob.c
99381 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99382 /*
99383 * Return the size of a slob block.
99384 */
99385 -static slobidx_t slob_units(slob_t *s)
99386 +static slobidx_t slob_units(const slob_t *s)
99387 {
99388 if (s->units > 0)
99389 return s->units;
99390 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99391 /*
99392 * Return the next free slob block pointer after this one.
99393 */
99394 -static slob_t *slob_next(slob_t *s)
99395 +static slob_t *slob_next(const slob_t *s)
99396 {
99397 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99398 slobidx_t next;
99399 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99400 /*
99401 * Returns true if s is the last free block in its page.
99402 */
99403 -static int slob_last(slob_t *s)
99404 +static int slob_last(const slob_t *s)
99405 {
99406 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99407 }
99408
99409 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99410 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99411 {
99412 - void *page;
99413 + struct page *page;
99414
99415 #ifdef CONFIG_NUMA
99416 if (node != NUMA_NO_NODE)
99417 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99418 if (!page)
99419 return NULL;
99420
99421 - return page_address(page);
99422 + __SetPageSlab(page);
99423 + return page;
99424 }
99425
99426 -static void slob_free_pages(void *b, int order)
99427 +static void slob_free_pages(struct page *sp, int order)
99428 {
99429 if (current->reclaim_state)
99430 current->reclaim_state->reclaimed_slab += 1 << order;
99431 - free_pages((unsigned long)b, order);
99432 + __ClearPageSlab(sp);
99433 + page_mapcount_reset(sp);
99434 + sp->private = 0;
99435 + __free_pages(sp, order);
99436 }
99437
99438 /*
99439 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99440
99441 /* Not enough space: must allocate a new page */
99442 if (!b) {
99443 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99444 - if (!b)
99445 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99446 + if (!sp)
99447 return NULL;
99448 - sp = virt_to_page(b);
99449 - __SetPageSlab(sp);
99450 + b = page_address(sp);
99451
99452 spin_lock_irqsave(&slob_lock, flags);
99453 sp->units = SLOB_UNITS(PAGE_SIZE);
99454 sp->freelist = b;
99455 + sp->private = 0;
99456 INIT_LIST_HEAD(&sp->lru);
99457 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99458 set_slob_page_free(sp, slob_list);
99459 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99460 /*
99461 * slob_free: entry point into the slob allocator.
99462 */
99463 -static void slob_free(void *block, int size)
99464 +static void slob_free(struct kmem_cache *c, void *block, int size)
99465 {
99466 struct page *sp;
99467 slob_t *prev, *next, *b = (slob_t *)block;
99468 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99469 if (slob_page_free(sp))
99470 clear_slob_page_free(sp);
99471 spin_unlock_irqrestore(&slob_lock, flags);
99472 - __ClearPageSlab(sp);
99473 - page_mapcount_reset(sp);
99474 - slob_free_pages(b, 0);
99475 + slob_free_pages(sp, 0);
99476 return;
99477 }
99478
99479 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99480 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99481 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99482 +#endif
99483 +
99484 if (!slob_page_free(sp)) {
99485 /* This slob page is about to become partially free. Easy! */
99486 sp->units = units;
99487 @@ -424,11 +431,10 @@ out:
99488 */
99489
99490 static __always_inline void *
99491 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99492 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99493 {
99494 - unsigned int *m;
99495 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99496 - void *ret;
99497 + slob_t *m;
99498 + void *ret = NULL;
99499
99500 gfp &= gfp_allowed_mask;
99501
99502 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99503
99504 if (!m)
99505 return NULL;
99506 - *m = size;
99507 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99508 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99509 + m[0].units = size;
99510 + m[1].units = align;
99511 ret = (void *)m + align;
99512
99513 trace_kmalloc_node(caller, ret,
99514 size, size + align, gfp, node);
99515 } else {
99516 unsigned int order = get_order(size);
99517 + struct page *page;
99518
99519 if (likely(order))
99520 gfp |= __GFP_COMP;
99521 - ret = slob_new_pages(gfp, order, node);
99522 + page = slob_new_pages(gfp, order, node);
99523 + if (page) {
99524 + ret = page_address(page);
99525 + page->private = size;
99526 + }
99527
99528 trace_kmalloc_node(caller, ret,
99529 size, PAGE_SIZE << order, gfp, node);
99530 }
99531
99532 - kmemleak_alloc(ret, size, 1, gfp);
99533 + return ret;
99534 +}
99535 +
99536 +static __always_inline void *
99537 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99538 +{
99539 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99540 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99541 +
99542 + if (!ZERO_OR_NULL_PTR(ret))
99543 + kmemleak_alloc(ret, size, 1, gfp);
99544 return ret;
99545 }
99546
99547 @@ -491,34 +515,112 @@ void kfree(const void *block)
99548 return;
99549 kmemleak_free(block);
99550
99551 + VM_BUG_ON(!virt_addr_valid(block));
99552 sp = virt_to_page(block);
99553 - if (PageSlab(sp)) {
99554 + VM_BUG_ON(!PageSlab(sp));
99555 + if (!sp->private) {
99556 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99557 - unsigned int *m = (unsigned int *)(block - align);
99558 - slob_free(m, *m + align);
99559 - } else
99560 + slob_t *m = (slob_t *)(block - align);
99561 + slob_free(NULL, m, m[0].units + align);
99562 + } else {
99563 + __ClearPageSlab(sp);
99564 + page_mapcount_reset(sp);
99565 + sp->private = 0;
99566 __free_pages(sp, compound_order(sp));
99567 + }
99568 }
99569 EXPORT_SYMBOL(kfree);
99570
99571 +bool is_usercopy_object(const void *ptr)
99572 +{
99573 + if (!slab_is_available())
99574 + return false;
99575 +
99576 + // PAX: TODO
99577 +
99578 + return false;
99579 +}
99580 +
99581 +#ifdef CONFIG_PAX_USERCOPY
99582 +const char *check_heap_object(const void *ptr, unsigned long n)
99583 +{
99584 + struct page *page;
99585 + const slob_t *free;
99586 + const void *base;
99587 + unsigned long flags;
99588 +
99589 + if (ZERO_OR_NULL_PTR(ptr))
99590 + return "<null>";
99591 +
99592 + if (!virt_addr_valid(ptr))
99593 + return NULL;
99594 +
99595 + page = virt_to_head_page(ptr);
99596 + if (!PageSlab(page))
99597 + return NULL;
99598 +
99599 + if (page->private) {
99600 + base = page;
99601 + if (base <= ptr && n <= page->private - (ptr - base))
99602 + return NULL;
99603 + return "<slob>";
99604 + }
99605 +
99606 + /* some tricky double walking to find the chunk */
99607 + spin_lock_irqsave(&slob_lock, flags);
99608 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99609 + free = page->freelist;
99610 +
99611 + while (!slob_last(free) && (void *)free <= ptr) {
99612 + base = free + slob_units(free);
99613 + free = slob_next(free);
99614 + }
99615 +
99616 + while (base < (void *)free) {
99617 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99618 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99619 + int offset;
99620 +
99621 + if (ptr < base + align)
99622 + break;
99623 +
99624 + offset = ptr - base - align;
99625 + if (offset >= m) {
99626 + base += size;
99627 + continue;
99628 + }
99629 +
99630 + if (n > m - offset)
99631 + break;
99632 +
99633 + spin_unlock_irqrestore(&slob_lock, flags);
99634 + return NULL;
99635 + }
99636 +
99637 + spin_unlock_irqrestore(&slob_lock, flags);
99638 + return "<slob>";
99639 +}
99640 +#endif
99641 +
99642 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99643 size_t ksize(const void *block)
99644 {
99645 struct page *sp;
99646 int align;
99647 - unsigned int *m;
99648 + slob_t *m;
99649
99650 BUG_ON(!block);
99651 if (unlikely(block == ZERO_SIZE_PTR))
99652 return 0;
99653
99654 sp = virt_to_page(block);
99655 - if (unlikely(!PageSlab(sp)))
99656 - return PAGE_SIZE << compound_order(sp);
99657 + VM_BUG_ON(!PageSlab(sp));
99658 + if (sp->private)
99659 + return sp->private;
99660
99661 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99662 - m = (unsigned int *)(block - align);
99663 - return SLOB_UNITS(*m) * SLOB_UNIT;
99664 + m = (slob_t *)(block - align);
99665 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99666 }
99667 EXPORT_SYMBOL(ksize);
99668
99669 @@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99670
99671 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99672 {
99673 - void *b;
99674 + void *b = NULL;
99675
99676 flags &= gfp_allowed_mask;
99677
99678 lockdep_trace_alloc(flags);
99679
99680 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99681 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99682 +#else
99683 if (c->size < PAGE_SIZE) {
99684 b = slob_alloc(c->size, flags, c->align, node);
99685 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99686 SLOB_UNITS(c->size) * SLOB_UNIT,
99687 flags, node);
99688 } else {
99689 - b = slob_new_pages(flags, get_order(c->size), node);
99690 + struct page *sp;
99691 +
99692 + sp = slob_new_pages(flags, get_order(c->size), node);
99693 + if (sp) {
99694 + b = page_address(sp);
99695 + sp->private = c->size;
99696 + }
99697 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99698 PAGE_SIZE << get_order(c->size),
99699 flags, node);
99700 }
99701 +#endif
99702
99703 if (b && c->ctor)
99704 c->ctor(b);
99705 @@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99706 EXPORT_SYMBOL(kmem_cache_alloc_node);
99707 #endif
99708
99709 -static void __kmem_cache_free(void *b, int size)
99710 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99711 {
99712 - if (size < PAGE_SIZE)
99713 - slob_free(b, size);
99714 + struct page *sp;
99715 +
99716 + sp = virt_to_page(b);
99717 + BUG_ON(!PageSlab(sp));
99718 + if (!sp->private)
99719 + slob_free(c, b, size);
99720 else
99721 - slob_free_pages(b, get_order(size));
99722 + slob_free_pages(sp, get_order(size));
99723 }
99724
99725 static void kmem_rcu_free(struct rcu_head *head)
99726 @@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99727 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99728 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99729
99730 - __kmem_cache_free(b, slob_rcu->size);
99731 + __kmem_cache_free(NULL, b, slob_rcu->size);
99732 }
99733
99734 void kmem_cache_free(struct kmem_cache *c, void *b)
99735 {
99736 + int size = c->size;
99737 +
99738 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99739 + if (size + c->align < PAGE_SIZE) {
99740 + size += c->align;
99741 + b -= c->align;
99742 + }
99743 +#endif
99744 +
99745 kmemleak_free_recursive(b, c->flags);
99746 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99747 struct slob_rcu *slob_rcu;
99748 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99749 - slob_rcu->size = c->size;
99750 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99751 + slob_rcu->size = size;
99752 call_rcu(&slob_rcu->head, kmem_rcu_free);
99753 } else {
99754 - __kmem_cache_free(b, c->size);
99755 + __kmem_cache_free(c, b, size);
99756 }
99757
99758 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99759 + trace_kfree(_RET_IP_, b);
99760 +#else
99761 trace_kmem_cache_free(_RET_IP_, b);
99762 +#endif
99763 +
99764 }
99765 EXPORT_SYMBOL(kmem_cache_free);
99766
99767 diff --git a/mm/slub.c b/mm/slub.c
99768 index ae7b9f1..7b3fdbe 100644
99769 --- a/mm/slub.c
99770 +++ b/mm/slub.c
99771 @@ -197,7 +197,7 @@ struct track {
99772
99773 enum track_item { TRACK_ALLOC, TRACK_FREE };
99774
99775 -#ifdef CONFIG_SYSFS
99776 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99777 static int sysfs_slab_add(struct kmem_cache *);
99778 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99779 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99780 @@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99781 if (!t->addr)
99782 return;
99783
99784 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99785 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99786 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99787 #ifdef CONFIG_STACKTRACE
99788 {
99789 @@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99790
99791 slab_free_hook(s, x);
99792
99793 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99794 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99795 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99796 + if (s->ctor)
99797 + s->ctor(x);
99798 + }
99799 +#endif
99800 +
99801 redo:
99802 /*
99803 * Determine the currently cpus per cpu slab.
99804 @@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99805 s->inuse = size;
99806
99807 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99808 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99809 + (!(flags & SLAB_NO_SANITIZE)) ||
99810 +#endif
99811 s->ctor)) {
99812 /*
99813 * Relocate free pointer after the object if it is not
99814 @@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99815 EXPORT_SYMBOL(__kmalloc_node);
99816 #endif
99817
99818 +bool is_usercopy_object(const void *ptr)
99819 +{
99820 + struct page *page;
99821 + struct kmem_cache *s;
99822 +
99823 + if (ZERO_OR_NULL_PTR(ptr))
99824 + return false;
99825 +
99826 + if (!slab_is_available())
99827 + return false;
99828 +
99829 + if (!virt_addr_valid(ptr))
99830 + return false;
99831 +
99832 + page = virt_to_head_page(ptr);
99833 +
99834 + if (!PageSlab(page))
99835 + return false;
99836 +
99837 + s = page->slab_cache;
99838 + return s->flags & SLAB_USERCOPY;
99839 +}
99840 +
99841 +#ifdef CONFIG_PAX_USERCOPY
99842 +const char *check_heap_object(const void *ptr, unsigned long n)
99843 +{
99844 + struct page *page;
99845 + struct kmem_cache *s;
99846 + unsigned long offset;
99847 +
99848 + if (ZERO_OR_NULL_PTR(ptr))
99849 + return "<null>";
99850 +
99851 + if (!virt_addr_valid(ptr))
99852 + return NULL;
99853 +
99854 + page = virt_to_head_page(ptr);
99855 +
99856 + if (!PageSlab(page))
99857 + return NULL;
99858 +
99859 + s = page->slab_cache;
99860 + if (!(s->flags & SLAB_USERCOPY))
99861 + return s->name;
99862 +
99863 + offset = (ptr - page_address(page)) % s->size;
99864 + if (offset <= s->object_size && n <= s->object_size - offset)
99865 + return NULL;
99866 +
99867 + return s->name;
99868 +}
99869 +#endif
99870 +
99871 size_t ksize(const void *object)
99872 {
99873 struct page *page;
99874 @@ -3329,6 +3393,7 @@ void kfree(const void *x)
99875 if (unlikely(ZERO_OR_NULL_PTR(x)))
99876 return;
99877
99878 + VM_BUG_ON(!virt_addr_valid(x));
99879 page = virt_to_head_page(x);
99880 if (unlikely(!PageSlab(page))) {
99881 BUG_ON(!PageCompound(page));
99882 @@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99883 int i;
99884 struct kmem_cache *c;
99885
99886 - s->refcount++;
99887 + atomic_inc(&s->refcount);
99888
99889 /*
99890 * Adjust the object sizes so that we clear
99891 @@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99892 }
99893
99894 if (sysfs_slab_alias(s, name)) {
99895 - s->refcount--;
99896 + atomic_dec(&s->refcount);
99897 s = NULL;
99898 }
99899 }
99900 @@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99901 }
99902 #endif
99903
99904 -#ifdef CONFIG_SYSFS
99905 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99906 static int count_inuse(struct page *page)
99907 {
99908 return page->inuse;
99909 @@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99910 len += sprintf(buf + len, "%7ld ", l->count);
99911
99912 if (l->addr)
99913 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99914 + len += sprintf(buf + len, "%pS", NULL);
99915 +#else
99916 len += sprintf(buf + len, "%pS", (void *)l->addr);
99917 +#endif
99918 else
99919 len += sprintf(buf + len, "<not-available>");
99920
99921 @@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99922 validate_slab_cache(kmalloc_caches[9]);
99923 }
99924 #else
99925 -#ifdef CONFIG_SYSFS
99926 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99927 static void resiliency_test(void) {};
99928 #endif
99929 #endif
99930
99931 -#ifdef CONFIG_SYSFS
99932 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99933 enum slab_stat_type {
99934 SL_ALL, /* All slabs */
99935 SL_PARTIAL, /* Only partially allocated slabs */
99936 @@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99937 {
99938 if (!s->ctor)
99939 return 0;
99940 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99941 + return sprintf(buf, "%pS\n", NULL);
99942 +#else
99943 return sprintf(buf, "%pS\n", s->ctor);
99944 +#endif
99945 }
99946 SLAB_ATTR_RO(ctor);
99947
99948 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99949 {
99950 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99951 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99952 }
99953 SLAB_ATTR_RO(aliases);
99954
99955 @@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99956 SLAB_ATTR_RO(cache_dma);
99957 #endif
99958
99959 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99960 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99961 +{
99962 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99963 +}
99964 +SLAB_ATTR_RO(usercopy);
99965 +#endif
99966 +
99967 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99968 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99969 +{
99970 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99971 +}
99972 +SLAB_ATTR_RO(sanitize);
99973 +#endif
99974 +
99975 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99976 {
99977 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99978 @@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
99979 * as well as cause other issues like converting a mergeable
99980 * cache into an umergeable one.
99981 */
99982 - if (s->refcount > 1)
99983 + if (atomic_read(&s->refcount) > 1)
99984 return -EINVAL;
99985
99986 s->flags &= ~SLAB_TRACE;
99987 @@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
99988 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
99989 size_t length)
99990 {
99991 - if (s->refcount > 1)
99992 + if (atomic_read(&s->refcount) > 1)
99993 return -EINVAL;
99994
99995 s->flags &= ~SLAB_FAILSLAB;
99996 @@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
99997 #ifdef CONFIG_ZONE_DMA
99998 &cache_dma_attr.attr,
99999 #endif
100000 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100001 + &usercopy_attr.attr,
100002 +#endif
100003 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100004 + &sanitize_attr.attr,
100005 +#endif
100006 #ifdef CONFIG_NUMA
100007 &remote_node_defrag_ratio_attr.attr,
100008 #endif
100009 @@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
100010 return name;
100011 }
100012
100013 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100014 static int sysfs_slab_add(struct kmem_cache *s)
100015 {
100016 int err;
100017 @@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100018 kobject_del(&s->kobj);
100019 kobject_put(&s->kobj);
100020 }
100021 +#endif
100022
100023 /*
100024 * Need to buffer aliases during bootup until sysfs becomes
100025 @@ -5154,6 +5251,7 @@ struct saved_alias {
100026
100027 static struct saved_alias *alias_list;
100028
100029 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100030 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100031 {
100032 struct saved_alias *al;
100033 @@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100034 alias_list = al;
100035 return 0;
100036 }
100037 +#endif
100038
100039 static int __init slab_sysfs_init(void)
100040 {
100041 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100042 index 4cba9c2..b4f9fcc 100644
100043 --- a/mm/sparse-vmemmap.c
100044 +++ b/mm/sparse-vmemmap.c
100045 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100046 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100047 if (!p)
100048 return NULL;
100049 - pud_populate(&init_mm, pud, p);
100050 + pud_populate_kernel(&init_mm, pud, p);
100051 }
100052 return pud;
100053 }
100054 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100055 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100056 if (!p)
100057 return NULL;
100058 - pgd_populate(&init_mm, pgd, p);
100059 + pgd_populate_kernel(&init_mm, pgd, p);
100060 }
100061 return pgd;
100062 }
100063 diff --git a/mm/sparse.c b/mm/sparse.c
100064 index d1b48b6..6e8590e 100644
100065 --- a/mm/sparse.c
100066 +++ b/mm/sparse.c
100067 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100068
100069 for (i = 0; i < PAGES_PER_SECTION; i++) {
100070 if (PageHWPoison(&memmap[i])) {
100071 - atomic_long_sub(1, &num_poisoned_pages);
100072 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100073 ClearPageHWPoison(&memmap[i]);
100074 }
100075 }
100076 diff --git a/mm/swap.c b/mm/swap.c
100077 index 8a12b33..7068e78 100644
100078 --- a/mm/swap.c
100079 +++ b/mm/swap.c
100080 @@ -31,6 +31,7 @@
100081 #include <linux/memcontrol.h>
100082 #include <linux/gfp.h>
100083 #include <linux/uio.h>
100084 +#include <linux/hugetlb.h>
100085
100086 #include "internal.h"
100087
100088 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100089
100090 __page_cache_release(page);
100091 dtor = get_compound_page_dtor(page);
100092 + if (!PageHuge(page))
100093 + BUG_ON(dtor != free_compound_page);
100094 (*dtor)(page);
100095 }
100096
100097 diff --git a/mm/swapfile.c b/mm/swapfile.c
100098 index 8798b2e..348f9dd 100644
100099 --- a/mm/swapfile.c
100100 +++ b/mm/swapfile.c
100101 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100102
100103 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100104 /* Activity counter to indicate that a swapon or swapoff has occurred */
100105 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100106 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100107
100108 static inline unsigned char swap_count(unsigned char ent)
100109 {
100110 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100111 spin_unlock(&swap_lock);
100112
100113 err = 0;
100114 - atomic_inc(&proc_poll_event);
100115 + atomic_inc_unchecked(&proc_poll_event);
100116 wake_up_interruptible(&proc_poll_wait);
100117
100118 out_dput:
100119 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100120
100121 poll_wait(file, &proc_poll_wait, wait);
100122
100123 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100124 - seq->poll_event = atomic_read(&proc_poll_event);
100125 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100126 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100127 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100128 }
100129
100130 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100131 return ret;
100132
100133 seq = file->private_data;
100134 - seq->poll_event = atomic_read(&proc_poll_event);
100135 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100136 return 0;
100137 }
100138
100139 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100140 (frontswap_map) ? "FS" : "");
100141
100142 mutex_unlock(&swapon_mutex);
100143 - atomic_inc(&proc_poll_event);
100144 + atomic_inc_unchecked(&proc_poll_event);
100145 wake_up_interruptible(&proc_poll_wait);
100146
100147 if (S_ISREG(inode->i_mode))
100148 diff --git a/mm/util.c b/mm/util.c
100149 index fec39d4..3e60325 100644
100150 --- a/mm/util.c
100151 +++ b/mm/util.c
100152 @@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
100153 void arch_pick_mmap_layout(struct mm_struct *mm)
100154 {
100155 mm->mmap_base = TASK_UNMAPPED_BASE;
100156 +
100157 +#ifdef CONFIG_PAX_RANDMMAP
100158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100159 + mm->mmap_base += mm->delta_mmap;
100160 +#endif
100161 +
100162 mm->get_unmapped_area = arch_get_unmapped_area;
100163 }
100164 #endif
100165 @@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100166 if (!mm->arg_end)
100167 goto out_mm; /* Shh! No looking before we're done */
100168
100169 + if (gr_acl_handle_procpidmem(task))
100170 + goto out_mm;
100171 +
100172 len = mm->arg_end - mm->arg_start;
100173
100174 if (len > buflen)
100175 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100176 index 90520af..24231aa 100644
100177 --- a/mm/vmalloc.c
100178 +++ b/mm/vmalloc.c
100179 @@ -40,6 +40,21 @@ struct vfree_deferred {
100180 };
100181 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100182
100183 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100184 +struct stack_deferred_llist {
100185 + struct llist_head list;
100186 + void *stack;
100187 + void *lowmem_stack;
100188 +};
100189 +
100190 +struct stack_deferred {
100191 + struct stack_deferred_llist list;
100192 + struct work_struct wq;
100193 +};
100194 +
100195 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100196 +#endif
100197 +
100198 static void __vunmap(const void *, int);
100199
100200 static void free_work(struct work_struct *w)
100201 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100202 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100203 struct llist_node *llnode = llist_del_all(&p->list);
100204 while (llnode) {
100205 - void *p = llnode;
100206 + void *x = llnode;
100207 llnode = llist_next(llnode);
100208 - __vunmap(p, 1);
100209 + __vunmap(x, 1);
100210 }
100211 }
100212
100213 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100214 +static void unmap_work(struct work_struct *w)
100215 +{
100216 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100217 + struct llist_node *llnode = llist_del_all(&p->list.list);
100218 + while (llnode) {
100219 + struct stack_deferred_llist *x =
100220 + llist_entry((struct llist_head *)llnode,
100221 + struct stack_deferred_llist, list);
100222 + void *stack = ACCESS_ONCE(x->stack);
100223 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100224 + llnode = llist_next(llnode);
100225 + __vunmap(stack, 0);
100226 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100227 + }
100228 +}
100229 +#endif
100230 +
100231 /*** Page table manipulation functions ***/
100232
100233 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100234 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100235
100236 pte = pte_offset_kernel(pmd, addr);
100237 do {
100238 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100239 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100240 +
100241 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100242 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100243 + BUG_ON(!pte_exec(*pte));
100244 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100245 + continue;
100246 + }
100247 +#endif
100248 +
100249 + {
100250 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100251 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100252 + }
100253 } while (pte++, addr += PAGE_SIZE, addr != end);
100254 }
100255
100256 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100257 pte = pte_alloc_kernel(pmd, addr);
100258 if (!pte)
100259 return -ENOMEM;
100260 +
100261 + pax_open_kernel();
100262 do {
100263 struct page *page = pages[*nr];
100264
100265 - if (WARN_ON(!pte_none(*pte)))
100266 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100267 + if (pgprot_val(prot) & _PAGE_NX)
100268 +#endif
100269 +
100270 + if (!pte_none(*pte)) {
100271 + pax_close_kernel();
100272 + WARN_ON(1);
100273 return -EBUSY;
100274 - if (WARN_ON(!page))
100275 + }
100276 + if (!page) {
100277 + pax_close_kernel();
100278 + WARN_ON(1);
100279 return -ENOMEM;
100280 + }
100281 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100282 (*nr)++;
100283 } while (pte++, addr += PAGE_SIZE, addr != end);
100284 + pax_close_kernel();
100285 return 0;
100286 }
100287
100288 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100289 pmd_t *pmd;
100290 unsigned long next;
100291
100292 - pmd = pmd_alloc(&init_mm, pud, addr);
100293 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100294 if (!pmd)
100295 return -ENOMEM;
100296 do {
100297 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100298 pud_t *pud;
100299 unsigned long next;
100300
100301 - pud = pud_alloc(&init_mm, pgd, addr);
100302 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100303 if (!pud)
100304 return -ENOMEM;
100305 do {
100306 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100307 if (addr >= MODULES_VADDR && addr < MODULES_END)
100308 return 1;
100309 #endif
100310 +
100311 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100312 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100313 + return 1;
100314 +#endif
100315 +
100316 return is_vmalloc_addr(x);
100317 }
100318
100319 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100320
100321 if (!pgd_none(*pgd)) {
100322 pud_t *pud = pud_offset(pgd, addr);
100323 +#ifdef CONFIG_X86
100324 + if (!pud_large(*pud))
100325 +#endif
100326 if (!pud_none(*pud)) {
100327 pmd_t *pmd = pmd_offset(pud, addr);
100328 +#ifdef CONFIG_X86
100329 + if (!pmd_large(*pmd))
100330 +#endif
100331 if (!pmd_none(*pmd)) {
100332 pte_t *ptep, pte;
100333
100334 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100335 for_each_possible_cpu(i) {
100336 struct vmap_block_queue *vbq;
100337 struct vfree_deferred *p;
100338 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100339 + struct stack_deferred *p2;
100340 +#endif
100341
100342 vbq = &per_cpu(vmap_block_queue, i);
100343 spin_lock_init(&vbq->lock);
100344 INIT_LIST_HEAD(&vbq->free);
100345 +
100346 p = &per_cpu(vfree_deferred, i);
100347 init_llist_head(&p->list);
100348 INIT_WORK(&p->wq, free_work);
100349 +
100350 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100351 + p2 = &per_cpu(stack_deferred, i);
100352 + init_llist_head(&p2->list.list);
100353 + INIT_WORK(&p2->wq, unmap_work);
100354 +#endif
100355 }
100356
100357 /* Import existing vmlist entries. */
100358 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100359 struct vm_struct *area;
100360
100361 BUG_ON(in_interrupt());
100362 +
100363 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100364 + if (flags & VM_KERNEXEC) {
100365 + if (start != VMALLOC_START || end != VMALLOC_END)
100366 + return NULL;
100367 + start = (unsigned long)MODULES_EXEC_VADDR;
100368 + end = (unsigned long)MODULES_EXEC_END;
100369 + }
100370 +#endif
100371 +
100372 if (flags & VM_IOREMAP)
100373 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100374
100375 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100376 }
100377 EXPORT_SYMBOL(vunmap);
100378
100379 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100380 +void unmap_process_stacks(struct task_struct *task)
100381 +{
100382 + if (unlikely(in_interrupt())) {
100383 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100384 + struct stack_deferred_llist *list = task->stack;
100385 + list->stack = task->stack;
100386 + list->lowmem_stack = task->lowmem_stack;
100387 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100388 + schedule_work(&p->wq);
100389 + } else {
100390 + __vunmap(task->stack, 0);
100391 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100392 + }
100393 +}
100394 +#endif
100395 +
100396 /**
100397 * vmap - map an array of pages into virtually contiguous space
100398 * @pages: array of page pointers
100399 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100400 if (count > totalram_pages)
100401 return NULL;
100402
100403 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100404 + if (!(pgprot_val(prot) & _PAGE_NX))
100405 + flags |= VM_KERNEXEC;
100406 +#endif
100407 +
100408 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100409 __builtin_return_address(0));
100410 if (!area)
100411 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100412 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100413 goto fail;
100414
100415 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100416 + if (!(pgprot_val(prot) & _PAGE_NX))
100417 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100418 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100419 + else
100420 +#endif
100421 +
100422 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100423 start, end, node, gfp_mask, caller);
100424 if (!area)
100425 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100426 * For tight control over page level allocator and protection flags
100427 * use __vmalloc() instead.
100428 */
100429 -
100430 void *vmalloc_exec(unsigned long size)
100431 {
100432 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100433 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100434 NUMA_NO_NODE, __builtin_return_address(0));
100435 }
100436
100437 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100438 {
100439 struct vm_struct *area;
100440
100441 + BUG_ON(vma->vm_mirror);
100442 +
100443 size = PAGE_ALIGN(size);
100444
100445 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100446 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100447 v->addr, v->addr + v->size, v->size);
100448
100449 if (v->caller)
100450 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100451 + seq_printf(m, " %pK", v->caller);
100452 +#else
100453 seq_printf(m, " %pS", v->caller);
100454 +#endif
100455
100456 if (v->nr_pages)
100457 seq_printf(m, " pages=%d", v->nr_pages);
100458 diff --git a/mm/vmstat.c b/mm/vmstat.c
100459 index 1b12d39..57b29b2 100644
100460 --- a/mm/vmstat.c
100461 +++ b/mm/vmstat.c
100462 @@ -22,6 +22,7 @@
100463 #include <linux/writeback.h>
100464 #include <linux/compaction.h>
100465 #include <linux/mm_inline.h>
100466 +#include <linux/grsecurity.h>
100467
100468 #include "internal.h"
100469
100470 @@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100471 *
100472 * vm_stat contains the global counters
100473 */
100474 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100475 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100476 EXPORT_SYMBOL(vm_stat);
100477
100478 #ifdef CONFIG_SMP
100479 @@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100480
100481 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100482 if (diff[i]) {
100483 - atomic_long_add(diff[i], &vm_stat[i]);
100484 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100485 changes++;
100486 }
100487 return changes;
100488 @@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100489 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100490 if (v) {
100491
100492 - atomic_long_add(v, &zone->vm_stat[i]);
100493 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100494 global_diff[i] += v;
100495 #ifdef CONFIG_NUMA
100496 /* 3 seconds idle till flush */
100497 @@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100498
100499 v = p->vm_stat_diff[i];
100500 p->vm_stat_diff[i] = 0;
100501 - atomic_long_add(v, &zone->vm_stat[i]);
100502 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100503 global_diff[i] += v;
100504 }
100505 }
100506 @@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100507 if (pset->vm_stat_diff[i]) {
100508 int v = pset->vm_stat_diff[i];
100509 pset->vm_stat_diff[i] = 0;
100510 - atomic_long_add(v, &zone->vm_stat[i]);
100511 - atomic_long_add(v, &vm_stat[i]);
100512 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100513 + atomic_long_add_unchecked(v, &vm_stat[i]);
100514 }
100515 }
100516 #endif
100517 @@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100518 stat_items_size += sizeof(struct vm_event_state);
100519 #endif
100520
100521 - v = kmalloc(stat_items_size, GFP_KERNEL);
100522 + v = kzalloc(stat_items_size, GFP_KERNEL);
100523 m->private = v;
100524 if (!v)
100525 return ERR_PTR(-ENOMEM);
100526 +
100527 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100528 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100529 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100530 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100531 + && !in_group_p(grsec_proc_gid)
100532 +#endif
100533 + )
100534 + return (unsigned long *)m->private + *pos;
100535 +#endif
100536 +#endif
100537 +
100538 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100539 v[i] = global_page_state(i);
100540 v += NR_VM_ZONE_STAT_ITEMS;
100541 @@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100542 cpu_notifier_register_done();
100543 #endif
100544 #ifdef CONFIG_PROC_FS
100545 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100546 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100547 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100548 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100549 + {
100550 + mode_t gr_mode = S_IRUGO;
100551 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100552 + gr_mode = S_IRUSR;
100553 +#endif
100554 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100555 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100556 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100557 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100558 + }
100559 #endif
100560 return 0;
100561 }
100562 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100563 index 64c6bed..b79a5de 100644
100564 --- a/net/8021q/vlan.c
100565 +++ b/net/8021q/vlan.c
100566 @@ -481,7 +481,7 @@ out:
100567 return NOTIFY_DONE;
100568 }
100569
100570 -static struct notifier_block vlan_notifier_block __read_mostly = {
100571 +static struct notifier_block vlan_notifier_block = {
100572 .notifier_call = vlan_device_event,
100573 };
100574
100575 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100576 err = -EPERM;
100577 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100578 break;
100579 - if ((args.u.name_type >= 0) &&
100580 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100581 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100582 struct vlan_net *vn;
100583
100584 vn = net_generic(net, vlan_net_id);
100585 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100586 index 8ac8a5c..991defc 100644
100587 --- a/net/8021q/vlan_netlink.c
100588 +++ b/net/8021q/vlan_netlink.c
100589 @@ -238,7 +238,7 @@ nla_put_failure:
100590 return -EMSGSIZE;
100591 }
100592
100593 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
100594 +struct rtnl_link_ops vlan_link_ops = {
100595 .kind = "vlan",
100596 .maxtype = IFLA_VLAN_MAX,
100597 .policy = vlan_policy,
100598 diff --git a/net/9p/client.c b/net/9p/client.c
100599 index e86a9bea..e91f70e 100644
100600 --- a/net/9p/client.c
100601 +++ b/net/9p/client.c
100602 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100603 len - inline_len);
100604 } else {
100605 err = copy_from_user(ename + inline_len,
100606 - uidata, len - inline_len);
100607 + (char __force_user *)uidata, len - inline_len);
100608 if (err) {
100609 err = -EFAULT;
100610 goto out_err;
100611 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100612 kernel_buf = 1;
100613 indata = data;
100614 } else
100615 - indata = (__force char *)udata;
100616 + indata = (__force_kernel char *)udata;
100617 /*
100618 * response header len is 11
100619 * PDU Header(7) + IO Size (4)
100620 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100621 kernel_buf = 1;
100622 odata = data;
100623 } else
100624 - odata = (char *)udata;
100625 + odata = (char __force_kernel *)udata;
100626 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100627 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100628 fid->fid, offset, rsize);
100629 diff --git a/net/9p/mod.c b/net/9p/mod.c
100630 index 6ab36ae..6f1841b 100644
100631 --- a/net/9p/mod.c
100632 +++ b/net/9p/mod.c
100633 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100634 void v9fs_register_trans(struct p9_trans_module *m)
100635 {
100636 spin_lock(&v9fs_trans_lock);
100637 - list_add_tail(&m->list, &v9fs_trans_list);
100638 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100639 spin_unlock(&v9fs_trans_lock);
100640 }
100641 EXPORT_SYMBOL(v9fs_register_trans);
100642 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100643 void v9fs_unregister_trans(struct p9_trans_module *m)
100644 {
100645 spin_lock(&v9fs_trans_lock);
100646 - list_del_init(&m->list);
100647 + pax_list_del_init((struct list_head *)&m->list);
100648 spin_unlock(&v9fs_trans_lock);
100649 }
100650 EXPORT_SYMBOL(v9fs_unregister_trans);
100651 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100652 index 80d08f6..de63fd1 100644
100653 --- a/net/9p/trans_fd.c
100654 +++ b/net/9p/trans_fd.c
100655 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100656 oldfs = get_fs();
100657 set_fs(get_ds());
100658 /* The cast to a user pointer is valid due to the set_fs() */
100659 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100660 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100661 set_fs(oldfs);
100662
100663 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100664 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100665 index af46bc4..f9adfcd 100644
100666 --- a/net/appletalk/atalk_proc.c
100667 +++ b/net/appletalk/atalk_proc.c
100668 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100669 struct proc_dir_entry *p;
100670 int rc = -ENOMEM;
100671
100672 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100673 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100674 if (!atalk_proc_dir)
100675 goto out;
100676
100677 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100678 index 876fbe8..8bbea9f 100644
100679 --- a/net/atm/atm_misc.c
100680 +++ b/net/atm/atm_misc.c
100681 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100682 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100683 return 1;
100684 atm_return(vcc, truesize);
100685 - atomic_inc(&vcc->stats->rx_drop);
100686 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100687 return 0;
100688 }
100689 EXPORT_SYMBOL(atm_charge);
100690 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100691 }
100692 }
100693 atm_return(vcc, guess);
100694 - atomic_inc(&vcc->stats->rx_drop);
100695 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100696 return NULL;
100697 }
100698 EXPORT_SYMBOL(atm_alloc_charge);
100699 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100700
100701 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100702 {
100703 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100704 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100705 __SONET_ITEMS
100706 #undef __HANDLE_ITEM
100707 }
100708 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100709
100710 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100711 {
100712 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100713 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100714 __SONET_ITEMS
100715 #undef __HANDLE_ITEM
100716 }
100717 diff --git a/net/atm/lec.c b/net/atm/lec.c
100718 index 4b98f89..5a2f6cb 100644
100719 --- a/net/atm/lec.c
100720 +++ b/net/atm/lec.c
100721 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100722 }
100723
100724 static struct lane2_ops lane2_ops = {
100725 - lane2_resolve, /* resolve, spec 3.1.3 */
100726 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100727 - NULL /* associate indicator, spec 3.1.5 */
100728 + .resolve = lane2_resolve,
100729 + .associate_req = lane2_associate_req,
100730 + .associate_indicator = NULL
100731 };
100732
100733 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100734 diff --git a/net/atm/lec.h b/net/atm/lec.h
100735 index 4149db1..f2ab682 100644
100736 --- a/net/atm/lec.h
100737 +++ b/net/atm/lec.h
100738 @@ -48,7 +48,7 @@ struct lane2_ops {
100739 const u8 *tlvs, u32 sizeoftlvs);
100740 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100741 const u8 *tlvs, u32 sizeoftlvs);
100742 -};
100743 +} __no_const;
100744
100745 /*
100746 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100747 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100748 index d1b2d9a..d549f7f 100644
100749 --- a/net/atm/mpoa_caches.c
100750 +++ b/net/atm/mpoa_caches.c
100751 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100752
100753
100754 static struct in_cache_ops ingress_ops = {
100755 - in_cache_add_entry, /* add_entry */
100756 - in_cache_get, /* get */
100757 - in_cache_get_with_mask, /* get_with_mask */
100758 - in_cache_get_by_vcc, /* get_by_vcc */
100759 - in_cache_put, /* put */
100760 - in_cache_remove_entry, /* remove_entry */
100761 - cache_hit, /* cache_hit */
100762 - clear_count_and_expired, /* clear_count */
100763 - check_resolving_entries, /* check_resolving */
100764 - refresh_entries, /* refresh */
100765 - in_destroy_cache /* destroy_cache */
100766 + .add_entry = in_cache_add_entry,
100767 + .get = in_cache_get,
100768 + .get_with_mask = in_cache_get_with_mask,
100769 + .get_by_vcc = in_cache_get_by_vcc,
100770 + .put = in_cache_put,
100771 + .remove_entry = in_cache_remove_entry,
100772 + .cache_hit = cache_hit,
100773 + .clear_count = clear_count_and_expired,
100774 + .check_resolving = check_resolving_entries,
100775 + .refresh = refresh_entries,
100776 + .destroy_cache = in_destroy_cache
100777 };
100778
100779 static struct eg_cache_ops egress_ops = {
100780 - eg_cache_add_entry, /* add_entry */
100781 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100782 - eg_cache_get_by_tag, /* get_by_tag */
100783 - eg_cache_get_by_vcc, /* get_by_vcc */
100784 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100785 - eg_cache_put, /* put */
100786 - eg_cache_remove_entry, /* remove_entry */
100787 - update_eg_cache_entry, /* update */
100788 - clear_expired, /* clear_expired */
100789 - eg_destroy_cache /* destroy_cache */
100790 + .add_entry = eg_cache_add_entry,
100791 + .get_by_cache_id = eg_cache_get_by_cache_id,
100792 + .get_by_tag = eg_cache_get_by_tag,
100793 + .get_by_vcc = eg_cache_get_by_vcc,
100794 + .get_by_src_ip = eg_cache_get_by_src_ip,
100795 + .put = eg_cache_put,
100796 + .remove_entry = eg_cache_remove_entry,
100797 + .update = update_eg_cache_entry,
100798 + .clear_expired = clear_expired,
100799 + .destroy_cache = eg_destroy_cache
100800 };
100801
100802
100803 diff --git a/net/atm/proc.c b/net/atm/proc.c
100804 index bbb6461..cf04016 100644
100805 --- a/net/atm/proc.c
100806 +++ b/net/atm/proc.c
100807 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100808 const struct k_atm_aal_stats *stats)
100809 {
100810 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100811 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100812 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100813 - atomic_read(&stats->rx_drop));
100814 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100815 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100816 + atomic_read_unchecked(&stats->rx_drop));
100817 }
100818
100819 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100820 diff --git a/net/atm/resources.c b/net/atm/resources.c
100821 index 0447d5d..3cf4728 100644
100822 --- a/net/atm/resources.c
100823 +++ b/net/atm/resources.c
100824 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100825 static void copy_aal_stats(struct k_atm_aal_stats *from,
100826 struct atm_aal_stats *to)
100827 {
100828 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100829 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100830 __AAL_STAT_ITEMS
100831 #undef __HANDLE_ITEM
100832 }
100833 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100834 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100835 struct atm_aal_stats *to)
100836 {
100837 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100838 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100839 __AAL_STAT_ITEMS
100840 #undef __HANDLE_ITEM
100841 }
100842 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100843 index 919a5ce..cc6b444 100644
100844 --- a/net/ax25/sysctl_net_ax25.c
100845 +++ b/net/ax25/sysctl_net_ax25.c
100846 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100847 {
100848 char path[sizeof("net/ax25/") + IFNAMSIZ];
100849 int k;
100850 - struct ctl_table *table;
100851 + ctl_table_no_const *table;
100852
100853 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100854 if (!table)
100855 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100856 index 1e80539..676c37a 100644
100857 --- a/net/batman-adv/bat_iv_ogm.c
100858 +++ b/net/batman-adv/bat_iv_ogm.c
100859 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100860
100861 /* randomize initial seqno to avoid collision */
100862 get_random_bytes(&random_seqno, sizeof(random_seqno));
100863 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100864 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100865
100866 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100867 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100868 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100869 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100870
100871 /* change sequence number to network order */
100872 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100873 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100874 batadv_ogm_packet->seqno = htonl(seqno);
100875 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100876 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100877
100878 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100879
100880 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100881 return;
100882
100883 /* could be changed by schedule_own_packet() */
100884 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100885 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100886
100887 if (ogm_packet->flags & BATADV_DIRECTLINK)
100888 has_directlink_flag = true;
100889 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100890 index 00f9e14..e1c7203 100644
100891 --- a/net/batman-adv/fragmentation.c
100892 +++ b/net/batman-adv/fragmentation.c
100893 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100894 frag_header.packet_type = BATADV_UNICAST_FRAG;
100895 frag_header.version = BATADV_COMPAT_VERSION;
100896 frag_header.ttl = BATADV_TTL;
100897 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100898 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100899 frag_header.reserved = 0;
100900 frag_header.no = 0;
100901 frag_header.total_size = htons(skb->len);
100902 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100903 index 5467955..75ad4e3 100644
100904 --- a/net/batman-adv/soft-interface.c
100905 +++ b/net/batman-adv/soft-interface.c
100906 @@ -296,7 +296,7 @@ send:
100907 primary_if->net_dev->dev_addr);
100908
100909 /* set broadcast sequence number */
100910 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100911 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100912 bcast_packet->seqno = htonl(seqno);
100913
100914 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100915 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100916 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100917
100918 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100919 - atomic_set(&bat_priv->bcast_seqno, 1);
100920 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100921 atomic_set(&bat_priv->tt.vn, 0);
100922 atomic_set(&bat_priv->tt.local_changes, 0);
100923 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100924 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100925
100926 /* randomize initial seqno to avoid collision */
100927 get_random_bytes(&random_seqno, sizeof(random_seqno));
100928 - atomic_set(&bat_priv->frag_seqno, random_seqno);
100929 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100930
100931 bat_priv->primary_if = NULL;
100932 bat_priv->num_ifaces = 0;
100933 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100934 return 0;
100935 }
100936
100937 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
100938 +struct rtnl_link_ops batadv_link_ops = {
100939 .kind = "batadv",
100940 .priv_size = sizeof(struct batadv_priv),
100941 .setup = batadv_softif_init_early,
100942 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100943 index 8854c05..ee5d5497 100644
100944 --- a/net/batman-adv/types.h
100945 +++ b/net/batman-adv/types.h
100946 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100947 struct batadv_hard_iface_bat_iv {
100948 unsigned char *ogm_buff;
100949 int ogm_buff_len;
100950 - atomic_t ogm_seqno;
100951 + atomic_unchecked_t ogm_seqno;
100952 };
100953
100954 /**
100955 @@ -768,7 +768,7 @@ struct batadv_priv {
100956 atomic_t bonding;
100957 atomic_t fragmentation;
100958 atomic_t packet_size_max;
100959 - atomic_t frag_seqno;
100960 + atomic_unchecked_t frag_seqno;
100961 #ifdef CONFIG_BATMAN_ADV_BLA
100962 atomic_t bridge_loop_avoidance;
100963 #endif
100964 @@ -787,7 +787,7 @@ struct batadv_priv {
100965 #endif
100966 uint32_t isolation_mark;
100967 uint32_t isolation_mark_mask;
100968 - atomic_t bcast_seqno;
100969 + atomic_unchecked_t bcast_seqno;
100970 atomic_t bcast_queue_left;
100971 atomic_t batman_queue_left;
100972 char num_ifaces;
100973 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
100974 index cfbb39e..0bbfc9d 100644
100975 --- a/net/bluetooth/6lowpan.c
100976 +++ b/net/bluetooth/6lowpan.c
100977 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
100978
100979 drop:
100980 dev->stats.rx_dropped++;
100981 - kfree_skb(skb);
100982 return NET_RX_DROP;
100983 }
100984
100985 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
100986 index 85bcc21..ce82722d 100644
100987 --- a/net/bluetooth/bnep/core.c
100988 +++ b/net/bluetooth/bnep/core.c
100989 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
100990
100991 BT_DBG("");
100992
100993 + if (!l2cap_is_socket(sock))
100994 + return -EBADFD;
100995 +
100996 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
100997 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
100998
100999 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
101000 index 67fe5e8..278a194 100644
101001 --- a/net/bluetooth/cmtp/core.c
101002 +++ b/net/bluetooth/cmtp/core.c
101003 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
101004
101005 BT_DBG("");
101006
101007 + if (!l2cap_is_socket(sock))
101008 + return -EBADFD;
101009 +
101010 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
101011 if (!session)
101012 return -ENOMEM;
101013 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101014 index 115f149..f0ba286 100644
101015 --- a/net/bluetooth/hci_sock.c
101016 +++ b/net/bluetooth/hci_sock.c
101017 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101018 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101019 }
101020
101021 - len = min_t(unsigned int, len, sizeof(uf));
101022 + len = min((size_t)len, sizeof(uf));
101023 if (copy_from_user(&uf, optval, len)) {
101024 err = -EFAULT;
101025 break;
101026 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
101027 index 1b7d605..02ebd10 100644
101028 --- a/net/bluetooth/hidp/core.c
101029 +++ b/net/bluetooth/hidp/core.c
101030 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
101031 {
101032 struct hidp_session *session;
101033 struct l2cap_conn *conn;
101034 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
101035 + struct l2cap_chan *chan;
101036 int ret;
101037
101038 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
101039 if (ret)
101040 return ret;
101041
101042 + chan = l2cap_pi(ctrl_sock->sk)->chan;
101043 conn = NULL;
101044 l2cap_chan_lock(chan);
101045 if (chan->conn)
101046 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101047 index b6f9777..36d3039 100644
101048 --- a/net/bluetooth/l2cap_core.c
101049 +++ b/net/bluetooth/l2cap_core.c
101050 @@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101051 break;
101052
101053 case L2CAP_CONF_RFC:
101054 - if (olen == sizeof(rfc))
101055 - memcpy(&rfc, (void *)val, olen);
101056 + if (olen != sizeof(rfc))
101057 + break;
101058 +
101059 + memcpy(&rfc, (void *)val, olen);
101060
101061 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101062 rfc.mode != chan->mode)
101063 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101064 index 31f106e..323f606 100644
101065 --- a/net/bluetooth/l2cap_sock.c
101066 +++ b/net/bluetooth/l2cap_sock.c
101067 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101068 struct sock *sk = sock->sk;
101069 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101070 struct l2cap_options opts;
101071 - int len, err = 0;
101072 + int err = 0;
101073 + size_t len = optlen;
101074 u32 opt;
101075
101076 BT_DBG("sk %p", sk);
101077 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101078 opts.max_tx = chan->max_tx;
101079 opts.txwin_size = chan->tx_win;
101080
101081 - len = min_t(unsigned int, sizeof(opts), optlen);
101082 + len = min(sizeof(opts), len);
101083 if (copy_from_user((char *) &opts, optval, len)) {
101084 err = -EFAULT;
101085 break;
101086 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101087 struct bt_security sec;
101088 struct bt_power pwr;
101089 struct l2cap_conn *conn;
101090 - int len, err = 0;
101091 + int err = 0;
101092 + size_t len = optlen;
101093 u32 opt;
101094
101095 BT_DBG("sk %p", sk);
101096 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101097
101098 sec.level = BT_SECURITY_LOW;
101099
101100 - len = min_t(unsigned int, sizeof(sec), optlen);
101101 + len = min(sizeof(sec), len);
101102 if (copy_from_user((char *) &sec, optval, len)) {
101103 err = -EFAULT;
101104 break;
101105 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101106
101107 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101108
101109 - len = min_t(unsigned int, sizeof(pwr), optlen);
101110 + len = min(sizeof(pwr), len);
101111 if (copy_from_user((char *) &pwr, optval, len)) {
101112 err = -EFAULT;
101113 break;
101114 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101115 index 8bbbb5e..6fc0950 100644
101116 --- a/net/bluetooth/rfcomm/sock.c
101117 +++ b/net/bluetooth/rfcomm/sock.c
101118 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101119 struct sock *sk = sock->sk;
101120 struct bt_security sec;
101121 int err = 0;
101122 - size_t len;
101123 + size_t len = optlen;
101124 u32 opt;
101125
101126 BT_DBG("sk %p", sk);
101127 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101128
101129 sec.level = BT_SECURITY_LOW;
101130
101131 - len = min_t(unsigned int, sizeof(sec), optlen);
101132 + len = min(sizeof(sec), len);
101133 if (copy_from_user((char *) &sec, optval, len)) {
101134 err = -EFAULT;
101135 break;
101136 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101137 index 8e385a0..a5bdd8e 100644
101138 --- a/net/bluetooth/rfcomm/tty.c
101139 +++ b/net/bluetooth/rfcomm/tty.c
101140 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101141 BT_DBG("tty %p id %d", tty, tty->index);
101142
101143 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101144 - dev->channel, dev->port.count);
101145 + dev->channel, atomic_read(&dev->port.count));
101146
101147 err = tty_port_open(&dev->port, tty, filp);
101148 if (err)
101149 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101150 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101151
101152 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101153 - dev->port.count);
101154 + atomic_read(&dev->port.count));
101155
101156 tty_port_close(&dev->port, tty, filp);
101157 }
101158 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101159 index e5ec470..cbfabd1 100644
101160 --- a/net/bridge/br_netlink.c
101161 +++ b/net/bridge/br_netlink.c
101162 @@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
101163 .get_link_af_size = br_get_link_af_size,
101164 };
101165
101166 -struct rtnl_link_ops br_link_ops __read_mostly = {
101167 +struct rtnl_link_ops br_link_ops = {
101168 .kind = "bridge",
101169 .priv_size = sizeof(struct net_bridge),
101170 .setup = br_dev_setup,
101171 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101172 index d9a8c05..8dadc6c6 100644
101173 --- a/net/bridge/netfilter/ebtables.c
101174 +++ b/net/bridge/netfilter/ebtables.c
101175 @@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101176 tmp.valid_hooks = t->table->valid_hooks;
101177 }
101178 mutex_unlock(&ebt_mutex);
101179 - if (copy_to_user(user, &tmp, *len) != 0) {
101180 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101181 BUGPRINT("c2u Didn't work\n");
101182 ret = -EFAULT;
101183 break;
101184 @@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101185 goto out;
101186 tmp.valid_hooks = t->valid_hooks;
101187
101188 - if (copy_to_user(user, &tmp, *len) != 0) {
101189 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101190 ret = -EFAULT;
101191 break;
101192 }
101193 @@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101194 tmp.entries_size = t->table->entries_size;
101195 tmp.valid_hooks = t->table->valid_hooks;
101196
101197 - if (copy_to_user(user, &tmp, *len) != 0) {
101198 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101199 ret = -EFAULT;
101200 break;
101201 }
101202 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101203 index f5afda1..dcf770a 100644
101204 --- a/net/caif/cfctrl.c
101205 +++ b/net/caif/cfctrl.c
101206 @@ -10,6 +10,7 @@
101207 #include <linux/spinlock.h>
101208 #include <linux/slab.h>
101209 #include <linux/pkt_sched.h>
101210 +#include <linux/sched.h>
101211 #include <net/caif/caif_layer.h>
101212 #include <net/caif/cfpkt.h>
101213 #include <net/caif/cfctrl.h>
101214 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101215 memset(&dev_info, 0, sizeof(dev_info));
101216 dev_info.id = 0xff;
101217 cfsrvl_init(&this->serv, 0, &dev_info, false);
101218 - atomic_set(&this->req_seq_no, 1);
101219 - atomic_set(&this->rsp_seq_no, 1);
101220 + atomic_set_unchecked(&this->req_seq_no, 1);
101221 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101222 this->serv.layer.receive = cfctrl_recv;
101223 sprintf(this->serv.layer.name, "ctrl");
101224 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101225 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101226 struct cfctrl_request_info *req)
101227 {
101228 spin_lock_bh(&ctrl->info_list_lock);
101229 - atomic_inc(&ctrl->req_seq_no);
101230 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101231 + atomic_inc_unchecked(&ctrl->req_seq_no);
101232 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101233 list_add_tail(&req->list, &ctrl->list);
101234 spin_unlock_bh(&ctrl->info_list_lock);
101235 }
101236 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101237 if (p != first)
101238 pr_warn("Requests are not received in order\n");
101239
101240 - atomic_set(&ctrl->rsp_seq_no,
101241 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101242 p->sequence_no);
101243 list_del(&p->list);
101244 goto out;
101245 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101246 index 4589ff67..46d6b8f 100644
101247 --- a/net/caif/chnl_net.c
101248 +++ b/net/caif/chnl_net.c
101249 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101250 };
101251
101252
101253 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101254 +static struct rtnl_link_ops ipcaif_link_ops = {
101255 .kind = "caif",
101256 .priv_size = sizeof(struct chnl_net),
101257 .setup = ipcaif_net_setup,
101258 diff --git a/net/can/af_can.c b/net/can/af_can.c
101259 index ce82337..5d17b4d 100644
101260 --- a/net/can/af_can.c
101261 +++ b/net/can/af_can.c
101262 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101263 };
101264
101265 /* notifier block for netdevice event */
101266 -static struct notifier_block can_netdev_notifier __read_mostly = {
101267 +static struct notifier_block can_netdev_notifier = {
101268 .notifier_call = can_notifier,
101269 };
101270
101271 diff --git a/net/can/bcm.c b/net/can/bcm.c
101272 index dcb75c0..24b1b43 100644
101273 --- a/net/can/bcm.c
101274 +++ b/net/can/bcm.c
101275 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101276 }
101277
101278 /* create /proc/net/can-bcm directory */
101279 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101280 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101281 return 0;
101282 }
101283
101284 diff --git a/net/can/gw.c b/net/can/gw.c
101285 index 050a211..bb9fe33 100644
101286 --- a/net/can/gw.c
101287 +++ b/net/can/gw.c
101288 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101289 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101290
101291 static HLIST_HEAD(cgw_list);
101292 -static struct notifier_block notifier;
101293
101294 static struct kmem_cache *cgw_cache __read_mostly;
101295
101296 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101297 return err;
101298 }
101299
101300 +static struct notifier_block notifier = {
101301 + .notifier_call = cgw_notifier
101302 +};
101303 +
101304 static __init int cgw_module_init(void)
101305 {
101306 /* sanitize given module parameter */
101307 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101308 return -ENOMEM;
101309
101310 /* set notifier */
101311 - notifier.notifier_call = cgw_notifier;
101312 register_netdevice_notifier(&notifier);
101313
101314 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101315 diff --git a/net/can/proc.c b/net/can/proc.c
101316 index 1a19b98..df2b4ec 100644
101317 --- a/net/can/proc.c
101318 +++ b/net/can/proc.c
101319 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101320 void can_init_proc(void)
101321 {
101322 /* create /proc/net/can directory */
101323 - can_dir = proc_mkdir("can", init_net.proc_net);
101324 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101325
101326 if (!can_dir) {
101327 printk(KERN_INFO "can: failed to create /proc/net/can . "
101328 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101329 index 8d1653c..77ad145 100644
101330 --- a/net/ceph/messenger.c
101331 +++ b/net/ceph/messenger.c
101332 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101333 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101334
101335 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101336 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101337 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101338
101339 static struct page *zero_page; /* used in certain error cases */
101340
101341 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101342 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101343 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101344
101345 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101346 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101347 s = addr_str[i];
101348
101349 switch (ss->ss_family) {
101350 diff --git a/net/compat.c b/net/compat.c
101351 index bc8aeef..f9c070c 100644
101352 --- a/net/compat.c
101353 +++ b/net/compat.c
101354 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101355 return -EFAULT;
101356 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101357 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101358 - kmsg->msg_name = compat_ptr(tmp1);
101359 - kmsg->msg_iov = compat_ptr(tmp2);
101360 - kmsg->msg_control = compat_ptr(tmp3);
101361 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101362 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101363 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101364 return 0;
101365 }
101366
101367 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101368
101369 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101370 if (mode == VERIFY_READ) {
101371 - int err = move_addr_to_kernel(kern_msg->msg_name,
101372 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101373 kern_msg->msg_namelen,
101374 kern_address);
101375 if (err < 0)
101376 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101377 }
101378
101379 tot_len = iov_from_user_compat_to_kern(kern_iov,
101380 - (struct compat_iovec __user *)kern_msg->msg_iov,
101381 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101382 kern_msg->msg_iovlen);
101383 if (tot_len >= 0)
101384 kern_msg->msg_iov = kern_iov;
101385 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101386
101387 #define CMSG_COMPAT_FIRSTHDR(msg) \
101388 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101389 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101390 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101391 (struct compat_cmsghdr __user *)NULL)
101392
101393 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101394 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101395 (ucmlen) <= (unsigned long) \
101396 ((mhdr)->msg_controllen - \
101397 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101398 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101399
101400 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101401 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101402 {
101403 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101404 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101405 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101406 msg->msg_controllen)
101407 return NULL;
101408 return (struct compat_cmsghdr __user *)ptr;
101409 @@ -223,7 +223,7 @@ Efault:
101410
101411 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101412 {
101413 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101414 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101415 struct compat_cmsghdr cmhdr;
101416 struct compat_timeval ctv;
101417 struct compat_timespec cts[3];
101418 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101419
101420 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101421 {
101422 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101423 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101424 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101425 int fdnum = scm->fp->count;
101426 struct file **fp = scm->fp->fp;
101427 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101428 return -EFAULT;
101429 old_fs = get_fs();
101430 set_fs(KERNEL_DS);
101431 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101432 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101433 set_fs(old_fs);
101434
101435 return err;
101436 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101437 len = sizeof(ktime);
101438 old_fs = get_fs();
101439 set_fs(KERNEL_DS);
101440 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101441 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101442 set_fs(old_fs);
101443
101444 if (!err) {
101445 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101446 case MCAST_JOIN_GROUP:
101447 case MCAST_LEAVE_GROUP:
101448 {
101449 - struct compat_group_req __user *gr32 = (void *)optval;
101450 + struct compat_group_req __user *gr32 = (void __user *)optval;
101451 struct group_req __user *kgr =
101452 compat_alloc_user_space(sizeof(struct group_req));
101453 u32 interface;
101454 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101455 case MCAST_BLOCK_SOURCE:
101456 case MCAST_UNBLOCK_SOURCE:
101457 {
101458 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101459 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101460 struct group_source_req __user *kgsr = compat_alloc_user_space(
101461 sizeof(struct group_source_req));
101462 u32 interface;
101463 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101464 }
101465 case MCAST_MSFILTER:
101466 {
101467 - struct compat_group_filter __user *gf32 = (void *)optval;
101468 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101469 struct group_filter __user *kgf;
101470 u32 interface, fmode, numsrc;
101471
101472 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101473 char __user *optval, int __user *optlen,
101474 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101475 {
101476 - struct compat_group_filter __user *gf32 = (void *)optval;
101477 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101478 struct group_filter __user *kgf;
101479 int __user *koptlen;
101480 u32 interface, fmode, numsrc;
101481 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101482
101483 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101484 return -EINVAL;
101485 - if (copy_from_user(a, args, nas[call]))
101486 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101487 return -EFAULT;
101488 a0 = a[0];
101489 a1 = a[1];
101490 diff --git a/net/core/datagram.c b/net/core/datagram.c
101491 index fdbc9a8..cd6972c 100644
101492 --- a/net/core/datagram.c
101493 +++ b/net/core/datagram.c
101494 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101495 }
101496
101497 kfree_skb(skb);
101498 - atomic_inc(&sk->sk_drops);
101499 + atomic_inc_unchecked(&sk->sk_drops);
101500 sk_mem_reclaim_partial(sk);
101501
101502 return err;
101503 diff --git a/net/core/dev.c b/net/core/dev.c
101504 index 8440968..e14d2b7 100644
101505 --- a/net/core/dev.c
101506 +++ b/net/core/dev.c
101507 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101508 {
101509 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101510 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101511 - atomic_long_inc(&dev->rx_dropped);
101512 + atomic_long_inc_unchecked(&dev->rx_dropped);
101513 kfree_skb(skb);
101514 return NET_RX_DROP;
101515 }
101516 }
101517
101518 if (unlikely(!is_skb_forwardable(dev, skb))) {
101519 - atomic_long_inc(&dev->rx_dropped);
101520 + atomic_long_inc_unchecked(&dev->rx_dropped);
101521 kfree_skb(skb);
101522 return NET_RX_DROP;
101523 }
101524 @@ -2994,7 +2994,7 @@ recursion_alert:
101525 drop:
101526 rcu_read_unlock_bh();
101527
101528 - atomic_long_inc(&dev->tx_dropped);
101529 + atomic_long_inc_unchecked(&dev->tx_dropped);
101530 kfree_skb_list(skb);
101531 return rc;
101532 out:
101533 @@ -3337,7 +3337,7 @@ enqueue:
101534
101535 local_irq_restore(flags);
101536
101537 - atomic_long_inc(&skb->dev->rx_dropped);
101538 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101539 kfree_skb(skb);
101540 return NET_RX_DROP;
101541 }
101542 @@ -3414,7 +3414,7 @@ int netif_rx_ni(struct sk_buff *skb)
101543 }
101544 EXPORT_SYMBOL(netif_rx_ni);
101545
101546 -static void net_tx_action(struct softirq_action *h)
101547 +static __latent_entropy void net_tx_action(void)
101548 {
101549 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101550
101551 @@ -3747,7 +3747,7 @@ ncls:
101552 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101553 } else {
101554 drop:
101555 - atomic_long_inc(&skb->dev->rx_dropped);
101556 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101557 kfree_skb(skb);
101558 /* Jamal, now you will not able to escape explaining
101559 * me how you were going to use this. :-)
101560 @@ -4511,7 +4511,7 @@ void netif_napi_del(struct napi_struct *napi)
101561 }
101562 EXPORT_SYMBOL(netif_napi_del);
101563
101564 -static void net_rx_action(struct softirq_action *h)
101565 +static __latent_entropy void net_rx_action(void)
101566 {
101567 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101568 unsigned long time_limit = jiffies + 2;
101569 @@ -5247,7 +5247,7 @@ void netdev_upper_dev_unlink(struct net_device *dev,
101570 }
101571 EXPORT_SYMBOL(netdev_upper_dev_unlink);
101572
101573 -void netdev_adjacent_add_links(struct net_device *dev)
101574 +static void netdev_adjacent_add_links(struct net_device *dev)
101575 {
101576 struct netdev_adjacent *iter;
101577
101578 @@ -5272,7 +5272,7 @@ void netdev_adjacent_add_links(struct net_device *dev)
101579 }
101580 }
101581
101582 -void netdev_adjacent_del_links(struct net_device *dev)
101583 +static void netdev_adjacent_del_links(struct net_device *dev)
101584 {
101585 struct netdev_adjacent *iter;
101586
101587 @@ -6557,8 +6557,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101588 } else {
101589 netdev_stats_to_stats64(storage, &dev->stats);
101590 }
101591 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101592 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101593 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101594 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101595 return storage;
101596 }
101597 EXPORT_SYMBOL(dev_get_stats);
101598 @@ -6574,7 +6574,7 @@ struct netdev_queue *dev_ingress_queue_create(struct net_device *dev)
101599 if (!queue)
101600 return NULL;
101601 netdev_init_one_queue(dev, queue, NULL);
101602 - queue->qdisc = &noop_qdisc;
101603 + RCU_INIT_POINTER(queue->qdisc, &noop_qdisc);
101604 queue->qdisc_sleeping = &noop_qdisc;
101605 rcu_assign_pointer(dev->ingress_queue, queue);
101606 #endif
101607 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101608 index 72e899a..79a9409 100644
101609 --- a/net/core/dev_ioctl.c
101610 +++ b/net/core/dev_ioctl.c
101611 @@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101612 no_module = !dev;
101613 if (no_module && capable(CAP_NET_ADMIN))
101614 no_module = request_module("netdev-%s", name);
101615 - if (no_module && capable(CAP_SYS_MODULE))
101616 + if (no_module && capable(CAP_SYS_MODULE)) {
101617 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101618 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101619 +#else
101620 request_module("%s", name);
101621 +#endif
101622 + }
101623 }
101624 EXPORT_SYMBOL(dev_load);
101625
101626 diff --git a/net/core/filter.c b/net/core/filter.c
101627 index 647b122..18a7ff6 100644
101628 --- a/net/core/filter.c
101629 +++ b/net/core/filter.c
101630 @@ -532,7 +532,11 @@ do_pass:
101631
101632 /* Unkown instruction. */
101633 default:
101634 - goto err;
101635 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101636 + fp->code, fp->jt, fp->jf, fp->k);
101637 + kfree(addrs);
101638 + BUG();
101639 + return -EINVAL;
101640 }
101641
101642 insn++;
101643 @@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101644 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101645 int pc, ret = 0;
101646
101647 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101648 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101649
101650 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101651 if (!masks)
101652 @@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101653 if (!fp)
101654 return -ENOMEM;
101655
101656 - memcpy(fp->insns, fprog->filter, fsize);
101657 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101658
101659 fp->len = fprog->len;
101660 /* Since unattached filters are not copied back to user
101661 diff --git a/net/core/flow.c b/net/core/flow.c
101662 index a0348fd..340f65d 100644
101663 --- a/net/core/flow.c
101664 +++ b/net/core/flow.c
101665 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101666 static int flow_entry_valid(struct flow_cache_entry *fle,
101667 struct netns_xfrm *xfrm)
101668 {
101669 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101670 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101671 return 0;
101672 if (fle->object && !fle->object->ops->check(fle->object))
101673 return 0;
101674 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101675 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101676 fcp->hash_count++;
101677 }
101678 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101679 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101680 flo = fle->object;
101681 if (!flo)
101682 goto ret_object;
101683 @@ -263,7 +263,7 @@ nocache:
101684 }
101685 flo = resolver(net, key, family, dir, flo, ctx);
101686 if (fle) {
101687 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101688 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101689 if (!IS_ERR(flo))
101690 fle->object = flo;
101691 else
101692 @@ -379,7 +379,7 @@ done:
101693 static void flow_cache_flush_task(struct work_struct *work)
101694 {
101695 struct netns_xfrm *xfrm = container_of(work, struct netns_xfrm,
101696 - flow_cache_gc_work);
101697 + flow_cache_flush_work);
101698 struct net *net = container_of(xfrm, struct net, xfrm);
101699
101700 flow_cache_flush(net);
101701 diff --git a/net/core/iovec.c b/net/core/iovec.c
101702 index e1ec45a..e5c6f16 100644
101703 --- a/net/core/iovec.c
101704 +++ b/net/core/iovec.c
101705 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101706 if (m->msg_name && m->msg_namelen) {
101707 if (mode == VERIFY_READ) {
101708 void __user *namep;
101709 - namep = (void __user __force *) m->msg_name;
101710 + namep = (void __force_user *) m->msg_name;
101711 err = move_addr_to_kernel(namep, m->msg_namelen,
101712 address);
101713 if (err < 0)
101714 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101715 }
101716
101717 size = m->msg_iovlen * sizeof(struct iovec);
101718 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101719 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101720 return -EFAULT;
101721
101722 m->msg_iov = iov;
101723 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101724 index ef31fef..8be66d9 100644
101725 --- a/net/core/neighbour.c
101726 +++ b/net/core/neighbour.c
101727 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101728 void __user *buffer, size_t *lenp, loff_t *ppos)
101729 {
101730 int size, ret;
101731 - struct ctl_table tmp = *ctl;
101732 + ctl_table_no_const tmp = *ctl;
101733
101734 tmp.extra1 = &zero;
101735 tmp.extra2 = &unres_qlen_max;
101736 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101737 void __user *buffer,
101738 size_t *lenp, loff_t *ppos)
101739 {
101740 - struct ctl_table tmp = *ctl;
101741 + ctl_table_no_const tmp = *ctl;
101742 int ret;
101743
101744 tmp.extra1 = &zero;
101745 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101746 index 2bf8329..2eb1423 100644
101747 --- a/net/core/net-procfs.c
101748 +++ b/net/core/net-procfs.c
101749 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101750 struct rtnl_link_stats64 temp;
101751 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101752
101753 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101754 + if (gr_proc_is_restricted())
101755 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101756 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101757 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101758 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101759 + else
101760 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101761 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101762 dev->name, stats->rx_bytes, stats->rx_packets,
101763 stats->rx_errors,
101764 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101765 return 0;
101766 }
101767
101768 -static const struct seq_operations dev_seq_ops = {
101769 +const struct seq_operations dev_seq_ops = {
101770 .start = dev_seq_start,
101771 .next = dev_seq_next,
101772 .stop = dev_seq_stop,
101773 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101774
101775 static int softnet_seq_open(struct inode *inode, struct file *file)
101776 {
101777 - return seq_open(file, &softnet_seq_ops);
101778 + return seq_open_restrict(file, &softnet_seq_ops);
101779 }
101780
101781 static const struct file_operations softnet_seq_fops = {
101782 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101783 else
101784 seq_printf(seq, "%04x", ntohs(pt->type));
101785
101786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101787 + seq_printf(seq, " %-8s %pf\n",
101788 + pt->dev ? pt->dev->name : "", NULL);
101789 +#else
101790 seq_printf(seq, " %-8s %pf\n",
101791 pt->dev ? pt->dev->name : "", pt->func);
101792 +#endif
101793 }
101794
101795 return 0;
101796 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101797 index 9dd0669..c52fb1b 100644
101798 --- a/net/core/net-sysfs.c
101799 +++ b/net/core/net-sysfs.c
101800 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101801 {
101802 struct net_device *netdev = to_net_dev(dev);
101803 return sprintf(buf, fmt_dec,
101804 - atomic_read(&netdev->carrier_changes));
101805 + atomic_read_unchecked(&netdev->carrier_changes));
101806 }
101807 static DEVICE_ATTR_RO(carrier_changes);
101808
101809 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101810 index 7f15517..f7d65c0 100644
101811 --- a/net/core/net_namespace.c
101812 +++ b/net/core/net_namespace.c
101813 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101814 int error;
101815 LIST_HEAD(net_exit_list);
101816
101817 - list_add_tail(&ops->list, list);
101818 + pax_list_add_tail((struct list_head *)&ops->list, list);
101819 if (ops->init || (ops->id && ops->size)) {
101820 for_each_net(net) {
101821 error = ops_init(ops, net);
101822 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101823
101824 out_undo:
101825 /* If I have an error cleanup all namespaces I initialized */
101826 - list_del(&ops->list);
101827 + pax_list_del((struct list_head *)&ops->list);
101828 ops_exit_list(ops, &net_exit_list);
101829 ops_free_list(ops, &net_exit_list);
101830 return error;
101831 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101832 struct net *net;
101833 LIST_HEAD(net_exit_list);
101834
101835 - list_del(&ops->list);
101836 + pax_list_del((struct list_head *)&ops->list);
101837 for_each_net(net)
101838 list_add_tail(&net->exit_list, &net_exit_list);
101839 ops_exit_list(ops, &net_exit_list);
101840 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101841 mutex_lock(&net_mutex);
101842 error = register_pernet_operations(&pernet_list, ops);
101843 if (!error && (first_device == &pernet_list))
101844 - first_device = &ops->list;
101845 + first_device = (struct list_head *)&ops->list;
101846 mutex_unlock(&net_mutex);
101847 return error;
101848 }
101849 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101850 index e6645b4..43e1af9 100644
101851 --- a/net/core/netpoll.c
101852 +++ b/net/core/netpoll.c
101853 @@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101854 struct udphdr *udph;
101855 struct iphdr *iph;
101856 struct ethhdr *eth;
101857 - static atomic_t ip_ident;
101858 + static atomic_unchecked_t ip_ident;
101859 struct ipv6hdr *ip6h;
101860
101861 udp_len = len + sizeof(*udph);
101862 @@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101863 put_unaligned(0x45, (unsigned char *)iph);
101864 iph->tos = 0;
101865 put_unaligned(htons(ip_len), &(iph->tot_len));
101866 - iph->id = htons(atomic_inc_return(&ip_ident));
101867 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101868 iph->frag_off = 0;
101869 iph->ttl = 64;
101870 iph->protocol = IPPROTO_UDP;
101871 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101872 index 443256b..bbff424 100644
101873 --- a/net/core/pktgen.c
101874 +++ b/net/core/pktgen.c
101875 @@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101876 pn->net = net;
101877 INIT_LIST_HEAD(&pn->pktgen_threads);
101878 pn->pktgen_exiting = false;
101879 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101880 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101881 if (!pn->proc_dir) {
101882 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101883 return -ENODEV;
101884 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101885 index 76321ea..3129bd6 100644
101886 --- a/net/core/rtnetlink.c
101887 +++ b/net/core/rtnetlink.c
101888 @@ -58,7 +58,7 @@ struct rtnl_link {
101889 rtnl_doit_func doit;
101890 rtnl_dumpit_func dumpit;
101891 rtnl_calcit_func calcit;
101892 -};
101893 +} __no_const;
101894
101895 static DEFINE_MUTEX(rtnl_mutex);
101896
101897 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101898 * to use the ops for creating device. So do not
101899 * fill up dellink as well. That disables rtnl_dellink.
101900 */
101901 - if (ops->setup && !ops->dellink)
101902 - ops->dellink = unregister_netdevice_queue;
101903 + if (ops->setup && !ops->dellink) {
101904 + pax_open_kernel();
101905 + *(void **)&ops->dellink = unregister_netdevice_queue;
101906 + pax_close_kernel();
101907 + }
101908
101909 - list_add_tail(&ops->list, &link_ops);
101910 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101911 return 0;
101912 }
101913 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101914 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101915 for_each_net(net) {
101916 __rtnl_kill_links(net, ops);
101917 }
101918 - list_del(&ops->list);
101919 + pax_list_del((struct list_head *)&ops->list);
101920 }
101921 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101922
101923 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101924 (dev->ifalias &&
101925 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101926 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101927 - atomic_read(&dev->carrier_changes)))
101928 + atomic_read_unchecked(&dev->carrier_changes)))
101929 goto nla_put_failure;
101930
101931 if (1) {
101932 diff --git a/net/core/scm.c b/net/core/scm.c
101933 index b442e7e..6f5b5a2 100644
101934 --- a/net/core/scm.c
101935 +++ b/net/core/scm.c
101936 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101937 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101938 {
101939 struct cmsghdr __user *cm
101940 - = (__force struct cmsghdr __user *)msg->msg_control;
101941 + = (struct cmsghdr __force_user *)msg->msg_control;
101942 struct cmsghdr cmhdr;
101943 int cmlen = CMSG_LEN(len);
101944 int err;
101945 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101946 err = -EFAULT;
101947 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101948 goto out;
101949 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101950 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101951 goto out;
101952 cmlen = CMSG_SPACE(len);
101953 if (msg->msg_controllen < cmlen)
101954 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101955 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101956 {
101957 struct cmsghdr __user *cm
101958 - = (__force struct cmsghdr __user*)msg->msg_control;
101959 + = (struct cmsghdr __force_user *)msg->msg_control;
101960
101961 int fdmax = 0;
101962 int fdnum = scm->fp->count;
101963 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101964 if (fdnum < fdmax)
101965 fdmax = fdnum;
101966
101967 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101968 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101969 i++, cmfptr++)
101970 {
101971 struct socket *sock;
101972 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101973 index d7543d0..ff96aec 100644
101974 --- a/net/core/skbuff.c
101975 +++ b/net/core/skbuff.c
101976 @@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
101977 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101978 int len, __wsum csum)
101979 {
101980 - const struct skb_checksum_ops ops = {
101981 + static const struct skb_checksum_ops ops = {
101982 .update = csum_partial_ext,
101983 .combine = csum_block_add_ext,
101984 };
101985 @@ -3255,12 +3255,14 @@ void __init skb_init(void)
101986 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101987 sizeof(struct sk_buff),
101988 0,
101989 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101990 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101991 + SLAB_NO_SANITIZE,
101992 NULL);
101993 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101994 sizeof(struct sk_buff_fclones),
101995 0,
101996 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101997 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101998 + SLAB_NO_SANITIZE,
101999 NULL);
102000 }
102001
102002 diff --git a/net/core/sock.c b/net/core/sock.c
102003 index 15e0c67..0310f4a 100644
102004 --- a/net/core/sock.c
102005 +++ b/net/core/sock.c
102006 @@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102007 struct sk_buff_head *list = &sk->sk_receive_queue;
102008
102009 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102010 - atomic_inc(&sk->sk_drops);
102011 + atomic_inc_unchecked(&sk->sk_drops);
102012 trace_sock_rcvqueue_full(sk, skb);
102013 return -ENOMEM;
102014 }
102015 @@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102016 return err;
102017
102018 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102019 - atomic_inc(&sk->sk_drops);
102020 + atomic_inc_unchecked(&sk->sk_drops);
102021 return -ENOBUFS;
102022 }
102023
102024 @@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102025 skb_dst_force(skb);
102026
102027 spin_lock_irqsave(&list->lock, flags);
102028 - skb->dropcount = atomic_read(&sk->sk_drops);
102029 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102030 __skb_queue_tail(list, skb);
102031 spin_unlock_irqrestore(&list->lock, flags);
102032
102033 @@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102034 skb->dev = NULL;
102035
102036 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102037 - atomic_inc(&sk->sk_drops);
102038 + atomic_inc_unchecked(&sk->sk_drops);
102039 goto discard_and_relse;
102040 }
102041 if (nested)
102042 @@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102043 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102044 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102045 bh_unlock_sock(sk);
102046 - atomic_inc(&sk->sk_drops);
102047 + atomic_inc_unchecked(&sk->sk_drops);
102048 goto discard_and_relse;
102049 }
102050
102051 @@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102052 struct timeval tm;
102053 } v;
102054
102055 - int lv = sizeof(int);
102056 - int len;
102057 + unsigned int lv = sizeof(int);
102058 + unsigned int len;
102059
102060 if (get_user(len, optlen))
102061 return -EFAULT;
102062 - if (len < 0)
102063 + if (len > INT_MAX)
102064 return -EINVAL;
102065
102066 memset(&v, 0, sizeof(v));
102067 @@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102068
102069 case SO_PEERNAME:
102070 {
102071 - char address[128];
102072 + char address[_K_SS_MAXSIZE];
102073
102074 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102075 return -ENOTCONN;
102076 - if (lv < len)
102077 + if (lv < len || sizeof address < len)
102078 return -EINVAL;
102079 if (copy_to_user(optval, address, len))
102080 return -EFAULT;
102081 @@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102082
102083 if (len > lv)
102084 len = lv;
102085 - if (copy_to_user(optval, &v, len))
102086 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102087 return -EFAULT;
102088 lenout:
102089 if (put_user(len, optlen))
102090 @@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102091 */
102092 smp_wmb();
102093 atomic_set(&sk->sk_refcnt, 1);
102094 - atomic_set(&sk->sk_drops, 0);
102095 + atomic_set_unchecked(&sk->sk_drops, 0);
102096 }
102097 EXPORT_SYMBOL(sock_init_data);
102098
102099 @@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102100 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102101 int level, int type)
102102 {
102103 + struct sock_extended_err ee;
102104 struct sock_exterr_skb *serr;
102105 struct sk_buff *skb;
102106 int copied, err;
102107 @@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102108 sock_recv_timestamp(msg, sk, skb);
102109
102110 serr = SKB_EXT_ERR(skb);
102111 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102112 + ee = serr->ee;
102113 + put_cmsg(msg, level, type, sizeof ee, &ee);
102114
102115 msg->msg_flags |= MSG_ERRQUEUE;
102116 err = copied;
102117 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102118 index ad704c7..ca48aff 100644
102119 --- a/net/core/sock_diag.c
102120 +++ b/net/core/sock_diag.c
102121 @@ -9,26 +9,33 @@
102122 #include <linux/inet_diag.h>
102123 #include <linux/sock_diag.h>
102124
102125 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102126 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102127 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102128 static DEFINE_MUTEX(sock_diag_table_mutex);
102129
102130 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102131 {
102132 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102133 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102134 cookie[1] != INET_DIAG_NOCOOKIE) &&
102135 ((u32)(unsigned long)sk != cookie[0] ||
102136 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102137 return -ESTALE;
102138 else
102139 +#endif
102140 return 0;
102141 }
102142 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102143
102144 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102145 {
102146 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102147 + cookie[0] = 0;
102148 + cookie[1] = 0;
102149 +#else
102150 cookie[0] = (u32)(unsigned long)sk;
102151 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102152 +#endif
102153 }
102154 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102155
102156 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102157 mutex_lock(&sock_diag_table_mutex);
102158 if (sock_diag_handlers[hndl->family])
102159 err = -EBUSY;
102160 - else
102161 + else {
102162 + pax_open_kernel();
102163 sock_diag_handlers[hndl->family] = hndl;
102164 + pax_close_kernel();
102165 + }
102166 mutex_unlock(&sock_diag_table_mutex);
102167
102168 return err;
102169 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102170
102171 mutex_lock(&sock_diag_table_mutex);
102172 BUG_ON(sock_diag_handlers[family] != hnld);
102173 + pax_open_kernel();
102174 sock_diag_handlers[family] = NULL;
102175 + pax_close_kernel();
102176 mutex_unlock(&sock_diag_table_mutex);
102177 }
102178 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102179 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102180 index cf9cd13..50683950 100644
102181 --- a/net/core/sysctl_net_core.c
102182 +++ b/net/core/sysctl_net_core.c
102183 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102184 {
102185 unsigned int orig_size, size;
102186 int ret, i;
102187 - struct ctl_table tmp = {
102188 + ctl_table_no_const tmp = {
102189 .data = &size,
102190 .maxlen = sizeof(size),
102191 .mode = table->mode
102192 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102193 void __user *buffer, size_t *lenp, loff_t *ppos)
102194 {
102195 char id[IFNAMSIZ];
102196 - struct ctl_table tbl = {
102197 + ctl_table_no_const tbl = {
102198 .data = id,
102199 .maxlen = IFNAMSIZ,
102200 };
102201 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102202 .mode = 0644,
102203 .proc_handler = proc_dointvec
102204 },
102205 -#ifdef CONFIG_BPF_JIT
102206 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102207 {
102208 .procname = "bpf_jit_enable",
102209 .data = &bpf_jit_enable,
102210 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102211
102212 static __net_init int sysctl_core_net_init(struct net *net)
102213 {
102214 - struct ctl_table *tbl;
102215 + ctl_table_no_const *tbl = NULL;
102216
102217 net->core.sysctl_somaxconn = SOMAXCONN;
102218
102219 - tbl = netns_core_table;
102220 if (!net_eq(net, &init_net)) {
102221 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102222 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102223 if (tbl == NULL)
102224 goto err_dup;
102225
102226 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102227 if (net->user_ns != &init_user_ns) {
102228 tbl[0].procname = NULL;
102229 }
102230 - }
102231 -
102232 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102233 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102234 + } else
102235 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102236 if (net->core.sysctl_hdr == NULL)
102237 goto err_reg;
102238
102239 return 0;
102240
102241 err_reg:
102242 - if (tbl != netns_core_table)
102243 - kfree(tbl);
102244 + kfree(tbl);
102245 err_dup:
102246 return -ENOMEM;
102247 }
102248 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102249 kfree(tbl);
102250 }
102251
102252 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102253 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102254 .init = sysctl_core_net_init,
102255 .exit = sysctl_core_net_exit,
102256 };
102257 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102258 index 25733d5..b9360f0 100644
102259 --- a/net/decnet/af_decnet.c
102260 +++ b/net/decnet/af_decnet.c
102261 @@ -466,6 +466,7 @@ static struct proto dn_proto = {
102262 .sysctl_rmem = sysctl_decnet_rmem,
102263 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102264 .obj_size = sizeof(struct dn_sock),
102265 + .slab_flags = SLAB_USERCOPY,
102266 };
102267
102268 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102269 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102270 index 4400da7..3429972 100644
102271 --- a/net/decnet/dn_dev.c
102272 +++ b/net/decnet/dn_dev.c
102273 @@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
102274 .extra1 = &min_t3,
102275 .extra2 = &max_t3
102276 },
102277 - {0}
102278 + { }
102279 },
102280 };
102281
102282 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102283 index 5325b54..a0d4d69 100644
102284 --- a/net/decnet/sysctl_net_decnet.c
102285 +++ b/net/decnet/sysctl_net_decnet.c
102286 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102287
102288 if (len > *lenp) len = *lenp;
102289
102290 - if (copy_to_user(buffer, addr, len))
102291 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102292 return -EFAULT;
102293
102294 *lenp = len;
102295 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102296
102297 if (len > *lenp) len = *lenp;
102298
102299 - if (copy_to_user(buffer, devname, len))
102300 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102301 return -EFAULT;
102302
102303 *lenp = len;
102304 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102305 index a2c7e4c..3dc9f67 100644
102306 --- a/net/hsr/hsr_netlink.c
102307 +++ b/net/hsr/hsr_netlink.c
102308 @@ -102,7 +102,7 @@ nla_put_failure:
102309 return -EMSGSIZE;
102310 }
102311
102312 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102313 +static struct rtnl_link_ops hsr_link_ops = {
102314 .kind = "hsr",
102315 .maxtype = IFLA_HSR_MAX,
102316 .policy = hsr_policy,
102317 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102318 index 4413629..dea596a 100644
102319 --- a/net/ieee802154/6lowpan_rtnl.c
102320 +++ b/net/ieee802154/6lowpan_rtnl.c
102321 @@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102322 dev_put(real_dev);
102323 }
102324
102325 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102326 +static struct rtnl_link_ops lowpan_link_ops = {
102327 .kind = "lowpan",
102328 .priv_size = sizeof(struct lowpan_dev_info),
102329 .setup = lowpan_setup,
102330 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102331 index 7cfcd68..84ca5b7 100644
102332 --- a/net/ieee802154/reassembly.c
102333 +++ b/net/ieee802154/reassembly.c
102334 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102335
102336 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102337 {
102338 - struct ctl_table *table;
102339 + ctl_table_no_const *table = NULL;
102340 struct ctl_table_header *hdr;
102341 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102342 net_ieee802154_lowpan(net);
102343
102344 - table = lowpan_frags_ns_ctl_table;
102345 if (!net_eq(net, &init_net)) {
102346 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102347 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102348 GFP_KERNEL);
102349 if (table == NULL)
102350 goto err_alloc;
102351 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102352 /* Don't export sysctls to unprivileged users */
102353 if (net->user_ns != &init_user_ns)
102354 table[0].procname = NULL;
102355 - }
102356 -
102357 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102358 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102359 + } else
102360 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102361 if (hdr == NULL)
102362 goto err_reg;
102363
102364 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102365 return 0;
102366
102367 err_reg:
102368 - if (!net_eq(net, &init_net))
102369 - kfree(table);
102370 + kfree(table);
102371 err_alloc:
102372 return -ENOMEM;
102373 }
102374 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102375 index e67da4e..da217942 100644
102376 --- a/net/ipv4/af_inet.c
102377 +++ b/net/ipv4/af_inet.c
102378 @@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102379 return ip_recv_error(sk, msg, len, addr_len);
102380 #if IS_ENABLED(CONFIG_IPV6)
102381 if (sk->sk_family == AF_INET6)
102382 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102383 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102384 #endif
102385 return -EINVAL;
102386 }
102387 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102388 index 214882e..ec032f6 100644
102389 --- a/net/ipv4/devinet.c
102390 +++ b/net/ipv4/devinet.c
102391 @@ -69,7 +69,8 @@
102392
102393 static struct ipv4_devconf ipv4_devconf = {
102394 .data = {
102395 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102396 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102397 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102398 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102399 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102400 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102401 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102402
102403 static struct ipv4_devconf ipv4_devconf_dflt = {
102404 .data = {
102405 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102406 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102407 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102408 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102409 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102410 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102411 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102412 idx = 0;
102413 head = &net->dev_index_head[h];
102414 rcu_read_lock();
102415 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102416 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102417 net->dev_base_seq;
102418 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102419 if (idx < s_idx)
102420 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102421 idx = 0;
102422 head = &net->dev_index_head[h];
102423 rcu_read_lock();
102424 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102425 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102426 net->dev_base_seq;
102427 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102428 if (idx < s_idx)
102429 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102430 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102431 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102432
102433 -static struct devinet_sysctl_table {
102434 +static const struct devinet_sysctl_table {
102435 struct ctl_table_header *sysctl_header;
102436 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102437 } devinet_sysctl = {
102438 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102439 int err;
102440 struct ipv4_devconf *all, *dflt;
102441 #ifdef CONFIG_SYSCTL
102442 - struct ctl_table *tbl = ctl_forward_entry;
102443 + ctl_table_no_const *tbl = NULL;
102444 struct ctl_table_header *forw_hdr;
102445 #endif
102446
102447 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102448 goto err_alloc_dflt;
102449
102450 #ifdef CONFIG_SYSCTL
102451 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102452 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102453 if (tbl == NULL)
102454 goto err_alloc_ctl;
102455
102456 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102457 goto err_reg_dflt;
102458
102459 err = -ENOMEM;
102460 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102461 + if (!net_eq(net, &init_net))
102462 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102463 + else
102464 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102465 if (forw_hdr == NULL)
102466 goto err_reg_ctl;
102467 net->ipv4.forw_hdr = forw_hdr;
102468 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102469 err_reg_dflt:
102470 __devinet_sysctl_unregister(all);
102471 err_reg_all:
102472 - if (tbl != ctl_forward_entry)
102473 - kfree(tbl);
102474 + kfree(tbl);
102475 err_alloc_ctl:
102476 #endif
102477 if (dflt != &ipv4_devconf_dflt)
102478 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102479 index 23104a3..9f5570b 100644
102480 --- a/net/ipv4/fib_frontend.c
102481 +++ b/net/ipv4/fib_frontend.c
102482 @@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102483 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102484 fib_sync_up(dev);
102485 #endif
102486 - atomic_inc(&net->ipv4.dev_addr_genid);
102487 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102488 rt_cache_flush(dev_net(dev));
102489 break;
102490 case NETDEV_DOWN:
102491 fib_del_ifaddr(ifa, NULL);
102492 - atomic_inc(&net->ipv4.dev_addr_genid);
102493 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102494 if (ifa->ifa_dev->ifa_list == NULL) {
102495 /* Last address was deleted from this interface.
102496 * Disable IP.
102497 @@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102498 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102499 fib_sync_up(dev);
102500 #endif
102501 - atomic_inc(&net->ipv4.dev_addr_genid);
102502 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102503 rt_cache_flush(net);
102504 break;
102505 case NETDEV_DOWN:
102506 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102507 index f99f41b..1879da9 100644
102508 --- a/net/ipv4/fib_semantics.c
102509 +++ b/net/ipv4/fib_semantics.c
102510 @@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102511 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102512 nh->nh_gw,
102513 nh->nh_parent->fib_scope);
102514 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102515 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102516
102517 return nh->nh_saddr;
102518 }
102519 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102520 index 9111a4e..3576905 100644
102521 --- a/net/ipv4/inet_hashtables.c
102522 +++ b/net/ipv4/inet_hashtables.c
102523 @@ -18,6 +18,7 @@
102524 #include <linux/sched.h>
102525 #include <linux/slab.h>
102526 #include <linux/wait.h>
102527 +#include <linux/security.h>
102528
102529 #include <net/inet_connection_sock.h>
102530 #include <net/inet_hashtables.h>
102531 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102532 return inet_ehashfn(net, laddr, lport, faddr, fport);
102533 }
102534
102535 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102536 +
102537 /*
102538 * Allocate and initialize a new local port bind bucket.
102539 * The bindhash mutex for snum's hash chain must be held here.
102540 @@ -554,6 +557,8 @@ ok:
102541 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102542 spin_unlock(&head->lock);
102543
102544 + gr_update_task_in_ip_table(inet_sk(sk));
102545 +
102546 if (tw) {
102547 inet_twsk_deschedule(tw, death_row);
102548 while (twrefcnt) {
102549 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102550 index 241afd7..31b95d5 100644
102551 --- a/net/ipv4/inetpeer.c
102552 +++ b/net/ipv4/inetpeer.c
102553 @@ -461,7 +461,7 @@ relookup:
102554 if (p) {
102555 p->daddr = *daddr;
102556 atomic_set(&p->refcnt, 1);
102557 - atomic_set(&p->rid, 0);
102558 + atomic_set_unchecked(&p->rid, 0);
102559 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102560 p->rate_tokens = 0;
102561 /* 60*HZ is arbitrary, but chosen enough high so that the first
102562 diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
102563 index 3a83ce5..787b3c2 100644
102564 --- a/net/ipv4/ip_forward.c
102565 +++ b/net/ipv4/ip_forward.c
102566 @@ -129,7 +129,8 @@ int ip_forward(struct sk_buff *skb)
102567 * We now generate an ICMP HOST REDIRECT giving the route
102568 * we calculated.
102569 */
102570 - if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb_sec_path(skb))
102571 + if (IPCB(skb)->flags & IPSKB_DOREDIRECT && !opt->srr &&
102572 + !skb_sec_path(skb))
102573 ip_rt_send_redirect(skb);
102574
102575 skb->priority = rt_tos2priority(iph->tos);
102576 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102577 index 2811cc1..ad5a534 100644
102578 --- a/net/ipv4/ip_fragment.c
102579 +++ b/net/ipv4/ip_fragment.c
102580 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102581 return 0;
102582
102583 start = qp->rid;
102584 - end = atomic_inc_return(&peer->rid);
102585 + end = atomic_inc_return_unchecked(&peer->rid);
102586 qp->rid = end;
102587
102588 rc = qp->q.fragments && (end - start) > max;
102589 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102590
102591 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102592 {
102593 - struct ctl_table *table;
102594 + ctl_table_no_const *table = NULL;
102595 struct ctl_table_header *hdr;
102596
102597 - table = ip4_frags_ns_ctl_table;
102598 if (!net_eq(net, &init_net)) {
102599 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102600 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102601 if (table == NULL)
102602 goto err_alloc;
102603
102604 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102605 /* Don't export sysctls to unprivileged users */
102606 if (net->user_ns != &init_user_ns)
102607 table[0].procname = NULL;
102608 - }
102609 + hdr = register_net_sysctl(net, "net/ipv4", table);
102610 + } else
102611 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102612
102613 - hdr = register_net_sysctl(net, "net/ipv4", table);
102614 if (hdr == NULL)
102615 goto err_reg;
102616
102617 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102618 return 0;
102619
102620 err_reg:
102621 - if (!net_eq(net, &init_net))
102622 - kfree(table);
102623 + kfree(table);
102624 err_alloc:
102625 return -ENOMEM;
102626 }
102627 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102628 index 69aaf0a..8298c029 100644
102629 --- a/net/ipv4/ip_gre.c
102630 +++ b/net/ipv4/ip_gre.c
102631 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102632 module_param(log_ecn_error, bool, 0644);
102633 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102634
102635 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102636 +static struct rtnl_link_ops ipgre_link_ops;
102637 static int ipgre_tunnel_init(struct net_device *dev);
102638
102639 static int ipgre_net_id __read_mostly;
102640 @@ -816,7 +816,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102641 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102642 };
102643
102644 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102645 +static struct rtnl_link_ops ipgre_link_ops = {
102646 .kind = "gre",
102647 .maxtype = IFLA_GRE_MAX,
102648 .policy = ipgre_policy,
102649 @@ -830,7 +830,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102650 .fill_info = ipgre_fill_info,
102651 };
102652
102653 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102654 +static struct rtnl_link_ops ipgre_tap_ops = {
102655 .kind = "gretap",
102656 .maxtype = IFLA_GRE_MAX,
102657 .policy = ipgre_policy,
102658 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102659 index 3d4da2c..40f9c29 100644
102660 --- a/net/ipv4/ip_input.c
102661 +++ b/net/ipv4/ip_input.c
102662 @@ -147,6 +147,10 @@
102663 #include <linux/mroute.h>
102664 #include <linux/netlink.h>
102665
102666 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102667 +extern int grsec_enable_blackhole;
102668 +#endif
102669 +
102670 /*
102671 * Process Router Attention IP option (RFC 2113)
102672 */
102673 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102674 if (!raw) {
102675 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102676 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102677 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102678 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102679 +#endif
102680 icmp_send(skb, ICMP_DEST_UNREACH,
102681 ICMP_PROT_UNREACH, 0);
102682 }
102683 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102684 index bc6471d..c5e8a0c 100644
102685 --- a/net/ipv4/ip_output.c
102686 +++ b/net/ipv4/ip_output.c
102687 @@ -1517,6 +1517,7 @@ static DEFINE_PER_CPU(struct inet_sock, unicast_sock) = {
102688 .sk_wmem_alloc = ATOMIC_INIT(1),
102689 .sk_allocation = GFP_ATOMIC,
102690 .sk_flags = (1UL << SOCK_USE_WRITE_QUEUE),
102691 + .sk_pacing_rate = ~0U,
102692 },
102693 .pmtudisc = IP_PMTUDISC_WANT,
102694 .uc_ttl = -1,
102695 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102696 index 9daf217..373d454 100644
102697 --- a/net/ipv4/ip_sockglue.c
102698 +++ b/net/ipv4/ip_sockglue.c
102699 @@ -443,15 +443,12 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102700
102701 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
102702 sin = &errhdr.offender;
102703 - sin->sin_family = AF_UNSPEC;
102704 + memset(sin, 0, sizeof(*sin));
102705 +
102706 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) {
102707 - struct inet_sock *inet = inet_sk(sk);
102708 -
102709 sin->sin_family = AF_INET;
102710 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
102711 - sin->sin_port = 0;
102712 - memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
102713 - if (inet->cmsg_flags)
102714 + if (inet_sk(sk)->cmsg_flags)
102715 ip_cmsg_recv(msg, skb);
102716 }
102717
102718 @@ -1177,7 +1174,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102719 len = min_t(unsigned int, len, opt->optlen);
102720 if (put_user(len, optlen))
102721 return -EFAULT;
102722 - if (copy_to_user(optval, opt->__data, len))
102723 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102724 + copy_to_user(optval, opt->__data, len))
102725 return -EFAULT;
102726 return 0;
102727 }
102728 @@ -1308,7 +1306,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102729 if (sk->sk_type != SOCK_STREAM)
102730 return -ENOPROTOOPT;
102731
102732 - msg.msg_control = (__force void *) optval;
102733 + msg.msg_control = (__force_kernel void *) optval;
102734 msg.msg_controllen = len;
102735 msg.msg_flags = flags;
102736
102737 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102738 index 1a7e979..fd05aa4 100644
102739 --- a/net/ipv4/ip_vti.c
102740 +++ b/net/ipv4/ip_vti.c
102741 @@ -45,7 +45,7 @@
102742 #include <net/net_namespace.h>
102743 #include <net/netns/generic.h>
102744
102745 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102746 +static struct rtnl_link_ops vti_link_ops;
102747
102748 static int vti_net_id __read_mostly;
102749 static int vti_tunnel_init(struct net_device *dev);
102750 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102751 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102752 };
102753
102754 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102755 +static struct rtnl_link_ops vti_link_ops = {
102756 .kind = "vti",
102757 .maxtype = IFLA_VTI_MAX,
102758 .policy = vti_policy,
102759 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102760 index 648fa14..97864d0 100644
102761 --- a/net/ipv4/ipconfig.c
102762 +++ b/net/ipv4/ipconfig.c
102763 @@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102764
102765 mm_segment_t oldfs = get_fs();
102766 set_fs(get_ds());
102767 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102768 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102769 set_fs(oldfs);
102770 return res;
102771 }
102772 @@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102773
102774 mm_segment_t oldfs = get_fs();
102775 set_fs(get_ds());
102776 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102777 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102778 set_fs(oldfs);
102779 return res;
102780 }
102781 @@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102782
102783 mm_segment_t oldfs = get_fs();
102784 set_fs(get_ds());
102785 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102786 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102787 set_fs(oldfs);
102788 return res;
102789 }
102790 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102791 index 37096d6..86abb03 100644
102792 --- a/net/ipv4/ipip.c
102793 +++ b/net/ipv4/ipip.c
102794 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102795 static int ipip_net_id __read_mostly;
102796
102797 static int ipip_tunnel_init(struct net_device *dev);
102798 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102799 +static struct rtnl_link_ops ipip_link_ops;
102800
102801 static int ipip_err(struct sk_buff *skb, u32 info)
102802 {
102803 @@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102804 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102805 };
102806
102807 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102808 +static struct rtnl_link_ops ipip_link_ops = {
102809 .kind = "ipip",
102810 .maxtype = IFLA_IPTUN_MAX,
102811 .policy = ipip_policy,
102812 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102813 index f95b6f9..2ee2097 100644
102814 --- a/net/ipv4/netfilter/arp_tables.c
102815 +++ b/net/ipv4/netfilter/arp_tables.c
102816 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102817 #endif
102818
102819 static int get_info(struct net *net, void __user *user,
102820 - const int *len, int compat)
102821 + int len, int compat)
102822 {
102823 char name[XT_TABLE_MAXNAMELEN];
102824 struct xt_table *t;
102825 int ret;
102826
102827 - if (*len != sizeof(struct arpt_getinfo)) {
102828 - duprintf("length %u != %Zu\n", *len,
102829 + if (len != sizeof(struct arpt_getinfo)) {
102830 + duprintf("length %u != %Zu\n", len,
102831 sizeof(struct arpt_getinfo));
102832 return -EINVAL;
102833 }
102834 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102835 info.size = private->size;
102836 strcpy(info.name, name);
102837
102838 - if (copy_to_user(user, &info, *len) != 0)
102839 + if (copy_to_user(user, &info, len) != 0)
102840 ret = -EFAULT;
102841 else
102842 ret = 0;
102843 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102844
102845 switch (cmd) {
102846 case ARPT_SO_GET_INFO:
102847 - ret = get_info(sock_net(sk), user, len, 1);
102848 + ret = get_info(sock_net(sk), user, *len, 1);
102849 break;
102850 case ARPT_SO_GET_ENTRIES:
102851 ret = compat_get_entries(sock_net(sk), user, len);
102852 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102853
102854 switch (cmd) {
102855 case ARPT_SO_GET_INFO:
102856 - ret = get_info(sock_net(sk), user, len, 0);
102857 + ret = get_info(sock_net(sk), user, *len, 0);
102858 break;
102859
102860 case ARPT_SO_GET_ENTRIES:
102861 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102862 index 99e810f..3711b81 100644
102863 --- a/net/ipv4/netfilter/ip_tables.c
102864 +++ b/net/ipv4/netfilter/ip_tables.c
102865 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102866 #endif
102867
102868 static int get_info(struct net *net, void __user *user,
102869 - const int *len, int compat)
102870 + int len, int compat)
102871 {
102872 char name[XT_TABLE_MAXNAMELEN];
102873 struct xt_table *t;
102874 int ret;
102875
102876 - if (*len != sizeof(struct ipt_getinfo)) {
102877 - duprintf("length %u != %zu\n", *len,
102878 + if (len != sizeof(struct ipt_getinfo)) {
102879 + duprintf("length %u != %zu\n", len,
102880 sizeof(struct ipt_getinfo));
102881 return -EINVAL;
102882 }
102883 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102884 info.size = private->size;
102885 strcpy(info.name, name);
102886
102887 - if (copy_to_user(user, &info, *len) != 0)
102888 + if (copy_to_user(user, &info, len) != 0)
102889 ret = -EFAULT;
102890 else
102891 ret = 0;
102892 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102893
102894 switch (cmd) {
102895 case IPT_SO_GET_INFO:
102896 - ret = get_info(sock_net(sk), user, len, 1);
102897 + ret = get_info(sock_net(sk), user, *len, 1);
102898 break;
102899 case IPT_SO_GET_ENTRIES:
102900 ret = compat_get_entries(sock_net(sk), user, len);
102901 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102902
102903 switch (cmd) {
102904 case IPT_SO_GET_INFO:
102905 - ret = get_info(sock_net(sk), user, len, 0);
102906 + ret = get_info(sock_net(sk), user, *len, 0);
102907 break;
102908
102909 case IPT_SO_GET_ENTRIES:
102910 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102911 index e90f83a..3e6acca 100644
102912 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102913 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102914 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102915 spin_lock_init(&cn->lock);
102916
102917 #ifdef CONFIG_PROC_FS
102918 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102919 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102920 if (!cn->procdir) {
102921 pr_err("Unable to proc dir entry\n");
102922 return -ENOMEM;
102923 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102924 index 5d740cc..22c8e65 100644
102925 --- a/net/ipv4/ping.c
102926 +++ b/net/ipv4/ping.c
102927 @@ -59,7 +59,7 @@ struct ping_table {
102928 };
102929
102930 static struct ping_table ping_table;
102931 -struct pingv6_ops pingv6_ops;
102932 +struct pingv6_ops *pingv6_ops;
102933 EXPORT_SYMBOL_GPL(pingv6_ops);
102934
102935 static u16 ping_port_rover;
102936 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102937 return -ENODEV;
102938 }
102939 }
102940 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102941 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102942 scoped);
102943 rcu_read_unlock();
102944
102945 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102946 }
102947 #if IS_ENABLED(CONFIG_IPV6)
102948 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102949 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102950 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102951 #endif
102952 }
102953
102954 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102955 info, (u8 *)icmph);
102956 #if IS_ENABLED(CONFIG_IPV6)
102957 } else if (family == AF_INET6) {
102958 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102959 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102960 info, (u8 *)icmph);
102961 #endif
102962 }
102963 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102964 }
102965
102966 if (inet6_sk(sk)->rxopt.all)
102967 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102968 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102969 if (skb->protocol == htons(ETH_P_IPV6) &&
102970 inet6_sk(sk)->rxopt.all)
102971 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102972 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102973 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102974 ip_cmsg_recv(msg, skb);
102975 #endif
102976 @@ -965,8 +965,11 @@ void ping_rcv(struct sk_buff *skb)
102977
102978 sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id));
102979 if (sk != NULL) {
102980 + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
102981 +
102982 pr_debug("rcv on socket %p\n", sk);
102983 - ping_queue_rcv_skb(sk, skb_get(skb));
102984 + if (skb2)
102985 + ping_queue_rcv_skb(sk, skb2);
102986 sock_put(sk);
102987 return;
102988 }
102989 @@ -1105,7 +1108,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102990 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102991 0, sock_i_ino(sp),
102992 atomic_read(&sp->sk_refcnt), sp,
102993 - atomic_read(&sp->sk_drops));
102994 + atomic_read_unchecked(&sp->sk_drops));
102995 }
102996
102997 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102998 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102999 index 739db31..74f0210 100644
103000 --- a/net/ipv4/raw.c
103001 +++ b/net/ipv4/raw.c
103002 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103003 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103004 {
103005 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103006 - atomic_inc(&sk->sk_drops);
103007 + atomic_inc_unchecked(&sk->sk_drops);
103008 kfree_skb(skb);
103009 return NET_RX_DROP;
103010 }
103011 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103012
103013 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103014 {
103015 + struct icmp_filter filter;
103016 +
103017 if (optlen > sizeof(struct icmp_filter))
103018 optlen = sizeof(struct icmp_filter);
103019 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103020 + if (copy_from_user(&filter, optval, optlen))
103021 return -EFAULT;
103022 + raw_sk(sk)->filter = filter;
103023 return 0;
103024 }
103025
103026 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103027 {
103028 int len, ret = -EFAULT;
103029 + struct icmp_filter filter;
103030
103031 if (get_user(len, optlen))
103032 goto out;
103033 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103034 if (len > sizeof(struct icmp_filter))
103035 len = sizeof(struct icmp_filter);
103036 ret = -EFAULT;
103037 - if (put_user(len, optlen) ||
103038 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103039 + filter = raw_sk(sk)->filter;
103040 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103041 goto out;
103042 ret = 0;
103043 out: return ret;
103044 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103045 0, 0L, 0,
103046 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103047 0, sock_i_ino(sp),
103048 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103049 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103050 }
103051
103052 static int raw_seq_show(struct seq_file *seq, void *v)
103053 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103054 index 6a2155b..47de388 100644
103055 --- a/net/ipv4/route.c
103056 +++ b/net/ipv4/route.c
103057 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103058
103059 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103060 {
103061 - return seq_open(file, &rt_cache_seq_ops);
103062 + return seq_open_restrict(file, &rt_cache_seq_ops);
103063 }
103064
103065 static const struct file_operations rt_cache_seq_fops = {
103066 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103067
103068 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103069 {
103070 - return seq_open(file, &rt_cpu_seq_ops);
103071 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103072 }
103073
103074 static const struct file_operations rt_cpu_seq_fops = {
103075 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103076
103077 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103078 {
103079 - return single_open(file, rt_acct_proc_show, NULL);
103080 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103081 }
103082
103083 static const struct file_operations rt_acct_proc_fops = {
103084 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103085
103086 #define IP_IDENTS_SZ 2048u
103087 struct ip_ident_bucket {
103088 - atomic_t id;
103089 + atomic_unchecked_t id;
103090 u32 stamp32;
103091 };
103092
103093 -static struct ip_ident_bucket *ip_idents __read_mostly;
103094 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103095
103096 /* In order to protect privacy, we add a perturbation to identifiers
103097 * if one generator is seldom used. This makes hard for an attacker
103098 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103099 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103100 delta = prandom_u32_max(now - old);
103101
103102 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103103 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103104 }
103105 EXPORT_SYMBOL(ip_idents_reserve);
103106
103107 @@ -1554,11 +1554,10 @@ static int __mkroute_input(struct sk_buff *skb,
103108
103109 do_cache = res->fi && !itag;
103110 if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
103111 + skb->protocol == htons(ETH_P_IP) &&
103112 (IN_DEV_SHARED_MEDIA(out_dev) ||
103113 - inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res)))) {
103114 - flags |= RTCF_DOREDIRECT;
103115 - do_cache = false;
103116 - }
103117 + inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
103118 + IPCB(skb)->flags |= IPSKB_DOREDIRECT;
103119
103120 if (skb->protocol != htons(ETH_P_IP)) {
103121 /* Not IP (i.e. ARP). Do not create route, if it is
103122 @@ -2303,6 +2302,8 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
103123 r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
103124 if (rt->rt_flags & RTCF_NOTIFY)
103125 r->rtm_flags |= RTM_F_NOTIFY;
103126 + if (IPCB(skb)->flags & IPSKB_DOREDIRECT)
103127 + r->rtm_flags |= RTCF_DOREDIRECT;
103128
103129 if (nla_put_be32(skb, RTA_DST, dst))
103130 goto nla_put_failure;
103131 @@ -2624,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103132 .maxlen = sizeof(int),
103133 .mode = 0200,
103134 .proc_handler = ipv4_sysctl_rtcache_flush,
103135 + .extra1 = &init_net,
103136 },
103137 { },
103138 };
103139
103140 static __net_init int sysctl_route_net_init(struct net *net)
103141 {
103142 - struct ctl_table *tbl;
103143 + ctl_table_no_const *tbl = NULL;
103144
103145 - tbl = ipv4_route_flush_table;
103146 if (!net_eq(net, &init_net)) {
103147 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103148 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103149 if (tbl == NULL)
103150 goto err_dup;
103151
103152 /* Don't export sysctls to unprivileged users */
103153 if (net->user_ns != &init_user_ns)
103154 tbl[0].procname = NULL;
103155 - }
103156 - tbl[0].extra1 = net;
103157 + tbl[0].extra1 = net;
103158 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103159 + } else
103160 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103161
103162 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103163 if (net->ipv4.route_hdr == NULL)
103164 goto err_reg;
103165 return 0;
103166
103167 err_reg:
103168 - if (tbl != ipv4_route_flush_table)
103169 - kfree(tbl);
103170 + kfree(tbl);
103171 err_dup:
103172 return -ENOMEM;
103173 }
103174 @@ -2674,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103175
103176 static __net_init int rt_genid_init(struct net *net)
103177 {
103178 - atomic_set(&net->ipv4.rt_genid, 0);
103179 - atomic_set(&net->fnhe_genid, 0);
103180 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103181 + atomic_set_unchecked(&net->fnhe_genid, 0);
103182 get_random_bytes(&net->ipv4.dev_addr_genid,
103183 sizeof(net->ipv4.dev_addr_genid));
103184 return 0;
103185 @@ -2718,11 +2719,7 @@ int __init ip_rt_init(void)
103186 {
103187 int rc = 0;
103188
103189 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103190 - if (!ip_idents)
103191 - panic("IP: failed to allocate ip_idents\n");
103192 -
103193 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103194 + prandom_bytes(ip_idents, sizeof(ip_idents));
103195
103196 #ifdef CONFIG_IP_ROUTE_CLASSID
103197 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103198 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103199 index b3c53c8..35cc18d 100644
103200 --- a/net/ipv4/sysctl_net_ipv4.c
103201 +++ b/net/ipv4/sysctl_net_ipv4.c
103202 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103203 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103204 int ret;
103205 int range[2];
103206 - struct ctl_table tmp = {
103207 + ctl_table_no_const tmp = {
103208 .data = &range,
103209 .maxlen = sizeof(range),
103210 .mode = table->mode,
103211 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103212 int ret;
103213 gid_t urange[2];
103214 kgid_t low, high;
103215 - struct ctl_table tmp = {
103216 + ctl_table_no_const tmp = {
103217 .data = &urange,
103218 .maxlen = sizeof(urange),
103219 .mode = table->mode,
103220 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103221 void __user *buffer, size_t *lenp, loff_t *ppos)
103222 {
103223 char val[TCP_CA_NAME_MAX];
103224 - struct ctl_table tbl = {
103225 + ctl_table_no_const tbl = {
103226 .data = val,
103227 .maxlen = TCP_CA_NAME_MAX,
103228 };
103229 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103230 void __user *buffer, size_t *lenp,
103231 loff_t *ppos)
103232 {
103233 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103234 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103235 int ret;
103236
103237 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103238 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103239 void __user *buffer, size_t *lenp,
103240 loff_t *ppos)
103241 {
103242 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103243 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103244 int ret;
103245
103246 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103247 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103248 void __user *buffer, size_t *lenp,
103249 loff_t *ppos)
103250 {
103251 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103252 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103253 struct tcp_fastopen_context *ctxt;
103254 int ret;
103255 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103256 @@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
103257
103258 static __net_init int ipv4_sysctl_init_net(struct net *net)
103259 {
103260 - struct ctl_table *table;
103261 + ctl_table_no_const *table = NULL;
103262
103263 - table = ipv4_net_table;
103264 if (!net_eq(net, &init_net)) {
103265 int i;
103266
103267 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103268 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103269 if (table == NULL)
103270 goto err_alloc;
103271
103272 @@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103273 table[i].data += (void *)net - (void *)&init_net;
103274 }
103275
103276 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103277 + if (!net_eq(net, &init_net))
103278 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103279 + else
103280 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103281 if (net->ipv4.ipv4_hdr == NULL)
103282 goto err_reg;
103283
103284 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103285 index d107ee2..bcebf11 100644
103286 --- a/net/ipv4/tcp_input.c
103287 +++ b/net/ipv4/tcp_input.c
103288 @@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103289 * without any lock. We want to make sure compiler wont store
103290 * intermediate values in this location.
103291 */
103292 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103293 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103294 sk->sk_max_pacing_rate);
103295 }
103296
103297 @@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103298 * simplifies code)
103299 */
103300 static void
103301 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103302 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103303 struct sk_buff *head, struct sk_buff *tail,
103304 u32 start, u32 end)
103305 {
103306 @@ -5506,6 +5506,7 @@ discard:
103307 tcp_paws_reject(&tp->rx_opt, 0))
103308 goto discard_and_undo;
103309
103310 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103311 if (th->syn) {
103312 /* We see SYN without ACK. It is attempt of
103313 * simultaneous connect with crossed SYNs.
103314 @@ -5556,6 +5557,7 @@ discard:
103315 goto discard;
103316 #endif
103317 }
103318 +#endif
103319 /* "fifth, if neither of the SYN or RST bits is set then
103320 * drop the segment and return."
103321 */
103322 @@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103323 goto discard;
103324
103325 if (th->syn) {
103326 - if (th->fin)
103327 + if (th->fin || th->urg || th->psh)
103328 goto discard;
103329 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103330 return 1;
103331 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103332 index ef7089c..a3e65fb 100644
103333 --- a/net/ipv4/tcp_ipv4.c
103334 +++ b/net/ipv4/tcp_ipv4.c
103335 @@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
103336 int sysctl_tcp_low_latency __read_mostly;
103337 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103338
103339 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103340 +extern int grsec_enable_blackhole;
103341 +#endif
103342 +
103343 #ifdef CONFIG_TCP_MD5SIG
103344 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103345 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103346 @@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103347 return 0;
103348
103349 reset:
103350 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103351 + if (!grsec_enable_blackhole)
103352 +#endif
103353 tcp_v4_send_reset(rsk, skb);
103354 discard:
103355 kfree_skb(skb);
103356 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103357 TCP_SKB_CB(skb)->sacked = 0;
103358
103359 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103360 - if (!sk)
103361 + if (!sk) {
103362 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103363 + ret = 1;
103364 +#endif
103365 goto no_tcp_socket;
103366 -
103367 + }
103368 process:
103369 - if (sk->sk_state == TCP_TIME_WAIT)
103370 + if (sk->sk_state == TCP_TIME_WAIT) {
103371 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103372 + ret = 2;
103373 +#endif
103374 goto do_time_wait;
103375 + }
103376
103377 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103378 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103379 @@ -1694,6 +1708,10 @@ csum_error:
103380 bad_packet:
103381 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103382 } else {
103383 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103384 + if (!grsec_enable_blackhole || (ret == 1 &&
103385 + (skb->dev->flags & IFF_LOOPBACK)))
103386 +#endif
103387 tcp_v4_send_reset(NULL, skb);
103388 }
103389
103390 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103391 index 63d2680..2db9d6b 100644
103392 --- a/net/ipv4/tcp_minisocks.c
103393 +++ b/net/ipv4/tcp_minisocks.c
103394 @@ -27,6 +27,10 @@
103395 #include <net/inet_common.h>
103396 #include <net/xfrm.h>
103397
103398 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103399 +extern int grsec_enable_blackhole;
103400 +#endif
103401 +
103402 int sysctl_tcp_syncookies __read_mostly = 1;
103403 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103404
103405 @@ -739,7 +743,10 @@ embryonic_reset:
103406 * avoid becoming vulnerable to outside attack aiming at
103407 * resetting legit local connections.
103408 */
103409 - req->rsk_ops->send_reset(sk, skb);
103410 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103411 + if (!grsec_enable_blackhole)
103412 +#endif
103413 + req->rsk_ops->send_reset(sk, skb);
103414 } else if (fastopen) { /* received a valid RST pkt */
103415 reqsk_fastopen_remove(sk, req, true);
103416 tcp_reset(sk);
103417 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103418 index ebf5ff5..4d1ff32 100644
103419 --- a/net/ipv4/tcp_probe.c
103420 +++ b/net/ipv4/tcp_probe.c
103421 @@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103422 if (cnt + width >= len)
103423 break;
103424
103425 - if (copy_to_user(buf + cnt, tbuf, width))
103426 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103427 return -EFAULT;
103428 cnt += width;
103429 }
103430 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103431 index 9b21ae8..4eb67df 100644
103432 --- a/net/ipv4/tcp_timer.c
103433 +++ b/net/ipv4/tcp_timer.c
103434 @@ -22,6 +22,10 @@
103435 #include <linux/gfp.h>
103436 #include <net/tcp.h>
103437
103438 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103439 +extern int grsec_lastack_retries;
103440 +#endif
103441 +
103442 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103443 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103444 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103445 @@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103446 }
103447 }
103448
103449 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103450 + if ((sk->sk_state == TCP_LAST_ACK) &&
103451 + (grsec_lastack_retries > 0) &&
103452 + (grsec_lastack_retries < retry_until))
103453 + retry_until = grsec_lastack_retries;
103454 +#endif
103455 +
103456 if (retransmits_timed_out(sk, retry_until,
103457 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103458 /* Has it gone just too far? */
103459 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103460 index cd0db54..93a6518 100644
103461 --- a/net/ipv4/udp.c
103462 +++ b/net/ipv4/udp.c
103463 @@ -87,6 +87,7 @@
103464 #include <linux/types.h>
103465 #include <linux/fcntl.h>
103466 #include <linux/module.h>
103467 +#include <linux/security.h>
103468 #include <linux/socket.h>
103469 #include <linux/sockios.h>
103470 #include <linux/igmp.h>
103471 @@ -114,6 +115,10 @@
103472 #include <net/busy_poll.h>
103473 #include "udp_impl.h"
103474
103475 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103476 +extern int grsec_enable_blackhole;
103477 +#endif
103478 +
103479 struct udp_table udp_table __read_mostly;
103480 EXPORT_SYMBOL(udp_table);
103481
103482 @@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103483 return true;
103484 }
103485
103486 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103487 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103488 +
103489 /*
103490 * This routine is called by the ICMP module when it gets some
103491 * sort of error condition. If err < 0 then the socket should
103492 @@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103493 dport = usin->sin_port;
103494 if (dport == 0)
103495 return -EINVAL;
103496 +
103497 + err = gr_search_udp_sendmsg(sk, usin);
103498 + if (err)
103499 + return err;
103500 } else {
103501 if (sk->sk_state != TCP_ESTABLISHED)
103502 return -EDESTADDRREQ;
103503 +
103504 + err = gr_search_udp_sendmsg(sk, NULL);
103505 + if (err)
103506 + return err;
103507 +
103508 daddr = inet->inet_daddr;
103509 dport = inet->inet_dport;
103510 /* Open fast path for connected socket.
103511 @@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103512 IS_UDPLITE(sk));
103513 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103514 IS_UDPLITE(sk));
103515 - atomic_inc(&sk->sk_drops);
103516 + atomic_inc_unchecked(&sk->sk_drops);
103517 __skb_unlink(skb, rcvq);
103518 __skb_queue_tail(&list_kill, skb);
103519 }
103520 @@ -1262,6 +1279,10 @@ try_again:
103521 if (!skb)
103522 goto out;
103523
103524 + err = gr_search_udp_recvmsg(sk, skb);
103525 + if (err)
103526 + goto out_free;
103527 +
103528 ulen = skb->len - sizeof(struct udphdr);
103529 copied = len;
103530 if (copied > ulen)
103531 @@ -1295,7 +1316,7 @@ try_again:
103532 if (unlikely(err)) {
103533 trace_kfree_skb(skb, udp_recvmsg);
103534 if (!peeked) {
103535 - atomic_inc(&sk->sk_drops);
103536 + atomic_inc_unchecked(&sk->sk_drops);
103537 UDP_INC_STATS_USER(sock_net(sk),
103538 UDP_MIB_INERRORS, is_udplite);
103539 }
103540 @@ -1592,7 +1613,7 @@ csum_error:
103541 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103542 drop:
103543 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103544 - atomic_inc(&sk->sk_drops);
103545 + atomic_inc_unchecked(&sk->sk_drops);
103546 kfree_skb(skb);
103547 return -1;
103548 }
103549 @@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103550 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103551
103552 if (!skb1) {
103553 - atomic_inc(&sk->sk_drops);
103554 + atomic_inc_unchecked(&sk->sk_drops);
103555 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103556 IS_UDPLITE(sk));
103557 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103558 @@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103559 goto csum_error;
103560
103561 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103562 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103563 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103564 +#endif
103565 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103566
103567 /*
103568 @@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103569 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103570 0, sock_i_ino(sp),
103571 atomic_read(&sp->sk_refcnt), sp,
103572 - atomic_read(&sp->sk_drops));
103573 + atomic_read_unchecked(&sp->sk_drops));
103574 }
103575
103576 int udp4_seq_show(struct seq_file *seq, void *v)
103577 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103578 index 6156f68..d6ab46d 100644
103579 --- a/net/ipv4/xfrm4_policy.c
103580 +++ b/net/ipv4/xfrm4_policy.c
103581 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103582 fl4->flowi4_tos = iph->tos;
103583 }
103584
103585 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103586 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103587 {
103588 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103589
103590 - xfrm4_policy_afinfo.garbage_collect(net);
103591 + xfrm_garbage_collect_deferred(net);
103592 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103593 }
103594
103595 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103596
103597 static int __net_init xfrm4_net_init(struct net *net)
103598 {
103599 - struct ctl_table *table;
103600 + ctl_table_no_const *table = NULL;
103601 struct ctl_table_header *hdr;
103602
103603 - table = xfrm4_policy_table;
103604 if (!net_eq(net, &init_net)) {
103605 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103606 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103607 if (!table)
103608 goto err_alloc;
103609
103610 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103611 - }
103612 -
103613 - hdr = register_net_sysctl(net, "net/ipv4", table);
103614 + hdr = register_net_sysctl(net, "net/ipv4", table);
103615 + } else
103616 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103617 if (!hdr)
103618 goto err_reg;
103619
103620 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103621 return 0;
103622
103623 err_reg:
103624 - if (!net_eq(net, &init_net))
103625 - kfree(table);
103626 + kfree(table);
103627 err_alloc:
103628 return -ENOMEM;
103629 }
103630 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103631 index 0169ccf..50d7b04 100644
103632 --- a/net/ipv6/addrconf.c
103633 +++ b/net/ipv6/addrconf.c
103634 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103635 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103636 .mtu6 = IPV6_MIN_MTU,
103637 .accept_ra = 1,
103638 - .accept_redirects = 1,
103639 + .accept_redirects = 0,
103640 .autoconf = 1,
103641 .force_mld_version = 0,
103642 .mldv1_unsolicited_report_interval = 10 * HZ,
103643 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103644 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103645 .mtu6 = IPV6_MIN_MTU,
103646 .accept_ra = 1,
103647 - .accept_redirects = 1,
103648 + .accept_redirects = 0,
103649 .autoconf = 1,
103650 .force_mld_version = 0,
103651 .mldv1_unsolicited_report_interval = 10 * HZ,
103652 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103653 idx = 0;
103654 head = &net->dev_index_head[h];
103655 rcu_read_lock();
103656 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103657 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103658 net->dev_base_seq;
103659 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103660 if (idx < s_idx)
103661 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103662 p.iph.ihl = 5;
103663 p.iph.protocol = IPPROTO_IPV6;
103664 p.iph.ttl = 64;
103665 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103666 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103667
103668 if (ops->ndo_do_ioctl) {
103669 mm_segment_t oldfs = get_fs();
103670 @@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103671 .release = seq_release_net,
103672 };
103673
103674 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103675 +extern void unregister_ipv6_seq_ops_addr(void);
103676 +
103677 static int __net_init if6_proc_net_init(struct net *net)
103678 {
103679 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103680 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103681 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103682 + unregister_ipv6_seq_ops_addr();
103683 return -ENOMEM;
103684 + }
103685 return 0;
103686 }
103687
103688 static void __net_exit if6_proc_net_exit(struct net *net)
103689 {
103690 remove_proc_entry("if_inet6", net->proc_net);
103691 + unregister_ipv6_seq_ops_addr();
103692 }
103693
103694 static struct pernet_operations if6_proc_net_ops = {
103695 @@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103696 s_ip_idx = ip_idx = cb->args[2];
103697
103698 rcu_read_lock();
103699 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103700 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103701 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103702 idx = 0;
103703 head = &net->dev_index_head[h];
103704 @@ -4788,7 +4795,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103705 rt_genid_bump_ipv6(net);
103706 break;
103707 }
103708 - atomic_inc(&net->ipv6.dev_addr_genid);
103709 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103710 }
103711
103712 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103713 @@ -4808,7 +4815,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103714 int *valp = ctl->data;
103715 int val = *valp;
103716 loff_t pos = *ppos;
103717 - struct ctl_table lctl;
103718 + ctl_table_no_const lctl;
103719 int ret;
103720
103721 /*
103722 @@ -4893,7 +4900,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103723 int *valp = ctl->data;
103724 int val = *valp;
103725 loff_t pos = *ppos;
103726 - struct ctl_table lctl;
103727 + ctl_table_no_const lctl;
103728 int ret;
103729
103730 /*
103731 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103732 index e8c4400..a4cd5da 100644
103733 --- a/net/ipv6/af_inet6.c
103734 +++ b/net/ipv6/af_inet6.c
103735 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103736 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103737 net->ipv6.sysctl.flowlabel_consistency = 1;
103738 net->ipv6.sysctl.auto_flowlabels = 0;
103739 - atomic_set(&net->ipv6.fib6_sernum, 1);
103740 + atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103741
103742 err = ipv6_init_mibs(net);
103743 if (err)
103744 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103745 index 2cdc383..4f1b785 100644
103746 --- a/net/ipv6/datagram.c
103747 +++ b/net/ipv6/datagram.c
103748 @@ -383,11 +383,10 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103749
103750 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
103751 sin = &errhdr.offender;
103752 - sin->sin6_family = AF_UNSPEC;
103753 + memset(sin, 0, sizeof(*sin));
103754 +
103755 if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
103756 sin->sin6_family = AF_INET6;
103757 - sin->sin6_flowinfo = 0;
103758 - sin->sin6_port = 0;
103759 if (np->rxopt.all)
103760 ip6_datagram_recv_common_ctl(sk, msg, skb);
103761 if (skb->protocol == htons(ETH_P_IPV6)) {
103762 @@ -398,12 +397,9 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103763 ipv6_iface_scope_id(&sin->sin6_addr,
103764 IP6CB(skb)->iif);
103765 } else {
103766 - struct inet_sock *inet = inet_sk(sk);
103767 -
103768 ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
103769 &sin->sin6_addr);
103770 - sin->sin6_scope_id = 0;
103771 - if (inet->cmsg_flags)
103772 + if (inet_sk(sk)->cmsg_flags)
103773 ip_cmsg_recv(msg, skb);
103774 }
103775 }
103776 @@ -928,5 +924,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103777 0,
103778 sock_i_ino(sp),
103779 atomic_read(&sp->sk_refcnt), sp,
103780 - atomic_read(&sp->sk_drops));
103781 + atomic_read_unchecked(&sp->sk_drops));
103782 }
103783 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103784 index 97ae700..18dcae0 100644
103785 --- a/net/ipv6/icmp.c
103786 +++ b/net/ipv6/icmp.c
103787 @@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103788
103789 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103790 {
103791 - struct ctl_table *table;
103792 + ctl_table_no_const *table;
103793
103794 table = kmemdup(ipv6_icmp_table_template,
103795 sizeof(ipv6_icmp_table_template),
103796 diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103797 index b2d1838..0194c04 100644
103798 --- a/net/ipv6/ip6_fib.c
103799 +++ b/net/ipv6/ip6_fib.c
103800 @@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103801 int new, old;
103802
103803 do {
103804 - old = atomic_read(&net->ipv6.fib6_sernum);
103805 + old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103806 new = old < INT_MAX ? old + 1 : 1;
103807 - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103808 + } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103809 old, new) != old);
103810 return new;
103811 }
103812 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103813 index 0e32d2e..dd45cdc 100644
103814 --- a/net/ipv6/ip6_gre.c
103815 +++ b/net/ipv6/ip6_gre.c
103816 @@ -71,8 +71,8 @@ struct ip6gre_net {
103817 struct net_device *fb_tunnel_dev;
103818 };
103819
103820 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103821 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103822 +static struct rtnl_link_ops ip6gre_link_ops;
103823 +static struct rtnl_link_ops ip6gre_tap_ops;
103824 static int ip6gre_tunnel_init(struct net_device *dev);
103825 static void ip6gre_tunnel_setup(struct net_device *dev);
103826 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103827 @@ -417,7 +417,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
103828 if (code == ICMPV6_HDR_FIELD)
103829 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
103830
103831 - if (teli && teli == info - 2) {
103832 + if (teli && teli == be32_to_cpu(info) - 2) {
103833 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
103834 if (tel->encap_limit == 0) {
103835 net_warn_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
103836 @@ -429,7 +429,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
103837 }
103838 break;
103839 case ICMPV6_PKT_TOOBIG:
103840 - mtu = info - offset;
103841 + mtu = be32_to_cpu(info) - offset;
103842 if (mtu < IPV6_MIN_MTU)
103843 mtu = IPV6_MIN_MTU;
103844 t->dev->mtu = mtu;
103845 @@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103846 }
103847
103848
103849 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103850 +static struct inet6_protocol ip6gre_protocol = {
103851 .handler = ip6gre_rcv,
103852 .err_handler = ip6gre_err,
103853 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103854 @@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103855 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103856 };
103857
103858 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103859 +static struct rtnl_link_ops ip6gre_link_ops = {
103860 .kind = "ip6gre",
103861 .maxtype = IFLA_GRE_MAX,
103862 .policy = ip6gre_policy,
103863 @@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103864 .fill_info = ip6gre_fill_info,
103865 };
103866
103867 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103868 +static struct rtnl_link_ops ip6gre_tap_ops = {
103869 .kind = "ip6gretap",
103870 .maxtype = IFLA_GRE_MAX,
103871 .policy = ip6gre_policy,
103872 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103873 index 9cb94cf..5678108 100644
103874 --- a/net/ipv6/ip6_tunnel.c
103875 +++ b/net/ipv6/ip6_tunnel.c
103876 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103877
103878 static int ip6_tnl_dev_init(struct net_device *dev);
103879 static void ip6_tnl_dev_setup(struct net_device *dev);
103880 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103881 +static struct rtnl_link_ops ip6_link_ops;
103882
103883 static int ip6_tnl_net_id __read_mostly;
103884 struct ip6_tnl_net {
103885 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103886 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103887 };
103888
103889 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103890 +static struct rtnl_link_ops ip6_link_ops = {
103891 .kind = "ip6tnl",
103892 .maxtype = IFLA_IPTUN_MAX,
103893 .policy = ip6_tnl_policy,
103894 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103895 index bcda14d..49378c9 100644
103896 --- a/net/ipv6/ip6_vti.c
103897 +++ b/net/ipv6/ip6_vti.c
103898 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103899
103900 static int vti6_dev_init(struct net_device *dev);
103901 static void vti6_dev_setup(struct net_device *dev);
103902 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103903 +static struct rtnl_link_ops vti6_link_ops;
103904
103905 static int vti6_net_id __read_mostly;
103906 struct vti6_net {
103907 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103908 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103909 };
103910
103911 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103912 +static struct rtnl_link_ops vti6_link_ops = {
103913 .kind = "vti6",
103914 .maxtype = IFLA_VTI_MAX,
103915 .policy = vti6_policy,
103916 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103917 index e1a9583..7dd8f4d 100644
103918 --- a/net/ipv6/ipv6_sockglue.c
103919 +++ b/net/ipv6/ipv6_sockglue.c
103920 @@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103921 if (sk->sk_type != SOCK_STREAM)
103922 return -ENOPROTOOPT;
103923
103924 - msg.msg_control = optval;
103925 + msg.msg_control = (void __force_kernel *)optval;
103926 msg.msg_controllen = len;
103927 msg.msg_flags = flags;
103928
103929 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103930 index e080fbb..412b3cf 100644
103931 --- a/net/ipv6/netfilter/ip6_tables.c
103932 +++ b/net/ipv6/netfilter/ip6_tables.c
103933 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103934 #endif
103935
103936 static int get_info(struct net *net, void __user *user,
103937 - const int *len, int compat)
103938 + int len, int compat)
103939 {
103940 char name[XT_TABLE_MAXNAMELEN];
103941 struct xt_table *t;
103942 int ret;
103943
103944 - if (*len != sizeof(struct ip6t_getinfo)) {
103945 - duprintf("length %u != %zu\n", *len,
103946 + if (len != sizeof(struct ip6t_getinfo)) {
103947 + duprintf("length %u != %zu\n", len,
103948 sizeof(struct ip6t_getinfo));
103949 return -EINVAL;
103950 }
103951 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103952 info.size = private->size;
103953 strcpy(info.name, name);
103954
103955 - if (copy_to_user(user, &info, *len) != 0)
103956 + if (copy_to_user(user, &info, len) != 0)
103957 ret = -EFAULT;
103958 else
103959 ret = 0;
103960 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103961
103962 switch (cmd) {
103963 case IP6T_SO_GET_INFO:
103964 - ret = get_info(sock_net(sk), user, len, 1);
103965 + ret = get_info(sock_net(sk), user, *len, 1);
103966 break;
103967 case IP6T_SO_GET_ENTRIES:
103968 ret = compat_get_entries(sock_net(sk), user, len);
103969 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103970
103971 switch (cmd) {
103972 case IP6T_SO_GET_INFO:
103973 - ret = get_info(sock_net(sk), user, len, 0);
103974 + ret = get_info(sock_net(sk), user, *len, 0);
103975 break;
103976
103977 case IP6T_SO_GET_ENTRIES:
103978 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103979 index 6f187c8..34b367f 100644
103980 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103981 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103982 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103983
103984 static int nf_ct_frag6_sysctl_register(struct net *net)
103985 {
103986 - struct ctl_table *table;
103987 + ctl_table_no_const *table = NULL;
103988 struct ctl_table_header *hdr;
103989
103990 - table = nf_ct_frag6_sysctl_table;
103991 if (!net_eq(net, &init_net)) {
103992 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103993 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103994 GFP_KERNEL);
103995 if (table == NULL)
103996 goto err_alloc;
103997 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103998 table[2].data = &net->nf_frag.frags.high_thresh;
103999 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104000 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104001 - }
104002 -
104003 - hdr = register_net_sysctl(net, "net/netfilter", table);
104004 + hdr = register_net_sysctl(net, "net/netfilter", table);
104005 + } else
104006 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104007 if (hdr == NULL)
104008 goto err_reg;
104009
104010 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104011 return 0;
104012
104013 err_reg:
104014 - if (!net_eq(net, &init_net))
104015 - kfree(table);
104016 + kfree(table);
104017 err_alloc:
104018 return -ENOMEM;
104019 }
104020 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104021 index 5b7a1ed..d9da205 100644
104022 --- a/net/ipv6/ping.c
104023 +++ b/net/ipv6/ping.c
104024 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104025 };
104026 #endif
104027
104028 +static struct pingv6_ops real_pingv6_ops = {
104029 + .ipv6_recv_error = ipv6_recv_error,
104030 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104031 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104032 + .icmpv6_err_convert = icmpv6_err_convert,
104033 + .ipv6_icmp_error = ipv6_icmp_error,
104034 + .ipv6_chk_addr = ipv6_chk_addr,
104035 +};
104036 +
104037 +static struct pingv6_ops dummy_pingv6_ops = {
104038 + .ipv6_recv_error = dummy_ipv6_recv_error,
104039 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104040 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104041 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
104042 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
104043 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
104044 +};
104045 +
104046 int __init pingv6_init(void)
104047 {
104048 #ifdef CONFIG_PROC_FS
104049 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
104050 if (ret)
104051 return ret;
104052 #endif
104053 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104054 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104055 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104056 - ip6_datagram_recv_specific_ctl;
104057 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104058 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104059 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104060 + pingv6_ops = &real_pingv6_ops;
104061 return inet6_register_protosw(&pingv6_protosw);
104062 }
104063
104064 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
104065 */
104066 void pingv6_exit(void)
104067 {
104068 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104069 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104070 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104071 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104072 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104073 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104074 #ifdef CONFIG_PROC_FS
104075 unregister_pernet_subsys(&ping_v6_net_ops);
104076 #endif
104077 + pingv6_ops = &dummy_pingv6_ops;
104078 inet6_unregister_protosw(&pingv6_protosw);
104079 }
104080 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104081 index 1752cd0..3c6af41 100644
104082 --- a/net/ipv6/proc.c
104083 +++ b/net/ipv6/proc.c
104084 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104085 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104086 goto proc_snmp6_fail;
104087
104088 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104089 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104090 if (!net->mib.proc_net_devsnmp6)
104091 goto proc_dev_snmp6_fail;
104092 return 0;
104093 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104094 index 896af88..6e2ba628 100644
104095 --- a/net/ipv6/raw.c
104096 +++ b/net/ipv6/raw.c
104097 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104098 {
104099 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104100 skb_checksum_complete(skb)) {
104101 - atomic_inc(&sk->sk_drops);
104102 + atomic_inc_unchecked(&sk->sk_drops);
104103 kfree_skb(skb);
104104 return NET_RX_DROP;
104105 }
104106 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104107 struct raw6_sock *rp = raw6_sk(sk);
104108
104109 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104110 - atomic_inc(&sk->sk_drops);
104111 + atomic_inc_unchecked(&sk->sk_drops);
104112 kfree_skb(skb);
104113 return NET_RX_DROP;
104114 }
104115 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104116
104117 if (inet->hdrincl) {
104118 if (skb_checksum_complete(skb)) {
104119 - atomic_inc(&sk->sk_drops);
104120 + atomic_inc_unchecked(&sk->sk_drops);
104121 kfree_skb(skb);
104122 return NET_RX_DROP;
104123 }
104124 @@ -608,7 +608,7 @@ out:
104125 return err;
104126 }
104127
104128 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104129 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104130 struct flowi6 *fl6, struct dst_entry **dstp,
104131 unsigned int flags)
104132 {
104133 @@ -914,12 +914,15 @@ do_confirm:
104134 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104135 char __user *optval, int optlen)
104136 {
104137 + struct icmp6_filter filter;
104138 +
104139 switch (optname) {
104140 case ICMPV6_FILTER:
104141 if (optlen > sizeof(struct icmp6_filter))
104142 optlen = sizeof(struct icmp6_filter);
104143 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104144 + if (copy_from_user(&filter, optval, optlen))
104145 return -EFAULT;
104146 + raw6_sk(sk)->filter = filter;
104147 return 0;
104148 default:
104149 return -ENOPROTOOPT;
104150 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104151 char __user *optval, int __user *optlen)
104152 {
104153 int len;
104154 + struct icmp6_filter filter;
104155
104156 switch (optname) {
104157 case ICMPV6_FILTER:
104158 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104159 len = sizeof(struct icmp6_filter);
104160 if (put_user(len, optlen))
104161 return -EFAULT;
104162 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104163 + filter = raw6_sk(sk)->filter;
104164 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104165 return -EFAULT;
104166 return 0;
104167 default:
104168 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104169 index 1a157ca..9fc05f4 100644
104170 --- a/net/ipv6/reassembly.c
104171 +++ b/net/ipv6/reassembly.c
104172 @@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104173
104174 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104175 {
104176 - struct ctl_table *table;
104177 + ctl_table_no_const *table = NULL;
104178 struct ctl_table_header *hdr;
104179
104180 - table = ip6_frags_ns_ctl_table;
104181 if (!net_eq(net, &init_net)) {
104182 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104183 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104184 if (table == NULL)
104185 goto err_alloc;
104186
104187 @@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104188 /* Don't export sysctls to unprivileged users */
104189 if (net->user_ns != &init_user_ns)
104190 table[0].procname = NULL;
104191 - }
104192 + hdr = register_net_sysctl(net, "net/ipv6", table);
104193 + } else
104194 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104195
104196 - hdr = register_net_sysctl(net, "net/ipv6", table);
104197 if (hdr == NULL)
104198 goto err_reg;
104199
104200 @@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104201 return 0;
104202
104203 err_reg:
104204 - if (!net_eq(net, &init_net))
104205 - kfree(table);
104206 + kfree(table);
104207 err_alloc:
104208 return -ENOMEM;
104209 }
104210 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104211 index a318dd89..42a612c 100644
104212 --- a/net/ipv6/route.c
104213 +++ b/net/ipv6/route.c
104214 @@ -1150,12 +1150,9 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
104215 struct net *net = dev_net(dst->dev);
104216
104217 rt6->rt6i_flags |= RTF_MODIFIED;
104218 - if (mtu < IPV6_MIN_MTU) {
104219 - u32 features = dst_metric(dst, RTAX_FEATURES);
104220 + if (mtu < IPV6_MIN_MTU)
104221 mtu = IPV6_MIN_MTU;
104222 - features |= RTAX_FEATURE_ALLFRAG;
104223 - dst_metric_set(dst, RTAX_FEATURES, features);
104224 - }
104225 +
104226 dst_metric_set(dst, RTAX_MTU, mtu);
104227 rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
104228 }
104229 @@ -2965,7 +2962,7 @@ struct ctl_table ipv6_route_table_template[] = {
104230
104231 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104232 {
104233 - struct ctl_table *table;
104234 + ctl_table_no_const *table;
104235
104236 table = kmemdup(ipv6_route_table_template,
104237 sizeof(ipv6_route_table_template),
104238 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104239 index a24557a..ade77d3 100644
104240 --- a/net/ipv6/sit.c
104241 +++ b/net/ipv6/sit.c
104242 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104243 static void ipip6_dev_free(struct net_device *dev);
104244 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104245 __be32 *v4dst);
104246 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104247 +static struct rtnl_link_ops sit_link_ops;
104248
104249 static int sit_net_id __read_mostly;
104250 struct sit_net {
104251 @@ -1505,12 +1505,12 @@ static bool ipip6_netlink_encap_parms(struct nlattr *data[],
104252
104253 if (data[IFLA_IPTUN_ENCAP_SPORT]) {
104254 ret = true;
104255 - ipencap->sport = nla_get_u16(data[IFLA_IPTUN_ENCAP_SPORT]);
104256 + ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
104257 }
104258
104259 if (data[IFLA_IPTUN_ENCAP_DPORT]) {
104260 ret = true;
104261 - ipencap->dport = nla_get_u16(data[IFLA_IPTUN_ENCAP_DPORT]);
104262 + ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
104263 }
104264
104265 return ret;
104266 @@ -1706,9 +1706,9 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
104267
104268 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE,
104269 tunnel->encap.type) ||
104270 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_SPORT,
104271 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT,
104272 tunnel->encap.sport) ||
104273 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_DPORT,
104274 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT,
104275 tunnel->encap.dport) ||
104276 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS,
104277 tunnel->encap.dport))
104278 @@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104279 unregister_netdevice_queue(dev, head);
104280 }
104281
104282 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104283 +static struct rtnl_link_ops sit_link_ops = {
104284 .kind = "sit",
104285 .maxtype = IFLA_IPTUN_MAX,
104286 .policy = ipip6_policy,
104287 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104288 index c5c10fa..2577d51 100644
104289 --- a/net/ipv6/sysctl_net_ipv6.c
104290 +++ b/net/ipv6/sysctl_net_ipv6.c
104291 @@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
104292
104293 static int __net_init ipv6_sysctl_net_init(struct net *net)
104294 {
104295 - struct ctl_table *ipv6_table;
104296 + ctl_table_no_const *ipv6_table;
104297 struct ctl_table *ipv6_route_table;
104298 struct ctl_table *ipv6_icmp_table;
104299 int err;
104300 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104301 index c113602..0cccb46 100644
104302 --- a/net/ipv6/tcp_ipv6.c
104303 +++ b/net/ipv6/tcp_ipv6.c
104304 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104305 }
104306 }
104307
104308 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104309 +extern int grsec_enable_blackhole;
104310 +#endif
104311 +
104312 static void tcp_v6_hash(struct sock *sk)
104313 {
104314 if (sk->sk_state != TCP_CLOSE) {
104315 @@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104316 return 0;
104317
104318 reset:
104319 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104320 + if (!grsec_enable_blackhole)
104321 +#endif
104322 tcp_v6_send_reset(sk, skb);
104323 discard:
104324 if (opt_skb)
104325 @@ -1441,12 +1448,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104326
104327 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
104328 inet6_iif(skb));
104329 - if (!sk)
104330 + if (!sk) {
104331 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104332 + ret = 1;
104333 +#endif
104334 goto no_tcp_socket;
104335 + }
104336
104337 process:
104338 - if (sk->sk_state == TCP_TIME_WAIT)
104339 + if (sk->sk_state == TCP_TIME_WAIT) {
104340 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104341 + ret = 2;
104342 +#endif
104343 goto do_time_wait;
104344 + }
104345
104346 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104347 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104348 @@ -1497,6 +1512,10 @@ csum_error:
104349 bad_packet:
104350 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104351 } else {
104352 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104353 + if (!grsec_enable_blackhole || (ret == 1 &&
104354 + (skb->dev->flags & IFF_LOOPBACK)))
104355 +#endif
104356 tcp_v6_send_reset(NULL, skb);
104357 }
104358
104359 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104360 index f6ba535..b41033f 100644
104361 --- a/net/ipv6/udp.c
104362 +++ b/net/ipv6/udp.c
104363 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104364 udp_ipv6_hash_secret + net_hash_mix(net));
104365 }
104366
104367 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104368 +extern int grsec_enable_blackhole;
104369 +#endif
104370 +
104371 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104372 {
104373 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104374 @@ -434,7 +438,7 @@ try_again:
104375 if (unlikely(err)) {
104376 trace_kfree_skb(skb, udpv6_recvmsg);
104377 if (!peeked) {
104378 - atomic_inc(&sk->sk_drops);
104379 + atomic_inc_unchecked(&sk->sk_drops);
104380 if (is_udp4)
104381 UDP_INC_STATS_USER(sock_net(sk),
104382 UDP_MIB_INERRORS,
104383 @@ -701,7 +705,7 @@ csum_error:
104384 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104385 drop:
104386 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104387 - atomic_inc(&sk->sk_drops);
104388 + atomic_inc_unchecked(&sk->sk_drops);
104389 kfree_skb(skb);
104390 return -1;
104391 }
104392 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104393 if (likely(skb1 == NULL))
104394 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104395 if (!skb1) {
104396 - atomic_inc(&sk->sk_drops);
104397 + atomic_inc_unchecked(&sk->sk_drops);
104398 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104399 IS_UDPLITE(sk));
104400 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104401 @@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104402 goto csum_error;
104403
104404 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104405 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104406 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104407 +#endif
104408 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104409
104410 kfree_skb(skb);
104411 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104412 index 5f98364..691985a 100644
104413 --- a/net/ipv6/xfrm6_policy.c
104414 +++ b/net/ipv6/xfrm6_policy.c
104415 @@ -130,12 +130,18 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104416 {
104417 struct flowi6 *fl6 = &fl->u.ip6;
104418 int onlyproto = 0;
104419 - u16 offset = skb_network_header_len(skb);
104420 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104421 + u16 offset = sizeof(*hdr);
104422 struct ipv6_opt_hdr *exthdr;
104423 const unsigned char *nh = skb_network_header(skb);
104424 - u8 nexthdr = nh[IP6CB(skb)->nhoff];
104425 + u16 nhoff = IP6CB(skb)->nhoff;
104426 int oif = 0;
104427 + u8 nexthdr;
104428 +
104429 + if (!nhoff)
104430 + nhoff = offsetof(struct ipv6hdr, nexthdr);
104431 +
104432 + nexthdr = nh[nhoff];
104433
104434 if (skb_dst(skb))
104435 oif = skb_dst(skb)->dev->ifindex;
104436 @@ -217,11 +223,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104437 }
104438 }
104439
104440 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104441 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104442 {
104443 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104444
104445 - xfrm6_policy_afinfo.garbage_collect(net);
104446 + xfrm_garbage_collect_deferred(net);
104447 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104448 }
104449
104450 @@ -334,19 +340,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104451
104452 static int __net_init xfrm6_net_init(struct net *net)
104453 {
104454 - struct ctl_table *table;
104455 + ctl_table_no_const *table = NULL;
104456 struct ctl_table_header *hdr;
104457
104458 - table = xfrm6_policy_table;
104459 if (!net_eq(net, &init_net)) {
104460 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104461 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104462 if (!table)
104463 goto err_alloc;
104464
104465 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104466 - }
104467 + hdr = register_net_sysctl(net, "net/ipv6", table);
104468 + } else
104469 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104470
104471 - hdr = register_net_sysctl(net, "net/ipv6", table);
104472 if (!hdr)
104473 goto err_reg;
104474
104475 @@ -354,8 +360,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104476 return 0;
104477
104478 err_reg:
104479 - if (!net_eq(net, &init_net))
104480 - kfree(table);
104481 + kfree(table);
104482 err_alloc:
104483 return -ENOMEM;
104484 }
104485 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104486 index e15c16a..7cf07aa 100644
104487 --- a/net/ipx/ipx_proc.c
104488 +++ b/net/ipx/ipx_proc.c
104489 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104490 struct proc_dir_entry *p;
104491 int rc = -ENOMEM;
104492
104493 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104494 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104495
104496 if (!ipx_proc_dir)
104497 goto out;
104498 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104499 index 61ceb4c..e788eb8 100644
104500 --- a/net/irda/ircomm/ircomm_tty.c
104501 +++ b/net/irda/ircomm/ircomm_tty.c
104502 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104503 add_wait_queue(&port->open_wait, &wait);
104504
104505 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104506 - __FILE__, __LINE__, tty->driver->name, port->count);
104507 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104508
104509 spin_lock_irqsave(&port->lock, flags);
104510 - port->count--;
104511 + atomic_dec(&port->count);
104512 port->blocked_open++;
104513 spin_unlock_irqrestore(&port->lock, flags);
104514
104515 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104516 }
104517
104518 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104519 - __FILE__, __LINE__, tty->driver->name, port->count);
104520 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104521
104522 schedule();
104523 }
104524 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104525
104526 spin_lock_irqsave(&port->lock, flags);
104527 if (!tty_hung_up_p(filp))
104528 - port->count++;
104529 + atomic_inc(&port->count);
104530 port->blocked_open--;
104531 spin_unlock_irqrestore(&port->lock, flags);
104532
104533 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104534 - __FILE__, __LINE__, tty->driver->name, port->count);
104535 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104536
104537 if (!retval)
104538 port->flags |= ASYNC_NORMAL_ACTIVE;
104539 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104540
104541 /* ++ is not atomic, so this should be protected - Jean II */
104542 spin_lock_irqsave(&self->port.lock, flags);
104543 - self->port.count++;
104544 + atomic_inc(&self->port.count);
104545 spin_unlock_irqrestore(&self->port.lock, flags);
104546 tty_port_tty_set(&self->port, tty);
104547
104548 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104549 - self->line, self->port.count);
104550 + self->line, atomic_read(&self->port.count));
104551
104552 /* Not really used by us, but lets do it anyway */
104553 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104554 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104555 tty_kref_put(port->tty);
104556 }
104557 port->tty = NULL;
104558 - port->count = 0;
104559 + atomic_set(&port->count, 0);
104560 spin_unlock_irqrestore(&port->lock, flags);
104561
104562 wake_up_interruptible(&port->open_wait);
104563 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104564 seq_putc(m, '\n');
104565
104566 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104567 - seq_printf(m, "Open count: %d\n", self->port.count);
104568 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104569 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104570 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104571
104572 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104573 index b9ac598..f88cc56 100644
104574 --- a/net/irda/irproc.c
104575 +++ b/net/irda/irproc.c
104576 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104577 {
104578 int i;
104579
104580 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104581 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104582 if (proc_irda == NULL)
104583 return;
104584
104585 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104586 index a089b6b..3ca3b60 100644
104587 --- a/net/iucv/af_iucv.c
104588 +++ b/net/iucv/af_iucv.c
104589 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104590 {
104591 char name[12];
104592
104593 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104594 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104595 while (__iucv_get_sock_by_name(name)) {
104596 sprintf(name, "%08x",
104597 - atomic_inc_return(&iucv_sk_list.autobind_name));
104598 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104599 }
104600 memcpy(iucv->src_name, name, 8);
104601 }
104602 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104603 index 2a6a1fd..6c112b0 100644
104604 --- a/net/iucv/iucv.c
104605 +++ b/net/iucv/iucv.c
104606 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104607 return NOTIFY_OK;
104608 }
104609
104610 -static struct notifier_block __refdata iucv_cpu_notifier = {
104611 +static struct notifier_block iucv_cpu_notifier = {
104612 .notifier_call = iucv_cpu_notify,
104613 };
104614
104615 diff --git a/net/key/af_key.c b/net/key/af_key.c
104616 index 1847ec4..26ef732 100644
104617 --- a/net/key/af_key.c
104618 +++ b/net/key/af_key.c
104619 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104620 static u32 get_acqseq(void)
104621 {
104622 u32 res;
104623 - static atomic_t acqseq;
104624 + static atomic_unchecked_t acqseq;
104625
104626 do {
104627 - res = atomic_inc_return(&acqseq);
104628 + res = atomic_inc_return_unchecked(&acqseq);
104629 } while (!res);
104630 return res;
104631 }
104632 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104633 index edb78e6..8dc654a 100644
104634 --- a/net/l2tp/l2tp_eth.c
104635 +++ b/net/l2tp/l2tp_eth.c
104636 @@ -42,12 +42,12 @@ struct l2tp_eth {
104637 struct sock *tunnel_sock;
104638 struct l2tp_session *session;
104639 struct list_head list;
104640 - atomic_long_t tx_bytes;
104641 - atomic_long_t tx_packets;
104642 - atomic_long_t tx_dropped;
104643 - atomic_long_t rx_bytes;
104644 - atomic_long_t rx_packets;
104645 - atomic_long_t rx_errors;
104646 + atomic_long_unchecked_t tx_bytes;
104647 + atomic_long_unchecked_t tx_packets;
104648 + atomic_long_unchecked_t tx_dropped;
104649 + atomic_long_unchecked_t rx_bytes;
104650 + atomic_long_unchecked_t rx_packets;
104651 + atomic_long_unchecked_t rx_errors;
104652 };
104653
104654 /* via l2tp_session_priv() */
104655 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104656 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104657
104658 if (likely(ret == NET_XMIT_SUCCESS)) {
104659 - atomic_long_add(len, &priv->tx_bytes);
104660 - atomic_long_inc(&priv->tx_packets);
104661 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104662 + atomic_long_inc_unchecked(&priv->tx_packets);
104663 } else {
104664 - atomic_long_inc(&priv->tx_dropped);
104665 + atomic_long_inc_unchecked(&priv->tx_dropped);
104666 }
104667 return NETDEV_TX_OK;
104668 }
104669 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104670 {
104671 struct l2tp_eth *priv = netdev_priv(dev);
104672
104673 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104674 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104675 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104676 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104677 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104678 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104679 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104680 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104681 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104682 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104683 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104684 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104685 return stats;
104686 }
104687
104688 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104689 nf_reset(skb);
104690
104691 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104692 - atomic_long_inc(&priv->rx_packets);
104693 - atomic_long_add(data_len, &priv->rx_bytes);
104694 + atomic_long_inc_unchecked(&priv->rx_packets);
104695 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104696 } else {
104697 - atomic_long_inc(&priv->rx_errors);
104698 + atomic_long_inc_unchecked(&priv->rx_errors);
104699 }
104700 return;
104701
104702 error:
104703 - atomic_long_inc(&priv->rx_errors);
104704 + atomic_long_inc_unchecked(&priv->rx_errors);
104705 kfree_skb(skb);
104706 }
104707
104708 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104709 index 1a3c7e0..80f8b0c 100644
104710 --- a/net/llc/llc_proc.c
104711 +++ b/net/llc/llc_proc.c
104712 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104713 int rc = -ENOMEM;
104714 struct proc_dir_entry *p;
104715
104716 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104717 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104718 if (!llc_proc_dir)
104719 goto out;
104720
104721 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104722 index 343da1e..509873f 100644
104723 --- a/net/mac80211/cfg.c
104724 +++ b/net/mac80211/cfg.c
104725 @@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104726 ret = ieee80211_vif_use_channel(sdata, chandef,
104727 IEEE80211_CHANCTX_EXCLUSIVE);
104728 }
104729 - } else if (local->open_count == local->monitors) {
104730 + } else if (local_read(&local->open_count) == local->monitors) {
104731 local->_oper_chandef = *chandef;
104732 ieee80211_hw_config(local, 0);
104733 }
104734 @@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104735 else
104736 local->probe_req_reg--;
104737
104738 - if (!local->open_count)
104739 + if (!local_read(&local->open_count))
104740 break;
104741
104742 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104743 @@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104744 if (chanctx_conf) {
104745 *chandef = sdata->vif.bss_conf.chandef;
104746 ret = 0;
104747 - } else if (local->open_count > 0 &&
104748 - local->open_count == local->monitors &&
104749 + } else if (local_read(&local->open_count) > 0 &&
104750 + local_read(&local->open_count) == local->monitors &&
104751 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104752 if (local->use_chanctx)
104753 *chandef = local->monitor_chandef;
104754 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104755 index 8c68da3..0695016 100644
104756 --- a/net/mac80211/ieee80211_i.h
104757 +++ b/net/mac80211/ieee80211_i.h
104758 @@ -29,6 +29,7 @@
104759 #include <net/ieee80211_radiotap.h>
104760 #include <net/cfg80211.h>
104761 #include <net/mac80211.h>
104762 +#include <asm/local.h>
104763 #include "key.h"
104764 #include "sta_info.h"
104765 #include "debug.h"
104766 @@ -1057,7 +1058,7 @@ struct ieee80211_local {
104767 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104768 spinlock_t queue_stop_reason_lock;
104769
104770 - int open_count;
104771 + local_t open_count;
104772 int monitors, cooked_mntrs;
104773 /* number of interfaces with corresponding FIF_ flags */
104774 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104775 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104776 index eeae0ab..0f24585 100644
104777 --- a/net/mac80211/iface.c
104778 +++ b/net/mac80211/iface.c
104779 @@ -533,7 +533,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104780 break;
104781 }
104782
104783 - if (local->open_count == 0) {
104784 + if (local_read(&local->open_count) == 0) {
104785 res = drv_start(local);
104786 if (res)
104787 goto err_del_bss;
104788 @@ -580,7 +580,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104789 res = drv_add_interface(local, sdata);
104790 if (res)
104791 goto err_stop;
104792 - } else if (local->monitors == 0 && local->open_count == 0) {
104793 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104794 res = ieee80211_add_virtual_monitor(local);
104795 if (res)
104796 goto err_stop;
104797 @@ -689,7 +689,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104798 atomic_inc(&local->iff_promiscs);
104799
104800 if (coming_up)
104801 - local->open_count++;
104802 + local_inc(&local->open_count);
104803
104804 if (hw_reconf_flags)
104805 ieee80211_hw_config(local, hw_reconf_flags);
104806 @@ -727,7 +727,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104807 err_del_interface:
104808 drv_remove_interface(local, sdata);
104809 err_stop:
104810 - if (!local->open_count)
104811 + if (!local_read(&local->open_count))
104812 drv_stop(local);
104813 err_del_bss:
104814 sdata->bss = NULL;
104815 @@ -893,7 +893,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104816 }
104817
104818 if (going_down)
104819 - local->open_count--;
104820 + local_dec(&local->open_count);
104821
104822 switch (sdata->vif.type) {
104823 case NL80211_IFTYPE_AP_VLAN:
104824 @@ -955,7 +955,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104825 }
104826 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104827
104828 - if (local->open_count == 0)
104829 + if (local_read(&local->open_count) == 0)
104830 ieee80211_clear_tx_pending(local);
104831
104832 /*
104833 @@ -998,7 +998,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104834 if (cancel_scan)
104835 flush_delayed_work(&local->scan_work);
104836
104837 - if (local->open_count == 0) {
104838 + if (local_read(&local->open_count) == 0) {
104839 ieee80211_stop_device(local);
104840
104841 /* no reconfiguring after stop! */
104842 @@ -1009,7 +1009,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104843 ieee80211_configure_filter(local);
104844 ieee80211_hw_config(local, hw_reconf_flags);
104845
104846 - if (local->monitors == local->open_count)
104847 + if (local->monitors == local_read(&local->open_count))
104848 ieee80211_add_virtual_monitor(local);
104849 }
104850
104851 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104852 index 0de7c93..884b2ca 100644
104853 --- a/net/mac80211/main.c
104854 +++ b/net/mac80211/main.c
104855 @@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104856 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104857 IEEE80211_CONF_CHANGE_POWER);
104858
104859 - if (changed && local->open_count) {
104860 + if (changed && local_read(&local->open_count)) {
104861 ret = drv_config(local, changed);
104862 /*
104863 * Goal:
104864 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104865 index 4c5192e..04cc0d8 100644
104866 --- a/net/mac80211/pm.c
104867 +++ b/net/mac80211/pm.c
104868 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104869 struct ieee80211_sub_if_data *sdata;
104870 struct sta_info *sta;
104871
104872 - if (!local->open_count)
104873 + if (!local_read(&local->open_count))
104874 goto suspend;
104875
104876 ieee80211_scan_cancel(local);
104877 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104878 cancel_work_sync(&local->dynamic_ps_enable_work);
104879 del_timer_sync(&local->dynamic_ps_timer);
104880
104881 - local->wowlan = wowlan && local->open_count;
104882 + local->wowlan = wowlan && local_read(&local->open_count);
104883 if (local->wowlan) {
104884 int err = drv_suspend(local, wowlan);
104885 if (err < 0) {
104886 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104887 WARN_ON(!list_empty(&local->chanctx_list));
104888
104889 /* stop hardware - this must stop RX */
104890 - if (local->open_count)
104891 + if (local_read(&local->open_count))
104892 ieee80211_stop_device(local);
104893
104894 suspend:
104895 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104896 index 6081329..ab23834 100644
104897 --- a/net/mac80211/rate.c
104898 +++ b/net/mac80211/rate.c
104899 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104900
104901 ASSERT_RTNL();
104902
104903 - if (local->open_count)
104904 + if (local_read(&local->open_count))
104905 return -EBUSY;
104906
104907 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104908 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104909 index 3c61060..7bed2e3 100644
104910 --- a/net/mac80211/util.c
104911 +++ b/net/mac80211/util.c
104912 @@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104913 }
104914 #endif
104915 /* everything else happens only if HW was up & running */
104916 - if (!local->open_count)
104917 + if (!local_read(&local->open_count))
104918 goto wake_up;
104919
104920 /*
104921 @@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104922 local->in_reconfig = false;
104923 barrier();
104924
104925 - if (local->monitors == local->open_count && local->monitors > 0)
104926 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104927 ieee80211_add_virtual_monitor(local);
104928
104929 /*
104930 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104931 index ae5096ab..e5aa70a 100644
104932 --- a/net/netfilter/Kconfig
104933 +++ b/net/netfilter/Kconfig
104934 @@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
104935
104936 To compile it as a module, choose M here. If unsure, say N.
104937
104938 +config NETFILTER_XT_MATCH_GRADM
104939 + tristate '"gradm" match support'
104940 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104941 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104942 + ---help---
104943 + The gradm match allows to match on grsecurity RBAC being enabled.
104944 + It is useful when iptables rules are applied early on bootup to
104945 + prevent connections to the machine (except from a trusted host)
104946 + while the RBAC system is disabled.
104947 +
104948 config NETFILTER_XT_MATCH_HASHLIMIT
104949 tristate '"hashlimit" match support'
104950 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104951 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104952 index a9571be..c59e173 100644
104953 --- a/net/netfilter/Makefile
104954 +++ b/net/netfilter/Makefile
104955 @@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104956 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104957 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104958 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104959 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104960 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104961 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104962 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104963 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104964 index d259da3..6a32b2c 100644
104965 --- a/net/netfilter/ipset/ip_set_core.c
104966 +++ b/net/netfilter/ipset/ip_set_core.c
104967 @@ -1952,7 +1952,7 @@ done:
104968 return ret;
104969 }
104970
104971 -static struct nf_sockopt_ops so_set __read_mostly = {
104972 +static struct nf_sockopt_ops so_set = {
104973 .pf = PF_INET,
104974 .get_optmin = SO_IP_SET,
104975 .get_optmax = SO_IP_SET + 1,
104976 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104977 index b0f7b62..0541842 100644
104978 --- a/net/netfilter/ipvs/ip_vs_conn.c
104979 +++ b/net/netfilter/ipvs/ip_vs_conn.c
104980 @@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104981 /* Increase the refcnt counter of the dest */
104982 ip_vs_dest_hold(dest);
104983
104984 - conn_flags = atomic_read(&dest->conn_flags);
104985 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
104986 if (cp->protocol != IPPROTO_UDP)
104987 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104988 flags = cp->flags;
104989 @@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
104990
104991 cp->control = NULL;
104992 atomic_set(&cp->n_control, 0);
104993 - atomic_set(&cp->in_pkts, 0);
104994 + atomic_set_unchecked(&cp->in_pkts, 0);
104995
104996 cp->packet_xmit = NULL;
104997 cp->app = NULL;
104998 @@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104999
105000 /* Don't drop the entry if its number of incoming packets is not
105001 located in [0, 8] */
105002 - i = atomic_read(&cp->in_pkts);
105003 + i = atomic_read_unchecked(&cp->in_pkts);
105004 if (i > 8 || i < 0) return 0;
105005
105006 if (!todrop_rate[i]) return 0;
105007 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105008 index 990decb..5075248 100644
105009 --- a/net/netfilter/ipvs/ip_vs_core.c
105010 +++ b/net/netfilter/ipvs/ip_vs_core.c
105011 @@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105012 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105013 /* do not touch skb anymore */
105014
105015 - atomic_inc(&cp->in_pkts);
105016 + atomic_inc_unchecked(&cp->in_pkts);
105017 ip_vs_conn_put(cp);
105018 return ret;
105019 }
105020 @@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105021 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105022 pkts = sysctl_sync_threshold(ipvs);
105023 else
105024 - pkts = atomic_add_return(1, &cp->in_pkts);
105025 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105026
105027 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105028 ip_vs_sync_conn(net, cp, pkts);
105029 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105030 index ac7ba68..9735acb9 100644
105031 --- a/net/netfilter/ipvs/ip_vs_ctl.c
105032 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
105033 @@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105034 */
105035 ip_vs_rs_hash(ipvs, dest);
105036 }
105037 - atomic_set(&dest->conn_flags, conn_flags);
105038 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
105039
105040 /* bind the service */
105041 old_svc = rcu_dereference_protected(dest->svc, 1);
105042 @@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105043 * align with netns init in ip_vs_control_net_init()
105044 */
105045
105046 -static struct ctl_table vs_vars[] = {
105047 +static ctl_table_no_const vs_vars[] __read_only = {
105048 {
105049 .procname = "amemthresh",
105050 .maxlen = sizeof(int),
105051 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105052 " %-7s %-6d %-10d %-10d\n",
105053 &dest->addr.in6,
105054 ntohs(dest->port),
105055 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105056 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105057 atomic_read(&dest->weight),
105058 atomic_read(&dest->activeconns),
105059 atomic_read(&dest->inactconns));
105060 @@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105061 "%-7s %-6d %-10d %-10d\n",
105062 ntohl(dest->addr.ip),
105063 ntohs(dest->port),
105064 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105065 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105066 atomic_read(&dest->weight),
105067 atomic_read(&dest->activeconns),
105068 atomic_read(&dest->inactconns));
105069 @@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105070
105071 entry.addr = dest->addr.ip;
105072 entry.port = dest->port;
105073 - entry.conn_flags = atomic_read(&dest->conn_flags);
105074 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105075 entry.weight = atomic_read(&dest->weight);
105076 entry.u_threshold = dest->u_threshold;
105077 entry.l_threshold = dest->l_threshold;
105078 @@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105079 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105080 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105081 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105082 - (atomic_read(&dest->conn_flags) &
105083 + (atomic_read_unchecked(&dest->conn_flags) &
105084 IP_VS_CONN_F_FWD_MASK)) ||
105085 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105086 atomic_read(&dest->weight)) ||
105087 @@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105088 {
105089 int idx;
105090 struct netns_ipvs *ipvs = net_ipvs(net);
105091 - struct ctl_table *tbl;
105092 + ctl_table_no_const *tbl;
105093
105094 atomic_set(&ipvs->dropentry, 0);
105095 spin_lock_init(&ipvs->dropentry_lock);
105096 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105097 index 127f140..553d652 100644
105098 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105099 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105100 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105101 * IPVS LBLC sysctl table
105102 */
105103 #ifdef CONFIG_SYSCTL
105104 -static struct ctl_table vs_vars_table[] = {
105105 +static ctl_table_no_const vs_vars_table[] __read_only = {
105106 {
105107 .procname = "lblc_expiration",
105108 .data = NULL,
105109 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105110 index 2229d2d..b32b785 100644
105111 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105112 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105113 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105114 * IPVS LBLCR sysctl table
105115 */
105116
105117 -static struct ctl_table vs_vars_table[] = {
105118 +static ctl_table_no_const vs_vars_table[] __read_only = {
105119 {
105120 .procname = "lblcr_expiration",
105121 .data = NULL,
105122 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105123 index 7162c86..9eeb60e 100644
105124 --- a/net/netfilter/ipvs/ip_vs_sync.c
105125 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105126 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105127 cp = cp->control;
105128 if (cp) {
105129 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105130 - pkts = atomic_add_return(1, &cp->in_pkts);
105131 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105132 else
105133 pkts = sysctl_sync_threshold(ipvs);
105134 ip_vs_sync_conn(net, cp->control, pkts);
105135 @@ -771,7 +771,7 @@ control:
105136 if (!cp)
105137 return;
105138 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105139 - pkts = atomic_add_return(1, &cp->in_pkts);
105140 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105141 else
105142 pkts = sysctl_sync_threshold(ipvs);
105143 goto sloop;
105144 @@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105145
105146 if (opt)
105147 memcpy(&cp->in_seq, opt, sizeof(*opt));
105148 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105149 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105150 cp->state = state;
105151 cp->old_state = cp->state;
105152 /*
105153 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105154 index bd90bf8..816a020d 100644
105155 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105156 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105157 @@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105158 else
105159 rc = NF_ACCEPT;
105160 /* do not touch skb anymore */
105161 - atomic_inc(&cp->in_pkts);
105162 + atomic_inc_unchecked(&cp->in_pkts);
105163 goto out;
105164 }
105165
105166 @@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105167 else
105168 rc = NF_ACCEPT;
105169 /* do not touch skb anymore */
105170 - atomic_inc(&cp->in_pkts);
105171 + atomic_inc_unchecked(&cp->in_pkts);
105172 goto out;
105173 }
105174
105175 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105176 index a4b5e2a..13b1de3 100644
105177 --- a/net/netfilter/nf_conntrack_acct.c
105178 +++ b/net/netfilter/nf_conntrack_acct.c
105179 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105180 #ifdef CONFIG_SYSCTL
105181 static int nf_conntrack_acct_init_sysctl(struct net *net)
105182 {
105183 - struct ctl_table *table;
105184 + ctl_table_no_const *table;
105185
105186 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105187 GFP_KERNEL);
105188 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105189 index c588012..b0d4ef8 100644
105190 --- a/net/netfilter/nf_conntrack_core.c
105191 +++ b/net/netfilter/nf_conntrack_core.c
105192 @@ -1737,6 +1737,10 @@ void nf_conntrack_init_end(void)
105193 #define DYING_NULLS_VAL ((1<<30)+1)
105194 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105195
105196 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105197 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105198 +#endif
105199 +
105200 int nf_conntrack_init_net(struct net *net)
105201 {
105202 int ret = -ENOMEM;
105203 @@ -1762,7 +1766,11 @@ int nf_conntrack_init_net(struct net *net)
105204 if (!net->ct.stat)
105205 goto err_pcpu_lists;
105206
105207 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105208 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105209 +#else
105210 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105211 +#endif
105212 if (!net->ct.slabname)
105213 goto err_slabname;
105214
105215 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105216 index 4e78c57..ec8fb74 100644
105217 --- a/net/netfilter/nf_conntrack_ecache.c
105218 +++ b/net/netfilter/nf_conntrack_ecache.c
105219 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105220 #ifdef CONFIG_SYSCTL
105221 static int nf_conntrack_event_init_sysctl(struct net *net)
105222 {
105223 - struct ctl_table *table;
105224 + ctl_table_no_const *table;
105225
105226 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105227 GFP_KERNEL);
105228 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105229 index 5b3eae7..dd4b8fe 100644
105230 --- a/net/netfilter/nf_conntrack_helper.c
105231 +++ b/net/netfilter/nf_conntrack_helper.c
105232 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105233
105234 static int nf_conntrack_helper_init_sysctl(struct net *net)
105235 {
105236 - struct ctl_table *table;
105237 + ctl_table_no_const *table;
105238
105239 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105240 GFP_KERNEL);
105241 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105242 index b65d586..beec902 100644
105243 --- a/net/netfilter/nf_conntrack_proto.c
105244 +++ b/net/netfilter/nf_conntrack_proto.c
105245 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105246
105247 static void
105248 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105249 - struct ctl_table **table,
105250 + ctl_table_no_const **table,
105251 unsigned int users)
105252 {
105253 if (users > 0)
105254 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105255 index cf65a1e..2f291e9 100644
105256 --- a/net/netfilter/nf_conntrack_standalone.c
105257 +++ b/net/netfilter/nf_conntrack_standalone.c
105258 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105259
105260 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105261 {
105262 - struct ctl_table *table;
105263 + ctl_table_no_const *table;
105264
105265 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105266 GFP_KERNEL);
105267 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105268 index 7a394df..bd91a8a 100644
105269 --- a/net/netfilter/nf_conntrack_timestamp.c
105270 +++ b/net/netfilter/nf_conntrack_timestamp.c
105271 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105272 #ifdef CONFIG_SYSCTL
105273 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105274 {
105275 - struct ctl_table *table;
105276 + ctl_table_no_const *table;
105277
105278 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105279 GFP_KERNEL);
105280 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105281 index d719764..311bc60 100644
105282 --- a/net/netfilter/nf_log.c
105283 +++ b/net/netfilter/nf_log.c
105284 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105285
105286 #ifdef CONFIG_SYSCTL
105287 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105288 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105289 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105290
105291 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105292 void __user *buffer, size_t *lenp, loff_t *ppos)
105293 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105294 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105295 mutex_unlock(&nf_log_mutex);
105296 } else {
105297 + ctl_table_no_const nf_log_table = *table;
105298 +
105299 mutex_lock(&nf_log_mutex);
105300 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105301 lockdep_is_held(&nf_log_mutex));
105302 if (!logger)
105303 - table->data = "NONE";
105304 + nf_log_table.data = "NONE";
105305 else
105306 - table->data = logger->name;
105307 - r = proc_dostring(table, write, buffer, lenp, ppos);
105308 + nf_log_table.data = logger->name;
105309 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105310 mutex_unlock(&nf_log_mutex);
105311 }
105312
105313 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105314 index c68c1e5..8b5d670 100644
105315 --- a/net/netfilter/nf_sockopt.c
105316 +++ b/net/netfilter/nf_sockopt.c
105317 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105318 }
105319 }
105320
105321 - list_add(&reg->list, &nf_sockopts);
105322 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105323 out:
105324 mutex_unlock(&nf_sockopt_mutex);
105325 return ret;
105326 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105327 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105328 {
105329 mutex_lock(&nf_sockopt_mutex);
105330 - list_del(&reg->list);
105331 + pax_list_del((struct list_head *)&reg->list);
105332 mutex_unlock(&nf_sockopt_mutex);
105333 }
105334 EXPORT_SYMBOL(nf_unregister_sockopt);
105335 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
105336 index 71b574c..d319e8b 100644
105337 --- a/net/netfilter/nf_tables_api.c
105338 +++ b/net/netfilter/nf_tables_api.c
105339 @@ -1134,9 +1134,11 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr)
105340 /* Restore old counters on this cpu, no problem. Per-cpu statistics
105341 * are not exposed to userspace.
105342 */
105343 + preempt_disable();
105344 stats = this_cpu_ptr(newstats);
105345 stats->bytes = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES]));
105346 stats->pkts = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS]));
105347 + preempt_enable();
105348
105349 return newstats;
105350 }
105351 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105352 index 5f1be5b..2cba8cd 100644
105353 --- a/net/netfilter/nfnetlink_log.c
105354 +++ b/net/netfilter/nfnetlink_log.c
105355 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105356 struct nfnl_log_net {
105357 spinlock_t instances_lock;
105358 struct hlist_head instance_table[INSTANCE_BUCKETS];
105359 - atomic_t global_seq;
105360 + atomic_unchecked_t global_seq;
105361 };
105362
105363 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105364 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105365 /* global sequence number */
105366 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105367 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105368 - htonl(atomic_inc_return(&log->global_seq))))
105369 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105370 goto nla_put_failure;
105371
105372 if (data_len) {
105373 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105374 new file mode 100644
105375 index 0000000..c566332
105376 --- /dev/null
105377 +++ b/net/netfilter/xt_gradm.c
105378 @@ -0,0 +1,51 @@
105379 +/*
105380 + * gradm match for netfilter
105381 + * Copyright © Zbigniew Krzystolik, 2010
105382 + *
105383 + * This program is free software; you can redistribute it and/or modify
105384 + * it under the terms of the GNU General Public License; either version
105385 + * 2 or 3 as published by the Free Software Foundation.
105386 + */
105387 +#include <linux/module.h>
105388 +#include <linux/moduleparam.h>
105389 +#include <linux/skbuff.h>
105390 +#include <linux/netfilter/x_tables.h>
105391 +#include <linux/grsecurity.h>
105392 +#include <linux/netfilter/xt_gradm.h>
105393 +
105394 +static bool
105395 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105396 +{
105397 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105398 + bool retval = false;
105399 + if (gr_acl_is_enabled())
105400 + retval = true;
105401 + return retval ^ info->invflags;
105402 +}
105403 +
105404 +static struct xt_match gradm_mt_reg __read_mostly = {
105405 + .name = "gradm",
105406 + .revision = 0,
105407 + .family = NFPROTO_UNSPEC,
105408 + .match = gradm_mt,
105409 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105410 + .me = THIS_MODULE,
105411 +};
105412 +
105413 +static int __init gradm_mt_init(void)
105414 +{
105415 + return xt_register_match(&gradm_mt_reg);
105416 +}
105417 +
105418 +static void __exit gradm_mt_exit(void)
105419 +{
105420 + xt_unregister_match(&gradm_mt_reg);
105421 +}
105422 +
105423 +module_init(gradm_mt_init);
105424 +module_exit(gradm_mt_exit);
105425 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105426 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105427 +MODULE_LICENSE("GPL");
105428 +MODULE_ALIAS("ipt_gradm");
105429 +MODULE_ALIAS("ip6t_gradm");
105430 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105431 index 05fbc2a..4424b5c 100644
105432 --- a/net/netfilter/xt_hashlimit.c
105433 +++ b/net/netfilter/xt_hashlimit.c
105434 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105435 {
105436 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105437
105438 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105439 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105440 if (!hashlimit_net->ipt_hashlimit)
105441 return -ENOMEM;
105442 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105443 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105444 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105445 if (!hashlimit_net->ip6t_hashlimit) {
105446 remove_proc_entry("ipt_hashlimit", net->proc_net);
105447 return -ENOMEM;
105448 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105449 index a9faae8..1ea30e0 100644
105450 --- a/net/netfilter/xt_recent.c
105451 +++ b/net/netfilter/xt_recent.c
105452 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105453 {
105454 struct recent_net *recent_net = recent_pernet(net);
105455
105456 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105457 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105458 if (!recent_net->xt_recent)
105459 return -ENOMEM;
105460 return 0;
105461 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105462 index 11de55e..f25e448 100644
105463 --- a/net/netfilter/xt_statistic.c
105464 +++ b/net/netfilter/xt_statistic.c
105465 @@ -19,7 +19,7 @@
105466 #include <linux/module.h>
105467
105468 struct xt_statistic_priv {
105469 - atomic_t count;
105470 + atomic_unchecked_t count;
105471 } ____cacheline_aligned_in_smp;
105472
105473 MODULE_LICENSE("GPL");
105474 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105475 break;
105476 case XT_STATISTIC_MODE_NTH:
105477 do {
105478 - oval = atomic_read(&info->master->count);
105479 + oval = atomic_read_unchecked(&info->master->count);
105480 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105481 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105482 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105483 if (nval == 0)
105484 ret = !ret;
105485 break;
105486 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105487 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105488 if (info->master == NULL)
105489 return -ENOMEM;
105490 - atomic_set(&info->master->count, info->u.nth.count);
105491 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105492
105493 return 0;
105494 }
105495 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105496 index 79c965a..ee2b76d 100644
105497 --- a/net/netlink/af_netlink.c
105498 +++ b/net/netlink/af_netlink.c
105499 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105500 sk->sk_error_report(sk);
105501 }
105502 }
105503 - atomic_inc(&sk->sk_drops);
105504 + atomic_inc_unchecked(&sk->sk_drops);
105505 }
105506
105507 static void netlink_rcv_wake(struct sock *sk)
105508 @@ -2990,7 +2990,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105509 sk_wmem_alloc_get(s),
105510 nlk->cb_running,
105511 atomic_read(&s->sk_refcnt),
105512 - atomic_read(&s->sk_drops),
105513 + atomic_read_unchecked(&s->sk_drops),
105514 sock_i_ino(s)
105515 );
105516
105517 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
105518 index 8451612..c8872bc 100644
105519 --- a/net/openvswitch/vport-internal_dev.c
105520 +++ b/net/openvswitch/vport-internal_dev.c
105521 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
105522 .ndo_get_stats64 = internal_dev_get_stats,
105523 };
105524
105525 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
105526 +static struct rtnl_link_ops internal_dev_link_ops = {
105527 .kind = "openvswitch",
105528 };
105529
105530 diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
105531 index 6015802..e81e8bf 100644
105532 --- a/net/openvswitch/vport.c
105533 +++ b/net/openvswitch/vport.c
105534 @@ -269,10 +269,10 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
105535 * netdev-stats can be directly read over netlink-ioctl.
105536 */
105537
105538 - stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
105539 - stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
105540 - stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
105541 - stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
105542 + stats->rx_errors = atomic_long_read_unchecked(&vport->err_stats.rx_errors);
105543 + stats->tx_errors = atomic_long_read_unchecked(&vport->err_stats.tx_errors);
105544 + stats->tx_dropped = atomic_long_read_unchecked(&vport->err_stats.tx_dropped);
105545 + stats->rx_dropped = atomic_long_read_unchecked(&vport->err_stats.rx_dropped);
105546
105547 for_each_possible_cpu(i) {
105548 const struct pcpu_sw_netstats *percpu_stats;
105549 @@ -503,19 +503,19 @@ static void ovs_vport_record_error(struct vport *vport,
105550 {
105551 switch (err_type) {
105552 case VPORT_E_RX_DROPPED:
105553 - atomic_long_inc(&vport->err_stats.rx_dropped);
105554 + atomic_long_inc_unchecked(&vport->err_stats.rx_dropped);
105555 break;
105556
105557 case VPORT_E_RX_ERROR:
105558 - atomic_long_inc(&vport->err_stats.rx_errors);
105559 + atomic_long_inc_unchecked(&vport->err_stats.rx_errors);
105560 break;
105561
105562 case VPORT_E_TX_DROPPED:
105563 - atomic_long_inc(&vport->err_stats.tx_dropped);
105564 + atomic_long_inc_unchecked(&vport->err_stats.tx_dropped);
105565 break;
105566
105567 case VPORT_E_TX_ERROR:
105568 - atomic_long_inc(&vport->err_stats.tx_errors);
105569 + atomic_long_inc_unchecked(&vport->err_stats.tx_errors);
105570 break;
105571 }
105572
105573 diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
105574 index 8942125..03ed887 100644
105575 --- a/net/openvswitch/vport.h
105576 +++ b/net/openvswitch/vport.h
105577 @@ -61,10 +61,10 @@ int ovs_vport_send(struct vport *, struct sk_buff *);
105578 /* The following definitions are for implementers of vport devices: */
105579
105580 struct vport_err_stats {
105581 - atomic_long_t rx_dropped;
105582 - atomic_long_t rx_errors;
105583 - atomic_long_t tx_dropped;
105584 - atomic_long_t tx_errors;
105585 + atomic_long_unchecked_t rx_dropped;
105586 + atomic_long_unchecked_t rx_errors;
105587 + atomic_long_unchecked_t tx_dropped;
105588 + atomic_long_unchecked_t tx_errors;
105589 };
105590 /**
105591 * struct vport_portids - array of netlink portids of a vport.
105592 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105593 index 07c04a8..3ca11eb 100644
105594 --- a/net/packet/af_packet.c
105595 +++ b/net/packet/af_packet.c
105596 @@ -269,7 +269,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105597
105598 return ret;
105599 drop:
105600 - atomic_long_inc(&dev->tx_dropped);
105601 + atomic_long_inc_unchecked(&dev->tx_dropped);
105602 kfree_skb(skb);
105603 return NET_XMIT_DROP;
105604 }
105605 @@ -1836,7 +1836,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105606
105607 spin_lock(&sk->sk_receive_queue.lock);
105608 po->stats.stats1.tp_packets++;
105609 - skb->dropcount = atomic_read(&sk->sk_drops);
105610 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105611 __skb_queue_tail(&sk->sk_receive_queue, skb);
105612 spin_unlock(&sk->sk_receive_queue.lock);
105613 sk->sk_data_ready(sk);
105614 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105615 drop_n_acct:
105616 spin_lock(&sk->sk_receive_queue.lock);
105617 po->stats.stats1.tp_drops++;
105618 - atomic_inc(&sk->sk_drops);
105619 + atomic_inc_unchecked(&sk->sk_drops);
105620 spin_unlock(&sk->sk_receive_queue.lock);
105621
105622 drop_n_restore:
105623 @@ -3460,7 +3460,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105624 case PACKET_HDRLEN:
105625 if (len > sizeof(int))
105626 len = sizeof(int);
105627 - if (copy_from_user(&val, optval, len))
105628 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105629 return -EFAULT;
105630 switch (val) {
105631 case TPACKET_V1:
105632 @@ -3506,7 +3506,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105633 len = lv;
105634 if (put_user(len, optlen))
105635 return -EFAULT;
105636 - if (copy_to_user(optval, data, len))
105637 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105638 return -EFAULT;
105639 return 0;
105640 }
105641 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105642 index 70a547e..23477fe 100644
105643 --- a/net/phonet/pep.c
105644 +++ b/net/phonet/pep.c
105645 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105646
105647 case PNS_PEP_CTRL_REQ:
105648 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105649 - atomic_inc(&sk->sk_drops);
105650 + atomic_inc_unchecked(&sk->sk_drops);
105651 break;
105652 }
105653 __skb_pull(skb, 4);
105654 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105655 }
105656
105657 if (pn->rx_credits == 0) {
105658 - atomic_inc(&sk->sk_drops);
105659 + atomic_inc_unchecked(&sk->sk_drops);
105660 err = -ENOBUFS;
105661 break;
105662 }
105663 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105664 }
105665
105666 if (pn->rx_credits == 0) {
105667 - atomic_inc(&sk->sk_drops);
105668 + atomic_inc_unchecked(&sk->sk_drops);
105669 err = NET_RX_DROP;
105670 break;
105671 }
105672 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105673 index 008214a..bb68240 100644
105674 --- a/net/phonet/socket.c
105675 +++ b/net/phonet/socket.c
105676 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105677 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105678 sock_i_ino(sk),
105679 atomic_read(&sk->sk_refcnt), sk,
105680 - atomic_read(&sk->sk_drops));
105681 + atomic_read_unchecked(&sk->sk_drops));
105682 }
105683 seq_pad(seq, '\n');
105684 return 0;
105685 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105686 index c02a8c4..3c5b600 100644
105687 --- a/net/phonet/sysctl.c
105688 +++ b/net/phonet/sysctl.c
105689 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105690 {
105691 int ret;
105692 int range[2] = {local_port_range[0], local_port_range[1]};
105693 - struct ctl_table tmp = {
105694 + ctl_table_no_const tmp = {
105695 .data = &range,
105696 .maxlen = sizeof(range),
105697 .mode = table->mode,
105698 diff --git a/net/rds/cong.c b/net/rds/cong.c
105699 index e5b65ac..f3b6fb7 100644
105700 --- a/net/rds/cong.c
105701 +++ b/net/rds/cong.c
105702 @@ -78,7 +78,7 @@
105703 * finds that the saved generation number is smaller than the global generation
105704 * number, it wakes up the process.
105705 */
105706 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105707 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105708
105709 /*
105710 * Congestion monitoring
105711 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105712 rdsdebug("waking map %p for %pI4\n",
105713 map, &map->m_addr);
105714 rds_stats_inc(s_cong_update_received);
105715 - atomic_inc(&rds_cong_generation);
105716 + atomic_inc_unchecked(&rds_cong_generation);
105717 if (waitqueue_active(&map->m_waitq))
105718 wake_up(&map->m_waitq);
105719 if (waitqueue_active(&rds_poll_waitq))
105720 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105721
105722 int rds_cong_updated_since(unsigned long *recent)
105723 {
105724 - unsigned long gen = atomic_read(&rds_cong_generation);
105725 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105726
105727 if (likely(*recent == gen))
105728 return 0;
105729 diff --git a/net/rds/ib.h b/net/rds/ib.h
105730 index 7280ab8..e04f4ea 100644
105731 --- a/net/rds/ib.h
105732 +++ b/net/rds/ib.h
105733 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105734 /* sending acks */
105735 unsigned long i_ack_flags;
105736 #ifdef KERNEL_HAS_ATOMIC64
105737 - atomic64_t i_ack_next; /* next ACK to send */
105738 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105739 #else
105740 spinlock_t i_ack_lock; /* protect i_ack_next */
105741 u64 i_ack_next; /* next ACK to send */
105742 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105743 index 31b74f5..dc1fbfa 100644
105744 --- a/net/rds/ib_cm.c
105745 +++ b/net/rds/ib_cm.c
105746 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105747 /* Clear the ACK state */
105748 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105749 #ifdef KERNEL_HAS_ATOMIC64
105750 - atomic64_set(&ic->i_ack_next, 0);
105751 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105752 #else
105753 ic->i_ack_next = 0;
105754 #endif
105755 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105756 index d67de45..73dbf51 100644
105757 --- a/net/rds/ib_recv.c
105758 +++ b/net/rds/ib_recv.c
105759 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105760 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105761 int ack_required)
105762 {
105763 - atomic64_set(&ic->i_ack_next, seq);
105764 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105765 if (ack_required) {
105766 smp_mb__before_atomic();
105767 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105768 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105769 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105770 smp_mb__after_atomic();
105771
105772 - return atomic64_read(&ic->i_ack_next);
105773 + return atomic64_read_unchecked(&ic->i_ack_next);
105774 }
105775 #endif
105776
105777 diff --git a/net/rds/iw.h b/net/rds/iw.h
105778 index 04ce3b1..48119a6 100644
105779 --- a/net/rds/iw.h
105780 +++ b/net/rds/iw.h
105781 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105782 /* sending acks */
105783 unsigned long i_ack_flags;
105784 #ifdef KERNEL_HAS_ATOMIC64
105785 - atomic64_t i_ack_next; /* next ACK to send */
105786 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105787 #else
105788 spinlock_t i_ack_lock; /* protect i_ack_next */
105789 u64 i_ack_next; /* next ACK to send */
105790 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105791 index a91e1db..cf3053f 100644
105792 --- a/net/rds/iw_cm.c
105793 +++ b/net/rds/iw_cm.c
105794 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105795 /* Clear the ACK state */
105796 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105797 #ifdef KERNEL_HAS_ATOMIC64
105798 - atomic64_set(&ic->i_ack_next, 0);
105799 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105800 #else
105801 ic->i_ack_next = 0;
105802 #endif
105803 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105804 index aa8bf67..b70133c 100644
105805 --- a/net/rds/iw_recv.c
105806 +++ b/net/rds/iw_recv.c
105807 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105808 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105809 int ack_required)
105810 {
105811 - atomic64_set(&ic->i_ack_next, seq);
105812 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105813 if (ack_required) {
105814 smp_mb__before_atomic();
105815 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105816 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105817 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105818 smp_mb__after_atomic();
105819
105820 - return atomic64_read(&ic->i_ack_next);
105821 + return atomic64_read_unchecked(&ic->i_ack_next);
105822 }
105823 #endif
105824
105825 diff --git a/net/rds/rds.h b/net/rds/rds.h
105826 index 48f8ffc..0ef3eec 100644
105827 --- a/net/rds/rds.h
105828 +++ b/net/rds/rds.h
105829 @@ -449,7 +449,7 @@ struct rds_transport {
105830 void (*sync_mr)(void *trans_private, int direction);
105831 void (*free_mr)(void *trans_private, int invalidate);
105832 void (*flush_mrs)(void);
105833 -};
105834 +} __do_const;
105835
105836 struct rds_sock {
105837 struct sock rs_sk;
105838 diff --git a/net/rds/sysctl.c b/net/rds/sysctl.c
105839 index c3b0cd4..c173f69 100644
105840 --- a/net/rds/sysctl.c
105841 +++ b/net/rds/sysctl.c
105842 @@ -71,14 +71,14 @@ static struct ctl_table rds_sysctl_rds_table[] = {
105843 {
105844 .procname = "max_unacked_packets",
105845 .data = &rds_sysctl_max_unacked_packets,
105846 - .maxlen = sizeof(unsigned long),
105847 + .maxlen = sizeof(int),
105848 .mode = 0644,
105849 .proc_handler = proc_dointvec,
105850 },
105851 {
105852 .procname = "max_unacked_bytes",
105853 .data = &rds_sysctl_max_unacked_bytes,
105854 - .maxlen = sizeof(unsigned long),
105855 + .maxlen = sizeof(int),
105856 .mode = 0644,
105857 .proc_handler = proc_dointvec,
105858 },
105859 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105860 index edac9ef..16bcb98 100644
105861 --- a/net/rds/tcp.c
105862 +++ b/net/rds/tcp.c
105863 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105864 int val = 1;
105865
105866 set_fs(KERNEL_DS);
105867 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105868 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105869 sizeof(val));
105870 set_fs(oldfs);
105871 }
105872 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105873 index 53b17ca..45463e7 100644
105874 --- a/net/rds/tcp_send.c
105875 +++ b/net/rds/tcp_send.c
105876 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105877
105878 oldfs = get_fs();
105879 set_fs(KERNEL_DS);
105880 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105881 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
105882 sizeof(val));
105883 set_fs(oldfs);
105884 }
105885 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
105886 index 7b16704..9628ec6 100644
105887 --- a/net/rxrpc/af_rxrpc.c
105888 +++ b/net/rxrpc/af_rxrpc.c
105889 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
105890 __be32 rxrpc_epoch;
105891
105892 /* current debugging ID */
105893 -atomic_t rxrpc_debug_id;
105894 +atomic_unchecked_t rxrpc_debug_id;
105895
105896 /* count of skbs currently in use */
105897 atomic_t rxrpc_n_skbs;
105898 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
105899 index c6be17a..2a6200a 100644
105900 --- a/net/rxrpc/ar-ack.c
105901 +++ b/net/rxrpc/ar-ack.c
105902 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105903
105904 _enter("{%d,%d,%d,%d},",
105905 call->acks_hard, call->acks_unacked,
105906 - atomic_read(&call->sequence),
105907 + atomic_read_unchecked(&call->sequence),
105908 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
105909
105910 stop = 0;
105911 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105912
105913 /* each Tx packet has a new serial number */
105914 sp->hdr.serial =
105915 - htonl(atomic_inc_return(&call->conn->serial));
105916 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
105917
105918 hdr = (struct rxrpc_header *) txb->head;
105919 hdr->serial = sp->hdr.serial;
105920 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
105921 */
105922 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
105923 {
105924 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
105925 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
105926 }
105927
105928 /*
105929 @@ -677,7 +677,7 @@ process_further:
105930
105931 latest = ntohl(sp->hdr.serial);
105932 hard = ntohl(ack.firstPacket);
105933 - tx = atomic_read(&call->sequence);
105934 + tx = atomic_read_unchecked(&call->sequence);
105935
105936 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105937 latest,
105938 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
105939 goto maybe_reschedule;
105940
105941 send_ACK_with_skew:
105942 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
105943 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
105944 ntohl(ack.serial));
105945 send_ACK:
105946 mtu = call->conn->trans->peer->if_mtu;
105947 @@ -1221,7 +1221,7 @@ send_ACK:
105948 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
105949 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
105950
105951 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105952 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105953 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105954 ntohl(hdr.serial),
105955 ntohs(ack.maxSkew),
105956 @@ -1239,7 +1239,7 @@ send_ACK:
105957 send_message:
105958 _debug("send message");
105959
105960 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105961 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105962 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
105963 send_message_2:
105964
105965 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
105966 index a9e05db..194e793 100644
105967 --- a/net/rxrpc/ar-call.c
105968 +++ b/net/rxrpc/ar-call.c
105969 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
105970 spin_lock_init(&call->lock);
105971 rwlock_init(&call->state_lock);
105972 atomic_set(&call->usage, 1);
105973 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
105974 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105975 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
105976
105977 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
105978 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
105979 index 6631f4f..bfdf056 100644
105980 --- a/net/rxrpc/ar-connection.c
105981 +++ b/net/rxrpc/ar-connection.c
105982 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
105983 rwlock_init(&conn->lock);
105984 spin_lock_init(&conn->state_lock);
105985 atomic_set(&conn->usage, 1);
105986 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
105987 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105988 conn->avail_calls = RXRPC_MAXCALLS;
105989 conn->size_align = 4;
105990 conn->header_size = sizeof(struct rxrpc_header);
105991 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
105992 index e7ed43a..6afa140 100644
105993 --- a/net/rxrpc/ar-connevent.c
105994 +++ b/net/rxrpc/ar-connevent.c
105995 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
105996
105997 len = iov[0].iov_len + iov[1].iov_len;
105998
105999 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106000 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106001 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
106002
106003 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106004 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
106005 index 481f89f..ceeaf8d 100644
106006 --- a/net/rxrpc/ar-input.c
106007 +++ b/net/rxrpc/ar-input.c
106008 @@ -331,9 +331,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
106009 /* track the latest serial number on this connection for ACK packet
106010 * information */
106011 serial = ntohl(sp->hdr.serial);
106012 - hi_serial = atomic_read(&call->conn->hi_serial);
106013 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
106014 while (serial > hi_serial)
106015 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
106016 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
106017 serial);
106018
106019 /* request ACK generation for any ACK or DATA packet that requests
106020 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
106021 index ba9fd36..9bbfe01 100644
106022 --- a/net/rxrpc/ar-internal.h
106023 +++ b/net/rxrpc/ar-internal.h
106024 @@ -272,8 +272,8 @@ struct rxrpc_connection {
106025 int error; /* error code for local abort */
106026 int debug_id; /* debug ID for printks */
106027 unsigned int call_counter; /* call ID counter */
106028 - atomic_t serial; /* packet serial number counter */
106029 - atomic_t hi_serial; /* highest serial number received */
106030 + atomic_unchecked_t serial; /* packet serial number counter */
106031 + atomic_unchecked_t hi_serial; /* highest serial number received */
106032 u8 avail_calls; /* number of calls available */
106033 u8 size_align; /* data size alignment (for security) */
106034 u8 header_size; /* rxrpc + security header size */
106035 @@ -346,7 +346,7 @@ struct rxrpc_call {
106036 spinlock_t lock;
106037 rwlock_t state_lock; /* lock for state transition */
106038 atomic_t usage;
106039 - atomic_t sequence; /* Tx data packet sequence counter */
106040 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106041 u32 abort_code; /* local/remote abort code */
106042 enum { /* current state of call */
106043 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106044 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106045 */
106046 extern atomic_t rxrpc_n_skbs;
106047 extern __be32 rxrpc_epoch;
106048 -extern atomic_t rxrpc_debug_id;
106049 +extern atomic_unchecked_t rxrpc_debug_id;
106050 extern struct workqueue_struct *rxrpc_workqueue;
106051
106052 /*
106053 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106054 index 87f7135..74d3703 100644
106055 --- a/net/rxrpc/ar-local.c
106056 +++ b/net/rxrpc/ar-local.c
106057 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106058 spin_lock_init(&local->lock);
106059 rwlock_init(&local->services_lock);
106060 atomic_set(&local->usage, 1);
106061 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106062 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106063 memcpy(&local->srx, srx, sizeof(*srx));
106064 }
106065
106066 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106067 index 0b4b9a7..966ffbb 100644
106068 --- a/net/rxrpc/ar-output.c
106069 +++ b/net/rxrpc/ar-output.c
106070 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106071 memset(skb_put(skb, pad), 0, pad);
106072 }
106073
106074 - seq = atomic_inc_return(&call->sequence);
106075 + seq = atomic_inc_return_unchecked(&call->sequence);
106076
106077 sp->hdr.epoch = conn->epoch;
106078 sp->hdr.cid = call->cid;
106079 sp->hdr.callNumber = call->call_id;
106080 sp->hdr.seq = htonl(seq);
106081 sp->hdr.serial =
106082 - htonl(atomic_inc_return(&conn->serial));
106083 + htonl(atomic_inc_return_unchecked(&conn->serial));
106084 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106085 sp->hdr.userStatus = 0;
106086 sp->hdr.securityIndex = conn->security_ix;
106087 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106088 index bebaa43..2644591 100644
106089 --- a/net/rxrpc/ar-peer.c
106090 +++ b/net/rxrpc/ar-peer.c
106091 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106092 INIT_LIST_HEAD(&peer->error_targets);
106093 spin_lock_init(&peer->lock);
106094 atomic_set(&peer->usage, 1);
106095 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106096 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106097 memcpy(&peer->srx, srx, sizeof(*srx));
106098
106099 rxrpc_assess_MTU_size(peer);
106100 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106101 index 38047f7..9f48511 100644
106102 --- a/net/rxrpc/ar-proc.c
106103 +++ b/net/rxrpc/ar-proc.c
106104 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106105 atomic_read(&conn->usage),
106106 rxrpc_conn_states[conn->state],
106107 key_serial(conn->key),
106108 - atomic_read(&conn->serial),
106109 - atomic_read(&conn->hi_serial));
106110 + atomic_read_unchecked(&conn->serial),
106111 + atomic_read_unchecked(&conn->hi_serial));
106112
106113 return 0;
106114 }
106115 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106116 index 1976dec..aa70be5 100644
106117 --- a/net/rxrpc/ar-transport.c
106118 +++ b/net/rxrpc/ar-transport.c
106119 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106120 spin_lock_init(&trans->client_lock);
106121 rwlock_init(&trans->conn_lock);
106122 atomic_set(&trans->usage, 1);
106123 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106124 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106125
106126 if (peer->srx.transport.family == AF_INET) {
106127 switch (peer->srx.transport_type) {
106128 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106129 index f226709..0e735a8 100644
106130 --- a/net/rxrpc/rxkad.c
106131 +++ b/net/rxrpc/rxkad.c
106132 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106133
106134 len = iov[0].iov_len + iov[1].iov_len;
106135
106136 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106137 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106138 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106139
106140 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106141 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106142
106143 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106144
106145 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106146 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106147 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106148
106149 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106150 diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
106151 index aad6a67..baef987 100644
106152 --- a/net/sched/cls_api.c
106153 +++ b/net/sched/cls_api.c
106154 @@ -556,8 +556,9 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
106155 }
106156 EXPORT_SYMBOL(tcf_exts_change);
106157
106158 -#define tcf_exts_first_act(ext) \
106159 - list_first_entry(&(exts)->actions, struct tc_action, list)
106160 +#define tcf_exts_first_act(ext) \
106161 + list_first_entry_or_null(&(exts)->actions, \
106162 + struct tc_action, list)
106163
106164 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
106165 {
106166 @@ -603,7 +604,7 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
106167 {
106168 #ifdef CONFIG_NET_CLS_ACT
106169 struct tc_action *a = tcf_exts_first_act(exts);
106170 - if (tcf_action_copy_stats(skb, a, 1) < 0)
106171 + if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
106172 return -1;
106173 #endif
106174 return 0;
106175 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
106176 index eed49d1..ce22514 100644
106177 --- a/net/sched/cls_bpf.c
106178 +++ b/net/sched/cls_bpf.c
106179 @@ -191,6 +191,11 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
106180 }
106181
106182 bpf_size = bpf_len * sizeof(*bpf_ops);
106183 + if (bpf_size != nla_len(tb[TCA_BPF_OPS])) {
106184 + ret = -EINVAL;
106185 + goto errout;
106186 + }
106187 +
106188 bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
106189 if (bpf_ops == NULL) {
106190 ret = -ENOMEM;
106191 @@ -226,15 +231,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
106192 struct cls_bpf_head *head)
106193 {
106194 unsigned int i = 0x80000000;
106195 + u32 handle;
106196
106197 do {
106198 if (++head->hgen == 0x7FFFFFFF)
106199 head->hgen = 1;
106200 } while (--i > 0 && cls_bpf_get(tp, head->hgen));
106201 - if (i == 0)
106202 +
106203 + if (unlikely(i == 0)) {
106204 pr_err("Insufficient number of handles\n");
106205 + handle = 0;
106206 + } else {
106207 + handle = head->hgen;
106208 + }
106209
106210 - return i;
106211 + return handle;
106212 }
106213
106214 static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
106215 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106216 index 6efca30..1259f82 100644
106217 --- a/net/sched/sch_generic.c
106218 +++ b/net/sched/sch_generic.c
106219 @@ -349,7 +349,7 @@ void netif_carrier_on(struct net_device *dev)
106220 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106221 if (dev->reg_state == NETREG_UNINITIALIZED)
106222 return;
106223 - atomic_inc(&dev->carrier_changes);
106224 + atomic_inc_unchecked(&dev->carrier_changes);
106225 linkwatch_fire_event(dev);
106226 if (netif_running(dev))
106227 __netdev_watchdog_up(dev);
106228 @@ -368,7 +368,7 @@ void netif_carrier_off(struct net_device *dev)
106229 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106230 if (dev->reg_state == NETREG_UNINITIALIZED)
106231 return;
106232 - atomic_inc(&dev->carrier_changes);
106233 + atomic_inc_unchecked(&dev->carrier_changes);
106234 linkwatch_fire_event(dev);
106235 }
106236 }
106237 diff --git a/net/sctp/associola.c b/net/sctp/associola.c
106238 index f791edd..26d06db 100644
106239 --- a/net/sctp/associola.c
106240 +++ b/net/sctp/associola.c
106241 @@ -1182,7 +1182,6 @@ void sctp_assoc_update(struct sctp_association *asoc,
106242 asoc->peer.peer_hmacs = new->peer.peer_hmacs;
106243 new->peer.peer_hmacs = NULL;
106244
106245 - sctp_auth_key_put(asoc->asoc_shared_key);
106246 sctp_auth_asoc_init_active_key(asoc, GFP_ATOMIC);
106247 }
106248
106249 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106250 index 0e4198e..f94193e 100644
106251 --- a/net/sctp/ipv6.c
106252 +++ b/net/sctp/ipv6.c
106253 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106254 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106255 };
106256
106257 -static struct sctp_af sctp_af_inet6 = {
106258 +static struct sctp_af sctp_af_inet6 __read_only = {
106259 .sa_family = AF_INET6,
106260 .sctp_xmit = sctp_v6_xmit,
106261 .setsockopt = ipv6_setsockopt,
106262 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106263 #endif
106264 };
106265
106266 -static struct sctp_pf sctp_pf_inet6 = {
106267 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106268 .event_msgname = sctp_inet6_event_msgname,
106269 .skb_msgname = sctp_inet6_skb_msgname,
106270 .af_supported = sctp_inet6_af_supported,
106271 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106272
106273 void sctp_v6_pf_exit(void)
106274 {
106275 - list_del(&sctp_af_inet6.list);
106276 + pax_list_del(&sctp_af_inet6.list);
106277 }
106278
106279 /* Initialize IPv6 support and register with socket layer. */
106280 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106281 index 8f34b27..b105385 100644
106282 --- a/net/sctp/protocol.c
106283 +++ b/net/sctp/protocol.c
106284 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106285 return 0;
106286 }
106287
106288 + pax_open_kernel();
106289 INIT_LIST_HEAD(&af->list);
106290 - list_add_tail(&af->list, &sctp_address_families);
106291 + pax_close_kernel();
106292 + pax_list_add_tail(&af->list, &sctp_address_families);
106293 return 1;
106294 }
106295
106296 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106297
106298 static struct sctp_af sctp_af_inet;
106299
106300 -static struct sctp_pf sctp_pf_inet = {
106301 +static struct sctp_pf sctp_pf_inet __read_only = {
106302 .event_msgname = sctp_inet_event_msgname,
106303 .skb_msgname = sctp_inet_skb_msgname,
106304 .af_supported = sctp_inet_af_supported,
106305 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106306 };
106307
106308 /* IPv4 address related functions. */
106309 -static struct sctp_af sctp_af_inet = {
106310 +static struct sctp_af sctp_af_inet __read_only = {
106311 .sa_family = AF_INET,
106312 .sctp_xmit = sctp_v4_xmit,
106313 .setsockopt = ip_setsockopt,
106314 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106315
106316 static void sctp_v4_pf_exit(void)
106317 {
106318 - list_del(&sctp_af_inet.list);
106319 + pax_list_del(&sctp_af_inet.list);
106320 }
106321
106322 static int sctp_v4_protosw_init(void)
106323 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106324 index fef2acd..c705c4f 100644
106325 --- a/net/sctp/sm_sideeffect.c
106326 +++ b/net/sctp/sm_sideeffect.c
106327 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106328 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106329 }
106330
106331 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106332 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106333 NULL,
106334 sctp_generate_t1_cookie_event,
106335 sctp_generate_t1_init_event,
106336 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106337 index 634a2ab..dfdaf9b 100644
106338 --- a/net/sctp/socket.c
106339 +++ b/net/sctp/socket.c
106340 @@ -1603,7 +1603,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106341 sctp_assoc_t associd = 0;
106342 sctp_cmsgs_t cmsgs = { NULL };
106343 sctp_scope_t scope;
106344 - bool fill_sinfo_ttl = false;
106345 + bool fill_sinfo_ttl = false, wait_connect = false;
106346 struct sctp_datamsg *datamsg;
106347 int msg_flags = msg->msg_flags;
106348 __u16 sinfo_flags = 0;
106349 @@ -1943,6 +1943,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106350 if (err < 0)
106351 goto out_free;
106352
106353 + wait_connect = true;
106354 pr_debug("%s: we associated primitively\n", __func__);
106355 }
106356
106357 @@ -1980,6 +1981,11 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106358 sctp_datamsg_put(datamsg);
106359 err = msg_len;
106360
106361 + if (unlikely(wait_connect)) {
106362 + timeo = sock_sndtimeo(sk, msg_flags & MSG_DONTWAIT);
106363 + sctp_wait_for_connect(asoc, &timeo);
106364 + }
106365 +
106366 /* If we are already past ASSOCIATE, the lower
106367 * layers are responsible for association cleanup.
106368 */
106369 @@ -2199,11 +2205,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106370 {
106371 struct sctp_association *asoc;
106372 struct sctp_ulpevent *event;
106373 + struct sctp_event_subscribe subscribe;
106374
106375 if (optlen > sizeof(struct sctp_event_subscribe))
106376 return -EINVAL;
106377 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106378 + if (copy_from_user(&subscribe, optval, optlen))
106379 return -EFAULT;
106380 + sctp_sk(sk)->subscribe = subscribe;
106381
106382 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106383 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106384 @@ -4372,13 +4380,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106385 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106386 int __user *optlen)
106387 {
106388 + struct sctp_event_subscribe subscribe;
106389 +
106390 if (len <= 0)
106391 return -EINVAL;
106392 if (len > sizeof(struct sctp_event_subscribe))
106393 len = sizeof(struct sctp_event_subscribe);
106394 if (put_user(len, optlen))
106395 return -EFAULT;
106396 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106397 + subscribe = sctp_sk(sk)->subscribe;
106398 + if (copy_to_user(optval, &subscribe, len))
106399 return -EFAULT;
106400 return 0;
106401 }
106402 @@ -4396,6 +4407,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106403 */
106404 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106405 {
106406 + __u32 autoclose;
106407 +
106408 /* Applicable to UDP-style socket only */
106409 if (sctp_style(sk, TCP))
106410 return -EOPNOTSUPP;
106411 @@ -4404,7 +4417,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106412 len = sizeof(int);
106413 if (put_user(len, optlen))
106414 return -EFAULT;
106415 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106416 + autoclose = sctp_sk(sk)->autoclose;
106417 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106418 return -EFAULT;
106419 return 0;
106420 }
106421 @@ -4778,12 +4792,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106422 */
106423 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106424 {
106425 + struct sctp_initmsg initmsg;
106426 +
106427 if (len < sizeof(struct sctp_initmsg))
106428 return -EINVAL;
106429 len = sizeof(struct sctp_initmsg);
106430 if (put_user(len, optlen))
106431 return -EFAULT;
106432 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106433 + initmsg = sctp_sk(sk)->initmsg;
106434 + if (copy_to_user(optval, &initmsg, len))
106435 return -EFAULT;
106436 return 0;
106437 }
106438 @@ -4824,6 +4841,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106439 ->addr_to_user(sp, &temp);
106440 if (space_left < addrlen)
106441 return -ENOMEM;
106442 + if (addrlen > sizeof(temp) || addrlen < 0)
106443 + return -EFAULT;
106444 if (copy_to_user(to, &temp, addrlen))
106445 return -EFAULT;
106446 to += addrlen;
106447 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106448 index 2e9ada1..40f425d 100644
106449 --- a/net/sctp/sysctl.c
106450 +++ b/net/sctp/sysctl.c
106451 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106452 loff_t *ppos)
106453 {
106454 struct net *net = current->nsproxy->net_ns;
106455 - struct ctl_table tbl;
106456 + ctl_table_no_const tbl;
106457 bool changed = false;
106458 char *none = "none";
106459 char tmp[8];
106460 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106461 struct net *net = current->nsproxy->net_ns;
106462 unsigned int min = *(unsigned int *) ctl->extra1;
106463 unsigned int max = *(unsigned int *) ctl->extra2;
106464 - struct ctl_table tbl;
106465 + ctl_table_no_const tbl;
106466 int ret, new_value;
106467
106468 memset(&tbl, 0, sizeof(struct ctl_table));
106469 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106470 struct net *net = current->nsproxy->net_ns;
106471 unsigned int min = *(unsigned int *) ctl->extra1;
106472 unsigned int max = *(unsigned int *) ctl->extra2;
106473 - struct ctl_table tbl;
106474 + ctl_table_no_const tbl;
106475 int ret, new_value;
106476
106477 memset(&tbl, 0, sizeof(struct ctl_table));
106478 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106479 loff_t *ppos)
106480 {
106481 struct net *net = current->nsproxy->net_ns;
106482 - struct ctl_table tbl;
106483 + ctl_table_no_const tbl;
106484 int new_value, ret;
106485
106486 memset(&tbl, 0, sizeof(struct ctl_table));
106487 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106488
106489 int sctp_sysctl_net_register(struct net *net)
106490 {
106491 - struct ctl_table *table;
106492 + ctl_table_no_const *table;
106493 int i;
106494
106495 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106496 diff --git a/net/socket.c b/net/socket.c
106497 index fe20c31..83a0ed6 100644
106498 --- a/net/socket.c
106499 +++ b/net/socket.c
106500 @@ -89,6 +89,7 @@
106501 #include <linux/magic.h>
106502 #include <linux/slab.h>
106503 #include <linux/xattr.h>
106504 +#include <linux/in.h>
106505
106506 #include <asm/uaccess.h>
106507 #include <asm/unistd.h>
106508 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106509 unsigned int sysctl_net_busy_poll __read_mostly;
106510 #endif
106511
106512 +#include <linux/grsock.h>
106513 +
106514 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106515 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106516 unsigned long nr_segs, loff_t pos);
106517 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106518 */
106519
106520 static DEFINE_SPINLOCK(net_family_lock);
106521 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106522 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106523
106524 /*
106525 * Statistics counters of the socket lists
106526 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106527 &sockfs_dentry_operations, SOCKFS_MAGIC);
106528 }
106529
106530 -static struct vfsmount *sock_mnt __read_mostly;
106531 +struct vfsmount *sock_mnt __read_mostly;
106532
106533 static struct file_system_type sock_fs_type = {
106534 .name = "sockfs",
106535 @@ -1263,6 +1266,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106536 return -EAFNOSUPPORT;
106537 if (type < 0 || type >= SOCK_MAX)
106538 return -EINVAL;
106539 + if (protocol < 0)
106540 + return -EINVAL;
106541
106542 /* Compatibility.
106543
106544 @@ -1283,6 +1288,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106545 if (err)
106546 return err;
106547
106548 + if(!kern && !gr_search_socket(family, type, protocol)) {
106549 + if (rcu_access_pointer(net_families[family]) == NULL)
106550 + return -EAFNOSUPPORT;
106551 + else
106552 + return -EACCES;
106553 + }
106554 +
106555 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106556 + if (rcu_access_pointer(net_families[family]) == NULL)
106557 + return -EAFNOSUPPORT;
106558 + else
106559 + return -EACCES;
106560 + }
106561 +
106562 /*
106563 * Allocate the socket and allow the family to set things up. if
106564 * the protocol is 0, the family is instructed to select an appropriate
106565 @@ -1534,6 +1553,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106566 if (sock) {
106567 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106568 if (err >= 0) {
106569 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106570 + err = -EACCES;
106571 + goto error;
106572 + }
106573 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106574 + if (err)
106575 + goto error;
106576 +
106577 err = security_socket_bind(sock,
106578 (struct sockaddr *)&address,
106579 addrlen);
106580 @@ -1542,6 +1569,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106581 (struct sockaddr *)
106582 &address, addrlen);
106583 }
106584 +error:
106585 fput_light(sock->file, fput_needed);
106586 }
106587 return err;
106588 @@ -1565,10 +1593,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106589 if ((unsigned int)backlog > somaxconn)
106590 backlog = somaxconn;
106591
106592 + if (gr_handle_sock_server_other(sock->sk)) {
106593 + err = -EPERM;
106594 + goto error;
106595 + }
106596 +
106597 + err = gr_search_listen(sock);
106598 + if (err)
106599 + goto error;
106600 +
106601 err = security_socket_listen(sock, backlog);
106602 if (!err)
106603 err = sock->ops->listen(sock, backlog);
106604
106605 +error:
106606 fput_light(sock->file, fput_needed);
106607 }
106608 return err;
106609 @@ -1612,6 +1650,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106610 newsock->type = sock->type;
106611 newsock->ops = sock->ops;
106612
106613 + if (gr_handle_sock_server_other(sock->sk)) {
106614 + err = -EPERM;
106615 + sock_release(newsock);
106616 + goto out_put;
106617 + }
106618 +
106619 + err = gr_search_accept(sock);
106620 + if (err) {
106621 + sock_release(newsock);
106622 + goto out_put;
106623 + }
106624 +
106625 /*
106626 * We don't need try_module_get here, as the listening socket (sock)
106627 * has the protocol module (sock->ops->owner) held.
106628 @@ -1657,6 +1707,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106629 fd_install(newfd, newfile);
106630 err = newfd;
106631
106632 + gr_attach_curr_ip(newsock->sk);
106633 +
106634 out_put:
106635 fput_light(sock->file, fput_needed);
106636 out:
106637 @@ -1689,6 +1741,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106638 int, addrlen)
106639 {
106640 struct socket *sock;
106641 + struct sockaddr *sck;
106642 struct sockaddr_storage address;
106643 int err, fput_needed;
106644
106645 @@ -1699,6 +1752,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106646 if (err < 0)
106647 goto out_put;
106648
106649 + sck = (struct sockaddr *)&address;
106650 +
106651 + if (gr_handle_sock_client(sck)) {
106652 + err = -EACCES;
106653 + goto out_put;
106654 + }
106655 +
106656 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106657 + if (err)
106658 + goto out_put;
106659 +
106660 err =
106661 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106662 if (err)
106663 @@ -1780,6 +1844,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106664 * the protocol.
106665 */
106666
106667 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106668 +
106669 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106670 unsigned int, flags, struct sockaddr __user *, addr,
106671 int, addr_len)
106672 @@ -1846,7 +1912,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106673 struct socket *sock;
106674 struct iovec iov;
106675 struct msghdr msg;
106676 - struct sockaddr_storage address;
106677 + struct sockaddr_storage address = { };
106678 int err, err2;
106679 int fput_needed;
106680
106681 @@ -2075,7 +2141,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106682 * checking falls down on this.
106683 */
106684 if (copy_from_user(ctl_buf,
106685 - (void __user __force *)msg_sys->msg_control,
106686 + (void __force_user *)msg_sys->msg_control,
106687 ctl_len))
106688 goto out_freectl;
106689 msg_sys->msg_control = ctl_buf;
106690 @@ -2226,7 +2292,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106691 int err, total_len, len;
106692
106693 /* kernel mode address */
106694 - struct sockaddr_storage addr;
106695 + struct sockaddr_storage addr = { };
106696
106697 /* user mode address pointers */
106698 struct sockaddr __user *uaddr;
106699 @@ -2255,7 +2321,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106700 /* Save the user-mode address (verify_iovec will change the
106701 * kernel msghdr to use the kernel address space)
106702 */
106703 - uaddr = (__force void __user *)msg_sys->msg_name;
106704 + uaddr = (void __force_user *)msg_sys->msg_name;
106705 uaddr_len = COMPAT_NAMELEN(msg);
106706 if (MSG_CMSG_COMPAT & flags)
106707 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106708 @@ -2896,7 +2962,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106709 ifr = compat_alloc_user_space(buf_size);
106710 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106711
106712 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106713 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106714 return -EFAULT;
106715
106716 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106717 @@ -3007,7 +3073,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106718 old_fs = get_fs();
106719 set_fs(KERNEL_DS);
106720 err = dev_ioctl(net, cmd,
106721 - (struct ifreq __user __force *) &kifr);
106722 + (struct ifreq __force_user *) &kifr);
106723 set_fs(old_fs);
106724
106725 return err;
106726 @@ -3100,7 +3166,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106727
106728 old_fs = get_fs();
106729 set_fs(KERNEL_DS);
106730 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106731 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106732 set_fs(old_fs);
106733
106734 if (cmd == SIOCGIFMAP && !err) {
106735 @@ -3184,7 +3250,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106736 ret |= get_user(rtdev, &(ur4->rt_dev));
106737 if (rtdev) {
106738 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106739 - r4.rt_dev = (char __user __force *)devname;
106740 + r4.rt_dev = (char __force_user *)devname;
106741 devname[15] = 0;
106742 } else
106743 r4.rt_dev = NULL;
106744 @@ -3411,8 +3477,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106745 int __user *uoptlen;
106746 int err;
106747
106748 - uoptval = (char __user __force *) optval;
106749 - uoptlen = (int __user __force *) optlen;
106750 + uoptval = (char __force_user *) optval;
106751 + uoptlen = (int __force_user *) optlen;
106752
106753 set_fs(KERNEL_DS);
106754 if (level == SOL_SOCKET)
106755 @@ -3432,7 +3498,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106756 char __user *uoptval;
106757 int err;
106758
106759 - uoptval = (char __user __force *) optval;
106760 + uoptval = (char __force_user *) optval;
106761
106762 set_fs(KERNEL_DS);
106763 if (level == SOL_SOCKET)
106764 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106765 index c548ab2..4e1b68b 100644
106766 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106767 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106768 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106769 uint64_t *handle)
106770 {
106771 struct rsc rsci, *rscp = NULL;
106772 - static atomic64_t ctxhctr;
106773 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106774 long long ctxh;
106775 struct gss_api_mech *gm = NULL;
106776 time_t expiry;
106777 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106778 status = -ENOMEM;
106779 /* the handle needs to be just a unique id,
106780 * use a static counter */
106781 - ctxh = atomic64_inc_return(&ctxhctr);
106782 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106783
106784 /* make a copy for the caller */
106785 *handle = ctxh;
106786 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106787 index 0663621..c4928d4 100644
106788 --- a/net/sunrpc/cache.c
106789 +++ b/net/sunrpc/cache.c
106790 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106791 struct sunrpc_net *sn;
106792
106793 sn = net_generic(net, sunrpc_net_id);
106794 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106795 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106796 if (cd->u.procfs.proc_ent == NULL)
106797 goto out_nomem;
106798 cd->u.procfs.channel_ent = NULL;
106799 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106800 index 9acd6ce..4353a72 100644
106801 --- a/net/sunrpc/clnt.c
106802 +++ b/net/sunrpc/clnt.c
106803 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106804 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106805
106806 /* Increment call count */
106807 - task->tk_msg.rpc_proc->p_count++;
106808 + pax_open_kernel();
106809 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106810 + pax_close_kernel();
106811 clnt->cl_stats->rpccnt++;
106812 task->tk_action = call_reserve;
106813 }
106814 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106815 index fe3441a..922c29e 100644
106816 --- a/net/sunrpc/sched.c
106817 +++ b/net/sunrpc/sched.c
106818 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106819 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106820 static void rpc_task_set_debuginfo(struct rpc_task *task)
106821 {
106822 - static atomic_t rpc_pid;
106823 + static atomic_unchecked_t rpc_pid;
106824
106825 - task->tk_pid = atomic_inc_return(&rpc_pid);
106826 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106827 }
106828 #else
106829 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106830 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106831 index 5453049..465669a 100644
106832 --- a/net/sunrpc/stats.c
106833 +++ b/net/sunrpc/stats.c
106834 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106835
106836 dprintk("RPC: registering /proc/net/rpc\n");
106837 sn = net_generic(net, sunrpc_net_id);
106838 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106839 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106840 if (sn->proc_net_rpc == NULL)
106841 return -ENOMEM;
106842
106843 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106844 index ca8a795..ddfc41b 100644
106845 --- a/net/sunrpc/svc.c
106846 +++ b/net/sunrpc/svc.c
106847 @@ -1165,7 +1165,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106848 svc_putnl(resv, RPC_SUCCESS);
106849
106850 /* Bump per-procedure stats counter */
106851 - procp->pc_count++;
106852 + pax_open_kernel();
106853 + (*(unsigned int *)&procp->pc_count)++;
106854 + pax_close_kernel();
106855
106856 /* Initialize storage for argp and resp */
106857 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106858 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106859 index 621ca7b..59421dd 100644
106860 --- a/net/sunrpc/svcauth_unix.c
106861 +++ b/net/sunrpc/svcauth_unix.c
106862 @@ -414,7 +414,7 @@ struct unix_gid {
106863 struct group_info *gi;
106864 };
106865
106866 -static int unix_gid_hash(kuid_t uid)
106867 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106868 {
106869 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106870 }
106871 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106872 (*bpp)[-1] = '\n';
106873 }
106874
106875 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106876 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106877
106878 static int unix_gid_parse(struct cache_detail *cd,
106879 char *mesg, int mlen)
106880 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106881 index c1b6270..05089c1 100644
106882 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106883 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106884 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106885 static unsigned int min_max_inline = 4096;
106886 static unsigned int max_max_inline = 65536;
106887
106888 -atomic_t rdma_stat_recv;
106889 -atomic_t rdma_stat_read;
106890 -atomic_t rdma_stat_write;
106891 -atomic_t rdma_stat_sq_starve;
106892 -atomic_t rdma_stat_rq_starve;
106893 -atomic_t rdma_stat_rq_poll;
106894 -atomic_t rdma_stat_rq_prod;
106895 -atomic_t rdma_stat_sq_poll;
106896 -atomic_t rdma_stat_sq_prod;
106897 +atomic_unchecked_t rdma_stat_recv;
106898 +atomic_unchecked_t rdma_stat_read;
106899 +atomic_unchecked_t rdma_stat_write;
106900 +atomic_unchecked_t rdma_stat_sq_starve;
106901 +atomic_unchecked_t rdma_stat_rq_starve;
106902 +atomic_unchecked_t rdma_stat_rq_poll;
106903 +atomic_unchecked_t rdma_stat_rq_prod;
106904 +atomic_unchecked_t rdma_stat_sq_poll;
106905 +atomic_unchecked_t rdma_stat_sq_prod;
106906
106907 /* Temporary NFS request map and context caches */
106908 struct kmem_cache *svc_rdma_map_cachep;
106909 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
106910 len -= *ppos;
106911 if (len > *lenp)
106912 len = *lenp;
106913 - if (len && copy_to_user(buffer, str_buf, len))
106914 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
106915 return -EFAULT;
106916 *lenp = len;
106917 *ppos += len;
106918 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
106919 {
106920 .procname = "rdma_stat_read",
106921 .data = &rdma_stat_read,
106922 - .maxlen = sizeof(atomic_t),
106923 + .maxlen = sizeof(atomic_unchecked_t),
106924 .mode = 0644,
106925 .proc_handler = read_reset_stat,
106926 },
106927 {
106928 .procname = "rdma_stat_recv",
106929 .data = &rdma_stat_recv,
106930 - .maxlen = sizeof(atomic_t),
106931 + .maxlen = sizeof(atomic_unchecked_t),
106932 .mode = 0644,
106933 .proc_handler = read_reset_stat,
106934 },
106935 {
106936 .procname = "rdma_stat_write",
106937 .data = &rdma_stat_write,
106938 - .maxlen = sizeof(atomic_t),
106939 + .maxlen = sizeof(atomic_unchecked_t),
106940 .mode = 0644,
106941 .proc_handler = read_reset_stat,
106942 },
106943 {
106944 .procname = "rdma_stat_sq_starve",
106945 .data = &rdma_stat_sq_starve,
106946 - .maxlen = sizeof(atomic_t),
106947 + .maxlen = sizeof(atomic_unchecked_t),
106948 .mode = 0644,
106949 .proc_handler = read_reset_stat,
106950 },
106951 {
106952 .procname = "rdma_stat_rq_starve",
106953 .data = &rdma_stat_rq_starve,
106954 - .maxlen = sizeof(atomic_t),
106955 + .maxlen = sizeof(atomic_unchecked_t),
106956 .mode = 0644,
106957 .proc_handler = read_reset_stat,
106958 },
106959 {
106960 .procname = "rdma_stat_rq_poll",
106961 .data = &rdma_stat_rq_poll,
106962 - .maxlen = sizeof(atomic_t),
106963 + .maxlen = sizeof(atomic_unchecked_t),
106964 .mode = 0644,
106965 .proc_handler = read_reset_stat,
106966 },
106967 {
106968 .procname = "rdma_stat_rq_prod",
106969 .data = &rdma_stat_rq_prod,
106970 - .maxlen = sizeof(atomic_t),
106971 + .maxlen = sizeof(atomic_unchecked_t),
106972 .mode = 0644,
106973 .proc_handler = read_reset_stat,
106974 },
106975 {
106976 .procname = "rdma_stat_sq_poll",
106977 .data = &rdma_stat_sq_poll,
106978 - .maxlen = sizeof(atomic_t),
106979 + .maxlen = sizeof(atomic_unchecked_t),
106980 .mode = 0644,
106981 .proc_handler = read_reset_stat,
106982 },
106983 {
106984 .procname = "rdma_stat_sq_prod",
106985 .data = &rdma_stat_sq_prod,
106986 - .maxlen = sizeof(atomic_t),
106987 + .maxlen = sizeof(atomic_unchecked_t),
106988 .mode = 0644,
106989 .proc_handler = read_reset_stat,
106990 },
106991 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106992 index e011027..9d3c4e1 100644
106993 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106994 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106995 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
106996 *page_no = pg_no;
106997 *page_offset = pg_off;
106998 ret = read;
106999 - atomic_inc(&rdma_stat_read);
107000 + atomic_inc_unchecked(&rdma_stat_read);
107001 return ret;
107002 err:
107003 svc_rdma_unmap_dma(ctxt);
107004 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
107005 *page_no = pg_no;
107006 *page_offset = pg_off;
107007 ret = read;
107008 - atomic_inc(&rdma_stat_read);
107009 + atomic_inc_unchecked(&rdma_stat_read);
107010 return ret;
107011 err:
107012 svc_rdma_unmap_dma(ctxt);
107013 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107014 dto_q);
107015 list_del_init(&ctxt->dto_q);
107016 } else {
107017 - atomic_inc(&rdma_stat_rq_starve);
107018 + atomic_inc_unchecked(&rdma_stat_rq_starve);
107019 clear_bit(XPT_DATA, &xprt->xpt_flags);
107020 ctxt = NULL;
107021 }
107022 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107023 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
107024 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
107025 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
107026 - atomic_inc(&rdma_stat_recv);
107027 + atomic_inc_unchecked(&rdma_stat_recv);
107028
107029 /* Build up the XDR from the receive buffers. */
107030 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
107031 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107032 index 9f1b506..2e0b321 100644
107033 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107034 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107035 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
107036 write_wr.wr.rdma.remote_addr = to;
107037
107038 /* Post It */
107039 - atomic_inc(&rdma_stat_write);
107040 + atomic_inc_unchecked(&rdma_stat_write);
107041 if (svc_rdma_send(xprt, &write_wr))
107042 goto err;
107043 return write_len - bc;
107044 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107045 index 4e61880..1f0d963 100644
107046 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
107047 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107048 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107049 return;
107050
107051 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
107052 - atomic_inc(&rdma_stat_rq_poll);
107053 + atomic_inc_unchecked(&rdma_stat_rq_poll);
107054
107055 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
107056 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
107057 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107058 }
107059
107060 if (ctxt)
107061 - atomic_inc(&rdma_stat_rq_prod);
107062 + atomic_inc_unchecked(&rdma_stat_rq_prod);
107063
107064 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
107065 /*
107066 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107067 return;
107068
107069 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
107070 - atomic_inc(&rdma_stat_sq_poll);
107071 + atomic_inc_unchecked(&rdma_stat_sq_poll);
107072 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
107073 int i;
107074
107075 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107076 }
107077
107078 if (ctxt)
107079 - atomic_inc(&rdma_stat_sq_prod);
107080 + atomic_inc_unchecked(&rdma_stat_sq_prod);
107081 }
107082
107083 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
107084 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
107085 spin_lock_bh(&xprt->sc_lock);
107086 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
107087 spin_unlock_bh(&xprt->sc_lock);
107088 - atomic_inc(&rdma_stat_sq_starve);
107089 + atomic_inc_unchecked(&rdma_stat_sq_starve);
107090
107091 /* See if we can opportunistically reap SQ WR to make room */
107092 sq_cq_reap(xprt);
107093 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
107094 index e7000be..e3b0ba7 100644
107095 --- a/net/sysctl_net.c
107096 +++ b/net/sysctl_net.c
107097 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
107098 kgid_t root_gid = make_kgid(net->user_ns, 0);
107099
107100 /* Allow network administrator to have same access as root. */
107101 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
107102 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
107103 uid_eq(root_uid, current_euid())) {
107104 int mode = (table->mode >> 6) & 7;
107105 return (mode << 6) | (mode << 3) | mode;
107106 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
107107 index 31b5cb2..566ff01 100644
107108 --- a/net/tipc/subscr.c
107109 +++ b/net/tipc/subscr.c
107110 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
107111 struct tipc_subscriber *subscriber = sub->subscriber;
107112 struct kvec msg_sect;
107113
107114 - msg_sect.iov_base = (void *)&sub->evt;
107115 + msg_sect.iov_base = &sub->evt;
107116 msg_sect.iov_len = sizeof(struct tipc_event);
107117 sub->evt.event = htohl(event, sub->swap);
107118 sub->evt.found_lower = htohl(found_lower, sub->swap);
107119 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
107120 index e968843..bc95776 100644
107121 --- a/net/unix/af_unix.c
107122 +++ b/net/unix/af_unix.c
107123 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
107124 err = -ECONNREFUSED;
107125 if (!S_ISSOCK(inode->i_mode))
107126 goto put_fail;
107127 +
107128 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
107129 + err = -EACCES;
107130 + goto put_fail;
107131 + }
107132 +
107133 u = unix_find_socket_byinode(inode);
107134 if (!u)
107135 goto put_fail;
107136 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
107137 if (u) {
107138 struct dentry *dentry;
107139 dentry = unix_sk(u)->path.dentry;
107140 +
107141 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107142 + err = -EPERM;
107143 + sock_put(u);
107144 + goto fail;
107145 + }
107146 +
107147 if (dentry)
107148 touch_atime(&unix_sk(u)->path);
107149 } else
107150 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107151 */
107152 err = security_path_mknod(&path, dentry, mode, 0);
107153 if (!err) {
107154 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107155 + err = -EACCES;
107156 + goto out;
107157 + }
107158 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107159 if (!err) {
107160 res->mnt = mntget(path.mnt);
107161 res->dentry = dget(dentry);
107162 + gr_handle_create(dentry, path.mnt);
107163 }
107164 }
107165 +out:
107166 done_path_create(&path, dentry);
107167 return err;
107168 }
107169 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107170 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107171 "Inode Path\n");
107172 else {
107173 - struct sock *s = v;
107174 + struct sock *s = v, *peer;
107175 struct unix_sock *u = unix_sk(s);
107176 unix_state_lock(s);
107177 + peer = unix_peer(s);
107178 + unix_state_unlock(s);
107179 +
107180 + unix_state_double_lock(s, peer);
107181
107182 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107183 s,
107184 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107185 }
107186 for ( ; i < len; i++)
107187 seq_putc(seq, u->addr->name->sun_path[i]);
107188 - }
107189 - unix_state_unlock(s);
107190 + } else if (peer)
107191 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107192 +
107193 + unix_state_double_unlock(s, peer);
107194 seq_putc(seq, '\n');
107195 }
107196
107197 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107198 index b3d5150..ff3a837 100644
107199 --- a/net/unix/sysctl_net_unix.c
107200 +++ b/net/unix/sysctl_net_unix.c
107201 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107202
107203 int __net_init unix_sysctl_register(struct net *net)
107204 {
107205 - struct ctl_table *table;
107206 + ctl_table_no_const *table;
107207
107208 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107209 if (table == NULL)
107210 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107211 index 9b7f207..2596621 100644
107212 --- a/net/vmw_vsock/vmci_transport_notify.c
107213 +++ b/net/vmw_vsock/vmci_transport_notify.c
107214 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107215
107216 /* Socket control packet based operations. */
107217 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107218 - vmci_transport_notify_pkt_socket_init,
107219 - vmci_transport_notify_pkt_socket_destruct,
107220 - vmci_transport_notify_pkt_poll_in,
107221 - vmci_transport_notify_pkt_poll_out,
107222 - vmci_transport_notify_pkt_handle_pkt,
107223 - vmci_transport_notify_pkt_recv_init,
107224 - vmci_transport_notify_pkt_recv_pre_block,
107225 - vmci_transport_notify_pkt_recv_pre_dequeue,
107226 - vmci_transport_notify_pkt_recv_post_dequeue,
107227 - vmci_transport_notify_pkt_send_init,
107228 - vmci_transport_notify_pkt_send_pre_block,
107229 - vmci_transport_notify_pkt_send_pre_enqueue,
107230 - vmci_transport_notify_pkt_send_post_enqueue,
107231 - vmci_transport_notify_pkt_process_request,
107232 - vmci_transport_notify_pkt_process_negotiate,
107233 + .socket_init = vmci_transport_notify_pkt_socket_init,
107234 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107235 + .poll_in = vmci_transport_notify_pkt_poll_in,
107236 + .poll_out = vmci_transport_notify_pkt_poll_out,
107237 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107238 + .recv_init = vmci_transport_notify_pkt_recv_init,
107239 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107240 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107241 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107242 + .send_init = vmci_transport_notify_pkt_send_init,
107243 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107244 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107245 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107246 + .process_request = vmci_transport_notify_pkt_process_request,
107247 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107248 };
107249 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107250 index dc9c792..3089de0 100644
107251 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107252 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107253 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107254
107255 /* Socket always on control packet based operations. */
107256 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107257 - vmci_transport_notify_pkt_socket_init,
107258 - vmci_transport_notify_pkt_socket_destruct,
107259 - vmci_transport_notify_pkt_poll_in,
107260 - vmci_transport_notify_pkt_poll_out,
107261 - vmci_transport_notify_pkt_handle_pkt,
107262 - vmci_transport_notify_pkt_recv_init,
107263 - vmci_transport_notify_pkt_recv_pre_block,
107264 - vmci_transport_notify_pkt_recv_pre_dequeue,
107265 - vmci_transport_notify_pkt_recv_post_dequeue,
107266 - vmci_transport_notify_pkt_send_init,
107267 - vmci_transport_notify_pkt_send_pre_block,
107268 - vmci_transport_notify_pkt_send_pre_enqueue,
107269 - vmci_transport_notify_pkt_send_post_enqueue,
107270 - vmci_transport_notify_pkt_process_request,
107271 - vmci_transport_notify_pkt_process_negotiate,
107272 + .socket_init = vmci_transport_notify_pkt_socket_init,
107273 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107274 + .poll_in = vmci_transport_notify_pkt_poll_in,
107275 + .poll_out = vmci_transport_notify_pkt_poll_out,
107276 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107277 + .recv_init = vmci_transport_notify_pkt_recv_init,
107278 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107279 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107280 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107281 + .send_init = vmci_transport_notify_pkt_send_init,
107282 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107283 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107284 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107285 + .process_request = vmci_transport_notify_pkt_process_request,
107286 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107287 };
107288 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107289 index c8717c1..08539f5 100644
107290 --- a/net/wireless/wext-core.c
107291 +++ b/net/wireless/wext-core.c
107292 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107293 */
107294
107295 /* Support for very large requests */
107296 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107297 - (user_length > descr->max_tokens)) {
107298 + if (user_length > descr->max_tokens) {
107299 /* Allow userspace to GET more than max so
107300 * we can support any size GET requests.
107301 * There is still a limit : -ENOMEM.
107302 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107303 }
107304 }
107305
107306 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107307 - /*
107308 - * If this is a GET, but not NOMAX, it means that the extra
107309 - * data is not bounded by userspace, but by max_tokens. Thus
107310 - * set the length to max_tokens. This matches the extra data
107311 - * allocation.
107312 - * The driver should fill it with the number of tokens it
107313 - * provided, and it may check iwp->length rather than having
107314 - * knowledge of max_tokens. If the driver doesn't change the
107315 - * iwp->length, this ioctl just copies back max_token tokens
107316 - * filled with zeroes. Hopefully the driver isn't claiming
107317 - * them to be valid data.
107318 - */
107319 - iwp->length = descr->max_tokens;
107320 - }
107321 -
107322 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107323
107324 iwp->length += essid_compat;
107325 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107326 index 4323952..a06dfe1 100644
107327 --- a/net/x25/sysctl_net_x25.c
107328 +++ b/net/x25/sysctl_net_x25.c
107329 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107330 .mode = 0644,
107331 .proc_handler = proc_dointvec,
107332 },
107333 - { 0, },
107334 + { },
107335 };
107336
107337 void __init x25_register_sysctl(void)
107338 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107339 index 0917f04..f4e3d8c 100644
107340 --- a/net/x25/x25_proc.c
107341 +++ b/net/x25/x25_proc.c
107342 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107343
107344 int __init x25_proc_init(void)
107345 {
107346 - if (!proc_mkdir("x25", init_net.proc_net))
107347 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107348 return -ENOMEM;
107349
107350 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107351 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107352 index 88bf289..7b0741b 100644
107353 --- a/net/xfrm/xfrm_policy.c
107354 +++ b/net/xfrm/xfrm_policy.c
107355 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107356 {
107357 policy->walk.dead = 1;
107358
107359 - atomic_inc(&policy->genid);
107360 + atomic_inc_unchecked(&policy->genid);
107361
107362 if (del_timer(&policy->polq.hold_timer))
107363 xfrm_pol_put(policy);
107364 @@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107365 hlist_add_head(&policy->bydst, chain);
107366 xfrm_pol_hold(policy);
107367 net->xfrm.policy_count[dir]++;
107368 - atomic_inc(&net->xfrm.flow_cache_genid);
107369 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107370
107371 /* After previous checking, family can either be AF_INET or AF_INET6 */
107372 if (policy->family == AF_INET)
107373 @@ -1871,7 +1871,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107374
107375 xdst->num_pols = num_pols;
107376 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107377 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107378 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107379
107380 return xdst;
107381 }
107382 @@ -2685,10 +2685,11 @@ void xfrm_garbage_collect(struct net *net)
107383 }
107384 EXPORT_SYMBOL(xfrm_garbage_collect);
107385
107386 -static void xfrm_garbage_collect_deferred(struct net *net)
107387 +void xfrm_garbage_collect_deferred(struct net *net)
107388 {
107389 flow_cache_flush_deferred(net);
107390 }
107391 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107392
107393 static void xfrm_init_pmtu(struct dst_entry *dst)
107394 {
107395 @@ -2738,7 +2739,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107396 if (xdst->xfrm_genid != dst->xfrm->genid)
107397 return 0;
107398 if (xdst->num_pols > 0 &&
107399 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107400 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107401 return 0;
107402
107403 mtu = dst_mtu(dst->child);
107404 @@ -2826,8 +2827,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107405 dst_ops->link_failure = xfrm_link_failure;
107406 if (likely(dst_ops->neigh_lookup == NULL))
107407 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107408 - if (likely(afinfo->garbage_collect == NULL))
107409 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107410 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107411 }
107412 spin_unlock(&xfrm_policy_afinfo_lock);
107413 @@ -2881,7 +2880,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107414 dst_ops->check = NULL;
107415 dst_ops->negative_advice = NULL;
107416 dst_ops->link_failure = NULL;
107417 - afinfo->garbage_collect = NULL;
107418 }
107419 return err;
107420 }
107421 @@ -3277,7 +3275,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107422 sizeof(pol->xfrm_vec[i].saddr));
107423 pol->xfrm_vec[i].encap_family = mp->new_family;
107424 /* flush bundles */
107425 - atomic_inc(&pol->genid);
107426 + atomic_inc_unchecked(&pol->genid);
107427 }
107428 }
107429
107430 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107431 index de971b6..b843409 100644
107432 --- a/net/xfrm/xfrm_state.c
107433 +++ b/net/xfrm/xfrm_state.c
107434 @@ -166,12 +166,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107435
107436 if (unlikely(afinfo == NULL))
107437 return -EAFNOSUPPORT;
107438 - typemap = afinfo->type_map;
107439 + typemap = (const struct xfrm_type **)afinfo->type_map;
107440 spin_lock_bh(&xfrm_type_lock);
107441
107442 - if (likely(typemap[type->proto] == NULL))
107443 + if (likely(typemap[type->proto] == NULL)) {
107444 + pax_open_kernel();
107445 typemap[type->proto] = type;
107446 - else
107447 + pax_close_kernel();
107448 + } else
107449 err = -EEXIST;
107450 spin_unlock_bh(&xfrm_type_lock);
107451 xfrm_state_put_afinfo(afinfo);
107452 @@ -187,13 +189,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107453
107454 if (unlikely(afinfo == NULL))
107455 return -EAFNOSUPPORT;
107456 - typemap = afinfo->type_map;
107457 + typemap = (const struct xfrm_type **)afinfo->type_map;
107458 spin_lock_bh(&xfrm_type_lock);
107459
107460 if (unlikely(typemap[type->proto] != type))
107461 err = -ENOENT;
107462 - else
107463 + else {
107464 + pax_open_kernel();
107465 typemap[type->proto] = NULL;
107466 + pax_close_kernel();
107467 + }
107468 spin_unlock_bh(&xfrm_type_lock);
107469 xfrm_state_put_afinfo(afinfo);
107470 return err;
107471 @@ -203,7 +208,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107472 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107473 {
107474 struct xfrm_state_afinfo *afinfo;
107475 - const struct xfrm_type **typemap;
107476 const struct xfrm_type *type;
107477 int modload_attempted = 0;
107478
107479 @@ -211,9 +215,8 @@ retry:
107480 afinfo = xfrm_state_get_afinfo(family);
107481 if (unlikely(afinfo == NULL))
107482 return NULL;
107483 - typemap = afinfo->type_map;
107484
107485 - type = typemap[proto];
107486 + type = afinfo->type_map[proto];
107487 if (unlikely(type && !try_module_get(type->owner)))
107488 type = NULL;
107489 if (!type && !modload_attempted) {
107490 @@ -247,7 +250,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107491 return -EAFNOSUPPORT;
107492
107493 err = -EEXIST;
107494 - modemap = afinfo->mode_map;
107495 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107496 spin_lock_bh(&xfrm_mode_lock);
107497 if (modemap[mode->encap])
107498 goto out;
107499 @@ -256,8 +259,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107500 if (!try_module_get(afinfo->owner))
107501 goto out;
107502
107503 - mode->afinfo = afinfo;
107504 + pax_open_kernel();
107505 + *(const void **)&mode->afinfo = afinfo;
107506 modemap[mode->encap] = mode;
107507 + pax_close_kernel();
107508 err = 0;
107509
107510 out:
107511 @@ -281,10 +286,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107512 return -EAFNOSUPPORT;
107513
107514 err = -ENOENT;
107515 - modemap = afinfo->mode_map;
107516 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107517 spin_lock_bh(&xfrm_mode_lock);
107518 if (likely(modemap[mode->encap] == mode)) {
107519 + pax_open_kernel();
107520 modemap[mode->encap] = NULL;
107521 + pax_close_kernel();
107522 module_put(mode->afinfo->owner);
107523 err = 0;
107524 }
107525 @@ -1505,10 +1512,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107526 u32 xfrm_get_acqseq(void)
107527 {
107528 u32 res;
107529 - static atomic_t acqseq;
107530 + static atomic_unchecked_t acqseq;
107531
107532 do {
107533 - res = atomic_inc_return(&acqseq);
107534 + res = atomic_inc_return_unchecked(&acqseq);
107535 } while (!res);
107536
107537 return res;
107538 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107539 index 05a6e3d..6716ec9 100644
107540 --- a/net/xfrm/xfrm_sysctl.c
107541 +++ b/net/xfrm/xfrm_sysctl.c
107542 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107543
107544 int __net_init xfrm_sysctl_init(struct net *net)
107545 {
107546 - struct ctl_table *table;
107547 + ctl_table_no_const *table;
107548
107549 __xfrm_sysctl_init(net);
107550
107551 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
107552 index 65e7b08..1b868d5 100644
107553 --- a/scripts/Kbuild.include
107554 +++ b/scripts/Kbuild.include
107555 @@ -144,7 +144,7 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3))
107556 # cc-ldoption
107557 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
107558 cc-ldoption = $(call try-run,\
107559 - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107560 + $(CC) $(1) -Wl,-r -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107561
107562 # ld-option
107563 # Usage: LDFLAGS += $(call ld-option, -X)
107564 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107565 index 649ce68..f6bc05c 100644
107566 --- a/scripts/Makefile.build
107567 +++ b/scripts/Makefile.build
107568 @@ -60,7 +60,7 @@ endif
107569 endif
107570
107571 # Do not include host rules unless needed
107572 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107573 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107574 include scripts/Makefile.host
107575 endif
107576
107577 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107578 index a609552..fde19cd 100644
107579 --- a/scripts/Makefile.clean
107580 +++ b/scripts/Makefile.clean
107581 @@ -41,7 +41,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107582 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107583 $(always) $(targets) $(clean-files) \
107584 $(host-progs) \
107585 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107586 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107587 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107588
107589 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107590
107591 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107592 index 133edfa..c9aa07f 100644
107593 --- a/scripts/Makefile.host
107594 +++ b/scripts/Makefile.host
107595 @@ -20,7 +20,19 @@
107596 # Will compile qconf as a C++ program, and menu as a C program.
107597 # They are linked as C++ code to the executable qconf
107598
107599 +# hostprogs-y := conf
107600 +# conf-objs := conf.o libkconfig.so
107601 +# libkconfig-objs := expr.o type.o
107602 +# Will create a shared library named libkconfig.so that consists of
107603 +# expr.o and type.o (they are both compiled as C code and the object files
107604 +# are made as position independent code).
107605 +# conf.c is compiled as a C program, and conf.o is linked together with
107606 +# libkconfig.so as the executable conf.
107607 +# Note: Shared libraries consisting of C++ files are not supported
107608 +
107609 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107610 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107611 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107612
107613 # C code
107614 # Executables compiled from a single .c file
107615 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107616 # C++ Object (.o) files compiled from .cc files
107617 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107618
107619 +# Shared libaries (only .c supported)
107620 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107621 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107622 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107623 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107624 +# Remove .so files from "xxx-objs"
107625 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107626 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107627 +
107628 +# Object (.o) files used by the shared libaries
107629 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107630 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107631 +
107632 # output directory for programs/.o files
107633 # hostprogs-y := tools/build may have been specified.
107634 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107635 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107636 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107637 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107638 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107639 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107640 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107641 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107642 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107643 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107644
107645 obj-dirs += $(host-objdirs)
107646 @@ -124,5 +153,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107647 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107648 $(call if_changed_dep,host-cxxobjs)
107649
107650 +# Compile .c file, create position independent .o file
107651 +# host-cshobjs -> .o
107652 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107653 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107654 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107655 + $(call if_changed_dep,host-cshobjs)
107656 +
107657 +# Compile .c file, create position independent .o file
107658 +# host-cxxshobjs -> .o
107659 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107660 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107661 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107662 + $(call if_changed_dep,host-cxxshobjs)
107663 +
107664 +# Link a shared library, based on position independent .o files
107665 +# *.o -> .so shared library (host-cshlib)
107666 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107667 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107668 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107669 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107670 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107671 + $(call if_changed,host-cshlib)
107672 +
107673 +# Link a shared library, based on position independent .o files
107674 +# *.o -> .so shared library (host-cxxshlib)
107675 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107676 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107677 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107678 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107679 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107680 + $(call if_changed,host-cxxshlib)
107681 +
107682 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107683 - $(host-cxxmulti) $(host-cxxobjs)
107684 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107685 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107686 index b304068..462d24e 100644
107687 --- a/scripts/basic/fixdep.c
107688 +++ b/scripts/basic/fixdep.c
107689 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107690 /*
107691 * Lookup a value in the configuration string.
107692 */
107693 -static int is_defined_config(const char *name, int len, unsigned int hash)
107694 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107695 {
107696 struct item *aux;
107697
107698 @@ -211,10 +211,10 @@ static void clear_config(void)
107699 /*
107700 * Record the use of a CONFIG_* word.
107701 */
107702 -static void use_config(const char *m, int slen)
107703 +static void use_config(const char *m, unsigned int slen)
107704 {
107705 unsigned int hash = strhash(m, slen);
107706 - int c, i;
107707 + unsigned int c, i;
107708
107709 if (is_defined_config(m, slen, hash))
107710 return;
107711 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107712
107713 static void parse_config_file(const char *map, size_t len)
107714 {
107715 - const int *end = (const int *) (map + len);
107716 + const unsigned int *end = (const unsigned int *) (map + len);
107717 /* start at +1, so that p can never be < map */
107718 - const int *m = (const int *) map + 1;
107719 + const unsigned int *m = (const unsigned int *) map + 1;
107720 const char *p, *q;
107721
107722 for (; m < end; m++) {
107723 @@ -435,7 +435,7 @@ static void print_deps(void)
107724 static void traps(void)
107725 {
107726 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107727 - int *p = (int *)test;
107728 + unsigned int *p = (unsigned int *)test;
107729
107730 if (*p != INT_CONF) {
107731 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107732 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107733 new file mode 100644
107734 index 0000000..42018ed
107735 --- /dev/null
107736 +++ b/scripts/gcc-plugin.sh
107737 @@ -0,0 +1,51 @@
107738 +#!/bin/sh
107739 +srctree=$(dirname "$0")
107740 +gccplugins_dir=$($3 -print-file-name=plugin)
107741 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107742 +#include "gcc-common.h"
107743 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107744 +#warning $2 CXX
107745 +#else
107746 +#warning $1 CC
107747 +#endif
107748 +EOF
107749 +)
107750 +
107751 +if [ $? -ne 0 ]
107752 +then
107753 + exit 1
107754 +fi
107755 +
107756 +case "$plugincc" in
107757 + *"$1 CC"*)
107758 + echo "$1"
107759 + exit 0
107760 + ;;
107761 +
107762 + *"$2 CXX"*)
107763 + # the c++ compiler needs another test, see below
107764 + ;;
107765 +
107766 + *)
107767 + exit 1
107768 + ;;
107769 +esac
107770 +
107771 +# we need a c++ compiler that supports the designated initializer GNU extension
107772 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107773 +#include "gcc-common.h"
107774 +class test {
107775 +public:
107776 + int test;
107777 +} test = {
107778 + .test = 1
107779 +};
107780 +EOF
107781 +)
107782 +
107783 +if [ $? -eq 0 ]
107784 +then
107785 + echo "$2"
107786 + exit 0
107787 +fi
107788 +exit 1
107789 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107790 index fdebd66..a349e33 100755
107791 --- a/scripts/headers_install.sh
107792 +++ b/scripts/headers_install.sh
107793 @@ -32,6 +32,7 @@ do
107794 FILE="$(basename "$i")"
107795 sed -r \
107796 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107797 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107798 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107799 -e 's@^#include <linux/compiler.h>@@' \
107800 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107801 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107802 index 86a4fe7..99e91f9 100755
107803 --- a/scripts/link-vmlinux.sh
107804 +++ b/scripts/link-vmlinux.sh
107805 @@ -166,7 +166,7 @@ else
107806 fi;
107807
107808 # final build of init/
107809 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107810 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107811
107812 kallsymso=""
107813 kallsyms_vmlinux=""
107814 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107815 index e614ef6..d9d2b01 100644
107816 --- a/scripts/mod/file2alias.c
107817 +++ b/scripts/mod/file2alias.c
107818 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107819 unsigned long size, unsigned long id_size,
107820 void *symval)
107821 {
107822 - int i;
107823 + unsigned int i;
107824
107825 if (size % id_size || size < id_size) {
107826 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107827 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107828 /* USB is special because the bcdDevice can be matched against a numeric range */
107829 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107830 static void do_usb_entry(void *symval,
107831 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107832 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107833 unsigned char range_lo, unsigned char range_hi,
107834 unsigned char max, struct module *mod)
107835 {
107836 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107837 {
107838 unsigned int devlo, devhi;
107839 unsigned char chi, clo, max;
107840 - int ndigits;
107841 + unsigned int ndigits;
107842
107843 DEF_FIELD(symval, usb_device_id, match_flags);
107844 DEF_FIELD(symval, usb_device_id, idVendor);
107845 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107846 for (i = 0; i < count; i++) {
107847 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107848 char acpi_id[sizeof(*id)];
107849 - int j;
107850 + unsigned int j;
107851
107852 buf_printf(&mod->dev_table_buf,
107853 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107854 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107855
107856 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107857 const char *id = (char *)(*devs)[j].id;
107858 - int i2, j2;
107859 + unsigned int i2, j2;
107860 int dup = 0;
107861
107862 if (!id[0])
107863 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107864 /* add an individual alias for every device entry */
107865 if (!dup) {
107866 char acpi_id[PNP_ID_LEN];
107867 - int k;
107868 + unsigned int k;
107869
107870 buf_printf(&mod->dev_table_buf,
107871 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107872 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107873 static int do_dmi_entry(const char *filename, void *symval,
107874 char *alias)
107875 {
107876 - int i, j;
107877 + unsigned int i, j;
107878 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107879 sprintf(alias, "dmi*");
107880
107881 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107882 index d439856..10c1eac 100644
107883 --- a/scripts/mod/modpost.c
107884 +++ b/scripts/mod/modpost.c
107885 @@ -921,6 +921,7 @@ enum mismatch {
107886 ANY_INIT_TO_ANY_EXIT,
107887 ANY_EXIT_TO_ANY_INIT,
107888 EXPORT_TO_INIT_EXIT,
107889 + DATA_TO_TEXT
107890 };
107891
107892 struct sectioncheck {
107893 @@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
107894 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
107895 .mismatch = EXPORT_TO_INIT_EXIT,
107896 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
107897 +},
107898 +/* Do not reference code from writable data */
107899 +{
107900 + .fromsec = { DATA_SECTIONS, NULL },
107901 + .tosec = { TEXT_SECTIONS, NULL },
107902 + .mismatch = DATA_TO_TEXT
107903 }
107904 };
107905
107906 @@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
107907 continue;
107908 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
107909 continue;
107910 - if (sym->st_value == addr)
107911 - return sym;
107912 /* Find a symbol nearby - addr are maybe negative */
107913 d = sym->st_value - addr;
107914 + if (d == 0)
107915 + return sym;
107916 if (d < 0)
107917 d = addr - sym->st_value;
107918 if (d < distance) {
107919 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
107920 tosym, prl_to, prl_to, tosym);
107921 free(prl_to);
107922 break;
107923 + case DATA_TO_TEXT:
107924 +#if 0
107925 + fprintf(stderr,
107926 + "The %s %s:%s references\n"
107927 + "the %s %s:%s%s\n",
107928 + from, fromsec, fromsym, to, tosec, tosym, to_p);
107929 +#endif
107930 + break;
107931 }
107932 fprintf(stderr, "\n");
107933 }
107934 @@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
107935 static void check_sec_ref(struct module *mod, const char *modname,
107936 struct elf_info *elf)
107937 {
107938 - int i;
107939 + unsigned int i;
107940 Elf_Shdr *sechdrs = elf->sechdrs;
107941
107942 /* Walk through all sections */
107943 @@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
107944 va_end(ap);
107945 }
107946
107947 -void buf_write(struct buffer *buf, const char *s, int len)
107948 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
107949 {
107950 if (buf->size - buf->pos < len) {
107951 buf->size += len + SZ;
107952 @@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
107953 if (fstat(fileno(file), &st) < 0)
107954 goto close_write;
107955
107956 - if (st.st_size != b->pos)
107957 + if (st.st_size != (off_t)b->pos)
107958 goto close_write;
107959
107960 tmp = NOFAIL(malloc(b->pos));
107961 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
107962 index 168b43d..77914bf 100644
107963 --- a/scripts/mod/modpost.h
107964 +++ b/scripts/mod/modpost.h
107965 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
107966
107967 struct buffer {
107968 char *p;
107969 - int pos;
107970 - int size;
107971 + unsigned int pos;
107972 + unsigned int size;
107973 };
107974
107975 void __attribute__((format(printf, 2, 3)))
107976 buf_printf(struct buffer *buf, const char *fmt, ...);
107977
107978 void
107979 -buf_write(struct buffer *buf, const char *s, int len);
107980 +buf_write(struct buffer *buf, const char *s, unsigned int len);
107981
107982 struct module {
107983 struct module *next;
107984 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
107985 index 944418d..15291e4 100644
107986 --- a/scripts/mod/sumversion.c
107987 +++ b/scripts/mod/sumversion.c
107988 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
107989 goto out;
107990 }
107991
107992 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
107993 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
107994 warn("writing sum in %s failed: %s\n",
107995 filename, strerror(errno));
107996 goto out;
107997 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
107998 index 0865b3e..7235dd4 100644
107999 --- a/scripts/module-common.lds
108000 +++ b/scripts/module-common.lds
108001 @@ -6,6 +6,10 @@
108002 SECTIONS {
108003 /DISCARD/ : { *(.discard) }
108004
108005 + .rodata : {
108006 + *(.rodata) *(.rodata.*)
108007 + *(.data..read_only)
108008 + }
108009 __ksymtab : { *(SORT(___ksymtab+*)) }
108010 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
108011 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
108012 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
108013 index 99ca6e7..3a1a1a1 100644
108014 --- a/scripts/package/Makefile
108015 +++ b/scripts/package/Makefile
108016 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
108017 ln -sf $(srctree) $(KERNELPATH)
108018 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
108019 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
108020 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108021 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108022 rm $(KERNELPATH)
108023 rm -f $(objtree)/.scmversion
108024 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
108025 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
108026 index 5972624..4028795 100755
108027 --- a/scripts/package/builddeb
108028 +++ b/scripts/package/builddeb
108029 @@ -293,6 +293,7 @@ fi
108030 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
108031 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
108032 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
108033 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
108034 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
108035 mkdir -p "$destdir"
108036 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
108037 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
108038 index 1395760..bca2734 100755
108039 --- a/scripts/package/mkspec
108040 +++ b/scripts/package/mkspec
108041 @@ -121,29 +121,40 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
108042 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
108043 echo "EXCLUDES=\"$RCS_TAR_IGNORE --exclude .tmp_versions --exclude=*vmlinux* --exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation --exclude=firmware --exclude .config.old --exclude .missing-syscalls.d\""
108044 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
108045 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
108046 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
108047 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
108048
108049 echo ""
108050 echo "%clean"
108051 echo 'rm -rf $RPM_BUILD_ROOT'
108052 echo ""
108053 +echo "%pre"
108054 +echo 'chmod -f 0500 /boot'
108055 +echo 'if [ -d /lib/modules ]; then'
108056 +echo 'chmod -f 0500 /lib/modules'
108057 +echo 'fi'
108058 +echo 'if [ -d /lib32/modules ]; then'
108059 +echo 'chmod -f 0500 /lib32/modules'
108060 +echo 'fi'
108061 +echo 'if [ -d /lib64/modules ]; then'
108062 +echo 'chmod -f 0500 /lib64/modules'
108063 +echo 'fi'
108064 +echo ""
108065 +echo "%post devel"
108066 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
108067 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
108068 +echo ""
108069 echo "%post"
108070 -echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
108071 -echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
108072 -echo "cp /boot/System.map-$KERNELRELEASE /boot/System.map-$KERNELRELEASE-rpm"
108073 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE"
108074 -echo "/sbin/installkernel $KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108075 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108076 +echo "if [ -x /sbin/dracut ]; then"
108077 +echo '/sbin/new-kernel-pkg --dracut --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108078 +echo "else"
108079 +echo '/sbin/new-kernel-pkg --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108080 echo "fi"
108081 echo ""
108082 echo "%files"
108083 -echo '%defattr (-, root, root)'
108084 +echo '%defattr (400, root, root, 500)'
108085 echo "%dir /lib/modules"
108086 -echo "/lib/modules/$KERNELRELEASE"
108087 echo "%exclude /lib/modules/$KERNELRELEASE/build"
108088 echo "%exclude /lib/modules/$KERNELRELEASE/source"
108089 +echo "/lib/modules/$KERNELRELEASE"
108090 echo "/lib/firmware/$KERNELRELEASE"
108091 echo "/boot/*"
108092 echo ""
108093 @@ -152,8 +163,7 @@ echo '%defattr (-, root, root)'
108094 echo "/usr/include"
108095 echo ""
108096 echo "%files devel"
108097 -echo '%defattr (-, root, root)'
108098 +echo '%defattr (400, root, root, 500)'
108099 +echo "%dir /lib/modules/$KERNELRELEASE"
108100 echo "/usr/src/kernels/$KERNELRELEASE"
108101 -echo "/lib/modules/$KERNELRELEASE/build"
108102 -echo "/lib/modules/$KERNELRELEASE/source"
108103 echo ""
108104 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
108105 index 4718d78..9220d58 100644
108106 --- a/scripts/pnmtologo.c
108107 +++ b/scripts/pnmtologo.c
108108 @@ -244,14 +244,14 @@ static void write_header(void)
108109 fprintf(out, " * Linux logo %s\n", logoname);
108110 fputs(" */\n\n", out);
108111 fputs("#include <linux/linux_logo.h>\n\n", out);
108112 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
108113 + fprintf(out, "static unsigned char %s_data[] = {\n",
108114 logoname);
108115 }
108116
108117 static void write_footer(void)
108118 {
108119 fputs("\n};\n\n", out);
108120 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
108121 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
108122 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
108123 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
108124 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
108125 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
108126 fputs("\n};\n\n", out);
108127
108128 /* write logo clut */
108129 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
108130 + fprintf(out, "static unsigned char %s_clut[] = {\n",
108131 logoname);
108132 write_hex_cnt = 0;
108133 for (i = 0; i < logo_clutsize; i++) {
108134 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
108135 index ba87004..3f4852c 100644
108136 --- a/scripts/sortextable.h
108137 +++ b/scripts/sortextable.h
108138 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
108139 const char *secstrtab;
108140 const char *strtab;
108141 char *extab_image;
108142 - int extab_index = 0;
108143 - int i;
108144 - int idx;
108145 + unsigned int extab_index = 0;
108146 + unsigned int i;
108147 + unsigned int idx;
108148 unsigned int num_sections;
108149 unsigned int secindex_strings;
108150
108151 diff --git a/scripts/tags.sh b/scripts/tags.sh
108152 index cdb491d..8d32bfc 100755
108153 --- a/scripts/tags.sh
108154 +++ b/scripts/tags.sh
108155 @@ -26,7 +26,7 @@ else
108156 fi
108157
108158 # ignore userspace tools
108159 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
108160 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
108161
108162 # Find all available archs
108163 find_all_archs()
108164 diff --git a/security/Kconfig b/security/Kconfig
108165 index beb86b5..1a953b1 100644
108166 --- a/security/Kconfig
108167 +++ b/security/Kconfig
108168 @@ -4,6 +4,974 @@
108169
108170 menu "Security options"
108171
108172 +menu "Grsecurity"
108173 +
108174 + config ARCH_TRACK_EXEC_LIMIT
108175 + bool
108176 +
108177 + config PAX_KERNEXEC_PLUGIN
108178 + bool
108179 +
108180 + config PAX_PER_CPU_PGD
108181 + bool
108182 +
108183 + config TASK_SIZE_MAX_SHIFT
108184 + int
108185 + depends on X86_64
108186 + default 47 if !PAX_PER_CPU_PGD
108187 + default 42 if PAX_PER_CPU_PGD
108188 +
108189 + config PAX_ENABLE_PAE
108190 + bool
108191 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
108192 +
108193 + config PAX_USERCOPY_SLABS
108194 + bool
108195 +
108196 +config GRKERNSEC
108197 + bool "Grsecurity"
108198 + select CRYPTO
108199 + select CRYPTO_SHA256
108200 + select PROC_FS
108201 + select STOP_MACHINE
108202 + select TTY
108203 + select DEBUG_KERNEL
108204 + select DEBUG_LIST
108205 + help
108206 + If you say Y here, you will be able to configure many features
108207 + that will enhance the security of your system. It is highly
108208 + recommended that you say Y here and read through the help
108209 + for each option so that you fully understand the features and
108210 + can evaluate their usefulness for your machine.
108211 +
108212 +choice
108213 + prompt "Configuration Method"
108214 + depends on GRKERNSEC
108215 + default GRKERNSEC_CONFIG_CUSTOM
108216 + help
108217 +
108218 +config GRKERNSEC_CONFIG_AUTO
108219 + bool "Automatic"
108220 + help
108221 + If you choose this configuration method, you'll be able to answer a small
108222 + number of simple questions about how you plan to use this kernel.
108223 + The settings of grsecurity and PaX will be automatically configured for
108224 + the highest commonly-used settings within the provided constraints.
108225 +
108226 + If you require additional configuration, custom changes can still be made
108227 + from the "custom configuration" menu.
108228 +
108229 +config GRKERNSEC_CONFIG_CUSTOM
108230 + bool "Custom"
108231 + help
108232 + If you choose this configuration method, you'll be able to configure all
108233 + grsecurity and PaX settings manually. Via this method, no options are
108234 + automatically enabled.
108235 +
108236 +endchoice
108237 +
108238 +choice
108239 + prompt "Usage Type"
108240 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108241 + default GRKERNSEC_CONFIG_SERVER
108242 + help
108243 +
108244 +config GRKERNSEC_CONFIG_SERVER
108245 + bool "Server"
108246 + help
108247 + Choose this option if you plan to use this kernel on a server.
108248 +
108249 +config GRKERNSEC_CONFIG_DESKTOP
108250 + bool "Desktop"
108251 + help
108252 + Choose this option if you plan to use this kernel on a desktop.
108253 +
108254 +endchoice
108255 +
108256 +choice
108257 + prompt "Virtualization Type"
108258 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108259 + default GRKERNSEC_CONFIG_VIRT_NONE
108260 + help
108261 +
108262 +config GRKERNSEC_CONFIG_VIRT_NONE
108263 + bool "None"
108264 + help
108265 + Choose this option if this kernel will be run on bare metal.
108266 +
108267 +config GRKERNSEC_CONFIG_VIRT_GUEST
108268 + bool "Guest"
108269 + help
108270 + Choose this option if this kernel will be run as a VM guest.
108271 +
108272 +config GRKERNSEC_CONFIG_VIRT_HOST
108273 + bool "Host"
108274 + help
108275 + Choose this option if this kernel will be run as a VM host.
108276 +
108277 +endchoice
108278 +
108279 +choice
108280 + prompt "Virtualization Hardware"
108281 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108282 + help
108283 +
108284 +config GRKERNSEC_CONFIG_VIRT_EPT
108285 + bool "EPT/RVI Processor Support"
108286 + depends on X86
108287 + help
108288 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108289 + hardware virtualization. This allows for additional kernel hardening protections
108290 + to operate without additional performance impact.
108291 +
108292 + To see if your Intel processor supports EPT, see:
108293 + http://ark.intel.com/Products/VirtualizationTechnology
108294 + (Most Core i3/5/7 support EPT)
108295 +
108296 + To see if your AMD processor supports RVI, see:
108297 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108298 +
108299 +config GRKERNSEC_CONFIG_VIRT_SOFT
108300 + bool "First-gen/No Hardware Virtualization"
108301 + help
108302 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108303 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108304 +
108305 +endchoice
108306 +
108307 +choice
108308 + prompt "Virtualization Software"
108309 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108310 + help
108311 +
108312 +config GRKERNSEC_CONFIG_VIRT_XEN
108313 + bool "Xen"
108314 + help
108315 + Choose this option if this kernel is running as a Xen guest or host.
108316 +
108317 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108318 + bool "VMWare"
108319 + help
108320 + Choose this option if this kernel is running as a VMWare guest or host.
108321 +
108322 +config GRKERNSEC_CONFIG_VIRT_KVM
108323 + bool "KVM"
108324 + help
108325 + Choose this option if this kernel is running as a KVM guest or host.
108326 +
108327 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108328 + bool "VirtualBox"
108329 + help
108330 + Choose this option if this kernel is running as a VirtualBox guest or host.
108331 +
108332 +config GRKERNSEC_CONFIG_VIRT_HYPERV
108333 + bool "Hyper-V"
108334 + help
108335 + Choose this option if this kernel is running as a Hyper-V guest.
108336 +
108337 +endchoice
108338 +
108339 +choice
108340 + prompt "Required Priorities"
108341 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108342 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108343 + help
108344 +
108345 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108346 + bool "Performance"
108347 + help
108348 + Choose this option if performance is of highest priority for this deployment
108349 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108350 + clearing of structures intended for userland, and freed memory sanitizing will
108351 + be disabled.
108352 +
108353 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108354 + bool "Security"
108355 + help
108356 + Choose this option if security is of highest priority for this deployment of
108357 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108358 + for userland, and freed memory sanitizing will be enabled for this kernel.
108359 + In a worst-case scenario, these features can introduce a 20% performance hit
108360 + (UDEREF on x64 contributing half of this hit).
108361 +
108362 +endchoice
108363 +
108364 +menu "Default Special Groups"
108365 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108366 +
108367 +config GRKERNSEC_PROC_GID
108368 + int "GID exempted from /proc restrictions"
108369 + default 1001
108370 + help
108371 + Setting this GID determines which group will be exempted from
108372 + grsecurity's /proc restrictions, allowing users of the specified
108373 + group to view network statistics and the existence of other users'
108374 + processes on the system. This GID may also be chosen at boot time
108375 + via "grsec_proc_gid=" on the kernel commandline.
108376 +
108377 +config GRKERNSEC_TPE_UNTRUSTED_GID
108378 + int "GID for TPE-untrusted users"
108379 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108380 + default 1005
108381 + help
108382 + Setting this GID determines which group untrusted users should
108383 + be added to. These users will be placed under grsecurity's Trusted Path
108384 + Execution mechanism, preventing them from executing their own binaries.
108385 + The users will only be able to execute binaries in directories owned and
108386 + writable only by the root user. If the sysctl option is enabled, a sysctl
108387 + option with name "tpe_gid" is created.
108388 +
108389 +config GRKERNSEC_TPE_TRUSTED_GID
108390 + int "GID for TPE-trusted users"
108391 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108392 + default 1005
108393 + help
108394 + Setting this GID determines what group TPE restrictions will be
108395 + *disabled* for. If the sysctl option is enabled, a sysctl option
108396 + with name "tpe_gid" is created.
108397 +
108398 +config GRKERNSEC_SYMLINKOWN_GID
108399 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108400 + depends on GRKERNSEC_CONFIG_SERVER
108401 + default 1006
108402 + help
108403 + Setting this GID determines what group kernel-enforced
108404 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108405 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108406 +
108407 +
108408 +endmenu
108409 +
108410 +menu "Customize Configuration"
108411 +depends on GRKERNSEC
108412 +
108413 +menu "PaX"
108414 +
108415 +config PAX
108416 + bool "Enable various PaX features"
108417 + default y if GRKERNSEC_CONFIG_AUTO
108418 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108419 + help
108420 + This allows you to enable various PaX features. PaX adds
108421 + intrusion prevention mechanisms to the kernel that reduce
108422 + the risks posed by exploitable memory corruption bugs.
108423 +
108424 +menu "PaX Control"
108425 + depends on PAX
108426 +
108427 +config PAX_SOFTMODE
108428 + bool 'Support soft mode'
108429 + help
108430 + Enabling this option will allow you to run PaX in soft mode, that
108431 + is, PaX features will not be enforced by default, only on executables
108432 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108433 + support as they are the only way to mark executables for soft mode use.
108434 +
108435 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108436 + line option on boot. Furthermore you can control various PaX features
108437 + at runtime via the entries in /proc/sys/kernel/pax.
108438 +
108439 +config PAX_EI_PAX
108440 + bool 'Use legacy ELF header marking'
108441 + default y if GRKERNSEC_CONFIG_AUTO
108442 + help
108443 + Enabling this option will allow you to control PaX features on
108444 + a per executable basis via the 'chpax' utility available at
108445 + http://pax.grsecurity.net/. The control flags will be read from
108446 + an otherwise reserved part of the ELF header. This marking has
108447 + numerous drawbacks (no support for soft-mode, toolchain does not
108448 + know about the non-standard use of the ELF header) therefore it
108449 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108450 + support.
108451 +
108452 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108453 + support as well, they will override the legacy EI_PAX marks.
108454 +
108455 + If you enable none of the marking options then all applications
108456 + will run with PaX enabled on them by default.
108457 +
108458 +config PAX_PT_PAX_FLAGS
108459 + bool 'Use ELF program header marking'
108460 + default y if GRKERNSEC_CONFIG_AUTO
108461 + help
108462 + Enabling this option will allow you to control PaX features on
108463 + a per executable basis via the 'paxctl' utility available at
108464 + http://pax.grsecurity.net/. The control flags will be read from
108465 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108466 + has the benefits of supporting both soft mode and being fully
108467 + integrated into the toolchain (the binutils patch is available
108468 + from http://pax.grsecurity.net).
108469 +
108470 + Note that if you enable the legacy EI_PAX marking support as well,
108471 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108472 +
108473 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108474 + must make sure that the marks are the same if a binary has both marks.
108475 +
108476 + If you enable none of the marking options then all applications
108477 + will run with PaX enabled on them by default.
108478 +
108479 +config PAX_XATTR_PAX_FLAGS
108480 + bool 'Use filesystem extended attributes marking'
108481 + default y if GRKERNSEC_CONFIG_AUTO
108482 + select CIFS_XATTR if CIFS
108483 + select F2FS_FS_XATTR if F2FS_FS
108484 + select EXT2_FS_XATTR if EXT2_FS
108485 + select EXT3_FS_XATTR if EXT3_FS
108486 + select JFFS2_FS_XATTR if JFFS2_FS
108487 + select REISERFS_FS_XATTR if REISERFS_FS
108488 + select SQUASHFS_XATTR if SQUASHFS
108489 + select TMPFS_XATTR if TMPFS
108490 + help
108491 + Enabling this option will allow you to control PaX features on
108492 + a per executable basis via the 'setfattr' utility. The control
108493 + flags will be read from the user.pax.flags extended attribute of
108494 + the file. This marking has the benefit of supporting binary-only
108495 + applications that self-check themselves (e.g., skype) and would
108496 + not tolerate chpax/paxctl changes. The main drawback is that
108497 + extended attributes are not supported by some filesystems (e.g.,
108498 + isofs, udf, vfat) so copying files through such filesystems will
108499 + lose the extended attributes and these PaX markings.
108500 +
108501 + Note that if you enable the legacy EI_PAX marking support as well,
108502 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108503 +
108504 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108505 + must make sure that the marks are the same if a binary has both marks.
108506 +
108507 + If you enable none of the marking options then all applications
108508 + will run with PaX enabled on them by default.
108509 +
108510 +choice
108511 + prompt 'MAC system integration'
108512 + default PAX_HAVE_ACL_FLAGS
108513 + help
108514 + Mandatory Access Control systems have the option of controlling
108515 + PaX flags on a per executable basis, choose the method supported
108516 + by your particular system.
108517 +
108518 + - "none": if your MAC system does not interact with PaX,
108519 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108520 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108521 +
108522 + NOTE: this option is for developers/integrators only.
108523 +
108524 + config PAX_NO_ACL_FLAGS
108525 + bool 'none'
108526 +
108527 + config PAX_HAVE_ACL_FLAGS
108528 + bool 'direct'
108529 +
108530 + config PAX_HOOK_ACL_FLAGS
108531 + bool 'hook'
108532 +endchoice
108533 +
108534 +endmenu
108535 +
108536 +menu "Non-executable pages"
108537 + depends on PAX
108538 +
108539 +config PAX_NOEXEC
108540 + bool "Enforce non-executable pages"
108541 + default y if GRKERNSEC_CONFIG_AUTO
108542 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108543 + help
108544 + By design some architectures do not allow for protecting memory
108545 + pages against execution or even if they do, Linux does not make
108546 + use of this feature. In practice this means that if a page is
108547 + readable (such as the stack or heap) it is also executable.
108548 +
108549 + There is a well known exploit technique that makes use of this
108550 + fact and a common programming mistake where an attacker can
108551 + introduce code of his choice somewhere in the attacked program's
108552 + memory (typically the stack or the heap) and then execute it.
108553 +
108554 + If the attacked program was running with different (typically
108555 + higher) privileges than that of the attacker, then he can elevate
108556 + his own privilege level (e.g. get a root shell, write to files for
108557 + which he does not have write access to, etc).
108558 +
108559 + Enabling this option will let you choose from various features
108560 + that prevent the injection and execution of 'foreign' code in
108561 + a program.
108562 +
108563 + This will also break programs that rely on the old behaviour and
108564 + expect that dynamically allocated memory via the malloc() family
108565 + of functions is executable (which it is not). Notable examples
108566 + are the XFree86 4.x server, the java runtime and wine.
108567 +
108568 +config PAX_PAGEEXEC
108569 + bool "Paging based non-executable pages"
108570 + default y if GRKERNSEC_CONFIG_AUTO
108571 + 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)
108572 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108573 + help
108574 + This implementation is based on the paging feature of the CPU.
108575 + On i386 without hardware non-executable bit support there is a
108576 + variable but usually low performance impact, however on Intel's
108577 + P4 core based CPUs it is very high so you should not enable this
108578 + for kernels meant to be used on such CPUs.
108579 +
108580 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108581 + with hardware non-executable bit support there is no performance
108582 + impact, on ppc the impact is negligible.
108583 +
108584 + Note that several architectures require various emulations due to
108585 + badly designed userland ABIs, this will cause a performance impact
108586 + but will disappear as soon as userland is fixed. For example, ppc
108587 + userland MUST have been built with secure-plt by a recent toolchain.
108588 +
108589 +config PAX_SEGMEXEC
108590 + bool "Segmentation based non-executable pages"
108591 + default y if GRKERNSEC_CONFIG_AUTO
108592 + depends on PAX_NOEXEC && X86_32
108593 + help
108594 + This implementation is based on the segmentation feature of the
108595 + CPU and has a very small performance impact, however applications
108596 + will be limited to a 1.5 GB address space instead of the normal
108597 + 3 GB.
108598 +
108599 +config PAX_EMUTRAMP
108600 + bool "Emulate trampolines"
108601 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108602 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108603 + help
108604 + There are some programs and libraries that for one reason or
108605 + another attempt to execute special small code snippets from
108606 + non-executable memory pages. Most notable examples are the
108607 + signal handler return code generated by the kernel itself and
108608 + the GCC trampolines.
108609 +
108610 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108611 + such programs will no longer work under your kernel.
108612 +
108613 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108614 + utilities to enable trampoline emulation for the affected programs
108615 + yet still have the protection provided by the non-executable pages.
108616 +
108617 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108618 + your system will not even boot.
108619 +
108620 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108621 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108622 + for the affected files.
108623 +
108624 + NOTE: enabling this feature *may* open up a loophole in the
108625 + protection provided by non-executable pages that an attacker
108626 + could abuse. Therefore the best solution is to not have any
108627 + files on your system that would require this option. This can
108628 + be achieved by not using libc5 (which relies on the kernel
108629 + signal handler return code) and not using or rewriting programs
108630 + that make use of the nested function implementation of GCC.
108631 + Skilled users can just fix GCC itself so that it implements
108632 + nested function calls in a way that does not interfere with PaX.
108633 +
108634 +config PAX_EMUSIGRT
108635 + bool "Automatically emulate sigreturn trampolines"
108636 + depends on PAX_EMUTRAMP && PARISC
108637 + default y
108638 + help
108639 + Enabling this option will have the kernel automatically detect
108640 + and emulate signal return trampolines executing on the stack
108641 + that would otherwise lead to task termination.
108642 +
108643 + This solution is intended as a temporary one for users with
108644 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108645 + Modula-3 runtime, etc) or executables linked to such, basically
108646 + everything that does not specify its own SA_RESTORER function in
108647 + normal executable memory like glibc 2.1+ does.
108648 +
108649 + On parisc you MUST enable this option, otherwise your system will
108650 + not even boot.
108651 +
108652 + NOTE: this feature cannot be disabled on a per executable basis
108653 + and since it *does* open up a loophole in the protection provided
108654 + by non-executable pages, the best solution is to not have any
108655 + files on your system that would require this option.
108656 +
108657 +config PAX_MPROTECT
108658 + bool "Restrict mprotect()"
108659 + default y if GRKERNSEC_CONFIG_AUTO
108660 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108661 + help
108662 + Enabling this option will prevent programs from
108663 + - changing the executable status of memory pages that were
108664 + not originally created as executable,
108665 + - making read-only executable pages writable again,
108666 + - creating executable pages from anonymous memory,
108667 + - making read-only-after-relocations (RELRO) data pages writable again.
108668 +
108669 + You should say Y here to complete the protection provided by
108670 + the enforcement of non-executable pages.
108671 +
108672 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108673 + this feature on a per file basis.
108674 +
108675 +config PAX_MPROTECT_COMPAT
108676 + bool "Use legacy/compat protection demoting (read help)"
108677 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108678 + depends on PAX_MPROTECT
108679 + help
108680 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108681 + by sending the proper error code to the application. For some broken
108682 + userland, this can cause problems with Python or other applications. The
108683 + current implementation however allows for applications like clamav to
108684 + detect if JIT compilation/execution is allowed and to fall back gracefully
108685 + to an interpreter-based mode if it does not. While we encourage everyone
108686 + to use the current implementation as-is and push upstream to fix broken
108687 + userland (note that the RWX logging option can assist with this), in some
108688 + environments this may not be possible. Having to disable MPROTECT
108689 + completely on certain binaries reduces the security benefit of PaX,
108690 + so this option is provided for those environments to revert to the old
108691 + behavior.
108692 +
108693 +config PAX_ELFRELOCS
108694 + bool "Allow ELF text relocations (read help)"
108695 + depends on PAX_MPROTECT
108696 + default n
108697 + help
108698 + Non-executable pages and mprotect() restrictions are effective
108699 + in preventing the introduction of new executable code into an
108700 + attacked task's address space. There remain only two venues
108701 + for this kind of attack: if the attacker can execute already
108702 + existing code in the attacked task then he can either have it
108703 + create and mmap() a file containing his code or have it mmap()
108704 + an already existing ELF library that does not have position
108705 + independent code in it and use mprotect() on it to make it
108706 + writable and copy his code there. While protecting against
108707 + the former approach is beyond PaX, the latter can be prevented
108708 + by having only PIC ELF libraries on one's system (which do not
108709 + need to relocate their code). If you are sure this is your case,
108710 + as is the case with all modern Linux distributions, then leave
108711 + this option disabled. You should say 'n' here.
108712 +
108713 +config PAX_ETEXECRELOCS
108714 + bool "Allow ELF ET_EXEC text relocations"
108715 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108716 + select PAX_ELFRELOCS
108717 + default y
108718 + help
108719 + On some architectures there are incorrectly created applications
108720 + that require text relocations and would not work without enabling
108721 + this option. If you are an alpha, ia64 or parisc user, you should
108722 + enable this option and disable it once you have made sure that
108723 + none of your applications need it.
108724 +
108725 +config PAX_EMUPLT
108726 + bool "Automatically emulate ELF PLT"
108727 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108728 + default y
108729 + help
108730 + Enabling this option will have the kernel automatically detect
108731 + and emulate the Procedure Linkage Table entries in ELF files.
108732 + On some architectures such entries are in writable memory, and
108733 + become non-executable leading to task termination. Therefore
108734 + it is mandatory that you enable this option on alpha, parisc,
108735 + sparc and sparc64, otherwise your system would not even boot.
108736 +
108737 + NOTE: this feature *does* open up a loophole in the protection
108738 + provided by the non-executable pages, therefore the proper
108739 + solution is to modify the toolchain to produce a PLT that does
108740 + not need to be writable.
108741 +
108742 +config PAX_DLRESOLVE
108743 + bool 'Emulate old glibc resolver stub'
108744 + depends on PAX_EMUPLT && SPARC
108745 + default n
108746 + help
108747 + This option is needed if userland has an old glibc (before 2.4)
108748 + that puts a 'save' instruction into the runtime generated resolver
108749 + stub that needs special emulation.
108750 +
108751 +config PAX_KERNEXEC
108752 + bool "Enforce non-executable kernel pages"
108753 + 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))
108754 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108755 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108756 + select PAX_KERNEXEC_PLUGIN if X86_64
108757 + help
108758 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108759 + that is, enabling this option will make it harder to inject
108760 + and execute 'foreign' code in kernel memory itself.
108761 +
108762 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108763 + the kernel command-line will result in an RWX physical map.
108764 +
108765 + Likewise, the EFI runtime services are necessarily mapped as
108766 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108767 + is recommended that you boot with "noefi" on the kernel
108768 + command-line if possible to eliminate the mapping.
108769 +
108770 +choice
108771 + prompt "Return Address Instrumentation Method"
108772 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108773 + depends on PAX_KERNEXEC_PLUGIN
108774 + help
108775 + Select the method used to instrument function pointer dereferences.
108776 + Note that binary modules cannot be instrumented by this approach.
108777 +
108778 + Note that the implementation requires a gcc with plugin support,
108779 + i.e., gcc 4.5 or newer. You may need to install the supporting
108780 + headers explicitly in addition to the normal gcc package.
108781 +
108782 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108783 + bool "bts"
108784 + help
108785 + This method is compatible with binary only modules but has
108786 + a higher runtime overhead.
108787 +
108788 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108789 + bool "or"
108790 + depends on !PARAVIRT
108791 + help
108792 + This method is incompatible with binary only modules but has
108793 + a lower runtime overhead.
108794 +endchoice
108795 +
108796 +config PAX_KERNEXEC_PLUGIN_METHOD
108797 + string
108798 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108799 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108800 + default ""
108801 +
108802 +config PAX_KERNEXEC_MODULE_TEXT
108803 + int "Minimum amount of memory reserved for module code"
108804 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108805 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108806 + depends on PAX_KERNEXEC && X86_32
108807 + help
108808 + Due to implementation details the kernel must reserve a fixed
108809 + amount of memory for runtime allocated code (such as modules)
108810 + at compile time that cannot be changed at runtime. Here you
108811 + can specify the minimum amount in MB that will be reserved.
108812 + Due to the same implementation details this size will always
108813 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108814 + the actually available memory for runtime allocated code will
108815 + usually be more than this minimum.
108816 +
108817 + The default 4 MB should be enough for most users but if you have
108818 + an excessive number of modules (e.g., most distribution configs
108819 + compile many drivers as modules) or use huge modules such as
108820 + nvidia's kernel driver, you will need to adjust this amount.
108821 + A good rule of thumb is to look at your currently loaded kernel
108822 + modules and add up their sizes.
108823 +
108824 +endmenu
108825 +
108826 +menu "Address Space Layout Randomization"
108827 + depends on PAX
108828 +
108829 +config PAX_ASLR
108830 + bool "Address Space Layout Randomization"
108831 + default y if GRKERNSEC_CONFIG_AUTO
108832 + help
108833 + Many if not most exploit techniques rely on the knowledge of
108834 + certain addresses in the attacked program. The following options
108835 + will allow the kernel to apply a certain amount of randomization
108836 + to specific parts of the program thereby forcing an attacker to
108837 + guess them in most cases. Any failed guess will most likely crash
108838 + the attacked program which allows the kernel to detect such attempts
108839 + and react on them. PaX itself provides no reaction mechanisms,
108840 + instead it is strongly encouraged that you make use of grsecurity's
108841 + (http://www.grsecurity.net/) built-in crash detection features or
108842 + develop one yourself.
108843 +
108844 + By saying Y here you can choose to randomize the following areas:
108845 + - top of the task's kernel stack
108846 + - top of the task's userland stack
108847 + - base address for mmap() requests that do not specify one
108848 + (this includes all libraries)
108849 + - base address of the main executable
108850 +
108851 + It is strongly recommended to say Y here as address space layout
108852 + randomization has negligible impact on performance yet it provides
108853 + a very effective protection.
108854 +
108855 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108856 + this feature on a per file basis.
108857 +
108858 +config PAX_RANDKSTACK
108859 + bool "Randomize kernel stack base"
108860 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108861 + depends on X86_TSC && X86
108862 + help
108863 + By saying Y here the kernel will randomize every task's kernel
108864 + stack on every system call. This will not only force an attacker
108865 + to guess it but also prevent him from making use of possible
108866 + leaked information about it.
108867 +
108868 + Since the kernel stack is a rather scarce resource, randomization
108869 + may cause unexpected stack overflows, therefore you should very
108870 + carefully test your system. Note that once enabled in the kernel
108871 + configuration, this feature cannot be disabled on a per file basis.
108872 +
108873 +config PAX_RANDUSTACK
108874 + bool
108875 +
108876 +config PAX_RANDMMAP
108877 + bool "Randomize user stack and mmap() bases"
108878 + default y if GRKERNSEC_CONFIG_AUTO
108879 + depends on PAX_ASLR
108880 + select PAX_RANDUSTACK
108881 + help
108882 + By saying Y here the kernel will randomize every task's userland
108883 + stack and use a randomized base address for mmap() requests that
108884 + do not specify one themselves.
108885 +
108886 + The stack randomization is done in two steps where the second
108887 + one may apply a big amount of shift to the top of the stack and
108888 + cause problems for programs that want to use lots of memory (more
108889 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108890 +
108891 + As a result of mmap randomization all dynamically loaded libraries
108892 + will appear at random addresses and therefore be harder to exploit
108893 + by a technique where an attacker attempts to execute library code
108894 + for his purposes (e.g. spawn a shell from an exploited program that
108895 + is running at an elevated privilege level).
108896 +
108897 + Furthermore, if a program is relinked as a dynamic ELF file, its
108898 + base address will be randomized as well, completing the full
108899 + randomization of the address space layout. Attacking such programs
108900 + becomes a guess game. You can find an example of doing this at
108901 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
108902 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
108903 +
108904 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
108905 + feature on a per file basis.
108906 +
108907 +endmenu
108908 +
108909 +menu "Miscellaneous hardening features"
108910 +
108911 +config PAX_MEMORY_SANITIZE
108912 + bool "Sanitize all freed memory"
108913 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108914 + help
108915 + By saying Y here the kernel will erase memory pages and slab objects
108916 + as soon as they are freed. This in turn reduces the lifetime of data
108917 + stored in them, making it less likely that sensitive information such
108918 + as passwords, cryptographic secrets, etc stay in memory for too long.
108919 +
108920 + This is especially useful for programs whose runtime is short, long
108921 + lived processes and the kernel itself benefit from this as long as
108922 + they ensure timely freeing of memory that may hold sensitive
108923 + information.
108924 +
108925 + A nice side effect of the sanitization of slab objects is the
108926 + reduction of possible info leaks caused by padding bytes within the
108927 + leaky structures. Use-after-free bugs for structures containing
108928 + pointers can also be detected as dereferencing the sanitized pointer
108929 + will generate an access violation.
108930 +
108931 + The tradeoff is performance impact, on a single CPU system kernel
108932 + compilation sees a 3% slowdown, other systems and workloads may vary
108933 + and you are advised to test this feature on your expected workload
108934 + before deploying it.
108935 +
108936 + The slab sanitization feature excludes a few slab caches per default
108937 + for performance reasons. To extend the feature to cover those as
108938 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
108939 +
108940 + To reduce the performance penalty by sanitizing pages only, albeit
108941 + limiting the effectiveness of this feature at the same time, slab
108942 + sanitization can be disabled with the kernel command line parameter
108943 + "pax_sanitize_slab=off".
108944 +
108945 + Note that this feature does not protect data stored in live pages,
108946 + e.g., process memory swapped to disk may stay there for a long time.
108947 +
108948 +config PAX_MEMORY_STACKLEAK
108949 + bool "Sanitize kernel stack"
108950 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108951 + depends on X86
108952 + help
108953 + By saying Y here the kernel will erase the kernel stack before it
108954 + returns from a system call. This in turn reduces the information
108955 + that a kernel stack leak bug can reveal.
108956 +
108957 + Note that such a bug can still leak information that was put on
108958 + the stack by the current system call (the one eventually triggering
108959 + the bug) but traces of earlier system calls on the kernel stack
108960 + cannot leak anymore.
108961 +
108962 + The tradeoff is performance impact: on a single CPU system kernel
108963 + compilation sees a 1% slowdown, other systems and workloads may vary
108964 + and you are advised to test this feature on your expected workload
108965 + before deploying it.
108966 +
108967 + Note that the full feature requires a gcc with plugin support,
108968 + i.e., gcc 4.5 or newer. You may need to install the supporting
108969 + headers explicitly in addition to the normal gcc package. Using
108970 + older gcc versions means that functions with large enough stack
108971 + frames may leave uninitialized memory behind that may be exposed
108972 + to a later syscall leaking the stack.
108973 +
108974 +config PAX_MEMORY_STRUCTLEAK
108975 + bool "Forcibly initialize local variables copied to userland"
108976 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108977 + help
108978 + By saying Y here the kernel will zero initialize some local
108979 + variables that are going to be copied to userland. This in
108980 + turn prevents unintended information leakage from the kernel
108981 + stack should later code forget to explicitly set all parts of
108982 + the copied variable.
108983 +
108984 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
108985 + at a much smaller coverage.
108986 +
108987 + Note that the implementation requires a gcc with plugin support,
108988 + i.e., gcc 4.5 or newer. You may need to install the supporting
108989 + headers explicitly in addition to the normal gcc package.
108990 +
108991 +config PAX_MEMORY_UDEREF
108992 + bool "Prevent invalid userland pointer dereference"
108993 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
108994 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
108995 + select PAX_PER_CPU_PGD if X86_64
108996 + help
108997 + By saying Y here the kernel will be prevented from dereferencing
108998 + userland pointers in contexts where the kernel expects only kernel
108999 + pointers. This is both a useful runtime debugging feature and a
109000 + security measure that prevents exploiting a class of kernel bugs.
109001 +
109002 + The tradeoff is that some virtualization solutions may experience
109003 + a huge slowdown and therefore you should not enable this feature
109004 + for kernels meant to run in such environments. Whether a given VM
109005 + solution is affected or not is best determined by simply trying it
109006 + out, the performance impact will be obvious right on boot as this
109007 + mechanism engages from very early on. A good rule of thumb is that
109008 + VMs running on CPUs without hardware virtualization support (i.e.,
109009 + the majority of IA-32 CPUs) will likely experience the slowdown.
109010 +
109011 + On X86_64 the kernel will make use of PCID support when available
109012 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
109013 + or performance impact. Pass pax_weakuderef on the kernel command
109014 + line to choose the latter.
109015 +
109016 +config PAX_REFCOUNT
109017 + bool "Prevent various kernel object reference counter overflows"
109018 + default y if GRKERNSEC_CONFIG_AUTO
109019 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
109020 + help
109021 + By saying Y here the kernel will detect and prevent overflowing
109022 + various (but not all) kinds of object reference counters. Such
109023 + overflows can normally occur due to bugs only and are often, if
109024 + not always, exploitable.
109025 +
109026 + The tradeoff is that data structures protected by an overflowed
109027 + refcount will never be freed and therefore will leak memory. Note
109028 + that this leak also happens even without this protection but in
109029 + that case the overflow can eventually trigger the freeing of the
109030 + data structure while it is still being used elsewhere, resulting
109031 + in the exploitable situation that this feature prevents.
109032 +
109033 + Since this has a negligible performance impact, you should enable
109034 + this feature.
109035 +
109036 +config PAX_CONSTIFY_PLUGIN
109037 + bool "Automatically constify eligible structures"
109038 + default y
109039 + depends on !UML && PAX_KERNEXEC
109040 + help
109041 + By saying Y here the compiler will automatically constify a class
109042 + of types that contain only function pointers. This reduces the
109043 + kernel's attack surface and also produces a better memory layout.
109044 +
109045 + Note that the implementation requires a gcc with plugin support,
109046 + i.e., gcc 4.5 or newer. You may need to install the supporting
109047 + headers explicitly in addition to the normal gcc package.
109048 +
109049 + Note that if some code really has to modify constified variables
109050 + then the source code will have to be patched to allow it. Examples
109051 + can be found in PaX itself (the no_const attribute) and for some
109052 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
109053 +
109054 +config PAX_USERCOPY
109055 + bool "Harden heap object copies between kernel and userland"
109056 + default y if GRKERNSEC_CONFIG_AUTO
109057 + depends on ARM || IA64 || PPC || SPARC || X86
109058 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
109059 + select PAX_USERCOPY_SLABS
109060 + help
109061 + By saying Y here the kernel will enforce the size of heap objects
109062 + when they are copied in either direction between the kernel and
109063 + userland, even if only a part of the heap object is copied.
109064 +
109065 + Specifically, this checking prevents information leaking from the
109066 + kernel heap during kernel to userland copies (if the kernel heap
109067 + object is otherwise fully initialized) and prevents kernel heap
109068 + overflows during userland to kernel copies.
109069 +
109070 + Note that the current implementation provides the strictest bounds
109071 + checks for the SLUB allocator.
109072 +
109073 + Enabling this option also enables per-slab cache protection against
109074 + data in a given cache being copied into/out of via userland
109075 + accessors. Though the whitelist of regions will be reduced over
109076 + time, it notably protects important data structures like task structs.
109077 +
109078 + If frame pointers are enabled on x86, this option will also restrict
109079 + copies into and out of the kernel stack to local variables within a
109080 + single frame.
109081 +
109082 + Since this has a negligible performance impact, you should enable
109083 + this feature.
109084 +
109085 +config PAX_USERCOPY_DEBUG
109086 + bool
109087 + depends on X86 && PAX_USERCOPY
109088 + default n
109089 +
109090 +config PAX_SIZE_OVERFLOW
109091 + bool "Prevent various integer overflows in function size parameters"
109092 + default y if GRKERNSEC_CONFIG_AUTO
109093 + depends on X86
109094 + help
109095 + By saying Y here the kernel recomputes expressions of function
109096 + arguments marked by a size_overflow attribute with double integer
109097 + precision (DImode/TImode for 32/64 bit integer types).
109098 +
109099 + The recomputed argument is checked against TYPE_MAX and an event
109100 + is logged on overflow and the triggering process is killed.
109101 +
109102 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
109103 +
109104 + Note that the implementation requires a gcc with plugin support,
109105 + i.e., gcc 4.5 or newer. You may need to install the supporting
109106 + headers explicitly in addition to the normal gcc package.
109107 +
109108 +config PAX_LATENT_ENTROPY
109109 + bool "Generate some entropy during boot and runtime"
109110 + default y if GRKERNSEC_CONFIG_AUTO
109111 + help
109112 + By saying Y here the kernel will instrument some kernel code to
109113 + extract some entropy from both original and artificially created
109114 + program state. This will help especially embedded systems where
109115 + there is little 'natural' source of entropy normally. The cost
109116 + is some slowdown of the boot process and fork and irq processing.
109117 +
109118 + When pax_extra_latent_entropy is passed on the kernel command line,
109119 + entropy will be extracted from up to the first 4GB of RAM while the
109120 + runtime memory allocator is being initialized. This costs even more
109121 + slowdown of the boot process.
109122 +
109123 + Note that the implementation requires a gcc with plugin support,
109124 + i.e., gcc 4.5 or newer. You may need to install the supporting
109125 + headers explicitly in addition to the normal gcc package.
109126 +
109127 + Note that entropy extracted this way is not cryptographically
109128 + secure!
109129 +
109130 +endmenu
109131 +
109132 +endmenu
109133 +
109134 +source grsecurity/Kconfig
109135 +
109136 +endmenu
109137 +
109138 +endmenu
109139 +
109140 source security/keys/Kconfig
109141
109142 config SECURITY_DMESG_RESTRICT
109143 @@ -103,7 +1071,7 @@ config INTEL_TXT
109144 config LSM_MMAP_MIN_ADDR
109145 int "Low address space for LSM to protect from user allocation"
109146 depends on SECURITY && SECURITY_SELINUX
109147 - default 32768 if ARM || (ARM64 && COMPAT)
109148 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
109149 default 65536
109150 help
109151 This is the portion of low virtual memory which should be protected
109152 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
109153 index fdaa50c..2761dcb 100644
109154 --- a/security/apparmor/file.c
109155 +++ b/security/apparmor/file.c
109156 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
109157 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
109158 struct path *new_dir, struct dentry *new_dentry)
109159 {
109160 - struct path link = { new_dir->mnt, new_dentry };
109161 - struct path target = { new_dir->mnt, old_dentry };
109162 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
109163 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
109164 struct path_cond cond = {
109165 old_dentry->d_inode->i_uid,
109166 old_dentry->d_inode->i_mode
109167 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
109168 index 65ca451..ad6f22d 100644
109169 --- a/security/apparmor/lsm.c
109170 +++ b/security/apparmor/lsm.c
109171 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109172 struct dentry *dentry, u32 mask,
109173 struct path_cond *cond)
109174 {
109175 - struct path path = { dir->mnt, dentry };
109176 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
109177
109178 return common_perm(op, &path, mask, cond);
109179 }
109180 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109181 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
109182 struct dentry *dentry, u32 mask)
109183 {
109184 - struct path path = { mnt, dentry };
109185 + struct path path = { .mnt = mnt, .dentry = dentry };
109186 struct path_cond cond = { dentry->d_inode->i_uid,
109187 dentry->d_inode->i_mode
109188 };
109189 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
109190
109191 profile = aa_current_profile();
109192 if (!unconfined(profile)) {
109193 - struct path old_path = { old_dir->mnt, old_dentry };
109194 - struct path new_path = { new_dir->mnt, new_dentry };
109195 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
109196 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
109197 struct path_cond cond = { old_dentry->d_inode->i_uid,
109198 old_dentry->d_inode->i_mode
109199 };
109200 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
109201 return error;
109202 }
109203
109204 -static struct security_operations apparmor_ops = {
109205 +static struct security_operations apparmor_ops __read_only = {
109206 .name = "apparmor",
109207
109208 .ptrace_access_check = apparmor_ptrace_access_check,
109209 diff --git a/security/commoncap.c b/security/commoncap.c
109210 index bab0611..f9a0ff5 100644
109211 --- a/security/commoncap.c
109212 +++ b/security/commoncap.c
109213 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109214 return 0;
109215 }
109216
109217 +/* returns:
109218 + 1 for suid privilege
109219 + 2 for sgid privilege
109220 + 3 for fscap privilege
109221 +*/
109222 +int is_privileged_binary(const struct dentry *dentry)
109223 +{
109224 + struct cpu_vfs_cap_data capdata;
109225 + struct inode *inode = dentry->d_inode;
109226 +
109227 + if (!inode || S_ISDIR(inode->i_mode))
109228 + return 0;
109229 +
109230 + if (inode->i_mode & S_ISUID)
109231 + return 1;
109232 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109233 + return 2;
109234 +
109235 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109236 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109237 + return 3;
109238 + }
109239 +
109240 + return 0;
109241 +}
109242 +
109243 /*
109244 * Attempt to get the on-exec apply capability sets for an executable file from
109245 * its xattrs and, if present, apply them to the proposed credentials being
109246 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109247 const struct cred *cred = current_cred();
109248 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109249
109250 + if (gr_acl_enable_at_secure())
109251 + return 1;
109252 +
109253 if (!uid_eq(cred->uid, root_uid)) {
109254 if (bprm->cap_effective)
109255 return 1;
109256 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109257 index 8ee997d..24c174b 100644
109258 --- a/security/integrity/ima/ima.h
109259 +++ b/security/integrity/ima/ima.h
109260 @@ -116,8 +116,8 @@ int ima_init_template(void);
109261 extern spinlock_t ima_queue_lock;
109262
109263 struct ima_h_table {
109264 - atomic_long_t len; /* number of stored measurements in the list */
109265 - atomic_long_t violations;
109266 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109267 + atomic_long_unchecked_t violations;
109268 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109269 };
109270 extern struct ima_h_table ima_htable;
109271 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109272 index 8688597..9fa80d2 100644
109273 --- a/security/integrity/ima/ima_api.c
109274 +++ b/security/integrity/ima/ima_api.c
109275 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109276 int result;
109277
109278 /* can overflow, only indicator */
109279 - atomic_long_inc(&ima_htable.violations);
109280 + atomic_long_inc_unchecked(&ima_htable.violations);
109281
109282 result = ima_alloc_init_template(NULL, file, filename,
109283 NULL, 0, &entry);
109284 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109285 index da92fcc..8a5d390 100644
109286 --- a/security/integrity/ima/ima_fs.c
109287 +++ b/security/integrity/ima/ima_fs.c
109288 @@ -28,12 +28,12 @@
109289 static int valid_policy = 1;
109290 #define TMPBUFLEN 12
109291 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109292 - loff_t *ppos, atomic_long_t *val)
109293 + loff_t *ppos, atomic_long_unchecked_t *val)
109294 {
109295 char tmpbuf[TMPBUFLEN];
109296 ssize_t len;
109297
109298 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109299 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109300 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109301 }
109302
109303 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109304 index 552705d..9920f4fb 100644
109305 --- a/security/integrity/ima/ima_queue.c
109306 +++ b/security/integrity/ima/ima_queue.c
109307 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109308 INIT_LIST_HEAD(&qe->later);
109309 list_add_tail_rcu(&qe->later, &ima_measurements);
109310
109311 - atomic_long_inc(&ima_htable.len);
109312 + atomic_long_inc_unchecked(&ima_htable.len);
109313 key = ima_hash_key(entry->digest);
109314 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109315 return 0;
109316 diff --git a/security/keys/compat.c b/security/keys/compat.c
109317 index 3478965..ec7bb9e 100644
109318 --- a/security/keys/compat.c
109319 +++ b/security/keys/compat.c
109320 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109321 if (ret == 0)
109322 goto no_payload_free;
109323
109324 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109325 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109326 err:
109327 if (iov != iovstack)
109328 kfree(iov);
109329 diff --git a/security/keys/internal.h b/security/keys/internal.h
109330 index 200e378..cdc74b5 100644
109331 --- a/security/keys/internal.h
109332 +++ b/security/keys/internal.h
109333 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109334 extern long keyctl_invalidate_key(key_serial_t);
109335
109336 extern long keyctl_instantiate_key_common(key_serial_t,
109337 - const struct iovec *,
109338 + const struct iovec __user *,
109339 unsigned, size_t, key_serial_t);
109340 #ifdef CONFIG_PERSISTENT_KEYRINGS
109341 extern long keyctl_get_persistent(uid_t, key_serial_t);
109342 diff --git a/security/keys/key.c b/security/keys/key.c
109343 index e17ba6a..2cc04a6 100644
109344 --- a/security/keys/key.c
109345 +++ b/security/keys/key.c
109346 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109347
109348 atomic_set(&key->usage, 1);
109349 init_rwsem(&key->sem);
109350 - lockdep_set_class(&key->sem, &type->lock_class);
109351 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109352 key->index_key.type = type;
109353 key->user = user;
109354 key->quotalen = quotalen;
109355 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109356 struct key_type *p;
109357 int ret;
109358
109359 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109360 + pax_open_kernel();
109361 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109362 + pax_close_kernel();
109363
109364 ret = -EEXIST;
109365 down_write(&key_types_sem);
109366 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109367 }
109368
109369 /* store the type */
109370 - list_add(&ktype->link, &key_types_list);
109371 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109372
109373 pr_notice("Key type %s registered\n", ktype->name);
109374 ret = 0;
109375 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109376 void unregister_key_type(struct key_type *ktype)
109377 {
109378 down_write(&key_types_sem);
109379 - list_del_init(&ktype->link);
109380 + pax_list_del_init((struct list_head *)&ktype->link);
109381 downgrade_write(&key_types_sem);
109382 key_gc_keytype(ktype);
109383 pr_notice("Key type %s unregistered\n", ktype->name);
109384 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109385 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109386
109387 /* add the special key types */
109388 - list_add_tail(&key_type_keyring.link, &key_types_list);
109389 - list_add_tail(&key_type_dead.link, &key_types_list);
109390 - list_add_tail(&key_type_user.link, &key_types_list);
109391 - list_add_tail(&key_type_logon.link, &key_types_list);
109392 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109393 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109394 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109395 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109396
109397 /* record the root user tracking */
109398 rb_link_node(&root_key_user.node,
109399 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109400 index 4743d71..170a185 100644
109401 --- a/security/keys/keyctl.c
109402 +++ b/security/keys/keyctl.c
109403 @@ -1000,7 +1000,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109404 /*
109405 * Copy the iovec data from userspace
109406 */
109407 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109408 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109409 unsigned ioc)
109410 {
109411 for (; ioc > 0; ioc--) {
109412 @@ -1022,7 +1022,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109413 * If successful, 0 will be returned.
109414 */
109415 long keyctl_instantiate_key_common(key_serial_t id,
109416 - const struct iovec *payload_iov,
109417 + const struct iovec __user *payload_iov,
109418 unsigned ioc,
109419 size_t plen,
109420 key_serial_t ringid)
109421 @@ -1117,7 +1117,7 @@ long keyctl_instantiate_key(key_serial_t id,
109422 [0].iov_len = plen
109423 };
109424
109425 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109426 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109427 }
109428
109429 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109430 @@ -1150,7 +1150,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109431 if (ret == 0)
109432 goto no_payload_free;
109433
109434 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109435 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109436 err:
109437 if (iov != iovstack)
109438 kfree(iov);
109439 diff --git a/security/min_addr.c b/security/min_addr.c
109440 index f728728..6457a0c 100644
109441 --- a/security/min_addr.c
109442 +++ b/security/min_addr.c
109443 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109444 */
109445 static void update_mmap_min_addr(void)
109446 {
109447 +#ifndef SPARC
109448 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109449 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109450 mmap_min_addr = dac_mmap_min_addr;
109451 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109452 #else
109453 mmap_min_addr = dac_mmap_min_addr;
109454 #endif
109455 +#endif
109456 }
109457
109458 /*
109459 diff --git a/security/security.c b/security/security.c
109460 index 18b35c6..c9fbc92 100644
109461 --- a/security/security.c
109462 +++ b/security/security.c
109463 @@ -33,8 +33,8 @@
109464 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109465 CONFIG_DEFAULT_SECURITY;
109466
109467 -static struct security_operations *security_ops;
109468 -static struct security_operations default_security_ops = {
109469 +struct security_operations *security_ops __read_only;
109470 +struct security_operations default_security_ops __read_only = {
109471 .name = "default",
109472 };
109473
109474 @@ -73,11 +73,6 @@ int __init security_init(void)
109475 return 0;
109476 }
109477
109478 -void reset_security_ops(void)
109479 -{
109480 - security_ops = &default_security_ops;
109481 -}
109482 -
109483 /* Save user chosen LSM */
109484 static int __init choose_lsm(char *str)
109485 {
109486 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109487 index a18f1fa..c9b9fc4 100644
109488 --- a/security/selinux/avc.c
109489 +++ b/security/selinux/avc.c
109490 @@ -59,7 +59,7 @@ struct avc_node {
109491 struct avc_cache {
109492 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109493 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109494 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109495 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109496 atomic_t active_nodes;
109497 u32 latest_notif; /* latest revocation notification */
109498 };
109499 @@ -167,7 +167,7 @@ void __init avc_init(void)
109500 spin_lock_init(&avc_cache.slots_lock[i]);
109501 }
109502 atomic_set(&avc_cache.active_nodes, 0);
109503 - atomic_set(&avc_cache.lru_hint, 0);
109504 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109505
109506 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109507 0, SLAB_PANIC, NULL);
109508 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109509 spinlock_t *lock;
109510
109511 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109512 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109513 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109514 head = &avc_cache.slots[hvalue];
109515 lock = &avc_cache.slots_lock[hvalue];
109516
109517 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109518 index c603b20..8716ec9 100644
109519 --- a/security/selinux/hooks.c
109520 +++ b/security/selinux/hooks.c
109521 @@ -95,8 +95,6 @@
109522 #include "audit.h"
109523 #include "avc_ss.h"
109524
109525 -extern struct security_operations *security_ops;
109526 -
109527 /* SECMARK reference count */
109528 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109529
109530 @@ -5809,7 +5807,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109531
109532 #endif
109533
109534 -static struct security_operations selinux_ops = {
109535 +static struct security_operations selinux_ops __read_only = {
109536 .name = "selinux",
109537
109538 .ptrace_access_check = selinux_ptrace_access_check,
109539 @@ -6150,6 +6148,9 @@ static void selinux_nf_ip_exit(void)
109540 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109541 static int selinux_disabled;
109542
109543 +extern struct security_operations *security_ops;
109544 +extern struct security_operations default_security_ops;
109545 +
109546 int selinux_disable(void)
109547 {
109548 if (ss_initialized) {
109549 @@ -6167,7 +6168,9 @@ int selinux_disable(void)
109550 selinux_disabled = 1;
109551 selinux_enabled = 0;
109552
109553 - reset_security_ops();
109554 + pax_open_kernel();
109555 + security_ops = &default_security_ops;
109556 + pax_close_kernel();
109557
109558 /* Try to destroy the avc node cache */
109559 avc_disable();
109560 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109561 index 1450f85..a91e0bc 100644
109562 --- a/security/selinux/include/xfrm.h
109563 +++ b/security/selinux/include/xfrm.h
109564 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109565
109566 rtnl_lock();
109567 for_each_net(net) {
109568 - atomic_inc(&net->xfrm.flow_cache_genid);
109569 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109570 rt_genid_bump_all(net);
109571 }
109572 rtnl_unlock();
109573 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109574 index d515ec2..8a4ca71 100644
109575 --- a/security/smack/smack_lsm.c
109576 +++ b/security/smack/smack_lsm.c
109577 @@ -4079,7 +4079,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109578 return 0;
109579 }
109580
109581 -struct security_operations smack_ops = {
109582 +struct security_operations smack_ops __read_only = {
109583 .name = "smack",
109584
109585 .ptrace_access_check = smack_ptrace_access_check,
109586 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109587 index 4003907..13a2b55 100644
109588 --- a/security/tomoyo/file.c
109589 +++ b/security/tomoyo/file.c
109590 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109591 {
109592 struct tomoyo_request_info r;
109593 struct tomoyo_obj_info obj = {
109594 - .path1 = *path,
109595 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109596 };
109597 int error = -ENOMEM;
109598 struct tomoyo_path_info buf;
109599 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109600 struct tomoyo_path_info buf;
109601 struct tomoyo_request_info r;
109602 struct tomoyo_obj_info obj = {
109603 - .path1 = *path,
109604 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109605 };
109606 int idx;
109607
109608 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109609 {
109610 struct tomoyo_request_info r;
109611 struct tomoyo_obj_info obj = {
109612 - .path1 = *path,
109613 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109614 };
109615 int error;
109616 struct tomoyo_path_info buf;
109617 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109618 {
109619 struct tomoyo_request_info r;
109620 struct tomoyo_obj_info obj = {
109621 - .path1 = *path,
109622 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109623 };
109624 int error = -ENOMEM;
109625 struct tomoyo_path_info buf;
109626 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109627 struct tomoyo_path_info buf2;
109628 struct tomoyo_request_info r;
109629 struct tomoyo_obj_info obj = {
109630 - .path1 = *path1,
109631 - .path2 = *path2,
109632 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109633 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109634 };
109635 int idx;
109636
109637 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109638 index 390c646..f2f8db3 100644
109639 --- a/security/tomoyo/mount.c
109640 +++ b/security/tomoyo/mount.c
109641 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109642 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109643 need_dev = -1; /* dev_name is a directory */
109644 } else {
109645 + if (!capable(CAP_SYS_ADMIN)) {
109646 + error = -EPERM;
109647 + goto out;
109648 + }
109649 fstype = get_fs_type(type);
109650 if (!fstype) {
109651 error = -ENODEV;
109652 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109653 index f0b756e..8aa497b 100644
109654 --- a/security/tomoyo/tomoyo.c
109655 +++ b/security/tomoyo/tomoyo.c
109656 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109657 */
109658 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109659 {
109660 - struct path path = { mnt, dentry };
109661 + struct path path = { .mnt = mnt, .dentry = dentry };
109662 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109663 }
109664
109665 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109666 */
109667 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109668 {
109669 - struct path path = { parent->mnt, dentry };
109670 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109671 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109672 }
109673
109674 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109675 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109676 umode_t mode)
109677 {
109678 - struct path path = { parent->mnt, dentry };
109679 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109680 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109681 mode & S_IALLUGO);
109682 }
109683 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109684 */
109685 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109686 {
109687 - struct path path = { parent->mnt, dentry };
109688 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109689 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109690 }
109691
109692 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109693 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109694 const char *old_name)
109695 {
109696 - struct path path = { parent->mnt, dentry };
109697 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109698 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109699 }
109700
109701 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109702 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109703 umode_t mode, unsigned int dev)
109704 {
109705 - struct path path = { parent->mnt, dentry };
109706 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109707 int type = TOMOYO_TYPE_CREATE;
109708 const unsigned int perm = mode & S_IALLUGO;
109709
109710 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109711 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109712 struct dentry *new_dentry)
109713 {
109714 - struct path path1 = { new_dir->mnt, old_dentry };
109715 - struct path path2 = { new_dir->mnt, new_dentry };
109716 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109717 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109718 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109719 }
109720
109721 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109722 struct path *new_parent,
109723 struct dentry *new_dentry)
109724 {
109725 - struct path path1 = { old_parent->mnt, old_dentry };
109726 - struct path path2 = { new_parent->mnt, new_dentry };
109727 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109728 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109729 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109730 }
109731
109732 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109733 */
109734 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109735 {
109736 - struct path path = { mnt, mnt->mnt_root };
109737 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109738 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109739 }
109740
109741 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109742 * tomoyo_security_ops is a "struct security_operations" which is used for
109743 * registering TOMOYO.
109744 */
109745 -static struct security_operations tomoyo_security_ops = {
109746 +static struct security_operations tomoyo_security_ops __read_only = {
109747 .name = "tomoyo",
109748 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109749 .cred_prepare = tomoyo_cred_prepare,
109750 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109751 index 20ef514..4182bed 100644
109752 --- a/security/yama/Kconfig
109753 +++ b/security/yama/Kconfig
109754 @@ -1,6 +1,6 @@
109755 config SECURITY_YAMA
109756 bool "Yama support"
109757 - depends on SECURITY
109758 + depends on SECURITY && !GRKERNSEC
109759 select SECURITYFS
109760 select SECURITY_PATH
109761 default n
109762 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109763 index 13c88fbc..f8c115e 100644
109764 --- a/security/yama/yama_lsm.c
109765 +++ b/security/yama/yama_lsm.c
109766 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109767 }
109768
109769 #ifndef CONFIG_SECURITY_YAMA_STACKED
109770 -static struct security_operations yama_ops = {
109771 +static struct security_operations yama_ops __read_only = {
109772 .name = "yama",
109773
109774 .ptrace_access_check = yama_ptrace_access_check,
109775 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109776 #endif
109777
109778 #ifdef CONFIG_SYSCTL
109779 +static int zero __read_only;
109780 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109781 +
109782 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109783 void __user *buffer, size_t *lenp, loff_t *ppos)
109784 {
109785 - int rc;
109786 + ctl_table_no_const yama_table;
109787
109788 if (write && !capable(CAP_SYS_PTRACE))
109789 return -EPERM;
109790
109791 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109792 - if (rc)
109793 - return rc;
109794 -
109795 + yama_table = *table;
109796 /* Lock the max value if it ever gets set. */
109797 - if (write && *(int *)table->data == *(int *)table->extra2)
109798 - table->extra1 = table->extra2;
109799 -
109800 - return rc;
109801 + if (ptrace_scope == max_scope)
109802 + yama_table.extra1 = &max_scope;
109803 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109804 }
109805
109806 -static int zero;
109807 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109808 -
109809 struct ctl_path yama_sysctl_path[] = {
109810 { .procname = "kernel", },
109811 { .procname = "yama", },
109812 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109813 index 401107b..b9c47c6 100644
109814 --- a/sound/aoa/codecs/onyx.c
109815 +++ b/sound/aoa/codecs/onyx.c
109816 @@ -54,7 +54,7 @@ struct onyx {
109817 spdif_locked:1,
109818 analog_locked:1,
109819 original_mute:2;
109820 - int open_count;
109821 + local_t open_count;
109822 struct codec_info *codec_info;
109823
109824 /* mutex serializes concurrent access to the device
109825 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109826 struct onyx *onyx = cii->codec_data;
109827
109828 mutex_lock(&onyx->mutex);
109829 - onyx->open_count++;
109830 + local_inc(&onyx->open_count);
109831 mutex_unlock(&onyx->mutex);
109832
109833 return 0;
109834 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109835 struct onyx *onyx = cii->codec_data;
109836
109837 mutex_lock(&onyx->mutex);
109838 - onyx->open_count--;
109839 - if (!onyx->open_count)
109840 + if (local_dec_and_test(&onyx->open_count))
109841 onyx->spdif_locked = onyx->analog_locked = 0;
109842 mutex_unlock(&onyx->mutex);
109843
109844 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109845 index ffd2025..df062c9 100644
109846 --- a/sound/aoa/codecs/onyx.h
109847 +++ b/sound/aoa/codecs/onyx.h
109848 @@ -11,6 +11,7 @@
109849 #include <linux/i2c.h>
109850 #include <asm/pmac_low_i2c.h>
109851 #include <asm/prom.h>
109852 +#include <asm/local.h>
109853
109854 /* PCM3052 register definitions */
109855
109856 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109857 index ada69d7..5f65386 100644
109858 --- a/sound/core/oss/pcm_oss.c
109859 +++ b/sound/core/oss/pcm_oss.c
109860 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109861 if (in_kernel) {
109862 mm_segment_t fs;
109863 fs = snd_enter_user();
109864 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109865 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109866 snd_leave_user(fs);
109867 } else {
109868 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109869 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109870 }
109871 if (ret != -EPIPE && ret != -ESTRPIPE)
109872 break;
109873 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109874 if (in_kernel) {
109875 mm_segment_t fs;
109876 fs = snd_enter_user();
109877 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109878 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109879 snd_leave_user(fs);
109880 } else {
109881 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109882 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109883 }
109884 if (ret == -EPIPE) {
109885 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
109886 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
109887 struct snd_pcm_plugin_channel *channels;
109888 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
109889 if (!in_kernel) {
109890 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
109891 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
109892 return -EFAULT;
109893 buf = runtime->oss.buffer;
109894 }
109895 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
109896 }
109897 } else {
109898 tmp = snd_pcm_oss_write2(substream,
109899 - (const char __force *)buf,
109900 + (const char __force_kernel *)buf,
109901 runtime->oss.period_bytes, 0);
109902 if (tmp <= 0)
109903 goto err;
109904 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
109905 struct snd_pcm_runtime *runtime = substream->runtime;
109906 snd_pcm_sframes_t frames, frames1;
109907 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
109908 - char __user *final_dst = (char __force __user *)buf;
109909 + char __user *final_dst = (char __force_user *)buf;
109910 if (runtime->oss.plugin_first) {
109911 struct snd_pcm_plugin_channel *channels;
109912 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
109913 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
109914 xfer += tmp;
109915 runtime->oss.buffer_used -= tmp;
109916 } else {
109917 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
109918 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
109919 runtime->oss.period_bytes, 0);
109920 if (tmp <= 0)
109921 goto err;
109922 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
109923 size1);
109924 size1 /= runtime->channels; /* frames */
109925 fs = snd_enter_user();
109926 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
109927 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
109928 snd_leave_user(fs);
109929 }
109930 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
109931 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
109932 index 2d957ba..fda022c 100644
109933 --- a/sound/core/pcm_compat.c
109934 +++ b/sound/core/pcm_compat.c
109935 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
109936 int err;
109937
109938 fs = snd_enter_user();
109939 - err = snd_pcm_delay(substream, &delay);
109940 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
109941 snd_leave_user(fs);
109942 if (err < 0)
109943 return err;
109944 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
109945 index 166d59c..89e3889 100644
109946 --- a/sound/core/pcm_native.c
109947 +++ b/sound/core/pcm_native.c
109948 @@ -2931,11 +2931,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
109949 switch (substream->stream) {
109950 case SNDRV_PCM_STREAM_PLAYBACK:
109951 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
109952 - (void __user *)arg);
109953 + (void __force_user *)arg);
109954 break;
109955 case SNDRV_PCM_STREAM_CAPTURE:
109956 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
109957 - (void __user *)arg);
109958 + (void __force_user *)arg);
109959 break;
109960 default:
109961 result = -EINVAL;
109962 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
109963 index 16d4267..fe8b49b 100644
109964 --- a/sound/core/seq/oss/seq_oss.c
109965 +++ b/sound/core/seq/oss/seq_oss.c
109966 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
109967 {
109968 int rc;
109969 static struct snd_seq_dev_ops ops = {
109970 - snd_seq_oss_synth_register,
109971 - snd_seq_oss_synth_unregister,
109972 + .init_device = snd_seq_oss_synth_register,
109973 + .free_device = snd_seq_oss_synth_unregister,
109974 };
109975
109976 snd_seq_autoload_lock();
109977 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
109978 index 91a786a..4c07ed4 100644
109979 --- a/sound/core/seq/seq_device.c
109980 +++ b/sound/core/seq/seq_device.c
109981 @@ -64,7 +64,7 @@ struct ops_list {
109982 int argsize; /* argument size */
109983
109984 /* operators */
109985 - struct snd_seq_dev_ops ops;
109986 + struct snd_seq_dev_ops *ops;
109987
109988 /* registered devices */
109989 struct list_head dev_list; /* list of devices */
109990 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
109991
109992 mutex_lock(&ops->reg_mutex);
109993 /* copy driver operators */
109994 - ops->ops = *entry;
109995 + ops->ops = entry;
109996 ops->driver |= DRIVER_LOADED;
109997 ops->argsize = argsize;
109998
109999 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
110000 dev->name, ops->id, ops->argsize, dev->argsize);
110001 return -EINVAL;
110002 }
110003 - if (ops->ops.init_device(dev) >= 0) {
110004 + if (ops->ops->init_device(dev) >= 0) {
110005 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
110006 ops->num_init_devices++;
110007 } else {
110008 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
110009 dev->name, ops->id, ops->argsize, dev->argsize);
110010 return -EINVAL;
110011 }
110012 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
110013 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
110014 dev->status = SNDRV_SEQ_DEVICE_FREE;
110015 dev->driver_data = NULL;
110016 ops->num_init_devices--;
110017 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
110018 index a1fd77a..69cd659 100644
110019 --- a/sound/core/seq/seq_midi.c
110020 +++ b/sound/core/seq/seq_midi.c
110021 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
110022 static int __init alsa_seq_midi_init(void)
110023 {
110024 static struct snd_seq_dev_ops ops = {
110025 - snd_seq_midisynth_register_port,
110026 - snd_seq_midisynth_unregister_port,
110027 + .init_device = snd_seq_midisynth_register_port,
110028 + .free_device = snd_seq_midisynth_unregister_port,
110029 };
110030 memset(&synths, 0, sizeof(synths));
110031 snd_seq_autoload_lock();
110032 diff --git a/sound/core/sound.c b/sound/core/sound.c
110033 index 38ad1a0..5010a40 100644
110034 --- a/sound/core/sound.c
110035 +++ b/sound/core/sound.c
110036 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
110037 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
110038 default: return;
110039 }
110040 - request_module(str);
110041 + request_module("%s", str);
110042 }
110043
110044 #endif /* modular kernel */
110045 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
110046 index f5fd448..6ae276da 100644
110047 --- a/sound/drivers/mts64.c
110048 +++ b/sound/drivers/mts64.c
110049 @@ -29,6 +29,7 @@
110050 #include <sound/initval.h>
110051 #include <sound/rawmidi.h>
110052 #include <sound/control.h>
110053 +#include <asm/local.h>
110054
110055 #define CARD_NAME "Miditerminal 4140"
110056 #define DRIVER_NAME "MTS64"
110057 @@ -67,7 +68,7 @@ struct mts64 {
110058 struct pardevice *pardev;
110059 int pardev_claimed;
110060
110061 - int open_count;
110062 + local_t open_count;
110063 int current_midi_output_port;
110064 int current_midi_input_port;
110065 u8 mode[MTS64_NUM_INPUT_PORTS];
110066 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110067 {
110068 struct mts64 *mts = substream->rmidi->private_data;
110069
110070 - if (mts->open_count == 0) {
110071 + if (local_read(&mts->open_count) == 0) {
110072 /* We don't need a spinlock here, because this is just called
110073 if the device has not been opened before.
110074 So there aren't any IRQs from the device */
110075 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110076
110077 msleep(50);
110078 }
110079 - ++(mts->open_count);
110080 + local_inc(&mts->open_count);
110081
110082 return 0;
110083 }
110084 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110085 struct mts64 *mts = substream->rmidi->private_data;
110086 unsigned long flags;
110087
110088 - --(mts->open_count);
110089 - if (mts->open_count == 0) {
110090 + if (local_dec_return(&mts->open_count) == 0) {
110091 /* We need the spinlock_irqsave here because we can still
110092 have IRQs at this point */
110093 spin_lock_irqsave(&mts->lock, flags);
110094 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110095
110096 msleep(500);
110097
110098 - } else if (mts->open_count < 0)
110099 - mts->open_count = 0;
110100 + } else if (local_read(&mts->open_count) < 0)
110101 + local_set(&mts->open_count, 0);
110102
110103 return 0;
110104 }
110105 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
110106 index 6839953..7a0f4b9 100644
110107 --- a/sound/drivers/opl3/opl3_seq.c
110108 +++ b/sound/drivers/opl3/opl3_seq.c
110109 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
110110 {
110111 static struct snd_seq_dev_ops ops =
110112 {
110113 - snd_opl3_seq_new_device,
110114 - snd_opl3_seq_delete_device
110115 + .init_device = snd_opl3_seq_new_device,
110116 + .free_device = snd_opl3_seq_delete_device
110117 };
110118
110119 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
110120 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
110121 index b953fb4..1999c01 100644
110122 --- a/sound/drivers/opl4/opl4_lib.c
110123 +++ b/sound/drivers/opl4/opl4_lib.c
110124 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
110125 MODULE_DESCRIPTION("OPL4 driver");
110126 MODULE_LICENSE("GPL");
110127
110128 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
110129 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
110130 {
110131 int timeout = 10;
110132 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
110133 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
110134 index 9919769..d7de36c 100644
110135 --- a/sound/drivers/opl4/opl4_seq.c
110136 +++ b/sound/drivers/opl4/opl4_seq.c
110137 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
110138 static int __init alsa_opl4_synth_init(void)
110139 {
110140 static struct snd_seq_dev_ops ops = {
110141 - snd_opl4_seq_new_device,
110142 - snd_opl4_seq_delete_device
110143 + .init_device = snd_opl4_seq_new_device,
110144 + .free_device = snd_opl4_seq_delete_device
110145 };
110146
110147 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
110148 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
110149 index 78ccfa4..7a0857b 100644
110150 --- a/sound/drivers/portman2x4.c
110151 +++ b/sound/drivers/portman2x4.c
110152 @@ -48,6 +48,7 @@
110153 #include <sound/initval.h>
110154 #include <sound/rawmidi.h>
110155 #include <sound/control.h>
110156 +#include <asm/local.h>
110157
110158 #define CARD_NAME "Portman 2x4"
110159 #define DRIVER_NAME "portman"
110160 @@ -85,7 +86,7 @@ struct portman {
110161 struct pardevice *pardev;
110162 int pardev_claimed;
110163
110164 - int open_count;
110165 + local_t open_count;
110166 int mode[PORTMAN_NUM_INPUT_PORTS];
110167 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
110168 };
110169 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
110170 index 95fc2eaf..ea5d6a7 100644
110171 --- a/sound/firewire/amdtp.c
110172 +++ b/sound/firewire/amdtp.c
110173 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
110174 ptr = s->pcm_buffer_pointer + frames;
110175 if (ptr >= pcm->runtime->buffer_size)
110176 ptr -= pcm->runtime->buffer_size;
110177 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
110178 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
110179
110180 s->pcm_period_pointer += frames;
110181 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
110182 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
110183 */
110184 void amdtp_stream_update(struct amdtp_stream *s)
110185 {
110186 - ACCESS_ONCE(s->source_node_id_field) =
110187 + ACCESS_ONCE_RW(s->source_node_id_field) =
110188 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
110189 }
110190 EXPORT_SYMBOL(amdtp_stream_update);
110191 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
110192 index 4823c08..47a5f7c 100644
110193 --- a/sound/firewire/amdtp.h
110194 +++ b/sound/firewire/amdtp.h
110195 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110196 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110197 struct snd_pcm_substream *pcm)
110198 {
110199 - ACCESS_ONCE(s->pcm) = pcm;
110200 + ACCESS_ONCE_RW(s->pcm) = pcm;
110201 }
110202
110203 /**
110204 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110205 struct snd_rawmidi_substream *midi)
110206 {
110207 if (port < s->midi_ports)
110208 - ACCESS_ONCE(s->midi[port]) = midi;
110209 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110210 }
110211
110212 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110213 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110214 index 7ac9443..0ec6274 100644
110215 --- a/sound/firewire/isight.c
110216 +++ b/sound/firewire/isight.c
110217 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110218 ptr += count;
110219 if (ptr >= runtime->buffer_size)
110220 ptr -= runtime->buffer_size;
110221 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110222 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110223
110224 isight->period_counter += count;
110225 if (isight->period_counter >= runtime->period_size) {
110226 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110227 if (err < 0)
110228 return err;
110229
110230 - ACCESS_ONCE(isight->pcm_active) = true;
110231 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110232
110233 return 0;
110234 }
110235 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110236 {
110237 struct isight *isight = substream->private_data;
110238
110239 - ACCESS_ONCE(isight->pcm_active) = false;
110240 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110241
110242 mutex_lock(&isight->mutex);
110243 isight_stop_streaming(isight);
110244 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110245
110246 switch (cmd) {
110247 case SNDRV_PCM_TRIGGER_START:
110248 - ACCESS_ONCE(isight->pcm_running) = true;
110249 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110250 break;
110251 case SNDRV_PCM_TRIGGER_STOP:
110252 - ACCESS_ONCE(isight->pcm_running) = false;
110253 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110254 break;
110255 default:
110256 return -EINVAL;
110257 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110258 index 2dba848..c682aef 100644
110259 --- a/sound/firewire/scs1x.c
110260 +++ b/sound/firewire/scs1x.c
110261 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110262 {
110263 struct scs *scs = stream->rmidi->private_data;
110264
110265 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110266 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110267 if (up) {
110268 scs->output_idle = false;
110269 tasklet_schedule(&scs->tasklet);
110270 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110271 {
110272 struct scs *scs = stream->rmidi->private_data;
110273
110274 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110275 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110276 }
110277
110278 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110279 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110280
110281 snd_card_disconnect(scs->card);
110282
110283 - ACCESS_ONCE(scs->output) = NULL;
110284 - ACCESS_ONCE(scs->input) = NULL;
110285 + ACCESS_ONCE_RW(scs->output) = NULL;
110286 + ACCESS_ONCE_RW(scs->input) = NULL;
110287
110288 wait_event(scs->idle_wait, scs->output_idle);
110289
110290 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110291 index 4e3fcfb..ab45a9d 100644
110292 --- a/sound/isa/sb/emu8000_synth.c
110293 +++ b/sound/isa/sb/emu8000_synth.c
110294 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110295 {
110296
110297 static struct snd_seq_dev_ops ops = {
110298 - snd_emu8000_new_device,
110299 - snd_emu8000_delete_device,
110300 + .init_device = snd_emu8000_new_device,
110301 + .free_device = snd_emu8000_delete_device,
110302 };
110303 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110304 sizeof(struct snd_emu8000*));
110305 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110306 index 048439a..3be9f6f 100644
110307 --- a/sound/oss/sb_audio.c
110308 +++ b/sound/oss/sb_audio.c
110309 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110310 buf16 = (signed short *)(localbuf + localoffs);
110311 while (c)
110312 {
110313 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110314 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110315 if (copy_from_user(lbuf8,
110316 userbuf+useroffs + p,
110317 locallen))
110318 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110319 index a33e8ce..2262303 100644
110320 --- a/sound/oss/swarm_cs4297a.c
110321 +++ b/sound/oss/swarm_cs4297a.c
110322 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110323 {
110324 struct cs4297a_state *s;
110325 u32 pwr, id;
110326 - mm_segment_t fs;
110327 int rval;
110328 u64 cfg;
110329 int mdio_val;
110330 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110331 if (!rval) {
110332 char *sb1250_duart_present;
110333
110334 +#if 0
110335 + mm_segment_t fs;
110336 fs = get_fs();
110337 set_fs(KERNEL_DS);
110338 -#if 0
110339 val = SOUND_MASK_LINE;
110340 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110341 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110342 val = initvol[i].vol;
110343 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110344 }
110345 + set_fs(fs);
110346 // cs4297a_write_ac97(s, 0x18, 0x0808);
110347 #else
110348 // cs4297a_write_ac97(s, 0x5e, 0x180);
110349 cs4297a_write_ac97(s, 0x02, 0x0808);
110350 cs4297a_write_ac97(s, 0x18, 0x0808);
110351 #endif
110352 - set_fs(fs);
110353
110354 list_add(&s->list, &cs4297a_devs);
110355
110356 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110357 index 4c41c90..37f3631 100644
110358 --- a/sound/pci/emu10k1/emu10k1_synth.c
110359 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110360 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110361 {
110362
110363 static struct snd_seq_dev_ops ops = {
110364 - snd_emu10k1_synth_new_device,
110365 - snd_emu10k1_synth_delete_device,
110366 + .init_device = snd_emu10k1_synth_new_device,
110367 + .free_device = snd_emu10k1_synth_delete_device,
110368 };
110369 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110370 sizeof(struct snd_emu10k1_synth_arg));
110371 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110372 index e708368..764dffe 100644
110373 --- a/sound/pci/hda/hda_codec.c
110374 +++ b/sound/pci/hda/hda_codec.c
110375 @@ -968,14 +968,10 @@ find_codec_preset(struct hda_codec *codec)
110376 mutex_unlock(&preset_mutex);
110377
110378 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110379 - char name[32];
110380 if (!mod_requested)
110381 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110382 - codec->vendor_id);
110383 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110384 else
110385 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110386 - (codec->vendor_id >> 16) & 0xffff);
110387 - request_module(name);
110388 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110389 mod_requested++;
110390 goto again;
110391 }
110392 @@ -2802,7 +2798,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110393 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110394 mm_segment_t fs = get_fs();
110395 set_fs(get_ds());
110396 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110397 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110398 tlv = _tlv;
110399 set_fs(fs);
110400 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110401 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110402 index 4631a23..001ae57 100644
110403 --- a/sound/pci/ymfpci/ymfpci.h
110404 +++ b/sound/pci/ymfpci/ymfpci.h
110405 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110406 spinlock_t reg_lock;
110407 spinlock_t voice_lock;
110408 wait_queue_head_t interrupt_sleep;
110409 - atomic_t interrupt_sleep_count;
110410 + atomic_unchecked_t interrupt_sleep_count;
110411 struct snd_info_entry *proc_entry;
110412 const struct firmware *dsp_microcode;
110413 const struct firmware *controller_microcode;
110414 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110415 index 81c916a..516f0bf 100644
110416 --- a/sound/pci/ymfpci/ymfpci_main.c
110417 +++ b/sound/pci/ymfpci/ymfpci_main.c
110418 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110419 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110420 break;
110421 }
110422 - if (atomic_read(&chip->interrupt_sleep_count)) {
110423 - atomic_set(&chip->interrupt_sleep_count, 0);
110424 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110425 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110426 wake_up(&chip->interrupt_sleep);
110427 }
110428 __end:
110429 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110430 continue;
110431 init_waitqueue_entry(&wait, current);
110432 add_wait_queue(&chip->interrupt_sleep, &wait);
110433 - atomic_inc(&chip->interrupt_sleep_count);
110434 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110435 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110436 remove_wait_queue(&chip->interrupt_sleep, &wait);
110437 }
110438 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110439 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110440 spin_unlock(&chip->reg_lock);
110441
110442 - if (atomic_read(&chip->interrupt_sleep_count)) {
110443 - atomic_set(&chip->interrupt_sleep_count, 0);
110444 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110445 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110446 wake_up(&chip->interrupt_sleep);
110447 }
110448 }
110449 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110450 spin_lock_init(&chip->reg_lock);
110451 spin_lock_init(&chip->voice_lock);
110452 init_waitqueue_head(&chip->interrupt_sleep);
110453 - atomic_set(&chip->interrupt_sleep_count, 0);
110454 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110455 chip->card = card;
110456 chip->pci = pci;
110457 chip->irq = -1;
110458 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110459 index b60ff56..7307f0f 100644
110460 --- a/sound/soc/soc-core.c
110461 +++ b/sound/soc/soc-core.c
110462 @@ -2132,8 +2132,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110463 if (ret)
110464 return ret;
110465
110466 - ops->warm_reset = snd_soc_ac97_warm_reset;
110467 - ops->reset = snd_soc_ac97_reset;
110468 + pax_open_kernel();
110469 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110470 + *(void **)&ops->reset = snd_soc_ac97_reset;
110471 + pax_close_kernel();
110472
110473 snd_ac97_rst_cfg = cfg;
110474 return 0;
110475 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110476 index 7778b8e..3d619fc 100644
110477 --- a/sound/synth/emux/emux_seq.c
110478 +++ b/sound/synth/emux/emux_seq.c
110479 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110480 * MIDI emulation operators
110481 */
110482 static struct snd_midi_op emux_ops = {
110483 - snd_emux_note_on,
110484 - snd_emux_note_off,
110485 - snd_emux_key_press,
110486 - snd_emux_terminate_note,
110487 - snd_emux_control,
110488 - snd_emux_nrpn,
110489 - snd_emux_sysex,
110490 + .note_on = snd_emux_note_on,
110491 + .note_off = snd_emux_note_off,
110492 + .key_press = snd_emux_key_press,
110493 + .note_terminate = snd_emux_terminate_note,
110494 + .control = snd_emux_control,
110495 + .nrpn = snd_emux_nrpn,
110496 + .sysex = snd_emux_sysex,
110497 };
110498
110499
110500 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110501 new file mode 100644
110502 index 0000000..de92ed9
110503 --- /dev/null
110504 +++ b/tools/gcc/.gitignore
110505 @@ -0,0 +1 @@
110506 +randomize_layout_seed.h
110507 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110508 new file mode 100644
110509 index 0000000..7b8921f
110510 --- /dev/null
110511 +++ b/tools/gcc/Makefile
110512 @@ -0,0 +1,52 @@
110513 +#CC := gcc
110514 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110515 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110516 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110517 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110518 +
110519 +ifeq ($(PLUGINCC),$(HOSTCC))
110520 +HOSTLIBS := hostlibs
110521 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110522 +export HOST_EXTRACFLAGS
110523 +else
110524 +HOSTLIBS := hostcxxlibs
110525 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110526 +export HOST_EXTRACXXFLAGS
110527 +endif
110528 +
110529 +export GCCPLUGINS_DIR HOSTLIBS
110530 +
110531 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110532 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110533 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110534 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110535 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110536 +$(HOSTLIBS)-y += colorize_plugin.so
110537 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110538 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110539 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110540 +
110541 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110542 +subdir- += size_overflow_plugin
110543 +
110544 +always := $($(HOSTLIBS)-y)
110545 +
110546 +constify_plugin-objs := constify_plugin.o
110547 +stackleak_plugin-objs := stackleak_plugin.o
110548 +kallocstat_plugin-objs := kallocstat_plugin.o
110549 +kernexec_plugin-objs := kernexec_plugin.o
110550 +checker_plugin-objs := checker_plugin.o
110551 +colorize_plugin-objs := colorize_plugin.o
110552 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110553 +structleak_plugin-objs := structleak_plugin.o
110554 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110555 +
110556 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110557 +
110558 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110559 + cmd_create_randomize_layout_seed = \
110560 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110561 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110562 + $(call if_changed,create_randomize_layout_seed)
110563 +
110564 +targets += randomize_layout_seed.h randomize_layout_hash.h
110565 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110566 new file mode 100644
110567 index 0000000..5452feea
110568 --- /dev/null
110569 +++ b/tools/gcc/checker_plugin.c
110570 @@ -0,0 +1,150 @@
110571 +/*
110572 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110573 + * Licensed under the GPL v2
110574 + *
110575 + * Note: the choice of the license means that the compilation process is
110576 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110577 + * but for the kernel it doesn't matter since it doesn't link against
110578 + * any of the gcc libraries
110579 + *
110580 + * gcc plugin to implement various sparse (source code checker) features
110581 + *
110582 + * TODO:
110583 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110584 + *
110585 + * BUGS:
110586 + * - none known
110587 + */
110588 +
110589 +#include "gcc-common.h"
110590 +
110591 +extern void c_register_addr_space (const char *str, addr_space_t as);
110592 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110593 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110594 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110595 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110596 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110597 +
110598 +int plugin_is_GPL_compatible;
110599 +
110600 +static struct plugin_info checker_plugin_info = {
110601 + .version = "201304082245",
110602 + .help = NULL,
110603 +};
110604 +
110605 +#define ADDR_SPACE_KERNEL 0
110606 +#define ADDR_SPACE_FORCE_KERNEL 1
110607 +#define ADDR_SPACE_USER 2
110608 +#define ADDR_SPACE_FORCE_USER 3
110609 +#define ADDR_SPACE_IOMEM 0
110610 +#define ADDR_SPACE_FORCE_IOMEM 0
110611 +#define ADDR_SPACE_PERCPU 0
110612 +#define ADDR_SPACE_FORCE_PERCPU 0
110613 +#define ADDR_SPACE_RCU 0
110614 +#define ADDR_SPACE_FORCE_RCU 0
110615 +
110616 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110617 +{
110618 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110619 +}
110620 +
110621 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110622 +{
110623 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110624 +}
110625 +
110626 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110627 +{
110628 + return default_addr_space_valid_pointer_mode(mode, as);
110629 +}
110630 +
110631 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110632 +{
110633 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110634 +}
110635 +
110636 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110637 +{
110638 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110639 +}
110640 +
110641 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110642 +{
110643 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110644 + return true;
110645 +
110646 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110647 + return true;
110648 +
110649 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110650 + return true;
110651 +
110652 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110653 + return true;
110654 +
110655 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110656 + return true;
110657 +
110658 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110659 + return true;
110660 +
110661 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110662 + return true;
110663 +
110664 + return subset == superset;
110665 +}
110666 +
110667 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110668 +{
110669 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110670 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110671 +
110672 + return op;
110673 +}
110674 +
110675 +static void register_checker_address_spaces(void *event_data, void *data)
110676 +{
110677 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110678 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110679 + c_register_addr_space("__user", ADDR_SPACE_USER);
110680 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110681 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110682 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110683 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110684 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110685 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110686 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110687 +
110688 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110689 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110690 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110691 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110692 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110693 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110694 + targetm.addr_space.convert = checker_addr_space_convert;
110695 +}
110696 +
110697 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110698 +{
110699 + const char * const plugin_name = plugin_info->base_name;
110700 + const int argc = plugin_info->argc;
110701 + const struct plugin_argument * const argv = plugin_info->argv;
110702 + int i;
110703 +
110704 + if (!plugin_default_version_check(version, &gcc_version)) {
110705 + error(G_("incompatible gcc/plugin versions"));
110706 + return 1;
110707 + }
110708 +
110709 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110710 +
110711 + for (i = 0; i < argc; ++i)
110712 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110713 +
110714 + if (TARGET_64BIT == 0)
110715 + return 0;
110716 +
110717 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110718 +
110719 + return 0;
110720 +}
110721 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110722 new file mode 100644
110723 index 0000000..54461af
110724 --- /dev/null
110725 +++ b/tools/gcc/colorize_plugin.c
110726 @@ -0,0 +1,210 @@
110727 +/*
110728 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110729 + * Licensed under the GPL v2
110730 + *
110731 + * Note: the choice of the license means that the compilation process is
110732 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110733 + * but for the kernel it doesn't matter since it doesn't link against
110734 + * any of the gcc libraries
110735 + *
110736 + * gcc plugin to colorize diagnostic output
110737 + *
110738 + */
110739 +
110740 +#include "gcc-common.h"
110741 +
110742 +int plugin_is_GPL_compatible;
110743 +
110744 +static struct plugin_info colorize_plugin_info = {
110745 + .version = "201404202350",
110746 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110747 +};
110748 +
110749 +#define GREEN "\033[32m\033[K"
110750 +#define LIGHTGREEN "\033[1;32m\033[K"
110751 +#define YELLOW "\033[33m\033[K"
110752 +#define LIGHTYELLOW "\033[1;33m\033[K"
110753 +#define RED "\033[31m\033[K"
110754 +#define LIGHTRED "\033[1;31m\033[K"
110755 +#define BLUE "\033[34m\033[K"
110756 +#define LIGHTBLUE "\033[1;34m\033[K"
110757 +#define BRIGHT "\033[1;m\033[K"
110758 +#define NORMAL "\033[m\033[K"
110759 +
110760 +static diagnostic_starter_fn old_starter;
110761 +static diagnostic_finalizer_fn old_finalizer;
110762 +
110763 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110764 +{
110765 + const char *color;
110766 + char *newprefix;
110767 +
110768 + switch (diagnostic->kind) {
110769 + case DK_NOTE:
110770 + color = LIGHTBLUE;
110771 + break;
110772 +
110773 + case DK_PEDWARN:
110774 + case DK_WARNING:
110775 + color = LIGHTYELLOW;
110776 + break;
110777 +
110778 + case DK_ERROR:
110779 + case DK_FATAL:
110780 + case DK_ICE:
110781 + case DK_PERMERROR:
110782 + case DK_SORRY:
110783 + color = LIGHTRED;
110784 + break;
110785 +
110786 + default:
110787 + color = NORMAL;
110788 + }
110789 +
110790 + old_starter(context, diagnostic);
110791 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110792 + return;
110793 + pp_destroy_prefix(context->printer);
110794 + pp_set_prefix(context->printer, newprefix);
110795 +}
110796 +
110797 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110798 +{
110799 + old_finalizer(context, diagnostic);
110800 +}
110801 +
110802 +static void colorize_arm(void)
110803 +{
110804 + old_starter = diagnostic_starter(global_dc);
110805 + old_finalizer = diagnostic_finalizer(global_dc);
110806 +
110807 + diagnostic_starter(global_dc) = start_colorize;
110808 + diagnostic_finalizer(global_dc) = finalize_colorize;
110809 +}
110810 +
110811 +static unsigned int execute_colorize_rearm(void)
110812 +{
110813 + if (diagnostic_starter(global_dc) == start_colorize)
110814 + return 0;
110815 +
110816 + colorize_arm();
110817 + return 0;
110818 +}
110819 +
110820 +#if BUILDING_GCC_VERSION >= 4009
110821 +static const struct pass_data colorize_rearm_pass_data = {
110822 +#else
110823 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110824 + .pass = {
110825 +#endif
110826 + .type = SIMPLE_IPA_PASS,
110827 + .name = "colorize_rearm",
110828 +#if BUILDING_GCC_VERSION >= 4008
110829 + .optinfo_flags = OPTGROUP_NONE,
110830 +#endif
110831 +#if BUILDING_GCC_VERSION >= 4009
110832 + .has_gate = false,
110833 + .has_execute = true,
110834 +#else
110835 + .gate = NULL,
110836 + .execute = execute_colorize_rearm,
110837 + .sub = NULL,
110838 + .next = NULL,
110839 + .static_pass_number = 0,
110840 +#endif
110841 + .tv_id = TV_NONE,
110842 + .properties_required = 0,
110843 + .properties_provided = 0,
110844 + .properties_destroyed = 0,
110845 + .todo_flags_start = 0,
110846 + .todo_flags_finish = 0
110847 +#if BUILDING_GCC_VERSION < 4009
110848 + }
110849 +#endif
110850 +};
110851 +
110852 +#if BUILDING_GCC_VERSION >= 4009
110853 +namespace {
110854 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110855 +public:
110856 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110857 + unsigned int execute() { return execute_colorize_rearm(); }
110858 +};
110859 +}
110860 +
110861 +static opt_pass *make_colorize_rearm_pass(void)
110862 +{
110863 + return new colorize_rearm_pass();
110864 +}
110865 +#else
110866 +static struct opt_pass *make_colorize_rearm_pass(void)
110867 +{
110868 + return &colorize_rearm_pass.pass;
110869 +}
110870 +#endif
110871 +
110872 +static void colorize_start_unit(void *gcc_data, void *user_data)
110873 +{
110874 + colorize_arm();
110875 +}
110876 +
110877 +static bool should_colorize(void)
110878 +{
110879 +#if BUILDING_GCC_VERSION >= 4009
110880 + return false;
110881 +#else
110882 + char const *t = getenv("TERM");
110883 +
110884 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
110885 +#endif
110886 +}
110887 +
110888 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110889 +{
110890 + const char * const plugin_name = plugin_info->base_name;
110891 + const int argc = plugin_info->argc;
110892 + const struct plugin_argument * const argv = plugin_info->argv;
110893 + int i;
110894 + struct register_pass_info colorize_rearm_pass_info;
110895 + bool colorize;
110896 +
110897 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
110898 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
110899 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
110900 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110901 +
110902 + if (!plugin_default_version_check(version, &gcc_version)) {
110903 + error(G_("incompatible gcc/plugin versions"));
110904 + return 1;
110905 + }
110906 +
110907 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
110908 +
110909 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
110910 +
110911 + for (i = 0; i < argc; ++i) {
110912 + if (!strcmp(argv[i].key, "color")) {
110913 + if (!argv[i].value) {
110914 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110915 + continue;
110916 + }
110917 + if (!strcmp(argv[i].value, "always"))
110918 + colorize = true;
110919 + else if (!strcmp(argv[i].value, "never"))
110920 + colorize = false;
110921 + else if (!strcmp(argv[i].value, "auto"))
110922 + colorize = should_colorize();
110923 + else
110924 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
110925 + continue;
110926 + }
110927 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110928 + }
110929 +
110930 + if (colorize) {
110931 + // TODO: parse GCC_COLORS as used by gcc 4.9+
110932 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
110933 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
110934 + }
110935 + return 0;
110936 +}
110937 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
110938 new file mode 100644
110939 index 0000000..82bc5a8
110940 --- /dev/null
110941 +++ b/tools/gcc/constify_plugin.c
110942 @@ -0,0 +1,557 @@
110943 +/*
110944 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
110945 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
110946 + * Licensed under the GPL v2, or (at your option) v3
110947 + *
110948 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
110949 + *
110950 + * Homepage:
110951 + * http://www.grsecurity.net/~ephox/const_plugin/
110952 + *
110953 + * Usage:
110954 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
110955 + * $ gcc -fplugin=constify_plugin.so test.c -O2
110956 + */
110957 +
110958 +#include "gcc-common.h"
110959 +
110960 +// unused C type flag in all versions 4.5-4.9
110961 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
110962 +
110963 +int plugin_is_GPL_compatible;
110964 +
110965 +static struct plugin_info const_plugin_info = {
110966 + .version = "201401270210",
110967 + .help = "no-constify\tturn off constification\n",
110968 +};
110969 +
110970 +typedef struct {
110971 + bool has_fptr_field;
110972 + bool has_writable_field;
110973 + bool has_do_const_field;
110974 + bool has_no_const_field;
110975 +} constify_info;
110976 +
110977 +static const_tree get_field_type(const_tree field)
110978 +{
110979 + return strip_array_types(TREE_TYPE(field));
110980 +}
110981 +
110982 +static bool is_fptr(const_tree field)
110983 +{
110984 + const_tree ptr = get_field_type(field);
110985 +
110986 + if (TREE_CODE(ptr) != POINTER_TYPE)
110987 + return false;
110988 +
110989 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
110990 +}
110991 +
110992 +/*
110993 + * determine whether the given structure type meets the requirements for automatic constification,
110994 + * including the constification attributes on nested structure types
110995 + */
110996 +static void constifiable(const_tree node, constify_info *cinfo)
110997 +{
110998 + const_tree field;
110999 +
111000 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111001 +
111002 + // e.g., pointer to structure fields while still constructing the structure type
111003 + if (TYPE_FIELDS(node) == NULL_TREE)
111004 + return;
111005 +
111006 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
111007 + const_tree type = get_field_type(field);
111008 + enum tree_code code = TREE_CODE(type);
111009 +
111010 + if (node == type)
111011 + continue;
111012 +
111013 + if (is_fptr(field))
111014 + cinfo->has_fptr_field = true;
111015 + else if (!TREE_READONLY(field))
111016 + cinfo->has_writable_field = true;
111017 +
111018 + if (code == RECORD_TYPE || code == UNION_TYPE) {
111019 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111020 + cinfo->has_do_const_field = true;
111021 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
111022 + cinfo->has_no_const_field = true;
111023 + else
111024 + constifiable(type, cinfo);
111025 + }
111026 + }
111027 +}
111028 +
111029 +static bool constified(const_tree node)
111030 +{
111031 + constify_info cinfo = {
111032 + .has_fptr_field = false,
111033 + .has_writable_field = false,
111034 + .has_do_const_field = false,
111035 + .has_no_const_field = false
111036 + };
111037 +
111038 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111039 +
111040 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
111041 +// gcc_assert(!TYPE_READONLY(node));
111042 + return false;
111043 + }
111044 +
111045 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
111046 + gcc_assert(TYPE_READONLY(node));
111047 + return true;
111048 + }
111049 +
111050 + constifiable(node, &cinfo);
111051 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
111052 + return false;
111053 +
111054 + return TYPE_READONLY(node);
111055 +}
111056 +
111057 +static void deconstify_tree(tree node);
111058 +
111059 +static void deconstify_type(tree type)
111060 +{
111061 + tree field;
111062 +
111063 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
111064 +
111065 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111066 + const_tree fieldtype = get_field_type(field);
111067 +
111068 + // special case handling of simple ptr-to-same-array-type members
111069 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
111070 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
111071 +
111072 + if (TREE_TYPE(TREE_TYPE(field)) == type)
111073 + continue;
111074 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
111075 + continue;
111076 + if (!constified(ptrtype))
111077 + continue;
111078 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
111079 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
111080 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
111081 + }
111082 + continue;
111083 + }
111084 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
111085 + continue;
111086 + if (!constified(fieldtype))
111087 + continue;
111088 +
111089 + deconstify_tree(field);
111090 + TREE_READONLY(field) = 0;
111091 + }
111092 + TYPE_READONLY(type) = 0;
111093 + C_TYPE_FIELDS_READONLY(type) = 0;
111094 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111095 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111096 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
111097 + }
111098 +}
111099 +
111100 +static void deconstify_tree(tree node)
111101 +{
111102 + tree old_type, new_type, field;
111103 +
111104 + old_type = TREE_TYPE(node);
111105 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
111106 + node = TREE_TYPE(node) = copy_node(old_type);
111107 + old_type = TREE_TYPE(old_type);
111108 + }
111109 +
111110 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
111111 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
111112 +
111113 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
111114 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
111115 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
111116 + DECL_FIELD_CONTEXT(field) = new_type;
111117 +
111118 + deconstify_type(new_type);
111119 +
111120 + TREE_TYPE(node) = new_type;
111121 +}
111122 +
111123 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111124 +{
111125 + tree type;
111126 + constify_info cinfo = {
111127 + .has_fptr_field = false,
111128 + .has_writable_field = false,
111129 + .has_do_const_field = false,
111130 + .has_no_const_field = false
111131 + };
111132 +
111133 + *no_add_attrs = true;
111134 + if (TREE_CODE(*node) == FUNCTION_DECL) {
111135 + error("%qE attribute does not apply to functions (%qF)", name, *node);
111136 + return NULL_TREE;
111137 + }
111138 +
111139 + if (TREE_CODE(*node) == PARM_DECL) {
111140 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
111141 + return NULL_TREE;
111142 + }
111143 +
111144 + if (TREE_CODE(*node) == VAR_DECL) {
111145 + error("%qE attribute does not apply to variables (%qD)", name, *node);
111146 + return NULL_TREE;
111147 + }
111148 +
111149 + if (TYPE_P(*node)) {
111150 + type = *node;
111151 + } else {
111152 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
111153 + type = TREE_TYPE(*node);
111154 + }
111155 +
111156 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
111157 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
111158 + return NULL_TREE;
111159 + }
111160 +
111161 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
111162 + error("%qE attribute is already applied to the type %qT", name, type);
111163 + return NULL_TREE;
111164 + }
111165 +
111166 + if (TYPE_P(*node)) {
111167 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111168 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
111169 + else
111170 + *no_add_attrs = false;
111171 + return NULL_TREE;
111172 + }
111173 +
111174 + constifiable(type, &cinfo);
111175 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111176 + deconstify_tree(*node);
111177 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
111178 + return NULL_TREE;
111179 + }
111180 +
111181 + error("%qE attribute used on type %qT that is not constified", name, type);
111182 + return NULL_TREE;
111183 +}
111184 +
111185 +static void constify_type(tree type)
111186 +{
111187 + TYPE_READONLY(type) = 1;
111188 + C_TYPE_FIELDS_READONLY(type) = 1;
111189 + TYPE_CONSTIFY_VISITED(type) = 1;
111190 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111191 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
111192 +}
111193 +
111194 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111195 +{
111196 + *no_add_attrs = true;
111197 + if (!TYPE_P(*node)) {
111198 + error("%qE attribute applies to types only (%qD)", name, *node);
111199 + return NULL_TREE;
111200 + }
111201 +
111202 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111203 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111204 + return NULL_TREE;
111205 + }
111206 +
111207 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111208 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111209 + return NULL_TREE;
111210 + }
111211 +
111212 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111213 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111214 + return NULL_TREE;
111215 + }
111216 +
111217 + *no_add_attrs = false;
111218 + return NULL_TREE;
111219 +}
111220 +
111221 +static struct attribute_spec no_const_attr = {
111222 + .name = "no_const",
111223 + .min_length = 0,
111224 + .max_length = 0,
111225 + .decl_required = false,
111226 + .type_required = false,
111227 + .function_type_required = false,
111228 + .handler = handle_no_const_attribute,
111229 +#if BUILDING_GCC_VERSION >= 4007
111230 + .affects_type_identity = true
111231 +#endif
111232 +};
111233 +
111234 +static struct attribute_spec do_const_attr = {
111235 + .name = "do_const",
111236 + .min_length = 0,
111237 + .max_length = 0,
111238 + .decl_required = false,
111239 + .type_required = false,
111240 + .function_type_required = false,
111241 + .handler = handle_do_const_attribute,
111242 +#if BUILDING_GCC_VERSION >= 4007
111243 + .affects_type_identity = true
111244 +#endif
111245 +};
111246 +
111247 +static void register_attributes(void *event_data, void *data)
111248 +{
111249 + register_attribute(&no_const_attr);
111250 + register_attribute(&do_const_attr);
111251 +}
111252 +
111253 +static void finish_type(void *event_data, void *data)
111254 +{
111255 + tree type = (tree)event_data;
111256 + constify_info cinfo = {
111257 + .has_fptr_field = false,
111258 + .has_writable_field = false,
111259 + .has_do_const_field = false,
111260 + .has_no_const_field = false
111261 + };
111262 +
111263 + if (type == NULL_TREE || type == error_mark_node)
111264 + return;
111265 +
111266 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111267 + return;
111268 +
111269 + constifiable(type, &cinfo);
111270 +
111271 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111272 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111273 + deconstify_type(type);
111274 + TYPE_CONSTIFY_VISITED(type) = 1;
111275 + } else
111276 + error("'no_const' attribute used on type %qT that is not constified", type);
111277 + return;
111278 + }
111279 +
111280 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111281 + if (!cinfo.has_writable_field) {
111282 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111283 + return;
111284 + }
111285 + constify_type(type);
111286 + return;
111287 + }
111288 +
111289 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111290 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111291 + error("'do_const' attribute used on type %qT that is constified", type);
111292 + return;
111293 + }
111294 + constify_type(type);
111295 + return;
111296 + }
111297 +
111298 + deconstify_type(type);
111299 + TYPE_CONSTIFY_VISITED(type) = 1;
111300 +}
111301 +
111302 +static void check_global_variables(void *event_data, void *data)
111303 +{
111304 +#if BUILDING_GCC_VERSION >= 4009
111305 + varpool_node *node;
111306 +#else
111307 + struct varpool_node *node;
111308 +#endif
111309 +
111310 + FOR_EACH_VARIABLE(node) {
111311 + tree var = NODE_DECL(node);
111312 + tree type = TREE_TYPE(var);
111313 +
111314 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111315 + continue;
111316 +
111317 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111318 + continue;
111319 +
111320 + if (!TYPE_CONSTIFY_VISITED(type))
111321 + continue;
111322 +
111323 + if (DECL_EXTERNAL(var))
111324 + continue;
111325 +
111326 + if (DECL_INITIAL(var))
111327 + continue;
111328 +
111329 + // this works around a gcc bug/feature where uninitialized globals
111330 + // are moved into the .bss section regardless of any constification
111331 + DECL_INITIAL(var) = build_constructor(type, NULL);
111332 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111333 + }
111334 +}
111335 +
111336 +static unsigned int check_local_variables(void)
111337 +{
111338 + unsigned int ret = 0;
111339 + tree var;
111340 +
111341 + unsigned int i;
111342 +
111343 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111344 + tree type = TREE_TYPE(var);
111345 +
111346 + gcc_assert(DECL_P(var));
111347 + if (is_global_var(var))
111348 + continue;
111349 +
111350 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111351 + continue;
111352 +
111353 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111354 + continue;
111355 +
111356 + if (!TYPE_CONSTIFY_VISITED(type))
111357 + continue;
111358 +
111359 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111360 + ret = 1;
111361 + }
111362 + return ret;
111363 +}
111364 +
111365 +#if BUILDING_GCC_VERSION >= 4009
111366 +static const struct pass_data check_local_variables_pass_data = {
111367 +#else
111368 +static struct gimple_opt_pass check_local_variables_pass = {
111369 + .pass = {
111370 +#endif
111371 + .type = GIMPLE_PASS,
111372 + .name = "check_local_variables",
111373 +#if BUILDING_GCC_VERSION >= 4008
111374 + .optinfo_flags = OPTGROUP_NONE,
111375 +#endif
111376 +#if BUILDING_GCC_VERSION >= 4009
111377 + .has_gate = false,
111378 + .has_execute = true,
111379 +#else
111380 + .gate = NULL,
111381 + .execute = check_local_variables,
111382 + .sub = NULL,
111383 + .next = NULL,
111384 + .static_pass_number = 0,
111385 +#endif
111386 + .tv_id = TV_NONE,
111387 + .properties_required = 0,
111388 + .properties_provided = 0,
111389 + .properties_destroyed = 0,
111390 + .todo_flags_start = 0,
111391 + .todo_flags_finish = 0
111392 +#if BUILDING_GCC_VERSION < 4009
111393 + }
111394 +#endif
111395 +};
111396 +
111397 +#if BUILDING_GCC_VERSION >= 4009
111398 +namespace {
111399 +class check_local_variables_pass : public gimple_opt_pass {
111400 +public:
111401 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111402 + unsigned int execute() { return check_local_variables(); }
111403 +};
111404 +}
111405 +
111406 +static opt_pass *make_check_local_variables_pass(void)
111407 +{
111408 + return new check_local_variables_pass();
111409 +}
111410 +#else
111411 +static struct opt_pass *make_check_local_variables_pass(void)
111412 +{
111413 + return &check_local_variables_pass.pass;
111414 +}
111415 +#endif
111416 +
111417 +static struct {
111418 + const char *name;
111419 + const char *asm_op;
111420 +} sections[] = {
111421 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111422 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111423 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111424 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111425 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111426 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111427 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111428 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111429 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111430 +};
111431 +
111432 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111433 +
111434 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111435 +{
111436 + size_t i;
111437 +
111438 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111439 + if (!strcmp(sections[i].name, name))
111440 + return 0;
111441 + return old_section_type_flags(decl, name, reloc);
111442 +}
111443 +
111444 +static void constify_start_unit(void *gcc_data, void *user_data)
111445 +{
111446 +// size_t i;
111447 +
111448 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111449 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111450 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111451 +
111452 + old_section_type_flags = targetm.section_type_flags;
111453 + targetm.section_type_flags = constify_section_type_flags;
111454 +}
111455 +
111456 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111457 +{
111458 + const char * const plugin_name = plugin_info->base_name;
111459 + const int argc = plugin_info->argc;
111460 + const struct plugin_argument * const argv = plugin_info->argv;
111461 + int i;
111462 + bool constify = true;
111463 +
111464 + struct register_pass_info check_local_variables_pass_info;
111465 +
111466 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111467 + check_local_variables_pass_info.reference_pass_name = "ssa";
111468 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111469 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111470 +
111471 + if (!plugin_default_version_check(version, &gcc_version)) {
111472 + error(G_("incompatible gcc/plugin versions"));
111473 + return 1;
111474 + }
111475 +
111476 + for (i = 0; i < argc; ++i) {
111477 + if (!(strcmp(argv[i].key, "no-constify"))) {
111478 + constify = false;
111479 + continue;
111480 + }
111481 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111482 + }
111483 +
111484 + if (strcmp(lang_hooks.name, "GNU C")) {
111485 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
111486 + constify = false;
111487 + }
111488 +
111489 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111490 + if (constify) {
111491 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111492 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111493 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111494 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111495 + }
111496 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111497 +
111498 + return 0;
111499 +}
111500 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111501 new file mode 100644
111502 index 0000000..e90c205
111503 --- /dev/null
111504 +++ b/tools/gcc/gcc-common.h
111505 @@ -0,0 +1,295 @@
111506 +#ifndef GCC_COMMON_H_INCLUDED
111507 +#define GCC_COMMON_H_INCLUDED
111508 +
111509 +#include "plugin.h"
111510 +#include "bversion.h"
111511 +#include "plugin-version.h"
111512 +#include "config.h"
111513 +#include "system.h"
111514 +#include "coretypes.h"
111515 +#include "tm.h"
111516 +#include "line-map.h"
111517 +#include "input.h"
111518 +#include "tree.h"
111519 +
111520 +#include "tree-inline.h"
111521 +#include "version.h"
111522 +#include "rtl.h"
111523 +#include "tm_p.h"
111524 +#include "flags.h"
111525 +//#include "insn-attr.h"
111526 +//#include "insn-config.h"
111527 +//#include "insn-flags.h"
111528 +#include "hard-reg-set.h"
111529 +//#include "recog.h"
111530 +#include "output.h"
111531 +#include "except.h"
111532 +#include "function.h"
111533 +#include "toplev.h"
111534 +//#include "expr.h"
111535 +#include "basic-block.h"
111536 +#include "intl.h"
111537 +#include "ggc.h"
111538 +//#include "regs.h"
111539 +#include "timevar.h"
111540 +
111541 +#include "params.h"
111542 +#include "pointer-set.h"
111543 +#include "emit-rtl.h"
111544 +//#include "reload.h"
111545 +//#include "ira.h"
111546 +//#include "dwarf2asm.h"
111547 +#include "debug.h"
111548 +#include "target.h"
111549 +#include "langhooks.h"
111550 +#include "cfgloop.h"
111551 +//#include "hosthooks.h"
111552 +#include "cgraph.h"
111553 +#include "opts.h"
111554 +//#include "coverage.h"
111555 +//#include "value-prof.h"
111556 +
111557 +#if BUILDING_GCC_VERSION >= 4007
111558 +#include "tree-pretty-print.h"
111559 +#include "gimple-pretty-print.h"
111560 +#include "c-tree.h"
111561 +//#include "alloc-pool.h"
111562 +#endif
111563 +
111564 +#if BUILDING_GCC_VERSION <= 4008
111565 +#include "tree-flow.h"
111566 +#else
111567 +#include "tree-cfgcleanup.h"
111568 +#endif
111569 +
111570 +#include "diagnostic.h"
111571 +//#include "tree-diagnostic.h"
111572 +#include "tree-dump.h"
111573 +#include "tree-pass.h"
111574 +//#include "df.h"
111575 +#include "predict.h"
111576 +#include "ipa-utils.h"
111577 +
111578 +#if BUILDING_GCC_VERSION >= 4009
111579 +#include "varasm.h"
111580 +#include "stor-layout.h"
111581 +#include "internal-fn.h"
111582 +#include "gimple-expr.h"
111583 +//#include "diagnostic-color.h"
111584 +#include "context.h"
111585 +#include "tree-ssa-alias.h"
111586 +#include "stringpool.h"
111587 +#include "tree-ssanames.h"
111588 +#include "print-tree.h"
111589 +#include "tree-eh.h"
111590 +#include "stmt.h"
111591 +#endif
111592 +
111593 +#include "gimple.h"
111594 +
111595 +#if BUILDING_GCC_VERSION >= 4009
111596 +#include "tree-ssa-operands.h"
111597 +#include "tree-phinodes.h"
111598 +#include "tree-cfg.h"
111599 +#include "gimple-iterator.h"
111600 +#include "gimple-ssa.h"
111601 +#include "ssa-iterators.h"
111602 +#endif
111603 +
111604 +//#include "lto/lto.h"
111605 +//#include "data-streamer.h"
111606 +//#include "lto-compress.h"
111607 +
111608 +//#include "expr.h" where are you...
111609 +extern rtx emit_move_insn(rtx x, rtx y);
111610 +
111611 +// missing from basic_block.h...
111612 +extern void debug_dominance_info(enum cdi_direction dir);
111613 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111614 +
111615 +#define __unused __attribute__((__unused__))
111616 +
111617 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111618 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111619 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111620 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111621 +
111622 +#if BUILDING_GCC_VERSION == 4005
111623 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111624 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111625 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111626 +#define TODO_rebuild_cgraph_edges 0
111627 +
111628 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111629 +{
111630 + tree fndecl;
111631 +
111632 + if (!is_gimple_call(stmt))
111633 + return false;
111634 + fndecl = gimple_call_fndecl(stmt);
111635 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111636 + return false;
111637 +// print_node(stderr, "pax", fndecl, 4);
111638 + return DECL_FUNCTION_CODE(fndecl) == code;
111639 +}
111640 +
111641 +static inline bool is_simple_builtin(tree decl)
111642 +{
111643 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111644 + return false;
111645 +
111646 + switch (DECL_FUNCTION_CODE(decl)) {
111647 + /* Builtins that expand to constants. */
111648 + case BUILT_IN_CONSTANT_P:
111649 + case BUILT_IN_EXPECT:
111650 + case BUILT_IN_OBJECT_SIZE:
111651 + case BUILT_IN_UNREACHABLE:
111652 + /* Simple register moves or loads from stack. */
111653 + case BUILT_IN_RETURN_ADDRESS:
111654 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111655 + case BUILT_IN_FROB_RETURN_ADDR:
111656 + case BUILT_IN_RETURN:
111657 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111658 + case BUILT_IN_FRAME_ADDRESS:
111659 + case BUILT_IN_VA_END:
111660 + case BUILT_IN_STACK_SAVE:
111661 + case BUILT_IN_STACK_RESTORE:
111662 + /* Exception state returns or moves registers around. */
111663 + case BUILT_IN_EH_FILTER:
111664 + case BUILT_IN_EH_POINTER:
111665 + case BUILT_IN_EH_COPY_VALUES:
111666 + return true;
111667 +
111668 + default:
111669 + return false;
111670 + }
111671 +}
111672 +#endif
111673 +
111674 +#if BUILDING_GCC_VERSION <= 4006
111675 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111676 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111677 +
111678 +// should come from c-tree.h if only it were installed for gcc 4.5...
111679 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111680 +
111681 +#define get_random_seed(noinit) ({ \
111682 + unsigned HOST_WIDE_INT seed; \
111683 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111684 + seed * seed; })
111685 +
111686 +static inline bool gimple_clobber_p(gimple s)
111687 +{
111688 + return false;
111689 +}
111690 +
111691 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111692 +{
111693 + return implicit_built_in_decls[fncode];
111694 +}
111695 +
111696 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111697 +{
111698 + struct cgraph_node *node = cgraph_get_node(decl);
111699 +
111700 + return node ? node : cgraph_node(decl);
111701 +}
111702 +
111703 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111704 +{
111705 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111706 +}
111707 +
111708 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111709 +{
111710 + struct cgraph_node *node;
111711 +
111712 + for (node = cgraph_nodes; node; node = node->next)
111713 + if (cgraph_function_with_gimple_body_p(node))
111714 + return node;
111715 + return NULL;
111716 +}
111717 +
111718 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111719 +{
111720 + for (node = node->next; node; node = node->next)
111721 + if (cgraph_function_with_gimple_body_p(node))
111722 + return node;
111723 + return NULL;
111724 +}
111725 +
111726 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111727 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111728 + (node) = cgraph_next_function_with_gimple_body(node))
111729 +#endif
111730 +
111731 +#if BUILDING_GCC_VERSION == 4006
111732 +extern void debug_gimple_stmt(gimple);
111733 +extern void debug_gimple_seq(gimple_seq);
111734 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111735 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111736 +extern void print_gimple_expr(FILE *, gimple, int, int);
111737 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111738 +#endif
111739 +
111740 +#if BUILDING_GCC_VERSION <= 4007
111741 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111742 +#define PROP_loops 0
111743 +
111744 +static inline int bb_loop_depth(const_basic_block bb)
111745 +{
111746 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111747 +}
111748 +
111749 +static inline bool gimple_store_p(gimple gs)
111750 +{
111751 + tree lhs = gimple_get_lhs(gs);
111752 + return lhs && !is_gimple_reg(lhs);
111753 +}
111754 +#endif
111755 +
111756 +#if BUILDING_GCC_VERSION >= 4007
111757 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111758 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111759 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111760 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111761 +#endif
111762 +
111763 +#if BUILDING_GCC_VERSION <= 4008
111764 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111765 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111766 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111767 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111768 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111769 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111770 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111771 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111772 +
111773 +static inline const char *get_tree_code_name(enum tree_code code)
111774 +{
111775 + gcc_assert(code < MAX_TREE_CODES);
111776 + return tree_code_name[code];
111777 +}
111778 +
111779 +#define ipa_remove_stmt_references(cnode, stmt)
111780 +#endif
111781 +
111782 +#if BUILDING_GCC_VERSION == 4008
111783 +#define NODE_DECL(node) node->symbol.decl
111784 +#else
111785 +#define NODE_DECL(node) node->decl
111786 +#endif
111787 +
111788 +#if BUILDING_GCC_VERSION >= 4008
111789 +#define add_referenced_var(var)
111790 +#define mark_sym_for_renaming(var)
111791 +#define varpool_mark_needed_node(node)
111792 +#define TODO_dump_func 0
111793 +#define TODO_dump_cgraph 0
111794 +#endif
111795 +
111796 +#if BUILDING_GCC_VERSION >= 4009
111797 +#define TODO_ggc_collect 0
111798 +#endif
111799 +
111800 +#endif
111801 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111802 new file mode 100644
111803 index 0000000..7514850
111804 --- /dev/null
111805 +++ b/tools/gcc/gen-random-seed.sh
111806 @@ -0,0 +1,8 @@
111807 +#!/bin/sh
111808 +
111809 +if [ ! -f "$1" ]; then
111810 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111811 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111812 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111813 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111814 +fi
111815 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111816 new file mode 100644
111817 index 0000000..d81c094
111818 --- /dev/null
111819 +++ b/tools/gcc/kallocstat_plugin.c
111820 @@ -0,0 +1,183 @@
111821 +/*
111822 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111823 + * Licensed under the GPL v2
111824 + *
111825 + * Note: the choice of the license means that the compilation process is
111826 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111827 + * but for the kernel it doesn't matter since it doesn't link against
111828 + * any of the gcc libraries
111829 + *
111830 + * gcc plugin to find the distribution of k*alloc sizes
111831 + *
111832 + * TODO:
111833 + *
111834 + * BUGS:
111835 + * - none known
111836 + */
111837 +
111838 +#include "gcc-common.h"
111839 +
111840 +int plugin_is_GPL_compatible;
111841 +
111842 +static struct plugin_info kallocstat_plugin_info = {
111843 + .version = "201401260140",
111844 + .help = NULL
111845 +};
111846 +
111847 +static const char * const kalloc_functions[] = {
111848 + "__kmalloc",
111849 + "kmalloc",
111850 + "kmalloc_large",
111851 + "kmalloc_node",
111852 + "kmalloc_order",
111853 + "kmalloc_order_trace",
111854 + "kmalloc_slab",
111855 + "kzalloc",
111856 + "kzalloc_node",
111857 +};
111858 +
111859 +static bool is_kalloc(const char *fnname)
111860 +{
111861 + size_t i;
111862 +
111863 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111864 + if (!strcmp(fnname, kalloc_functions[i]))
111865 + return true;
111866 + return false;
111867 +}
111868 +
111869 +static unsigned int execute_kallocstat(void)
111870 +{
111871 + basic_block bb;
111872 +
111873 + // 1. loop through BBs and GIMPLE statements
111874 + FOR_EACH_BB_FN(bb, cfun) {
111875 + gimple_stmt_iterator gsi;
111876 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111877 + // gimple match:
111878 + tree fndecl, size;
111879 + gimple stmt;
111880 + const char *fnname;
111881 +
111882 + // is it a call
111883 + stmt = gsi_stmt(gsi);
111884 + if (!is_gimple_call(stmt))
111885 + continue;
111886 + fndecl = gimple_call_fndecl(stmt);
111887 + if (fndecl == NULL_TREE)
111888 + continue;
111889 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
111890 + continue;
111891 +
111892 + // is it a call to k*alloc
111893 + fnname = DECL_NAME_POINTER(fndecl);
111894 + if (!is_kalloc(fnname))
111895 + continue;
111896 +
111897 + // is the size arg const or the result of a simple const assignment
111898 + size = gimple_call_arg(stmt, 0);
111899 + while (true) {
111900 + expanded_location xloc;
111901 + size_t size_val;
111902 +
111903 + if (TREE_CONSTANT(size)) {
111904 + xloc = expand_location(gimple_location(stmt));
111905 + if (!xloc.file)
111906 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111907 + size_val = TREE_INT_CST_LOW(size);
111908 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
111909 + break;
111910 + }
111911 +
111912 + if (TREE_CODE(size) != SSA_NAME)
111913 + break;
111914 + stmt = SSA_NAME_DEF_STMT(size);
111915 +//debug_gimple_stmt(stmt);
111916 +//debug_tree(size);
111917 + if (!stmt || !is_gimple_assign(stmt))
111918 + break;
111919 + if (gimple_num_ops(stmt) != 2)
111920 + break;
111921 + size = gimple_assign_rhs1(stmt);
111922 + }
111923 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111924 +//debug_tree(gimple_call_fn(call_stmt));
111925 +//print_node(stderr, "pax", fndecl, 4);
111926 + }
111927 + }
111928 +
111929 + return 0;
111930 +}
111931 +
111932 +#if BUILDING_GCC_VERSION >= 4009
111933 +static const struct pass_data kallocstat_pass_data = {
111934 +#else
111935 +static struct gimple_opt_pass kallocstat_pass = {
111936 + .pass = {
111937 +#endif
111938 + .type = GIMPLE_PASS,
111939 + .name = "kallocstat",
111940 +#if BUILDING_GCC_VERSION >= 4008
111941 + .optinfo_flags = OPTGROUP_NONE,
111942 +#endif
111943 +#if BUILDING_GCC_VERSION >= 4009
111944 + .has_gate = false,
111945 + .has_execute = true,
111946 +#else
111947 + .gate = NULL,
111948 + .execute = execute_kallocstat,
111949 + .sub = NULL,
111950 + .next = NULL,
111951 + .static_pass_number = 0,
111952 +#endif
111953 + .tv_id = TV_NONE,
111954 + .properties_required = 0,
111955 + .properties_provided = 0,
111956 + .properties_destroyed = 0,
111957 + .todo_flags_start = 0,
111958 + .todo_flags_finish = 0
111959 +#if BUILDING_GCC_VERSION < 4009
111960 + }
111961 +#endif
111962 +};
111963 +
111964 +#if BUILDING_GCC_VERSION >= 4009
111965 +namespace {
111966 +class kallocstat_pass : public gimple_opt_pass {
111967 +public:
111968 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
111969 + unsigned int execute() { return execute_kallocstat(); }
111970 +};
111971 +}
111972 +
111973 +static opt_pass *make_kallocstat_pass(void)
111974 +{
111975 + return new kallocstat_pass();
111976 +}
111977 +#else
111978 +static struct opt_pass *make_kallocstat_pass(void)
111979 +{
111980 + return &kallocstat_pass.pass;
111981 +}
111982 +#endif
111983 +
111984 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111985 +{
111986 + const char * const plugin_name = plugin_info->base_name;
111987 + struct register_pass_info kallocstat_pass_info;
111988 +
111989 + kallocstat_pass_info.pass = make_kallocstat_pass();
111990 + kallocstat_pass_info.reference_pass_name = "ssa";
111991 + kallocstat_pass_info.ref_pass_instance_number = 1;
111992 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111993 +
111994 + if (!plugin_default_version_check(version, &gcc_version)) {
111995 + error(G_("incompatible gcc/plugin versions"));
111996 + return 1;
111997 + }
111998 +
111999 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
112000 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
112001 +
112002 + return 0;
112003 +}
112004 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
112005 new file mode 100644
112006 index 0000000..89f256d
112007 --- /dev/null
112008 +++ b/tools/gcc/kernexec_plugin.c
112009 @@ -0,0 +1,522 @@
112010 +/*
112011 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112012 + * Licensed under the GPL v2
112013 + *
112014 + * Note: the choice of the license means that the compilation process is
112015 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112016 + * but for the kernel it doesn't matter since it doesn't link against
112017 + * any of the gcc libraries
112018 + *
112019 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
112020 + *
112021 + * TODO:
112022 + *
112023 + * BUGS:
112024 + * - none known
112025 + */
112026 +
112027 +#include "gcc-common.h"
112028 +
112029 +int plugin_is_GPL_compatible;
112030 +
112031 +static struct plugin_info kernexec_plugin_info = {
112032 + .version = "201401260140",
112033 + .help = "method=[bts|or]\tinstrumentation method\n"
112034 +};
112035 +
112036 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
112037 +static void (*kernexec_instrument_retaddr)(rtx);
112038 +
112039 +/*
112040 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
112041 + */
112042 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
112043 +{
112044 + gimple asm_movabs_stmt;
112045 +
112046 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
112047 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
112048 + gimple_asm_set_volatile(asm_movabs_stmt, true);
112049 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
112050 + update_stmt(asm_movabs_stmt);
112051 +}
112052 +
112053 +/*
112054 + * find all asm() stmts that clobber r12 and add a reload of r12
112055 + */
112056 +static unsigned int execute_kernexec_reload(void)
112057 +{
112058 + basic_block bb;
112059 +
112060 + // 1. loop through BBs and GIMPLE statements
112061 + FOR_EACH_BB_FN(bb, cfun) {
112062 + gimple_stmt_iterator gsi;
112063 +
112064 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112065 + // gimple match: __asm__ ("" : : : "r12");
112066 + gimple asm_stmt;
112067 + size_t nclobbers;
112068 +
112069 + // is it an asm ...
112070 + asm_stmt = gsi_stmt(gsi);
112071 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
112072 + continue;
112073 +
112074 + // ... clobbering r12
112075 + nclobbers = gimple_asm_nclobbers(asm_stmt);
112076 + while (nclobbers--) {
112077 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
112078 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
112079 + continue;
112080 + kernexec_reload_fptr_mask(&gsi);
112081 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
112082 + break;
112083 + }
112084 + }
112085 + }
112086 +
112087 + return 0;
112088 +}
112089 +
112090 +/*
112091 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
112092 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
112093 + */
112094 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
112095 +{
112096 + gimple assign_intptr, assign_new_fptr, call_stmt;
112097 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
112098 +
112099 + call_stmt = gsi_stmt(*gsi);
112100 + old_fptr = gimple_call_fn(call_stmt);
112101 +
112102 + // create temporary unsigned long variable used for bitops and cast fptr to it
112103 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
112104 + add_referenced_var(intptr);
112105 + intptr = make_ssa_name(intptr, NULL);
112106 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
112107 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112108 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112109 + update_stmt(assign_intptr);
112110 +
112111 + // apply logical or to temporary unsigned long and bitmask
112112 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
112113 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
112114 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
112115 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
112116 + assign_intptr = gimple_build_assign(intptr, orptr);
112117 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112118 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112119 + update_stmt(assign_intptr);
112120 +
112121 + // cast temporary unsigned long back to a temporary fptr variable
112122 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
112123 + add_referenced_var(new_fptr);
112124 + new_fptr = make_ssa_name(new_fptr, NULL);
112125 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
112126 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
112127 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
112128 + update_stmt(assign_new_fptr);
112129 +
112130 + // replace call stmt fn with the new fptr
112131 + gimple_call_set_fn(call_stmt, new_fptr);
112132 + update_stmt(call_stmt);
112133 +}
112134 +
112135 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
112136 +{
112137 + gimple asm_or_stmt, call_stmt;
112138 + tree old_fptr, new_fptr, input, output;
112139 +#if BUILDING_GCC_VERSION <= 4007
112140 + VEC(tree, gc) *inputs = NULL;
112141 + VEC(tree, gc) *outputs = NULL;
112142 +#else
112143 + vec<tree, va_gc> *inputs = NULL;
112144 + vec<tree, va_gc> *outputs = NULL;
112145 +#endif
112146 +
112147 + call_stmt = gsi_stmt(*gsi);
112148 + old_fptr = gimple_call_fn(call_stmt);
112149 +
112150 + // create temporary fptr variable
112151 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
112152 + add_referenced_var(new_fptr);
112153 + new_fptr = make_ssa_name(new_fptr, NULL);
112154 +
112155 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
112156 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
112157 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
112158 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
112159 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
112160 +#if BUILDING_GCC_VERSION <= 4007
112161 + VEC_safe_push(tree, gc, inputs, input);
112162 + VEC_safe_push(tree, gc, outputs, output);
112163 +#else
112164 + vec_safe_push(inputs, input);
112165 + vec_safe_push(outputs, output);
112166 +#endif
112167 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
112168 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
112169 + gimple_asm_set_volatile(asm_or_stmt, true);
112170 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
112171 + update_stmt(asm_or_stmt);
112172 +
112173 + // replace call stmt fn with the new fptr
112174 + gimple_call_set_fn(call_stmt, new_fptr);
112175 + update_stmt(call_stmt);
112176 +}
112177 +
112178 +/*
112179 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
112180 + */
112181 +static unsigned int execute_kernexec_fptr(void)
112182 +{
112183 + basic_block bb;
112184 +
112185 + // 1. loop through BBs and GIMPLE statements
112186 + FOR_EACH_BB_FN(bb, cfun) {
112187 + gimple_stmt_iterator gsi;
112188 +
112189 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112190 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
112191 + tree fn;
112192 + gimple call_stmt;
112193 +
112194 + // is it a call ...
112195 + call_stmt = gsi_stmt(gsi);
112196 + if (!is_gimple_call(call_stmt))
112197 + continue;
112198 + fn = gimple_call_fn(call_stmt);
112199 + if (TREE_CODE(fn) == ADDR_EXPR)
112200 + continue;
112201 + if (TREE_CODE(fn) != SSA_NAME)
112202 + gcc_unreachable();
112203 +
112204 + // ... through a function pointer
112205 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112206 + fn = SSA_NAME_VAR(fn);
112207 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112208 + debug_tree(fn);
112209 + gcc_unreachable();
112210 + }
112211 + }
112212 + fn = TREE_TYPE(fn);
112213 + if (TREE_CODE(fn) != POINTER_TYPE)
112214 + continue;
112215 + fn = TREE_TYPE(fn);
112216 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112217 + continue;
112218 +
112219 + kernexec_instrument_fptr(&gsi);
112220 +
112221 +//debug_tree(gimple_call_fn(call_stmt));
112222 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112223 + }
112224 + }
112225 +
112226 + return 0;
112227 +}
112228 +
112229 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112230 +static void kernexec_instrument_retaddr_bts(rtx insn)
112231 +{
112232 + rtx btsq;
112233 + rtvec argvec, constraintvec, labelvec;
112234 + int line;
112235 +
112236 + // create asm volatile("btsq $63,(%%rsp)":::)
112237 + argvec = rtvec_alloc(0);
112238 + constraintvec = rtvec_alloc(0);
112239 + labelvec = rtvec_alloc(0);
112240 + line = expand_location(RTL_LOCATION(insn)).line;
112241 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112242 + MEM_VOLATILE_P(btsq) = 1;
112243 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112244 + emit_insn_before(btsq, insn);
112245 +}
112246 +
112247 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112248 +static void kernexec_instrument_retaddr_or(rtx insn)
112249 +{
112250 + rtx orq;
112251 + rtvec argvec, constraintvec, labelvec;
112252 + int line;
112253 +
112254 + // create asm volatile("orq %%r12,(%%rsp)":::)
112255 + argvec = rtvec_alloc(0);
112256 + constraintvec = rtvec_alloc(0);
112257 + labelvec = rtvec_alloc(0);
112258 + line = expand_location(RTL_LOCATION(insn)).line;
112259 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112260 + MEM_VOLATILE_P(orq) = 1;
112261 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112262 + emit_insn_before(orq, insn);
112263 +}
112264 +
112265 +/*
112266 + * find all asm level function returns and forcibly set the highest bit of the return address
112267 + */
112268 +static unsigned int execute_kernexec_retaddr(void)
112269 +{
112270 + rtx insn;
112271 +
112272 +// if (stack_realign_drap)
112273 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112274 +
112275 + // 1. find function returns
112276 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112277 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112278 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112279 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112280 + rtx body;
112281 +
112282 + // is it a retn
112283 + if (!JUMP_P(insn))
112284 + continue;
112285 + body = PATTERN(insn);
112286 + if (GET_CODE(body) == PARALLEL)
112287 + body = XVECEXP(body, 0, 0);
112288 + if (!ANY_RETURN_P(body))
112289 + continue;
112290 + kernexec_instrument_retaddr(insn);
112291 + }
112292 +
112293 +// print_simple_rtl(stderr, get_insns());
112294 +// print_rtl(stderr, get_insns());
112295 +
112296 + return 0;
112297 +}
112298 +
112299 +static bool kernexec_cmodel_check(void)
112300 +{
112301 + tree section;
112302 +
112303 + if (ix86_cmodel != CM_KERNEL)
112304 + return false;
112305 +
112306 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112307 + if (!section || !TREE_VALUE(section))
112308 + return true;
112309 +
112310 + section = TREE_VALUE(TREE_VALUE(section));
112311 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112312 + return true;
112313 +
112314 + return false;
112315 +}
112316 +
112317 +#if BUILDING_GCC_VERSION >= 4009
112318 +static const struct pass_data kernexec_reload_pass_data = {
112319 +#else
112320 +static struct gimple_opt_pass kernexec_reload_pass = {
112321 + .pass = {
112322 +#endif
112323 + .type = GIMPLE_PASS,
112324 + .name = "kernexec_reload",
112325 +#if BUILDING_GCC_VERSION >= 4008
112326 + .optinfo_flags = OPTGROUP_NONE,
112327 +#endif
112328 +#if BUILDING_GCC_VERSION >= 4009
112329 + .has_gate = true,
112330 + .has_execute = true,
112331 +#else
112332 + .gate = kernexec_cmodel_check,
112333 + .execute = execute_kernexec_reload,
112334 + .sub = NULL,
112335 + .next = NULL,
112336 + .static_pass_number = 0,
112337 +#endif
112338 + .tv_id = TV_NONE,
112339 + .properties_required = 0,
112340 + .properties_provided = 0,
112341 + .properties_destroyed = 0,
112342 + .todo_flags_start = 0,
112343 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112344 +#if BUILDING_GCC_VERSION < 4009
112345 + }
112346 +#endif
112347 +};
112348 +
112349 +#if BUILDING_GCC_VERSION >= 4009
112350 +static const struct pass_data kernexec_fptr_pass_data = {
112351 +#else
112352 +static struct gimple_opt_pass kernexec_fptr_pass = {
112353 + .pass = {
112354 +#endif
112355 + .type = GIMPLE_PASS,
112356 + .name = "kernexec_fptr",
112357 +#if BUILDING_GCC_VERSION >= 4008
112358 + .optinfo_flags = OPTGROUP_NONE,
112359 +#endif
112360 +#if BUILDING_GCC_VERSION >= 4009
112361 + .has_gate = true,
112362 + .has_execute = true,
112363 +#else
112364 + .gate = kernexec_cmodel_check,
112365 + .execute = execute_kernexec_fptr,
112366 + .sub = NULL,
112367 + .next = NULL,
112368 + .static_pass_number = 0,
112369 +#endif
112370 + .tv_id = TV_NONE,
112371 + .properties_required = 0,
112372 + .properties_provided = 0,
112373 + .properties_destroyed = 0,
112374 + .todo_flags_start = 0,
112375 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112376 +#if BUILDING_GCC_VERSION < 4009
112377 + }
112378 +#endif
112379 +};
112380 +
112381 +#if BUILDING_GCC_VERSION >= 4009
112382 +static const struct pass_data kernexec_retaddr_pass_data = {
112383 +#else
112384 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112385 + .pass = {
112386 +#endif
112387 + .type = RTL_PASS,
112388 + .name = "kernexec_retaddr",
112389 +#if BUILDING_GCC_VERSION >= 4008
112390 + .optinfo_flags = OPTGROUP_NONE,
112391 +#endif
112392 +#if BUILDING_GCC_VERSION >= 4009
112393 + .has_gate = true,
112394 + .has_execute = true,
112395 +#else
112396 + .gate = kernexec_cmodel_check,
112397 + .execute = execute_kernexec_retaddr,
112398 + .sub = NULL,
112399 + .next = NULL,
112400 + .static_pass_number = 0,
112401 +#endif
112402 + .tv_id = TV_NONE,
112403 + .properties_required = 0,
112404 + .properties_provided = 0,
112405 + .properties_destroyed = 0,
112406 + .todo_flags_start = 0,
112407 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112408 +#if BUILDING_GCC_VERSION < 4009
112409 + }
112410 +#endif
112411 +};
112412 +
112413 +#if BUILDING_GCC_VERSION >= 4009
112414 +namespace {
112415 +class kernexec_reload_pass : public gimple_opt_pass {
112416 +public:
112417 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112418 + bool gate() { return kernexec_cmodel_check(); }
112419 + unsigned int execute() { return execute_kernexec_reload(); }
112420 +};
112421 +
112422 +class kernexec_fptr_pass : public gimple_opt_pass {
112423 +public:
112424 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112425 + bool gate() { return kernexec_cmodel_check(); }
112426 + unsigned int execute() { return execute_kernexec_fptr(); }
112427 +};
112428 +
112429 +class kernexec_retaddr_pass : public rtl_opt_pass {
112430 +public:
112431 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112432 + bool gate() { return kernexec_cmodel_check(); }
112433 + unsigned int execute() { return execute_kernexec_retaddr(); }
112434 +};
112435 +}
112436 +
112437 +static opt_pass *make_kernexec_reload_pass(void)
112438 +{
112439 + return new kernexec_reload_pass();
112440 +}
112441 +
112442 +static opt_pass *make_kernexec_fptr_pass(void)
112443 +{
112444 + return new kernexec_fptr_pass();
112445 +}
112446 +
112447 +static opt_pass *make_kernexec_retaddr_pass(void)
112448 +{
112449 + return new kernexec_retaddr_pass();
112450 +}
112451 +#else
112452 +static struct opt_pass *make_kernexec_reload_pass(void)
112453 +{
112454 + return &kernexec_reload_pass.pass;
112455 +}
112456 +
112457 +static struct opt_pass *make_kernexec_fptr_pass(void)
112458 +{
112459 + return &kernexec_fptr_pass.pass;
112460 +}
112461 +
112462 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112463 +{
112464 + return &kernexec_retaddr_pass.pass;
112465 +}
112466 +#endif
112467 +
112468 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112469 +{
112470 + const char * const plugin_name = plugin_info->base_name;
112471 + const int argc = plugin_info->argc;
112472 + const struct plugin_argument * const argv = plugin_info->argv;
112473 + int i;
112474 + struct register_pass_info kernexec_reload_pass_info;
112475 + struct register_pass_info kernexec_fptr_pass_info;
112476 + struct register_pass_info kernexec_retaddr_pass_info;
112477 +
112478 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112479 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112480 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112481 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112482 +
112483 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112484 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112485 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112486 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112487 +
112488 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112489 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112490 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112491 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112492 +
112493 + if (!plugin_default_version_check(version, &gcc_version)) {
112494 + error(G_("incompatible gcc/plugin versions"));
112495 + return 1;
112496 + }
112497 +
112498 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112499 +
112500 + if (TARGET_64BIT == 0)
112501 + return 0;
112502 +
112503 + for (i = 0; i < argc; ++i) {
112504 + if (!strcmp(argv[i].key, "method")) {
112505 + if (!argv[i].value) {
112506 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112507 + continue;
112508 + }
112509 + if (!strcmp(argv[i].value, "bts")) {
112510 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112511 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112512 + } else if (!strcmp(argv[i].value, "or")) {
112513 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112514 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112515 + fix_register("r12", 1, 1);
112516 + } else
112517 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112518 + continue;
112519 + }
112520 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112521 + }
112522 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112523 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112524 +
112525 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112526 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112527 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112528 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112529 +
112530 + return 0;
112531 +}
112532 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112533 new file mode 100644
112534 index 0000000..e48b323
112535 --- /dev/null
112536 +++ b/tools/gcc/latent_entropy_plugin.c
112537 @@ -0,0 +1,466 @@
112538 +/*
112539 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112540 + * Licensed under the GPL v2
112541 + *
112542 + * Note: the choice of the license means that the compilation process is
112543 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112544 + * but for the kernel it doesn't matter since it doesn't link against
112545 + * any of the gcc libraries
112546 + *
112547 + * gcc plugin to help generate a little bit of entropy from program state,
112548 + * used throughout the uptime of the kernel
112549 + *
112550 + * TODO:
112551 + * - add ipa pass to identify not explicitly marked candidate functions
112552 + * - mix in more program state (function arguments/return values, loop variables, etc)
112553 + * - more instrumentation control via attribute parameters
112554 + *
112555 + * BUGS:
112556 + * - LTO needs -flto-partition=none for now
112557 + */
112558 +
112559 +#include "gcc-common.h"
112560 +
112561 +int plugin_is_GPL_compatible;
112562 +
112563 +static tree latent_entropy_decl;
112564 +
112565 +static struct plugin_info latent_entropy_plugin_info = {
112566 + .version = "201409101820",
112567 + .help = NULL
112568 +};
112569 +
112570 +static unsigned HOST_WIDE_INT seed;
112571 +static unsigned HOST_WIDE_INT get_random_const(void)
112572 +{
112573 + unsigned int i;
112574 + unsigned HOST_WIDE_INT ret = 0;
112575 +
112576 + for (i = 0; i < 8 * sizeof ret; i++) {
112577 + ret = (ret << 1) | (seed & 1);
112578 + seed >>= 1;
112579 + if (ret & 1)
112580 + seed ^= 0xD800000000000000ULL;
112581 + }
112582 +
112583 + return ret;
112584 +}
112585 +
112586 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112587 +{
112588 + tree type;
112589 + unsigned long long mask;
112590 +#if BUILDING_GCC_VERSION <= 4007
112591 + VEC(constructor_elt, gc) *vals;
112592 +#else
112593 + vec<constructor_elt, va_gc> *vals;
112594 +#endif
112595 +
112596 + switch (TREE_CODE(*node)) {
112597 + default:
112598 + *no_add_attrs = true;
112599 + error("%qE attribute only applies to functions and variables", name);
112600 + break;
112601 +
112602 + case VAR_DECL:
112603 + if (DECL_INITIAL(*node)) {
112604 + *no_add_attrs = true;
112605 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112606 + break;
112607 + }
112608 +
112609 + if (!TREE_STATIC(*node)) {
112610 + *no_add_attrs = true;
112611 + error("variable %qD with %qE attribute must not be local", *node, name);
112612 + break;
112613 + }
112614 +
112615 + type = TREE_TYPE(*node);
112616 + switch (TREE_CODE(type)) {
112617 + default:
112618 + *no_add_attrs = true;
112619 + 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);
112620 + break;
112621 +
112622 + case RECORD_TYPE: {
112623 + tree field;
112624 + unsigned int nelt = 0;
112625 +
112626 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112627 + tree fieldtype;
112628 +
112629 + fieldtype = TREE_TYPE(field);
112630 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112631 + *no_add_attrs = true;
112632 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112633 + break;
112634 + }
112635 + }
112636 +
112637 + if (field)
112638 + break;
112639 +
112640 +#if BUILDING_GCC_VERSION <= 4007
112641 + vals = VEC_alloc(constructor_elt, gc, nelt);
112642 +#else
112643 + vec_alloc(vals, nelt);
112644 +#endif
112645 +
112646 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112647 + tree fieldtype;
112648 +
112649 + fieldtype = TREE_TYPE(field);
112650 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112651 + mask = 2 * (mask - 1) + 1;
112652 +
112653 + if (TYPE_UNSIGNED(fieldtype))
112654 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112655 + else
112656 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112657 + }
112658 +
112659 + DECL_INITIAL(*node) = build_constructor(type, vals);
112660 +//debug_tree(DECL_INITIAL(*node));
112661 + break;
112662 + }
112663 +
112664 + case INTEGER_TYPE:
112665 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112666 + mask = 2 * (mask - 1) + 1;
112667 +
112668 + if (TYPE_UNSIGNED(type))
112669 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112670 + else
112671 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112672 + break;
112673 +
112674 + case ARRAY_TYPE: {
112675 + tree elt_type, array_size, elt_size;
112676 + unsigned int i, nelt;
112677 +
112678 + elt_type = TREE_TYPE(type);
112679 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112680 + array_size = TYPE_SIZE_UNIT(type);
112681 +
112682 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112683 + *no_add_attrs = true;
112684 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112685 + break;
112686 + }
112687 +
112688 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112689 +#if BUILDING_GCC_VERSION <= 4007
112690 + vals = VEC_alloc(constructor_elt, gc, nelt);
112691 +#else
112692 + vec_alloc(vals, nelt);
112693 +#endif
112694 +
112695 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112696 + mask = 2 * (mask - 1) + 1;
112697 +
112698 + for (i = 0; i < nelt; i++)
112699 + if (TYPE_UNSIGNED(elt_type))
112700 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112701 + else
112702 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112703 +
112704 + DECL_INITIAL(*node) = build_constructor(type, vals);
112705 +//debug_tree(DECL_INITIAL(*node));
112706 + break;
112707 + }
112708 + }
112709 + break;
112710 +
112711 + case FUNCTION_DECL:
112712 + break;
112713 + }
112714 +
112715 + return NULL_TREE;
112716 +}
112717 +
112718 +static struct attribute_spec latent_entropy_attr = {
112719 + .name = "latent_entropy",
112720 + .min_length = 0,
112721 + .max_length = 0,
112722 + .decl_required = true,
112723 + .type_required = false,
112724 + .function_type_required = false,
112725 + .handler = handle_latent_entropy_attribute,
112726 +#if BUILDING_GCC_VERSION >= 4007
112727 + .affects_type_identity = false
112728 +#endif
112729 +};
112730 +
112731 +static void register_attributes(void *event_data, void *data)
112732 +{
112733 + register_attribute(&latent_entropy_attr);
112734 +}
112735 +
112736 +static bool gate_latent_entropy(void)
112737 +{
112738 + // don't bother with noreturn functions for now
112739 + if (TREE_THIS_VOLATILE(current_function_decl))
112740 + return false;
112741 +
112742 + // gcc-4.5 doesn't discover some trivial noreturn functions
112743 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112744 + return false;
112745 +
112746 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112747 +}
112748 +
112749 +static enum tree_code get_op(tree *rhs)
112750 +{
112751 + static enum tree_code op;
112752 + unsigned HOST_WIDE_INT random_const;
112753 +
112754 + random_const = get_random_const();
112755 +
112756 + switch (op) {
112757 + case BIT_XOR_EXPR:
112758 + op = PLUS_EXPR;
112759 + break;
112760 +
112761 + case PLUS_EXPR:
112762 + if (rhs) {
112763 + op = LROTATE_EXPR;
112764 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112765 + break;
112766 + }
112767 +
112768 + case LROTATE_EXPR:
112769 + default:
112770 + op = BIT_XOR_EXPR;
112771 + break;
112772 + }
112773 + if (rhs)
112774 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112775 + return op;
112776 +}
112777 +
112778 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112779 +{
112780 + gimple_stmt_iterator gsi;
112781 + gimple assign;
112782 + tree addxorrol, rhs;
112783 + enum tree_code op;
112784 +
112785 + op = get_op(&rhs);
112786 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112787 + assign = gimple_build_assign(local_entropy, addxorrol);
112788 + gsi = gsi_after_labels(bb);
112789 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112790 + update_stmt(assign);
112791 +//debug_bb(bb);
112792 +}
112793 +
112794 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112795 +{
112796 + gimple_stmt_iterator gsi;
112797 + gimple assign;
112798 + tree addxorrol, temp;
112799 +
112800 + // 1. create temporary copy of latent_entropy
112801 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112802 + add_referenced_var(temp);
112803 +
112804 + // 2. read...
112805 + temp = make_ssa_name(temp, NULL);
112806 + assign = gimple_build_assign(temp, latent_entropy_decl);
112807 + SSA_NAME_DEF_STMT(temp) = assign;
112808 + add_referenced_var(latent_entropy_decl);
112809 + gsi = gsi_after_labels(bb);
112810 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112811 + update_stmt(assign);
112812 +
112813 + // 3. ...modify...
112814 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112815 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112816 + assign = gimple_build_assign(temp, addxorrol);
112817 + SSA_NAME_DEF_STMT(temp) = assign;
112818 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112819 + update_stmt(assign);
112820 +
112821 + // 4. ...write latent_entropy
112822 + assign = gimple_build_assign(latent_entropy_decl, temp);
112823 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112824 + update_stmt(assign);
112825 +}
112826 +
112827 +static unsigned int execute_latent_entropy(void)
112828 +{
112829 + basic_block bb;
112830 + gimple assign;
112831 + gimple_stmt_iterator gsi;
112832 + tree local_entropy;
112833 +
112834 + if (!latent_entropy_decl) {
112835 +#if BUILDING_GCC_VERSION >= 4009
112836 + varpool_node *node;
112837 +#else
112838 + struct varpool_node *node;
112839 +#endif
112840 +
112841 + FOR_EACH_VARIABLE(node) {
112842 + tree var = NODE_DECL(node);
112843 +
112844 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112845 + continue;
112846 + latent_entropy_decl = var;
112847 +// debug_tree(var);
112848 + break;
112849 + }
112850 + if (!latent_entropy_decl) {
112851 +// debug_tree(current_function_decl);
112852 + return 0;
112853 + }
112854 + }
112855 +
112856 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112857 +
112858 + // 1. create local entropy variable
112859 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112860 + add_referenced_var(local_entropy);
112861 + mark_sym_for_renaming(local_entropy);
112862 +
112863 + // 2. initialize local entropy variable
112864 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112865 + if (dom_info_available_p(CDI_DOMINATORS))
112866 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112867 + gsi = gsi_start_bb(bb);
112868 +
112869 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112870 +// gimple_set_location(assign, loc);
112871 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112872 + update_stmt(assign);
112873 +//debug_bb(bb);
112874 + gcc_assert(single_succ_p(bb));
112875 + bb = single_succ(bb);
112876 +
112877 + // 3. instrument each BB with an operation on the local entropy variable
112878 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112879 + perturb_local_entropy(bb, local_entropy);
112880 +//debug_bb(bb);
112881 + bb = bb->next_bb;
112882 + };
112883 +
112884 + // 4. mix local entropy into the global entropy variable
112885 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112886 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
112887 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112888 + return 0;
112889 +}
112890 +
112891 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
112892 +{
112893 + tree latent_entropy_type;
112894 +
112895 + seed = get_random_seed(false);
112896 +
112897 + if (in_lto_p)
112898 + return;
112899 +
112900 + // extern volatile u64 latent_entropy
112901 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
112902 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
112903 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
112904 +
112905 + TREE_STATIC(latent_entropy_decl) = 1;
112906 + TREE_PUBLIC(latent_entropy_decl) = 1;
112907 + TREE_USED(latent_entropy_decl) = 1;
112908 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
112909 + DECL_EXTERNAL(latent_entropy_decl) = 1;
112910 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
112911 + lang_hooks.decls.pushdecl(latent_entropy_decl);
112912 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
112913 +// varpool_finalize_decl(latent_entropy_decl);
112914 +// varpool_mark_needed_node(latent_entropy_decl);
112915 +}
112916 +
112917 +#if BUILDING_GCC_VERSION >= 4009
112918 +static const struct pass_data latent_entropy_pass_data = {
112919 +#else
112920 +static struct gimple_opt_pass latent_entropy_pass = {
112921 + .pass = {
112922 +#endif
112923 + .type = GIMPLE_PASS,
112924 + .name = "latent_entropy",
112925 +#if BUILDING_GCC_VERSION >= 4008
112926 + .optinfo_flags = OPTGROUP_NONE,
112927 +#endif
112928 +#if BUILDING_GCC_VERSION >= 4009
112929 + .has_gate = true,
112930 + .has_execute = true,
112931 +#else
112932 + .gate = gate_latent_entropy,
112933 + .execute = execute_latent_entropy,
112934 + .sub = NULL,
112935 + .next = NULL,
112936 + .static_pass_number = 0,
112937 +#endif
112938 + .tv_id = TV_NONE,
112939 + .properties_required = PROP_gimple_leh | PROP_cfg,
112940 + .properties_provided = 0,
112941 + .properties_destroyed = 0,
112942 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
112943 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
112944 +#if BUILDING_GCC_VERSION < 4009
112945 + }
112946 +#endif
112947 +};
112948 +
112949 +#if BUILDING_GCC_VERSION >= 4009
112950 +namespace {
112951 +class latent_entropy_pass : public gimple_opt_pass {
112952 +public:
112953 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
112954 + bool gate() { return gate_latent_entropy(); }
112955 + unsigned int execute() { return execute_latent_entropy(); }
112956 +};
112957 +}
112958 +
112959 +static opt_pass *make_latent_entropy_pass(void)
112960 +{
112961 + return new latent_entropy_pass();
112962 +}
112963 +#else
112964 +static struct opt_pass *make_latent_entropy_pass(void)
112965 +{
112966 + return &latent_entropy_pass.pass;
112967 +}
112968 +#endif
112969 +
112970 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112971 +{
112972 + const char * const plugin_name = plugin_info->base_name;
112973 + struct register_pass_info latent_entropy_pass_info;
112974 +
112975 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
112976 + latent_entropy_pass_info.reference_pass_name = "optimized";
112977 + latent_entropy_pass_info.ref_pass_instance_number = 1;
112978 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
112979 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
112980 + {
112981 + .base = &latent_entropy_decl,
112982 + .nelt = 1,
112983 + .stride = sizeof(latent_entropy_decl),
112984 + .cb = &gt_ggc_mx_tree_node,
112985 + .pchw = &gt_pch_nx_tree_node
112986 + },
112987 + LAST_GGC_ROOT_TAB
112988 + };
112989 +
112990 + if (!plugin_default_version_check(version, &gcc_version)) {
112991 + error(G_("incompatible gcc/plugin versions"));
112992 + return 1;
112993 + }
112994 +
112995 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
112996 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
112997 + if (!in_lto_p)
112998 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
112999 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
113000 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113001 +
113002 + return 0;
113003 +}
113004 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
113005 new file mode 100644
113006 index 0000000..a5cb46b
113007 --- /dev/null
113008 +++ b/tools/gcc/randomize_layout_plugin.c
113009 @@ -0,0 +1,915 @@
113010 +/*
113011 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
113012 + * and PaX Team <pageexec@freemail.hu>
113013 + * Licensed under the GPL v2
113014 + *
113015 + * Usage:
113016 + * $ # for 4.5/4.6/C based 4.7
113017 + * $ 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
113018 + * $ # for C++ based 4.7/4.8+
113019 + * $ 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
113020 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
113021 + */
113022 +
113023 +#include "gcc-common.h"
113024 +#include "randomize_layout_seed.h"
113025 +
113026 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
113027 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
113028 +#endif
113029 +
113030 +#define ORIG_TYPE_NAME(node) \
113031 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
113032 +
113033 +int plugin_is_GPL_compatible;
113034 +
113035 +static int performance_mode;
113036 +
113037 +static struct plugin_info randomize_layout_plugin_info = {
113038 + .version = "201402201816",
113039 + .help = "disable\t\t\tdo not activate plugin\n"
113040 + "performance-mode\tenable cacheline-aware layout randomization\n"
113041 +};
113042 +
113043 +/* from old Linux dcache.h */
113044 +static inline unsigned long
113045 +partial_name_hash(unsigned long c, unsigned long prevhash)
113046 +{
113047 + return (prevhash + (c << 4) + (c >> 4)) * 11;
113048 +}
113049 +static inline unsigned int
113050 +name_hash(const unsigned char *name)
113051 +{
113052 + unsigned long hash = 0;
113053 + unsigned int len = strlen((const char *)name);
113054 + while (len--)
113055 + hash = partial_name_hash(*name++, hash);
113056 + return (unsigned int)hash;
113057 +}
113058 +
113059 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113060 +{
113061 + tree type;
113062 +
113063 + *no_add_attrs = true;
113064 + if (TREE_CODE(*node) == FUNCTION_DECL) {
113065 + error("%qE attribute does not apply to functions (%qF)", name, *node);
113066 + return NULL_TREE;
113067 + }
113068 +
113069 + if (TREE_CODE(*node) == PARM_DECL) {
113070 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
113071 + return NULL_TREE;
113072 + }
113073 +
113074 + if (TREE_CODE(*node) == VAR_DECL) {
113075 + error("%qE attribute does not apply to variables (%qD)", name, *node);
113076 + return NULL_TREE;
113077 + }
113078 +
113079 + if (TYPE_P(*node)) {
113080 + type = *node;
113081 + } else {
113082 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
113083 + type = TREE_TYPE(*node);
113084 + }
113085 +
113086 + if (TREE_CODE(type) != RECORD_TYPE) {
113087 + error("%qE attribute used on %qT applies to struct types only", name, type);
113088 + return NULL_TREE;
113089 + }
113090 +
113091 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
113092 + error("%qE attribute is already applied to the type %qT", name, type);
113093 + return NULL_TREE;
113094 + }
113095 +
113096 + *no_add_attrs = false;
113097 +
113098 + return NULL_TREE;
113099 +}
113100 +
113101 +/* set on complete types that we don't need to inspect further at all */
113102 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113103 +{
113104 + *no_add_attrs = false;
113105 + return NULL_TREE;
113106 +}
113107 +
113108 +/*
113109 + * set on types that we've performed a shuffle on, to prevent re-shuffling
113110 + * this does not preclude us from inspecting its fields for potential shuffles
113111 + */
113112 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113113 +{
113114 + *no_add_attrs = false;
113115 + return NULL_TREE;
113116 +}
113117 +
113118 +/*
113119 + * 64bit variant of Bob Jenkins' public domain PRNG
113120 + * 256 bits of internal state
113121 + */
113122 +
113123 +typedef unsigned long long u64;
113124 +
113125 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
113126 +
113127 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
113128 +static u64 ranval(ranctx *x) {
113129 + u64 e = x->a - rot(x->b, 7);
113130 + x->a = x->b ^ rot(x->c, 13);
113131 + x->b = x->c + rot(x->d, 37);
113132 + x->c = x->d + e;
113133 + x->d = e + x->a;
113134 + return x->d;
113135 +}
113136 +
113137 +static void raninit(ranctx *x, u64 *seed) {
113138 + int i;
113139 +
113140 + x->a = seed[0];
113141 + x->b = seed[1];
113142 + x->c = seed[2];
113143 + x->d = seed[3];
113144 +
113145 + for (i=0; i < 30; ++i)
113146 + (void)ranval(x);
113147 +}
113148 +
113149 +static u64 shuffle_seed[4];
113150 +
113151 +struct partition_group {
113152 + tree tree_start;
113153 + unsigned long start;
113154 + unsigned long length;
113155 +};
113156 +
113157 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
113158 +{
113159 + unsigned long i;
113160 + unsigned long accum_size = 0;
113161 + unsigned long accum_length = 0;
113162 + unsigned long group_idx = 0;
113163 +
113164 + gcc_assert(length < INT_MAX);
113165 +
113166 + memset(size_groups, 0, sizeof(struct partition_group) * length);
113167 +
113168 + for (i = 0; i < length; i++) {
113169 + if (size_groups[group_idx].tree_start == NULL_TREE) {
113170 + size_groups[group_idx].tree_start = fields[i];
113171 + size_groups[group_idx].start = i;
113172 + accum_length = 0;
113173 + accum_size = 0;
113174 + }
113175 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
113176 + accum_length++;
113177 + if (accum_size >= 64) {
113178 + size_groups[group_idx].length = accum_length;
113179 + accum_length = 0;
113180 + group_idx++;
113181 + }
113182 + }
113183 +
113184 + if (size_groups[group_idx].tree_start != NULL_TREE &&
113185 + !size_groups[group_idx].length) {
113186 + size_groups[group_idx].length = accum_length;
113187 + group_idx++;
113188 + }
113189 +
113190 + *num_groups = group_idx;
113191 +}
113192 +
113193 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113194 +{
113195 + unsigned long i, x;
113196 + struct partition_group size_group[length];
113197 + unsigned long num_groups = 0;
113198 + unsigned long randnum;
113199 +
113200 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113201 + for (i = num_groups - 1; i > 0; i--) {
113202 + struct partition_group tmp;
113203 + randnum = ranval(prng_state) % (i + 1);
113204 + tmp = size_group[i];
113205 + size_group[i] = size_group[randnum];
113206 + size_group[randnum] = tmp;
113207 + }
113208 +
113209 + for (x = 0; x < num_groups; x++) {
113210 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113211 + tree tmp;
113212 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113213 + continue;
113214 + randnum = ranval(prng_state) % (i + 1);
113215 + // we could handle this case differently if desired
113216 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113217 + continue;
113218 + tmp = newtree[i];
113219 + newtree[i] = newtree[randnum];
113220 + newtree[randnum] = tmp;
113221 + }
113222 + }
113223 +}
113224 +
113225 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113226 +{
113227 + unsigned long i, randnum;
113228 +
113229 + for (i = length - 1; i > 0; i--) {
113230 + tree tmp;
113231 + randnum = ranval(prng_state) % (i + 1);
113232 + tmp = newtree[i];
113233 + newtree[i] = newtree[randnum];
113234 + newtree[randnum] = tmp;
113235 + }
113236 +}
113237 +
113238 +/* modern in-place Fisher-Yates shuffle */
113239 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113240 +{
113241 + unsigned long i;
113242 + u64 seed[4];
113243 + ranctx prng_state;
113244 + const unsigned char *structname;
113245 +
113246 + if (length == 0)
113247 + return;
113248 +
113249 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113250 +
113251 + structname = ORIG_TYPE_NAME(type);
113252 +
113253 +#ifdef __DEBUG_PLUGIN
113254 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113255 +#ifdef __DEBUG_VERBOSE
113256 + debug_tree((tree)type);
113257 +#endif
113258 +#endif
113259 +
113260 + for (i = 0; i < 4; i++) {
113261 + seed[i] = shuffle_seed[i];
113262 + seed[i] ^= name_hash(structname);
113263 + }
113264 +
113265 + raninit(&prng_state, (u64 *)&seed);
113266 +
113267 + if (performance_mode)
113268 + performance_shuffle(newtree, length, &prng_state);
113269 + else
113270 + full_shuffle(newtree, length, &prng_state);
113271 +}
113272 +
113273 +static bool is_flexible_array(const_tree field)
113274 +{
113275 + const_tree fieldtype;
113276 + const_tree typesize;
113277 + const_tree elemtype;
113278 + const_tree elemsize;
113279 +
113280 + fieldtype = TREE_TYPE(field);
113281 + typesize = TYPE_SIZE(fieldtype);
113282 +
113283 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113284 + return false;
113285 +
113286 + elemtype = TREE_TYPE(fieldtype);
113287 + elemsize = TYPE_SIZE(elemtype);
113288 +
113289 + /* size of type is represented in bits */
113290 +
113291 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113292 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113293 + return true;
113294 +
113295 + if (typesize != NULL_TREE &&
113296 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113297 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113298 + return true;
113299 +
113300 + return false;
113301 +}
113302 +
113303 +static int relayout_struct(tree type)
113304 +{
113305 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113306 + unsigned long shuffle_length = num_fields;
113307 + tree field;
113308 + tree newtree[num_fields];
113309 + unsigned long i;
113310 + tree list;
113311 + tree variant;
113312 + expanded_location xloc;
113313 +
113314 + if (TYPE_FIELDS(type) == NULL_TREE)
113315 + return 0;
113316 +
113317 + if (num_fields < 2)
113318 + return 0;
113319 +
113320 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113321 +
113322 + gcc_assert(num_fields < INT_MAX);
113323 +
113324 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113325 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113326 + return 0;
113327 +
113328 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113329 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113330 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113331 + return 0;
113332 +
113333 + /* throw out any structs in uapi */
113334 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113335 +
113336 + if (strstr(xloc.file, "/uapi/"))
113337 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113338 +
113339 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113340 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113341 + newtree[i] = field;
113342 + }
113343 +
113344 + /*
113345 + * enforce that we don't randomize the layout of the last
113346 + * element of a struct if it's a 0 or 1-length array
113347 + * or a proper flexible array
113348 + */
113349 + if (is_flexible_array(newtree[num_fields - 1]))
113350 + shuffle_length--;
113351 +
113352 + shuffle(type, (tree *)newtree, shuffle_length);
113353 +
113354 + /*
113355 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113356 + * as gcc provides no other way to detect such code
113357 + */
113358 + list = make_node(FIELD_DECL);
113359 + TREE_CHAIN(list) = newtree[0];
113360 + TREE_TYPE(list) = void_type_node;
113361 + DECL_SIZE(list) = bitsize_zero_node;
113362 + DECL_NONADDRESSABLE_P(list) = 1;
113363 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113364 + DECL_SIZE_UNIT(list) = size_zero_node;
113365 + DECL_FIELD_OFFSET(list) = size_zero_node;
113366 + // to satisfy the constify plugin
113367 + TREE_READONLY(list) = 1;
113368 +
113369 + for (i = 0; i < num_fields - 1; i++)
113370 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113371 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113372 +
113373 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113374 + TYPE_FIELDS(variant) = list;
113375 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113376 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113377 + // force a re-layout
113378 + TYPE_SIZE(variant) = NULL_TREE;
113379 + layout_type(variant);
113380 + }
113381 +
113382 + return 1;
113383 +}
113384 +
113385 +/* from constify plugin */
113386 +static const_tree get_field_type(const_tree field)
113387 +{
113388 + return strip_array_types(TREE_TYPE(field));
113389 +}
113390 +
113391 +/* from constify plugin */
113392 +static bool is_fptr(const_tree fieldtype)
113393 +{
113394 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113395 + return false;
113396 +
113397 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113398 +}
113399 +
113400 +/* derived from constify plugin */
113401 +static int is_pure_ops_struct(const_tree node)
113402 +{
113403 + const_tree field;
113404 +
113405 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113406 +
113407 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113408 + const_tree fieldtype = get_field_type(field);
113409 + enum tree_code code = TREE_CODE(fieldtype);
113410 +
113411 + if (node == fieldtype)
113412 + continue;
113413 +
113414 + if (!is_fptr(fieldtype))
113415 + return 0;
113416 +
113417 + if (code != RECORD_TYPE && code != UNION_TYPE)
113418 + continue;
113419 +
113420 + if (!is_pure_ops_struct(fieldtype))
113421 + return 0;
113422 + }
113423 +
113424 + return 1;
113425 +}
113426 +
113427 +static void randomize_type(tree type)
113428 +{
113429 + tree variant;
113430 +
113431 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113432 +
113433 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113434 + return;
113435 +
113436 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113437 + relayout_struct(type);
113438 +
113439 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113440 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113441 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113442 + }
113443 +#ifdef __DEBUG_PLUGIN
113444 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113445 +#ifdef __DEBUG_VERBOSE
113446 + debug_tree(type);
113447 +#endif
113448 +#endif
113449 +}
113450 +
113451 +static void randomize_layout_finish_decl(void *event_data, void *data)
113452 +{
113453 + tree decl = (tree)event_data;
113454 + tree type;
113455 +
113456 + if (decl == NULL_TREE || decl == error_mark_node)
113457 + return;
113458 +
113459 + type = TREE_TYPE(decl);
113460 +
113461 + if (TREE_CODE(decl) != VAR_DECL)
113462 + return;
113463 +
113464 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113465 + return;
113466 +
113467 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113468 + return;
113469 +
113470 + relayout_decl(decl);
113471 +}
113472 +
113473 +static void finish_type(void *event_data, void *data)
113474 +{
113475 + tree type = (tree)event_data;
113476 +
113477 + if (type == NULL_TREE || type == error_mark_node)
113478 + return;
113479 +
113480 + if (TREE_CODE(type) != RECORD_TYPE)
113481 + return;
113482 +
113483 + if (TYPE_FIELDS(type) == NULL_TREE)
113484 + return;
113485 +
113486 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113487 + return;
113488 +
113489 +#ifdef __DEBUG_PLUGIN
113490 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113491 +#endif
113492 +#ifdef __DEBUG_VERBOSE
113493 + debug_tree(type);
113494 +#endif
113495 + randomize_type(type);
113496 +
113497 + return;
113498 +}
113499 +
113500 +static struct attribute_spec randomize_layout_attr = {
113501 + .name = "randomize_layout",
113502 + // related to args
113503 + .min_length = 0,
113504 + .max_length = 0,
113505 + .decl_required = false,
113506 + // need type declaration
113507 + .type_required = true,
113508 + .function_type_required = false,
113509 + .handler = handle_randomize_layout_attr,
113510 +#if BUILDING_GCC_VERSION >= 4007
113511 + .affects_type_identity = true
113512 +#endif
113513 +};
113514 +
113515 +static struct attribute_spec no_randomize_layout_attr = {
113516 + .name = "no_randomize_layout",
113517 + // related to args
113518 + .min_length = 0,
113519 + .max_length = 0,
113520 + .decl_required = false,
113521 + // need type declaration
113522 + .type_required = true,
113523 + .function_type_required = false,
113524 + .handler = handle_randomize_layout_attr,
113525 +#if BUILDING_GCC_VERSION >= 4007
113526 + .affects_type_identity = true
113527 +#endif
113528 +};
113529 +
113530 +static struct attribute_spec randomize_considered_attr = {
113531 + .name = "randomize_considered",
113532 + // related to args
113533 + .min_length = 0,
113534 + .max_length = 0,
113535 + .decl_required = false,
113536 + // need type declaration
113537 + .type_required = true,
113538 + .function_type_required = false,
113539 + .handler = handle_randomize_considered_attr,
113540 +#if BUILDING_GCC_VERSION >= 4007
113541 + .affects_type_identity = false
113542 +#endif
113543 +};
113544 +
113545 +static struct attribute_spec randomize_performed_attr = {
113546 + .name = "randomize_performed",
113547 + // related to args
113548 + .min_length = 0,
113549 + .max_length = 0,
113550 + .decl_required = false,
113551 + // need type declaration
113552 + .type_required = true,
113553 + .function_type_required = false,
113554 + .handler = handle_randomize_performed_attr,
113555 +#if BUILDING_GCC_VERSION >= 4007
113556 + .affects_type_identity = false
113557 +#endif
113558 +};
113559 +
113560 +static void register_attributes(void *event_data, void *data)
113561 +{
113562 + register_attribute(&randomize_layout_attr);
113563 + register_attribute(&no_randomize_layout_attr);
113564 + register_attribute(&randomize_considered_attr);
113565 + register_attribute(&randomize_performed_attr);
113566 +}
113567 +
113568 +static void check_bad_casts_in_constructor(tree var, tree init)
113569 +{
113570 + unsigned HOST_WIDE_INT idx;
113571 + tree field, val;
113572 + tree field_type, val_type;
113573 +
113574 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113575 + if (TREE_CODE(val) == CONSTRUCTOR) {
113576 + check_bad_casts_in_constructor(var, val);
113577 + continue;
113578 + }
113579 +
113580 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113581 + normal code which all have valid 'field' trees. work around this */
113582 + if (field == NULL_TREE)
113583 + continue;
113584 + field_type = TREE_TYPE(field);
113585 + val_type = TREE_TYPE(val);
113586 +
113587 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113588 + continue;
113589 +
113590 + if (field_type == val_type)
113591 + continue;
113592 +
113593 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113594 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113595 +
113596 + if (field_type == void_type_node)
113597 + continue;
113598 + if (field_type == val_type)
113599 + continue;
113600 + if (TREE_CODE(val_type) != RECORD_TYPE)
113601 + continue;
113602 +
113603 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113604 + continue;
113605 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113606 + }
113607 +}
113608 +
113609 +/* derived from the constify plugin */
113610 +static void check_global_variables(void *event_data, void *data)
113611 +{
113612 + struct varpool_node *node;
113613 + tree init;
113614 +
113615 + FOR_EACH_VARIABLE(node) {
113616 + tree var = NODE_DECL(node);
113617 + init = DECL_INITIAL(var);
113618 + if (init == NULL_TREE)
113619 + continue;
113620 +
113621 + if (TREE_CODE(init) != CONSTRUCTOR)
113622 + continue;
113623 +
113624 + check_bad_casts_in_constructor(var, init);
113625 + }
113626 +}
113627 +
113628 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113629 +{
113630 + basic_block dom;
113631 + gimple dom_stmt;
113632 + gimple call_stmt;
113633 + const_tree dom_lhs;
113634 + const_tree poss_is_err_cond;
113635 + const_tree poss_is_err_func;
113636 + const_tree is_err_arg;
113637 +
113638 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113639 + if (!dom)
113640 + return false;
113641 +
113642 + dom_stmt = last_stmt(dom);
113643 + if (!dom_stmt)
113644 + return false;
113645 +
113646 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113647 + return false;
113648 +
113649 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113650 + return false;
113651 +
113652 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113653 + return false;
113654 +
113655 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113656 +
113657 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113658 + return false;
113659 +
113660 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113661 +
113662 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113663 + return false;
113664 +
113665 + dom_lhs = gimple_get_lhs(call_stmt);
113666 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113667 + if (!poss_is_err_func)
113668 + return false;
113669 + if (dom_lhs != poss_is_err_cond)
113670 + return false;
113671 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113672 + return false;
113673 +
113674 + is_err_arg = gimple_call_arg(call_stmt, 0);
113675 + if (!is_err_arg)
113676 + return false;
113677 +
113678 + if (is_err_arg != rhs)
113679 + return false;
113680 +
113681 + return true;
113682 +}
113683 +
113684 +static void handle_local_var_initializers(void)
113685 +{
113686 + tree var;
113687 + unsigned int i;
113688 +
113689 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113690 + tree init = DECL_INITIAL(var);
113691 + if (!init)
113692 + continue;
113693 + if (TREE_CODE(init) != CONSTRUCTOR)
113694 + continue;
113695 + check_bad_casts_in_constructor(var, init);
113696 + }
113697 +}
113698 +
113699 +/*
113700 + * iterate over all statements to find "bad" casts:
113701 + * those where the address of the start of a structure is cast
113702 + * to a pointer of a structure of a different type, or a
113703 + * structure pointer type is cast to a different structure pointer type
113704 + */
113705 +static unsigned int find_bad_casts(void)
113706 +{
113707 + basic_block bb;
113708 +
113709 + handle_local_var_initializers();
113710 +
113711 + FOR_ALL_BB_FN(bb, cfun) {
113712 + gimple_stmt_iterator gsi;
113713 +
113714 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113715 + gimple stmt;
113716 + const_tree lhs;
113717 + const_tree lhs_type;
113718 + const_tree rhs1;
113719 + const_tree rhs_type;
113720 + const_tree ptr_lhs_type;
113721 + const_tree ptr_rhs_type;
113722 + const_tree op0;
113723 + const_tree op0_type;
113724 + enum tree_code rhs_code;
113725 +
113726 + stmt = gsi_stmt(gsi);
113727 +
113728 +#ifdef __DEBUG_PLUGIN
113729 +#ifdef __DEBUG_VERBOSE
113730 + debug_gimple_stmt(stmt);
113731 + debug_tree(gimple_get_lhs(stmt));
113732 +#endif
113733 +#endif
113734 +
113735 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113736 + continue;
113737 +
113738 +#ifdef __DEBUG_PLUGIN
113739 +#ifdef __DEBUG_VERBOSE
113740 + debug_tree(gimple_assign_rhs1(stmt));
113741 +#endif
113742 +#endif
113743 +
113744 + rhs_code = gimple_assign_rhs_code(stmt);
113745 +
113746 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113747 + continue;
113748 +
113749 + lhs = gimple_get_lhs(stmt);
113750 + lhs_type = TREE_TYPE(lhs);
113751 + rhs1 = gimple_assign_rhs1(stmt);
113752 + rhs_type = TREE_TYPE(rhs1);
113753 +
113754 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113755 + TREE_CODE(lhs_type) != POINTER_TYPE)
113756 + continue;
113757 +
113758 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113759 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113760 +
113761 + if (ptr_rhs_type == void_type_node)
113762 + continue;
113763 +
113764 + if (ptr_lhs_type == void_type_node)
113765 + continue;
113766 +
113767 + if (dominated_by_is_err(rhs1, bb))
113768 + continue;
113769 +
113770 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113771 +#ifndef __DEBUG_PLUGIN
113772 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113773 +#endif
113774 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113775 + continue;
113776 + }
113777 +
113778 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113779 + continue;
113780 +
113781 + if (rhs_code == ADDR_EXPR) {
113782 + op0 = TREE_OPERAND(rhs1, 0);
113783 +
113784 + if (op0 == NULL_TREE)
113785 + continue;
113786 +
113787 + if (TREE_CODE(op0) != VAR_DECL)
113788 + continue;
113789 +
113790 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113791 + if (op0_type == ptr_lhs_type)
113792 + continue;
113793 +
113794 +#ifndef __DEBUG_PLUGIN
113795 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113796 +#endif
113797 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113798 + } else {
113799 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113800 + /* skip bogus type casts introduced by container_of */
113801 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113802 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113803 + continue;
113804 +#ifndef __DEBUG_PLUGIN
113805 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113806 +#endif
113807 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113808 + }
113809 +
113810 + }
113811 + }
113812 + return 0;
113813 +}
113814 +
113815 +#if BUILDING_GCC_VERSION >= 4009
113816 +static const struct pass_data randomize_layout_bad_cast_data = {
113817 +#else
113818 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113819 + .pass = {
113820 +#endif
113821 + .type = GIMPLE_PASS,
113822 + .name = "randomize_layout_bad_cast",
113823 +#if BUILDING_GCC_VERSION >= 4008
113824 + .optinfo_flags = OPTGROUP_NONE,
113825 +#endif
113826 +#if BUILDING_GCC_VERSION >= 4009
113827 + .has_gate = false,
113828 + .has_execute = true,
113829 +#else
113830 + .gate = NULL,
113831 + .execute = find_bad_casts,
113832 + .sub = NULL,
113833 + .next = NULL,
113834 + .static_pass_number = 0,
113835 +#endif
113836 + .tv_id = TV_NONE,
113837 + .properties_required = PROP_cfg,
113838 + .properties_provided = 0,
113839 + .properties_destroyed = 0,
113840 + .todo_flags_start = 0,
113841 + .todo_flags_finish = TODO_dump_func
113842 +#if BUILDING_GCC_VERSION < 4009
113843 + }
113844 +#endif
113845 +};
113846 +
113847 +#if BUILDING_GCC_VERSION >= 4009
113848 +namespace {
113849 +class randomize_layout_bad_cast : public gimple_opt_pass {
113850 +public:
113851 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113852 + unsigned int execute() { return find_bad_casts(); }
113853 +};
113854 +}
113855 +#endif
113856 +
113857 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113858 +{
113859 +#if BUILDING_GCC_VERSION >= 4009
113860 + return new randomize_layout_bad_cast();
113861 +#else
113862 + return &randomize_layout_bad_cast.pass;
113863 +#endif
113864 +}
113865 +
113866 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113867 +{
113868 + int i;
113869 + const char * const plugin_name = plugin_info->base_name;
113870 + const int argc = plugin_info->argc;
113871 + const struct plugin_argument * const argv = plugin_info->argv;
113872 + bool enable = true;
113873 + int obtained_seed = 0;
113874 + struct register_pass_info randomize_layout_bad_cast_info;
113875 +
113876 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113877 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113878 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113879 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113880 +
113881 + if (!plugin_default_version_check(version, &gcc_version)) {
113882 + error(G_("incompatible gcc/plugin versions"));
113883 + return 1;
113884 + }
113885 +
113886 + if (strcmp(lang_hooks.name, "GNU C")) {
113887 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
113888 + enable = false;
113889 + }
113890 +
113891 + for (i = 0; i < argc; ++i) {
113892 + if (!strcmp(argv[i].key, "disable")) {
113893 + enable = false;
113894 + continue;
113895 + }
113896 + if (!strcmp(argv[i].key, "performance-mode")) {
113897 + performance_mode = 1;
113898 + continue;
113899 + }
113900 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113901 + }
113902 +
113903 + if (strlen(randstruct_seed) != 64) {
113904 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
113905 + return 1;
113906 + }
113907 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
113908 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
113909 + if (obtained_seed != 4) {
113910 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
113911 + return 1;
113912 + }
113913 +
113914 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
113915 + if (enable) {
113916 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
113917 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
113918 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
113919 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
113920 + }
113921 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113922 +
113923 + return 0;
113924 +}
113925 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
113926 new file mode 100644
113927 index 0000000..1f0214f
113928 --- /dev/null
113929 +++ b/tools/gcc/size_overflow_plugin/.gitignore
113930 @@ -0,0 +1,3 @@
113931 +randomize_layout_seed.h
113932 +size_overflow_hash.h
113933 +size_overflow_hash_aux.h
113934 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
113935 new file mode 100644
113936 index 0000000..1ae2ed5
113937 --- /dev/null
113938 +++ b/tools/gcc/size_overflow_plugin/Makefile
113939 @@ -0,0 +1,20 @@
113940 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
113941 +always := $($(HOSTLIBS)-y)
113942 +
113943 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
113944 +
113945 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
113946 +
113947 +quiet_cmd_build_size_overflow_hash = GENHASH $@
113948 + cmd_build_size_overflow_hash = \
113949 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
113950 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
113951 + $(call if_changed,build_size_overflow_hash)
113952 +
113953 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
113954 + cmd_build_size_overflow_hash_aux = \
113955 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
113956 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
113957 + $(call if_changed,build_size_overflow_hash_aux)
113958 +
113959 +targets += size_overflow_hash.h size_overflow_hash_aux.h
113960 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113961 new file mode 100644
113962 index 0000000..12b1e3b
113963 --- /dev/null
113964 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113965 @@ -0,0 +1,102 @@
113966 +#!/bin/bash
113967 +
113968 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
113969 +
113970 +header1="size_overflow_hash.h"
113971 +database="size_overflow_hash.data"
113972 +n=65536
113973 +hashtable_name="size_overflow_hash"
113974 +
113975 +usage() {
113976 +cat <<EOF
113977 +usage: $0 options
113978 +OPTIONS:
113979 + -h|--help help
113980 + -o header file
113981 + -d database file
113982 + -n hash array size
113983 + -s name of the hash table
113984 +EOF
113985 + return 0
113986 +}
113987 +
113988 +while true
113989 +do
113990 + case "$1" in
113991 + -h|--help) usage && exit 0;;
113992 + -n) n=$2; shift 2;;
113993 + -o) header1="$2"; shift 2;;
113994 + -d) database="$2"; shift 2;;
113995 + -s) hashtable_name="$2"; shift 2;;
113996 + --) shift 1; break ;;
113997 + *) break ;;
113998 + esac
113999 +done
114000 +
114001 +create_defines() {
114002 + for i in `seq 0 31`
114003 + do
114004 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
114005 + done
114006 + echo >> "$header1"
114007 +}
114008 +
114009 +create_structs() {
114010 + rm -f "$header1"
114011 +
114012 + create_defines
114013 +
114014 + cat "$database" | while read data
114015 + do
114016 + data_array=($data)
114017 + struct_hash_name="${data_array[0]}"
114018 + funcn="${data_array[1]}"
114019 + params="${data_array[2]}"
114020 + next="${data_array[4]}"
114021 +
114022 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
114023 +
114024 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
114025 + echo -en "\t.param\t= " >> "$header1"
114026 + line=
114027 + for param_num in ${params//-/ };
114028 + do
114029 + line="${line}PARAM"$param_num"|"
114030 + done
114031 +
114032 + echo -e "${line%?},\n};\n" >> "$header1"
114033 + done
114034 +}
114035 +
114036 +create_headers() {
114037 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
114038 +}
114039 +
114040 +create_array_elements() {
114041 + index=0
114042 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
114043 + do
114044 + data_array=($data)
114045 + i="${data_array[3]}"
114046 + hash="${data_array[0]}"
114047 + while [[ $index -lt $i ]]
114048 + do
114049 + echo -e "\t["$index"]\t= NULL," >> "$header1"
114050 + index=$(($index + 1))
114051 + done
114052 + index=$(($index + 1))
114053 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
114054 + done
114055 + echo '};' >> $header1
114056 +}
114057 +
114058 +size_overflow_plugin_dir=`dirname $header1`
114059 +if [ "$size_overflow_plugin_dir" != '.' ]; then
114060 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
114061 +fi
114062 +
114063 +create_structs
114064 +create_headers
114065 +create_array_elements
114066 +
114067 +exit 0
114068 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114069 new file mode 100644
114070 index 0000000..c43901f
114071 --- /dev/null
114072 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114073 @@ -0,0 +1,748 @@
114074 +/*
114075 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114076 + * Licensed under the GPL v2, or (at your option) v3
114077 + *
114078 + * Homepage:
114079 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114080 + *
114081 + * Documentation:
114082 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114083 + *
114084 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114085 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114086 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114087 + *
114088 + * Usage:
114089 + * $ make
114090 + * $ make run
114091 + */
114092 +
114093 +#include "gcc-common.h"
114094 +#include "size_overflow.h"
114095 +
114096 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114097 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114098 +
114099 +// data for the size_overflow asm stmt
114100 +struct asm_data {
114101 + gimple def_stmt;
114102 + tree input;
114103 + tree output;
114104 +};
114105 +
114106 +#if BUILDING_GCC_VERSION <= 4007
114107 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
114108 +#else
114109 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
114110 +#endif
114111 +{
114112 + tree list;
114113 +#if BUILDING_GCC_VERSION <= 4007
114114 + VEC(tree, gc) *vec_list = NULL;
114115 +#else
114116 + vec<tree, va_gc> *vec_list = NULL;
114117 +#endif
114118 +
114119 + list = build_tree_list(NULL_TREE, string);
114120 + list = chainon(NULL_TREE, build_tree_list(list, io));
114121 +#if BUILDING_GCC_VERSION <= 4007
114122 + VEC_safe_push(tree, gc, vec_list, list);
114123 +#else
114124 + vec_safe_push(vec_list, list);
114125 +#endif
114126 + return vec_list;
114127 +}
114128 +
114129 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
114130 +{
114131 + gimple asm_stmt;
114132 + gimple_stmt_iterator gsi;
114133 +#if BUILDING_GCC_VERSION <= 4007
114134 + VEC(tree, gc) *input, *output = NULL;
114135 +#else
114136 + vec<tree, va_gc> *input, *output = NULL;
114137 +#endif
114138 +
114139 + input = create_asm_io_list(str_input, asm_data->input);
114140 +
114141 + if (asm_data->output)
114142 + output = create_asm_io_list(str_output, asm_data->output);
114143 +
114144 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
114145 + gsi = gsi_for_stmt(asm_data->def_stmt);
114146 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
114147 +
114148 + if (asm_data->output)
114149 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
114150 +}
114151 +
114152 +static void replace_call_lhs(const struct asm_data *asm_data)
114153 +{
114154 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
114155 + update_stmt(asm_data->def_stmt);
114156 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
114157 +}
114158 +
114159 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
114160 +{
114161 + enum mark cur_fndecl_attr;
114162 + gimple phi = get_def_stmt(result);
114163 + unsigned int i, n = gimple_phi_num_args(phi);
114164 +
114165 + pointer_set_insert(visited, phi);
114166 + for (i = 0; i < n; i++) {
114167 + tree arg = gimple_phi_arg_def(phi, i);
114168 +
114169 + cur_fndecl_attr = search_intentional(visited, arg);
114170 + if (cur_fndecl_attr != MARK_NO)
114171 + return cur_fndecl_attr;
114172 + }
114173 + return MARK_NO;
114174 +}
114175 +
114176 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
114177 +{
114178 + enum mark cur_fndecl_attr;
114179 + const_tree rhs1, rhs2;
114180 + gimple def_stmt = get_def_stmt(lhs);
114181 +
114182 + rhs1 = gimple_assign_rhs1(def_stmt);
114183 + rhs2 = gimple_assign_rhs2(def_stmt);
114184 +
114185 + cur_fndecl_attr = search_intentional(visited, rhs1);
114186 + if (cur_fndecl_attr != MARK_NO)
114187 + return cur_fndecl_attr;
114188 + return search_intentional(visited, rhs2);
114189 +}
114190 +
114191 +// Look up the intentional_overflow attribute on the caller and the callee functions.
114192 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
114193 +{
114194 + const_gimple def_stmt;
114195 +
114196 + if (TREE_CODE(lhs) != SSA_NAME)
114197 + return get_intentional_attr_type(lhs);
114198 +
114199 + def_stmt = get_def_stmt(lhs);
114200 + if (!def_stmt)
114201 + return MARK_NO;
114202 +
114203 + if (pointer_set_contains(visited, def_stmt))
114204 + return MARK_NO;
114205 +
114206 + switch (gimple_code(def_stmt)) {
114207 + case GIMPLE_NOP:
114208 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114209 + case GIMPLE_ASM:
114210 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114211 + return MARK_TURN_OFF;
114212 + return MARK_NO;
114213 + case GIMPLE_CALL:
114214 + return MARK_NO;
114215 + case GIMPLE_PHI:
114216 + return search_intentional_phi(visited, lhs);
114217 + case GIMPLE_ASSIGN:
114218 + switch (gimple_num_ops(def_stmt)) {
114219 + case 2:
114220 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114221 + case 3:
114222 + return search_intentional_binary(visited, lhs);
114223 + }
114224 + case GIMPLE_RETURN:
114225 + return MARK_NO;
114226 + default:
114227 + debug_gimple_stmt((gimple)def_stmt);
114228 + error("%s: unknown gimple code", __func__);
114229 + gcc_unreachable();
114230 + }
114231 +}
114232 +
114233 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114234 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114235 +{
114236 + const_tree fndecl;
114237 + struct pointer_set_t *visited;
114238 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114239 +
114240 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114241 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114242 + decl_attr = MARK_NOT_INTENTIONAL;
114243 + else if (is_yes_intentional_attr(fndecl, argnum))
114244 + decl_attr = MARK_YES;
114245 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114246 + return MARK_TURN_OFF;
114247 + }
114248 +
114249 + visited = pointer_set_create();
114250 + cur_fndecl_attr = search_intentional(visited, arg);
114251 + pointer_set_destroy(visited);
114252 +
114253 + switch (cur_fndecl_attr) {
114254 + case MARK_NO:
114255 + case MARK_TURN_OFF:
114256 + return cur_fndecl_attr;
114257 + default:
114258 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114259 + return MARK_YES;
114260 + }
114261 +}
114262 +
114263 +static void check_missing_size_overflow_attribute(tree var)
114264 +{
114265 + tree orig_fndecl;
114266 + unsigned int num;
114267 +
114268 + if (is_a_return_check(var))
114269 + orig_fndecl = DECL_ORIGIN(var);
114270 + else
114271 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114272 +
114273 + num = get_function_num(var, orig_fndecl);
114274 + if (num == CANNOT_FIND_ARG)
114275 + return;
114276 +
114277 + is_missing_function(orig_fndecl, num);
114278 +}
114279 +
114280 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114281 +{
114282 + gimple phi = get_def_stmt(result);
114283 + unsigned int i, n = gimple_phi_num_args(phi);
114284 +
114285 + pointer_set_insert(visited, phi);
114286 + for (i = 0; i < n; i++) {
114287 + tree arg = gimple_phi_arg_def(phi, i);
114288 +
114289 + search_size_overflow_attribute(visited, arg);
114290 + }
114291 +}
114292 +
114293 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114294 +{
114295 + const_gimple def_stmt = get_def_stmt(lhs);
114296 + tree rhs1, rhs2;
114297 +
114298 + rhs1 = gimple_assign_rhs1(def_stmt);
114299 + rhs2 = gimple_assign_rhs2(def_stmt);
114300 +
114301 + search_size_overflow_attribute(visited, rhs1);
114302 + search_size_overflow_attribute(visited, rhs2);
114303 +}
114304 +
114305 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114306 +{
114307 + const_gimple def_stmt;
114308 +
114309 + if (TREE_CODE(lhs) == PARM_DECL) {
114310 + check_missing_size_overflow_attribute(lhs);
114311 + return;
114312 + }
114313 +
114314 + def_stmt = get_def_stmt(lhs);
114315 + if (!def_stmt)
114316 + return;
114317 +
114318 + if (pointer_set_insert(visited, def_stmt))
114319 + return;
114320 +
114321 + switch (gimple_code(def_stmt)) {
114322 + case GIMPLE_NOP:
114323 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114324 + case GIMPLE_ASM:
114325 + return;
114326 + case GIMPLE_CALL: {
114327 + tree fndecl = gimple_call_fndecl(def_stmt);
114328 +
114329 + if (fndecl == NULL_TREE)
114330 + return;
114331 + check_missing_size_overflow_attribute(fndecl);
114332 + return;
114333 + }
114334 + case GIMPLE_PHI:
114335 + return search_size_overflow_attribute_phi(visited, lhs);
114336 + case GIMPLE_ASSIGN:
114337 + switch (gimple_num_ops(def_stmt)) {
114338 + case 2:
114339 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114340 + case 3:
114341 + return search_size_overflow_attribute_binary(visited, lhs);
114342 + }
114343 + default:
114344 + debug_gimple_stmt((gimple)def_stmt);
114345 + error("%s: unknown gimple code", __func__);
114346 + gcc_unreachable();
114347 + }
114348 +}
114349 +
114350 +// Search missing entries in the hash table (invoked from the gimple pass)
114351 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114352 +{
114353 + tree fndecl = NULL_TREE;
114354 + tree lhs;
114355 + struct pointer_set_t *visited;
114356 +
114357 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114358 + return;
114359 +
114360 + if (num == 0) {
114361 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114362 + lhs = gimple_return_retval(stmt);
114363 + } else {
114364 + gcc_assert(is_gimple_call(stmt));
114365 + lhs = gimple_call_arg(stmt, num - 1);
114366 + fndecl = gimple_call_fndecl(stmt);
114367 + }
114368 +
114369 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114370 + return;
114371 +
114372 + visited = pointer_set_create();
114373 + search_size_overflow_attribute(visited, lhs);
114374 + pointer_set_destroy(visited);
114375 +}
114376 +
114377 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114378 +{
114379 + gimple_stmt_iterator gsi;
114380 + gimple assign;
114381 +
114382 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114383 + gsi = gsi_for_stmt(stmt);
114384 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114385 + asm_data->def_stmt = assign;
114386 +
114387 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114388 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114389 + if (gimple_code(stmt) == GIMPLE_RETURN)
114390 + gimple_return_set_retval(stmt, asm_data->output);
114391 + else
114392 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114393 + update_stmt(stmt);
114394 +}
114395 +
114396 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114397 +{
114398 + const char *fn_name;
114399 + char *asm_comment;
114400 + unsigned int len;
114401 +
114402 + if (argnum == 0)
114403 + fn_name = DECL_NAME_POINTER(current_function_decl);
114404 + else
114405 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114406 +
114407 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114408 + gcc_assert(len > 0);
114409 +
114410 + return asm_comment;
114411 +}
114412 +
114413 +static const char *convert_mark_to_str(enum mark mark)
114414 +{
114415 + switch (mark) {
114416 + case MARK_NO:
114417 + return OK_ASM_STR;
114418 + case MARK_YES:
114419 + case MARK_NOT_INTENTIONAL:
114420 + return YES_ASM_STR;
114421 + case MARK_TURN_OFF:
114422 + return TURN_OFF_ASM_STR;
114423 + }
114424 +
114425 + gcc_unreachable();
114426 +}
114427 +
114428 +/* Create the input of the size_overflow asm stmt.
114429 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114430 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114431 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114432 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114433 + */
114434 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114435 +{
114436 + if (!asm_data->def_stmt) {
114437 + asm_data->input = NULL_TREE;
114438 + return;
114439 + }
114440 +
114441 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114442 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114443 +
114444 + switch (gimple_code(asm_data->def_stmt)) {
114445 + case GIMPLE_ASSIGN:
114446 + case GIMPLE_CALL:
114447 + replace_call_lhs(asm_data);
114448 + break;
114449 + case GIMPLE_PHI:
114450 + create_output_from_phi(stmt, argnum, asm_data);
114451 + break;
114452 + case GIMPLE_NOP: {
114453 + enum mark mark;
114454 + const char *mark_str;
114455 + char *asm_comment;
114456 +
114457 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114458 +
114459 + asm_data->input = asm_data->output;
114460 + asm_data->output = NULL;
114461 + asm_data->def_stmt = stmt;
114462 +
114463 + mark_str = convert_mark_to_str(mark);
114464 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114465 +
114466 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114467 + free(asm_comment);
114468 + asm_data->input = NULL_TREE;
114469 + break;
114470 + }
114471 + case GIMPLE_ASM:
114472 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114473 + asm_data->input = NULL_TREE;
114474 + break;
114475 + }
114476 + default:
114477 + debug_gimple_stmt(asm_data->def_stmt);
114478 + gcc_unreachable();
114479 + }
114480 +}
114481 +
114482 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114483 + * is of the right kind create the appropriate size_overflow asm stmts:
114484 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114485 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114486 + */
114487 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114488 +{
114489 + struct asm_data asm_data;
114490 + const char *mark_str;
114491 + char *asm_comment;
114492 + enum mark mark;
114493 +
114494 + if (is_gimple_constant(output_node))
114495 + return;
114496 +
114497 + asm_data.output = output_node;
114498 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114499 + if (mark != MARK_TURN_OFF)
114500 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114501 +
114502 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114503 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114504 + return;
114505 +
114506 + create_asm_input(stmt, argnum, &asm_data);
114507 + if (asm_data.input == NULL_TREE)
114508 + return;
114509 +
114510 + mark_str = convert_mark_to_str(mark);
114511 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114512 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114513 + free(asm_comment);
114514 +}
114515 +
114516 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114517 +static bool create_mark_asm(gimple stmt, enum mark mark)
114518 +{
114519 + struct asm_data asm_data;
114520 + const char *asm_str;
114521 +
114522 + switch (mark) {
114523 + case MARK_TURN_OFF:
114524 + asm_str = TURN_OFF_ASM_STR;
114525 + break;
114526 + case MARK_NOT_INTENTIONAL:
114527 + case MARK_YES:
114528 + asm_str = YES_ASM_STR;
114529 + break;
114530 + default:
114531 + gcc_unreachable();
114532 + }
114533 +
114534 + asm_data.def_stmt = stmt;
114535 + asm_data.output = gimple_call_lhs(stmt);
114536 +
114537 + if (asm_data.output == NULL_TREE) {
114538 + asm_data.input = gimple_call_arg(stmt, 0);
114539 + if (is_gimple_constant(asm_data.input))
114540 + return false;
114541 + asm_data.output = NULL;
114542 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114543 + return true;
114544 + }
114545 +
114546 + create_asm_input(stmt, 0, &asm_data);
114547 + gcc_assert(asm_data.input != NULL_TREE);
114548 +
114549 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114550 + return true;
114551 +}
114552 +
114553 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114554 +{
114555 + gimple def_stmt;
114556 +
114557 + def_stmt = get_def_stmt(lhs);
114558 + if (!def_stmt)
114559 + return;
114560 +
114561 + if (pointer_set_insert(visited, def_stmt))
114562 + return;
114563 +
114564 + switch (gimple_code(def_stmt)) {
114565 + case GIMPLE_NOP:
114566 + case GIMPLE_ASM:
114567 + case GIMPLE_CALL:
114568 + break;
114569 + case GIMPLE_PHI: {
114570 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114571 +
114572 + pointer_set_insert(visited, def_stmt);
114573 +
114574 + for (i = 0; i < n; i++) {
114575 + tree arg = gimple_phi_arg_def(def_stmt, i);
114576 +
114577 + walk_use_def_ptr(visited, arg);
114578 + }
114579 + }
114580 + case GIMPLE_ASSIGN:
114581 + switch (gimple_num_ops(def_stmt)) {
114582 + case 2:
114583 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114584 + return;
114585 + case 3:
114586 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114587 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114588 + return;
114589 + default:
114590 + return;
114591 + }
114592 + default:
114593 + debug_gimple_stmt((gimple)def_stmt);
114594 + error("%s: unknown gimple code", __func__);
114595 + gcc_unreachable();
114596 + }
114597 +}
114598 +
114599 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114600 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114601 +{
114602 + struct pointer_set_t *visited;
114603 +
114604 + visited = pointer_set_create();
114605 + walk_use_def_ptr(visited, arg);
114606 + pointer_set_destroy(visited);
114607 +}
114608 +
114609 +// Determine the return value and insert the asm stmt to mark the return stmt.
114610 +static void insert_asm_ret(gimple stmt)
114611 +{
114612 + tree ret;
114613 +
114614 + ret = gimple_return_retval(stmt);
114615 + create_size_overflow_asm(stmt, ret, 0);
114616 +}
114617 +
114618 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114619 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114620 +{
114621 + tree arg;
114622 + unsigned int argnum;
114623 +
114624 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114625 + gcc_assert(argnum != 0);
114626 + if (argnum == CANNOT_FIND_ARG)
114627 + return;
114628 +
114629 + arg = gimple_call_arg(stmt, argnum - 1);
114630 + gcc_assert(arg != NULL_TREE);
114631 +
114632 + // skip all ptr - ptr expressions
114633 + insert_mark_not_intentional_asm_at_ptr(arg);
114634 +
114635 + create_size_overflow_asm(stmt, arg, argnum);
114636 +}
114637 +
114638 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114639 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114640 +{
114641 + unsigned int argnum;
114642 + tree attr_value;
114643 +
114644 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114645 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114646 + argnums[argnum] = true;
114647 + }
114648 +}
114649 +
114650 +// If a function arg or the return value is in the hash table then set its index in the array.
114651 +static void set_argnum_hash(tree fndecl, bool *argnums)
114652 +{
114653 + unsigned int num;
114654 + const struct size_overflow_hash *hash;
114655 +
114656 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114657 + if (!hash)
114658 + return;
114659 +
114660 + for (num = 0; num <= MAX_PARAM; num++) {
114661 + if (!(hash->param & (1U << num)))
114662 + continue;
114663 +
114664 + argnums[num] = true;
114665 + }
114666 +}
114667 +
114668 +static bool is_all_the_argnums_empty(bool *argnums)
114669 +{
114670 + unsigned int i;
114671 +
114672 + for (i = 0; i <= MAX_PARAM; i++)
114673 + if (argnums[i])
114674 + return false;
114675 + return true;
114676 +}
114677 +
114678 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114679 +static void search_interesting_args(tree fndecl, bool *argnums)
114680 +{
114681 + const_tree attr;
114682 +
114683 + set_argnum_hash(fndecl, argnums);
114684 + if (!is_all_the_argnums_empty(argnums))
114685 + return;
114686 +
114687 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114688 + if (attr && TREE_VALUE(attr))
114689 + set_argnum_attribute(attr, argnums);
114690 +}
114691 +
114692 +/*
114693 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114694 + * on the callee function.
114695 + */
114696 +static bool is_mark_turn_off_attribute(gimple stmt)
114697 +{
114698 + enum mark mark;
114699 + const_tree fndecl = gimple_call_fndecl(stmt);
114700 +
114701 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114702 + if (mark == MARK_TURN_OFF)
114703 + return true;
114704 + return false;
114705 +}
114706 +
114707 +// 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
114708 +static void handle_interesting_function(gimple stmt)
114709 +{
114710 + unsigned int argnum;
114711 + tree fndecl;
114712 + bool orig_argnums[MAX_PARAM + 1] = {false};
114713 +
114714 + if (gimple_call_num_args(stmt) == 0)
114715 + return;
114716 + fndecl = gimple_call_fndecl(stmt);
114717 + if (fndecl == NULL_TREE)
114718 + return;
114719 + fndecl = DECL_ORIGIN(fndecl);
114720 +
114721 + if (is_mark_turn_off_attribute(stmt)) {
114722 + create_mark_asm(stmt, MARK_TURN_OFF);
114723 + return;
114724 + }
114725 +
114726 + search_interesting_args(fndecl, orig_argnums);
114727 +
114728 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114729 + if (orig_argnums[argnum])
114730 + insert_asm_arg(stmt, argnum);
114731 +}
114732 +
114733 +// 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
114734 +static void handle_interesting_ret(gimple stmt)
114735 +{
114736 + bool orig_argnums[MAX_PARAM + 1] = {false};
114737 +
114738 + search_interesting_args(current_function_decl, orig_argnums);
114739 +
114740 + if (orig_argnums[0])
114741 + insert_asm_ret(stmt);
114742 +}
114743 +
114744 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114745 +static unsigned int search_interesting_functions(void)
114746 +{
114747 + basic_block bb;
114748 +
114749 + FOR_ALL_BB_FN(bb, cfun) {
114750 + gimple_stmt_iterator gsi;
114751 +
114752 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114753 + gimple stmt = gsi_stmt(gsi);
114754 +
114755 + if (is_size_overflow_asm(stmt))
114756 + continue;
114757 +
114758 + if (is_gimple_call(stmt))
114759 + handle_interesting_function(stmt);
114760 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114761 + handle_interesting_ret(stmt);
114762 + }
114763 + }
114764 + return 0;
114765 +}
114766 +
114767 +/*
114768 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114769 + * this pass inserts asm stmts to mark the interesting args
114770 + * that the ipa pass will detect and insert the size overflow checks for.
114771 + */
114772 +#if BUILDING_GCC_VERSION >= 4009
114773 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114774 +#else
114775 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114776 + .pass = {
114777 +#endif
114778 + .type = GIMPLE_PASS,
114779 + .name = "insert_size_overflow_asm",
114780 +#if BUILDING_GCC_VERSION >= 4008
114781 + .optinfo_flags = OPTGROUP_NONE,
114782 +#endif
114783 +#if BUILDING_GCC_VERSION >= 4009
114784 + .has_gate = false,
114785 + .has_execute = true,
114786 +#else
114787 + .gate = NULL,
114788 + .execute = search_interesting_functions,
114789 + .sub = NULL,
114790 + .next = NULL,
114791 + .static_pass_number = 0,
114792 +#endif
114793 + .tv_id = TV_NONE,
114794 + .properties_required = PROP_cfg,
114795 + .properties_provided = 0,
114796 + .properties_destroyed = 0,
114797 + .todo_flags_start = 0,
114798 + .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
114799 +#if BUILDING_GCC_VERSION < 4009
114800 + }
114801 +#endif
114802 +};
114803 +
114804 +#if BUILDING_GCC_VERSION >= 4009
114805 +namespace {
114806 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114807 +public:
114808 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114809 + unsigned int execute() { return search_interesting_functions(); }
114810 +};
114811 +}
114812 +#endif
114813 +
114814 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114815 +{
114816 +#if BUILDING_GCC_VERSION >= 4009
114817 + return new insert_size_overflow_asm_pass();
114818 +#else
114819 + return &insert_size_overflow_asm_pass.pass;
114820 +#endif
114821 +}
114822 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
114823 new file mode 100644
114824 index 0000000..73f0a12
114825 --- /dev/null
114826 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114827 @@ -0,0 +1,943 @@
114828 +/*
114829 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114830 + * Licensed under the GPL v2, or (at your option) v3
114831 + *
114832 + * Homepage:
114833 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114834 + *
114835 + * Documentation:
114836 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114837 + *
114838 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114839 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114840 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114841 + *
114842 + * Usage:
114843 + * $ make
114844 + * $ make run
114845 + */
114846 +
114847 +#include "gcc-common.h"
114848 +#include "size_overflow.h"
114849 +
114850 +#define MIN_CHECK true
114851 +#define MAX_CHECK false
114852 +
114853 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114854 +{
114855 + const_tree type;
114856 + tree new_type;
114857 +
114858 + gcc_assert(node != NULL_TREE);
114859 +
114860 + type = TREE_TYPE(node);
114861 +
114862 + if (pointer_set_contains(visited->my_stmts, stmt))
114863 + return TREE_TYPE(node);
114864 +
114865 + switch (TYPE_MODE(type)) {
114866 + case QImode:
114867 + new_type = size_overflow_type_HI;
114868 + break;
114869 + case HImode:
114870 + new_type = size_overflow_type_SI;
114871 + break;
114872 + case SImode:
114873 + new_type = size_overflow_type_DI;
114874 + break;
114875 + case DImode:
114876 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114877 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114878 + else
114879 + new_type = size_overflow_type_TI;
114880 + break;
114881 + case TImode:
114882 + gcc_assert(!TYPE_UNSIGNED(type));
114883 + new_type = size_overflow_type_TI;
114884 + break;
114885 + default:
114886 + debug_tree((tree)node);
114887 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114888 + gcc_unreachable();
114889 + }
114890 +
114891 + if (TYPE_QUALS(type) != 0)
114892 + return build_qualified_type(new_type, TYPE_QUALS(type));
114893 + return new_type;
114894 +}
114895 +
114896 +static tree get_lhs(const_gimple stmt)
114897 +{
114898 + switch (gimple_code(stmt)) {
114899 + case GIMPLE_ASSIGN:
114900 + case GIMPLE_CALL:
114901 + return gimple_get_lhs(stmt);
114902 + case GIMPLE_PHI:
114903 + return gimple_phi_result(stmt);
114904 + default:
114905 + return NULL_TREE;
114906 + }
114907 +}
114908 +
114909 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
114910 +{
114911 + gimple_stmt_iterator gsi;
114912 + tree lhs;
114913 + gimple new_stmt;
114914 +
114915 + if (rhs == NULL_TREE)
114916 + return NULL_TREE;
114917 +
114918 + gsi = gsi_for_stmt(stmt);
114919 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
114920 + pointer_set_insert(visited->my_stmts, new_stmt);
114921 +
114922 + lhs = get_lhs(new_stmt);
114923 + gcc_assert(lhs != NULL_TREE);
114924 + return lhs;
114925 +}
114926 +
114927 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
114928 +{
114929 + tree lhs, dst_type;
114930 + gimple_stmt_iterator gsi;
114931 +
114932 + if (rhs1 == NULL_TREE) {
114933 + debug_gimple_stmt(oldstmt);
114934 + error("%s: rhs1 is NULL_TREE", __func__);
114935 + gcc_unreachable();
114936 + }
114937 +
114938 + switch (gimple_code(oldstmt)) {
114939 + case GIMPLE_ASM:
114940 + lhs = rhs1;
114941 + break;
114942 + case GIMPLE_CALL:
114943 + case GIMPLE_ASSIGN:
114944 + lhs = gimple_get_lhs(oldstmt);
114945 + break;
114946 + default:
114947 + debug_gimple_stmt(oldstmt);
114948 + gcc_unreachable();
114949 + }
114950 +
114951 + gsi = gsi_for_stmt(oldstmt);
114952 + pointer_set_insert(visited->stmts, oldstmt);
114953 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
114954 + basic_block next_bb, cur_bb;
114955 + const_edge e;
114956 +
114957 + gcc_assert(before == false);
114958 + gcc_assert(stmt_can_throw_internal(oldstmt));
114959 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
114960 + gcc_assert(!gsi_end_p(gsi));
114961 +
114962 + cur_bb = gimple_bb(oldstmt);
114963 + next_bb = cur_bb->next_bb;
114964 + e = find_edge(cur_bb, next_bb);
114965 + gcc_assert(e != NULL);
114966 + gcc_assert(e->flags & EDGE_FALLTHRU);
114967 +
114968 + gsi = gsi_after_labels(next_bb);
114969 + gcc_assert(!gsi_end_p(gsi));
114970 +
114971 + before = true;
114972 + oldstmt = gsi_stmt(gsi);
114973 + }
114974 +
114975 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
114976 +
114977 + if (is_gimple_constant(rhs1))
114978 + return cast_a_tree(dst_type, rhs1);
114979 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
114980 +}
114981 +
114982 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
114983 +{
114984 + gimple stmt;
114985 + gimple_stmt_iterator gsi;
114986 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
114987 +
114988 + if (pointer_set_contains(visited->my_stmts, oldstmt))
114989 + return lhs;
114990 +
114991 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
114992 + rhs1 = gimple_assign_rhs1(oldstmt);
114993 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
114994 + }
114995 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
114996 + rhs2 = gimple_assign_rhs2(oldstmt);
114997 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
114998 + }
114999 +
115000 + stmt = gimple_copy(oldstmt);
115001 + gimple_set_location(stmt, gimple_location(oldstmt));
115002 + pointer_set_insert(visited->my_stmts, stmt);
115003 +
115004 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115005 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115006 +
115007 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
115008 +
115009 + new_var = create_new_var(size_overflow_type);
115010 + new_var = make_ssa_name(new_var, stmt);
115011 + gimple_assign_set_lhs(stmt, new_var);
115012 +
115013 + if (rhs1 != NULL_TREE)
115014 + gimple_assign_set_rhs1(stmt, rhs1);
115015 +
115016 + if (rhs2 != NULL_TREE)
115017 + gimple_assign_set_rhs2(stmt, rhs2);
115018 +#if BUILDING_GCC_VERSION >= 4006
115019 + if (rhs3 != NULL_TREE)
115020 + gimple_assign_set_rhs3(stmt, rhs3);
115021 +#endif
115022 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115023 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115024 +
115025 + gsi = gsi_for_stmt(oldstmt);
115026 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115027 + update_stmt(stmt);
115028 + pointer_set_insert(visited->stmts, oldstmt);
115029 + return gimple_assign_lhs(stmt);
115030 +}
115031 +
115032 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115033 +{
115034 + gimple assign;
115035 + gimple_stmt_iterator gsi;
115036 + basic_block first_bb;
115037 +
115038 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115039 +
115040 + if (bb->index == 0) {
115041 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115042 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115043 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115044 + bb = first_bb;
115045 + }
115046 +
115047 + gsi = gsi_after_labels(bb);
115048 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115049 + pointer_set_insert(visited->my_stmts, assign);
115050 +
115051 + return gimple_assign_lhs(assign);
115052 +}
115053 +
115054 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
115055 +{
115056 + gimple_stmt_iterator gsi;
115057 + gimple assign, def_stmt = get_def_stmt(new_arg);
115058 +
115059 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115060 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115061 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115062 + } else {
115063 + gsi = gsi_for_stmt(def_stmt);
115064 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115065 + }
115066 +
115067 + pointer_set_insert(visited->my_stmts, assign);
115068 + return gimple_assign_lhs(assign);
115069 +}
115070 +
115071 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
115072 +{
115073 + basic_block bb;
115074 + gimple_stmt_iterator gsi;
115075 + const_gimple def_stmt;
115076 + gimple assign;
115077 +
115078 + def_stmt = get_def_stmt(arg);
115079 + bb = gimple_bb(def_stmt);
115080 + gcc_assert(bb->index != 0);
115081 + gsi = gsi_after_labels(bb);
115082 +
115083 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115084 + pointer_set_insert(visited->my_stmts, assign);
115085 + return gimple_assign_lhs(assign);
115086 +}
115087 +
115088 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115089 +{
115090 + tree size_overflow_type;
115091 + tree arg;
115092 + const_gimple def_stmt;
115093 +
115094 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115095 + return new_arg;
115096 +
115097 + arg = gimple_phi_arg_def(oldstmt, i);
115098 + def_stmt = get_def_stmt(arg);
115099 + gcc_assert(def_stmt != NULL);
115100 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115101 +
115102 + switch (gimple_code(def_stmt)) {
115103 + case GIMPLE_PHI:
115104 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
115105 + case GIMPLE_NOP: {
115106 + basic_block bb;
115107 +
115108 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115109 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
115110 + }
115111 + case GIMPLE_ASM: {
115112 + gimple_stmt_iterator gsi;
115113 + gimple assign, stmt = get_def_stmt(arg);
115114 +
115115 + gsi = gsi_for_stmt(stmt);
115116 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115117 + pointer_set_insert(visited->my_stmts, assign);
115118 + return gimple_assign_lhs(assign);
115119 + }
115120 + default:
115121 + gcc_assert(new_arg != NULL_TREE);
115122 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115123 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
115124 + }
115125 +}
115126 +
115127 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
115128 +{
115129 + basic_block bb;
115130 + gimple phi;
115131 + gimple_seq seq;
115132 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115133 +
115134 + bb = gsi_bb(gsi);
115135 +
115136 + if (result == NULL_TREE) {
115137 + tree old_result = gimple_phi_result(oldstmt);
115138 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
115139 +
115140 + result = create_new_var(size_overflow_type);
115141 + }
115142 +
115143 + phi = create_phi_node(result, bb);
115144 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115145 + seq = phi_nodes(bb);
115146 + gsi = gsi_last(seq);
115147 + gsi_remove(&gsi, false);
115148 +
115149 + gsi = gsi_for_stmt(oldstmt);
115150 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115151 + gimple_set_bb(phi, bb);
115152 + return phi;
115153 +}
115154 +
115155 +#if BUILDING_GCC_VERSION <= 4007
115156 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115157 +#else
115158 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115159 +#endif
115160 +{
115161 + gimple new_phi;
115162 + unsigned int i;
115163 + tree arg, result;
115164 + location_t loc = gimple_location(oldstmt);
115165 +
115166 +#if BUILDING_GCC_VERSION <= 4007
115167 + gcc_assert(!VEC_empty(tree, *args));
115168 +#else
115169 + gcc_assert(!args->is_empty());
115170 +#endif
115171 +
115172 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
115173 + result = gimple_phi_result(new_phi);
115174 + ssa_name_var = SSA_NAME_VAR(result);
115175 +
115176 +#if BUILDING_GCC_VERSION <= 4007
115177 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115178 +#else
115179 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115180 +#endif
115181 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
115182 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115183 + }
115184 +
115185 +#if BUILDING_GCC_VERSION <= 4007
115186 + VEC_free(tree, heap, *args);
115187 +#else
115188 + vec_free(args);
115189 +#endif
115190 + update_stmt(new_phi);
115191 + pointer_set_insert(visited->my_stmts, new_phi);
115192 + return result;
115193 +}
115194 +
115195 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115196 +{
115197 + tree ssa_name_var = NULL_TREE;
115198 +#if BUILDING_GCC_VERSION <= 4007
115199 + VEC(tree, heap) *args = NULL;
115200 +#else
115201 + vec<tree, va_heap, vl_embed> *args = NULL;
115202 +#endif
115203 + gimple oldstmt = get_def_stmt(orig_result);
115204 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115205 +
115206 + pointer_set_insert(visited->stmts, oldstmt);
115207 + for (i = 0; i < len; i++) {
115208 + tree arg, new_arg;
115209 +
115210 + arg = gimple_phi_arg_def(oldstmt, i);
115211 + new_arg = expand(visited, caller_node, arg);
115212 +
115213 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115214 + ssa_name_var = SSA_NAME_VAR(new_arg);
115215 +
115216 + if (is_gimple_constant(arg)) {
115217 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115218 +
115219 + new_arg = cast_a_tree(size_overflow_type, arg);
115220 + }
115221 +
115222 +#if BUILDING_GCC_VERSION <= 4007
115223 + VEC_safe_push(tree, heap, args, new_arg);
115224 +#else
115225 + vec_safe_push(args, new_arg);
115226 +#endif
115227 + }
115228 +
115229 +#if BUILDING_GCC_VERSION <= 4007
115230 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115231 +#else
115232 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115233 +#endif
115234 +}
115235 +
115236 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115237 +{
115238 + tree rhs1 = gimple_assign_rhs1(stmt);
115239 + tree lhs = gimple_assign_lhs(stmt);
115240 + const_tree rhs1_type = TREE_TYPE(rhs1);
115241 + const_tree lhs_type = TREE_TYPE(lhs);
115242 +
115243 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115244 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115245 +
115246 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115247 +}
115248 +
115249 +static bool skip_lhs_cast_check(const_gimple stmt)
115250 +{
115251 + const_tree rhs = gimple_assign_rhs1(stmt);
115252 + const_gimple def_stmt = get_def_stmt(rhs);
115253 +
115254 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115255 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115256 + return true;
115257 +
115258 + if (is_const_plus_unsigned_signed_truncation(rhs))
115259 + return true;
115260 +
115261 + return false;
115262 +}
115263 +
115264 +static tree create_string_param(tree string)
115265 +{
115266 + tree i_type, a_type;
115267 + const int length = TREE_STRING_LENGTH(string);
115268 +
115269 + gcc_assert(length > 0);
115270 +
115271 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115272 + a_type = build_array_type(char_type_node, i_type);
115273 +
115274 + TREE_TYPE(string) = a_type;
115275 + TREE_CONSTANT(string) = 1;
115276 + TREE_READONLY(string) = 1;
115277 +
115278 + return build1(ADDR_EXPR, ptr_type_node, string);
115279 +}
115280 +
115281 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115282 +{
115283 + gimple cond_stmt;
115284 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115285 +
115286 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115287 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115288 + update_stmt(cond_stmt);
115289 +}
115290 +
115291 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115292 +{
115293 + gimple func_stmt;
115294 + const_gimple def_stmt;
115295 + const_tree loc_line;
115296 + tree loc_file, ssa_name, current_func;
115297 + expanded_location xloc;
115298 + char *ssa_name_buf;
115299 + int len;
115300 + struct cgraph_edge *edge;
115301 + struct cgraph_node *callee_node;
115302 + int frequency;
115303 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115304 +
115305 + def_stmt = get_def_stmt(arg);
115306 + xloc = expand_location(gimple_location(def_stmt));
115307 +
115308 + if (!gimple_has_location(def_stmt)) {
115309 + xloc = expand_location(gimple_location(stmt));
115310 + if (!gimple_has_location(stmt))
115311 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115312 + }
115313 +
115314 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115315 +
115316 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115317 + loc_file = create_string_param(loc_file);
115318 +
115319 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115320 + current_func = create_string_param(current_func);
115321 +
115322 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115323 + call_count++;
115324 + 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);
115325 + gcc_assert(len > 0);
115326 + ssa_name = build_string(len + 1, ssa_name_buf);
115327 + free(ssa_name_buf);
115328 + ssa_name = create_string_param(ssa_name);
115329 +
115330 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115331 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115332 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115333 +
115334 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115335 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115336 +
115337 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115338 + gcc_assert(edge != NULL);
115339 +}
115340 +
115341 +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)
115342 +{
115343 + basic_block cond_bb, join_bb, bb_true;
115344 + edge e;
115345 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115346 +
115347 + cond_bb = gimple_bb(stmt);
115348 + if (before)
115349 + gsi_prev(&gsi);
115350 + if (gsi_end_p(gsi))
115351 + e = split_block_after_labels(cond_bb);
115352 + else
115353 + e = split_block(cond_bb, gsi_stmt(gsi));
115354 + cond_bb = e->src;
115355 + join_bb = e->dest;
115356 + e->flags = EDGE_FALSE_VALUE;
115357 + e->probability = REG_BR_PROB_BASE;
115358 +
115359 + bb_true = create_empty_bb(cond_bb);
115360 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115361 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115362 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115363 +
115364 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115365 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115366 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115367 +
115368 + if (current_loops != NULL) {
115369 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115370 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115371 + }
115372 +
115373 + insert_cond(cond_bb, arg, cond_code, type_value);
115374 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115375 +
115376 +// print_the_code_insertions(stmt);
115377 +}
115378 +
115379 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115380 +{
115381 + const_tree rhs_type = TREE_TYPE(rhs);
115382 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115383 +
115384 + gcc_assert(rhs_type != NULL_TREE);
115385 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115386 + return;
115387 +
115388 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115389 +
115390 + if (is_const_plus_unsigned_signed_truncation(rhs))
115391 + return;
115392 +
115393 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115394 + // typemax (-1) < typemin (0)
115395 + if (TREE_OVERFLOW(type_max))
115396 + return;
115397 +
115398 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115399 +
115400 + cast_rhs_type = TREE_TYPE(cast_rhs);
115401 + type_max_type = TREE_TYPE(type_max);
115402 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115403 +
115404 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115405 +
115406 + // special case: get_size_overflow_type(), 32, u64->s
115407 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115408 + return;
115409 +
115410 + type_min_type = TREE_TYPE(type_min);
115411 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115412 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115413 +}
115414 +
115415 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115416 +{
115417 + bool cast_lhs, cast_rhs;
115418 + tree lhs = gimple_assign_lhs(stmt);
115419 + tree rhs = gimple_assign_rhs1(stmt);
115420 + const_tree lhs_type = TREE_TYPE(lhs);
115421 + const_tree rhs_type = TREE_TYPE(rhs);
115422 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115423 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115424 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115425 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115426 +
115427 + static bool check_lhs[3][4] = {
115428 + // ss su us uu
115429 + { false, true, true, false }, // lhs > rhs
115430 + { false, false, false, false }, // lhs = rhs
115431 + { true, true, true, true }, // lhs < rhs
115432 + };
115433 +
115434 + static bool check_rhs[3][4] = {
115435 + // ss su us uu
115436 + { true, false, true, true }, // lhs > rhs
115437 + { true, false, true, true }, // lhs = rhs
115438 + { true, false, true, true }, // lhs < rhs
115439 + };
115440 +
115441 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115442 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115443 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115444 +
115445 + if (lhs_size > rhs_size) {
115446 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115447 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115448 + } else if (lhs_size == rhs_size) {
115449 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115450 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115451 + } else {
115452 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115453 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115454 + }
115455 +
115456 + if (!cast_lhs && !cast_rhs)
115457 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115458 +
115459 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115460 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115461 +
115462 + if (cast_rhs)
115463 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115464 +
115465 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115466 +}
115467 +
115468 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115469 +{
115470 + enum tree_code rhs_code;
115471 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115472 +
115473 + if (pointer_set_contains(visited->my_stmts, stmt))
115474 + return lhs;
115475 +
115476 + rhs1 = gimple_assign_rhs1(stmt);
115477 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115478 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115479 +
115480 + new_rhs1 = expand(visited, caller_node, rhs1);
115481 +
115482 + if (new_rhs1 == NULL_TREE)
115483 + return create_cast_assign(visited, stmt);
115484 +
115485 + if (pointer_set_contains(visited->no_cast_check, stmt))
115486 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115487 +
115488 + rhs_code = gimple_assign_rhs_code(stmt);
115489 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115490 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115491 +
115492 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115493 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115494 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115495 + }
115496 +
115497 + if (!gimple_assign_cast_p(stmt))
115498 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115499 +
115500 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115501 +}
115502 +
115503 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115504 +{
115505 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115506 + gimple def_stmt = get_def_stmt(lhs);
115507 +
115508 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115509 + rhs1 = gimple_assign_rhs1(def_stmt);
115510 +
115511 + if (is_gimple_constant(rhs1))
115512 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115513 +
115514 + switch (TREE_CODE(rhs1)) {
115515 + case SSA_NAME: {
115516 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115517 +
115518 + if (gimple_assign_cast_p(stmt))
115519 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115520 + return ret;
115521 + }
115522 + case ARRAY_REF:
115523 + case BIT_FIELD_REF:
115524 + case ADDR_EXPR:
115525 + case COMPONENT_REF:
115526 + case INDIRECT_REF:
115527 +#if BUILDING_GCC_VERSION >= 4006
115528 + case MEM_REF:
115529 +#endif
115530 + case TARGET_MEM_REF:
115531 + case VIEW_CONVERT_EXPR:
115532 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115533 + case PARM_DECL:
115534 + case VAR_DECL:
115535 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115536 +
115537 + default:
115538 + debug_gimple_stmt(def_stmt);
115539 + debug_tree(rhs1);
115540 + gcc_unreachable();
115541 + }
115542 +}
115543 +
115544 +static void __unused print_the_code_insertions(const_gimple stmt)
115545 +{
115546 + location_t loc = gimple_location(stmt);
115547 +
115548 + inform(loc, "Integer size_overflow check applied here.");
115549 +}
115550 +
115551 +static bool is_from_cast(const_tree node)
115552 +{
115553 + gimple def_stmt = get_def_stmt(node);
115554 +
115555 + if (!def_stmt)
115556 + return false;
115557 +
115558 + if (gimple_assign_cast_p(def_stmt))
115559 + return true;
115560 +
115561 + return false;
115562 +}
115563 +
115564 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115565 +static bool is_a_ptr_minus(gimple stmt)
115566 +{
115567 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115568 +
115569 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115570 + return false;
115571 +
115572 + rhs1 = gimple_assign_rhs1(stmt);
115573 + if (!is_from_cast(rhs1))
115574 + return false;
115575 +
115576 + rhs2 = gimple_assign_rhs2(stmt);
115577 + if (!is_from_cast(rhs2))
115578 + return false;
115579 +
115580 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115581 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115582 +
115583 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115584 + return false;
115585 +
115586 + return true;
115587 +}
115588 +
115589 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115590 +{
115591 + enum intentional_overflow_type res;
115592 + tree rhs1, rhs2, new_lhs;
115593 + gimple def_stmt = get_def_stmt(lhs);
115594 + tree new_rhs1 = NULL_TREE;
115595 + tree new_rhs2 = NULL_TREE;
115596 +
115597 + if (is_a_ptr_minus(def_stmt))
115598 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115599 +
115600 + rhs1 = gimple_assign_rhs1(def_stmt);
115601 + rhs2 = gimple_assign_rhs2(def_stmt);
115602 +
115603 + /* no DImode/TImode division in the 32/64 bit kernel */
115604 + switch (gimple_assign_rhs_code(def_stmt)) {
115605 + case RDIV_EXPR:
115606 + case TRUNC_DIV_EXPR:
115607 + case CEIL_DIV_EXPR:
115608 + case FLOOR_DIV_EXPR:
115609 + case ROUND_DIV_EXPR:
115610 + case TRUNC_MOD_EXPR:
115611 + case CEIL_MOD_EXPR:
115612 + case FLOOR_MOD_EXPR:
115613 + case ROUND_MOD_EXPR:
115614 + case EXACT_DIV_EXPR:
115615 + case POINTER_PLUS_EXPR:
115616 + case BIT_AND_EXPR:
115617 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115618 + default:
115619 + break;
115620 + }
115621 +
115622 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115623 + if (new_lhs != NULL_TREE)
115624 + return new_lhs;
115625 +
115626 + if (TREE_CODE(rhs1) == SSA_NAME)
115627 + new_rhs1 = expand(visited, caller_node, rhs1);
115628 + if (TREE_CODE(rhs2) == SSA_NAME)
115629 + new_rhs2 = expand(visited, caller_node, rhs2);
115630 +
115631 + res = add_mul_intentional_overflow(def_stmt);
115632 + if (res != NO_INTENTIONAL_OVERFLOW) {
115633 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115634 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115635 + return new_lhs;
115636 + }
115637 +
115638 + if (skip_expr_on_double_type(def_stmt)) {
115639 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115640 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115641 + return new_lhs;
115642 + }
115643 +
115644 + if (is_a_neg_overflow(def_stmt, rhs2))
115645 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115646 + if (is_a_neg_overflow(def_stmt, rhs1))
115647 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115648 +
115649 +
115650 + if (is_a_constant_overflow(def_stmt, rhs2))
115651 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115652 + if (is_a_constant_overflow(def_stmt, rhs1))
115653 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115654 +
115655 + // the const is between 0 and (signed) MAX
115656 + if (is_gimple_constant(rhs1))
115657 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115658 + if (is_gimple_constant(rhs2))
115659 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115660 +
115661 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115662 +}
115663 +
115664 +#if BUILDING_GCC_VERSION >= 4006
115665 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115666 +{
115667 + if (is_gimple_constant(rhs))
115668 + return cast_a_tree(size_overflow_type, rhs);
115669 + if (TREE_CODE(rhs) != SSA_NAME)
115670 + return NULL_TREE;
115671 + return expand(visited, caller_node, rhs);
115672 +}
115673 +
115674 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115675 +{
115676 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115677 + gimple def_stmt = get_def_stmt(lhs);
115678 +
115679 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115680 +
115681 + rhs1 = gimple_assign_rhs1(def_stmt);
115682 + rhs2 = gimple_assign_rhs2(def_stmt);
115683 + rhs3 = gimple_assign_rhs3(def_stmt);
115684 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115685 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115686 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115687 +
115688 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115689 +}
115690 +#endif
115691 +
115692 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115693 +{
115694 + gimple_stmt_iterator gsi;
115695 + gimple next_stmt = NULL;
115696 +
115697 + gsi = gsi_for_stmt(stmt);
115698 +
115699 + do {
115700 + gsi_next(&gsi);
115701 + next_stmt = gsi_stmt(gsi);
115702 +
115703 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115704 + return NULL_TREE;
115705 +
115706 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115707 + break;
115708 +
115709 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115710 + } while (!gsi_end_p(gsi));
115711 +
115712 + gcc_assert(next_stmt);
115713 + return get_lhs(next_stmt);
115714 +}
115715 +
115716 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115717 +{
115718 + gimple_stmt_iterator gsi;
115719 + enum gimple_code code = gimple_code(def_stmt);
115720 +
115721 + if (code == GIMPLE_ASM)
115722 + return NULL_TREE;
115723 +
115724 + gsi = gsi_for_stmt(def_stmt);
115725 + gsi_next(&gsi);
115726 +
115727 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115728 + return NULL_TREE;
115729 + return get_my_stmt_lhs(visited, def_stmt);
115730 +}
115731 +
115732 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115733 +{
115734 + gimple def_stmt;
115735 +
115736 + def_stmt = get_def_stmt(lhs);
115737 +
115738 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115739 + return NULL_TREE;
115740 +
115741 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115742 + return lhs;
115743 +
115744 + if (pointer_set_contains(visited->stmts, def_stmt))
115745 + return expand_visited(visited, def_stmt);
115746 +
115747 + switch (gimple_code(def_stmt)) {
115748 + case GIMPLE_PHI:
115749 + return handle_phi(visited, caller_node, lhs);
115750 + case GIMPLE_CALL:
115751 + case GIMPLE_ASM:
115752 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115753 + case GIMPLE_ASSIGN:
115754 + switch (gimple_num_ops(def_stmt)) {
115755 + case 2:
115756 + return handle_unary_ops(visited, caller_node, def_stmt);
115757 + case 3:
115758 + return handle_binary_ops(visited, caller_node, lhs);
115759 +#if BUILDING_GCC_VERSION >= 4006
115760 + case 4:
115761 + return handle_ternary_ops(visited, caller_node, lhs);
115762 +#endif
115763 + }
115764 + default:
115765 + debug_gimple_stmt(def_stmt);
115766 + error("%s: unknown gimple code", __func__);
115767 + gcc_unreachable();
115768 + }
115769 +}
115770 +
115771 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
115772 new file mode 100644
115773 index 0000000..df50164
115774 --- /dev/null
115775 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115776 @@ -0,0 +1,1141 @@
115777 +/*
115778 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115779 + * Licensed under the GPL v2, or (at your option) v3
115780 + *
115781 + * Homepage:
115782 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115783 + *
115784 + * Documentation:
115785 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115786 + *
115787 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115788 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115789 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115790 + *
115791 + * Usage:
115792 + * $ make
115793 + * $ make run
115794 + */
115795 +
115796 +#include "gcc-common.h"
115797 +#include "size_overflow.h"
115798 +
115799 +#define VEC_LEN 128
115800 +#define RET_CHECK NULL_TREE
115801 +#define WRONG_NODE 32
115802 +#define NOT_INTENTIONAL_ASM NULL
115803 +
115804 +unsigned int call_count;
115805 +
115806 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115807 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115808 +
115809 +struct visited_fns {
115810 + struct visited_fns *next;
115811 + const_tree fndecl;
115812 + unsigned int num;
115813 + const_gimple first_stmt;
115814 +};
115815 +
115816 +struct next_cgraph_node {
115817 + struct next_cgraph_node *next;
115818 + struct cgraph_node *current_function;
115819 + tree callee_fndecl;
115820 + unsigned int num;
115821 +};
115822 +
115823 +// Don't want to duplicate entries in next_cgraph_node
115824 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115825 +{
115826 + const_tree new_callee_fndecl;
115827 + struct next_cgraph_node *cur_node;
115828 +
115829 + if (fndecl == RET_CHECK)
115830 + new_callee_fndecl = NODE_DECL(node);
115831 + else
115832 + new_callee_fndecl = fndecl;
115833 +
115834 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115835 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115836 + continue;
115837 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115838 + continue;
115839 + if (num == cur_node->num)
115840 + return true;
115841 + }
115842 + return false;
115843 +}
115844 +
115845 +/* Add a next_cgraph_node into the list for handle_function().
115846 + * handle_function() iterates over all the next cgraph nodes and
115847 + * starts the overflow check insertion process.
115848 + */
115849 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115850 +{
115851 + struct next_cgraph_node *new_node;
115852 +
115853 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115854 + return head;
115855 +
115856 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115857 + new_node->current_function = node;
115858 + new_node->next = NULL;
115859 + new_node->num = num;
115860 + if (fndecl == RET_CHECK)
115861 + new_node->callee_fndecl = NODE_DECL(node);
115862 + else
115863 + new_node->callee_fndecl = fndecl;
115864 +
115865 + if (!head)
115866 + return new_node;
115867 +
115868 + new_node->next = head;
115869 + return new_node;
115870 +}
115871 +
115872 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115873 +{
115874 + struct cgraph_edge *e;
115875 +
115876 + if (num == 0)
115877 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115878 +
115879 + for (e = node->callers; e; e = e->next_caller) {
115880 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115881 +
115882 + gcc_assert(fndecl != NULL_TREE);
115883 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115884 + }
115885 +
115886 + return head;
115887 +}
115888 +
115889 +struct missing_functions {
115890 + struct missing_functions *next;
115891 + const_tree node;
115892 + tree fndecl;
115893 +};
115894 +
115895 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115896 +{
115897 + struct missing_functions *new_function;
115898 +
115899 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115900 + new_function->node = node;
115901 + new_function->next = NULL;
115902 +
115903 + if (TREE_CODE(node) == FUNCTION_DECL)
115904 + new_function->fndecl = node;
115905 + else
115906 + new_function->fndecl = current_function_decl;
115907 + gcc_assert(new_function->fndecl);
115908 +
115909 + if (!missing_fn_head)
115910 + return new_function;
115911 +
115912 + new_function->next = missing_fn_head;
115913 + return new_function;
115914 +}
115915 +
115916 +/* If the function is missing from the hash table and it is a static function
115917 + * then create a next_cgraph_node from it for handle_function()
115918 + */
115919 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
115920 +{
115921 + unsigned int num;
115922 + const_tree orig_fndecl;
115923 + struct cgraph_node *next_node = NULL;
115924 +
115925 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
115926 +
115927 + num = get_function_num(missing_fn_head->node, orig_fndecl);
115928 + if (num == CANNOT_FIND_ARG)
115929 + return cnodes;
115930 +
115931 + if (!is_missing_function(orig_fndecl, num))
115932 + return cnodes;
115933 +
115934 + next_node = cgraph_get_node(missing_fn_head->fndecl);
115935 + if (next_node && next_node->local.local)
115936 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
115937 + return cnodes;
115938 +}
115939 +
115940 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
115941 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
115942 + */
115943 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
115944 +{
115945 + unsigned int i;
115946 + tree node;
115947 + struct missing_functions *cur, *missing_fn_head = NULL;
115948 +
115949 +#if BUILDING_GCC_VERSION <= 4007
115950 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
115951 +#else
115952 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
115953 +#endif
115954 + switch (TREE_CODE(node)) {
115955 + case PARM_DECL:
115956 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
115957 + break;
115958 + case FUNCTION_DECL:
115959 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
115960 + break;
115961 + default:
115962 + break;
115963 + }
115964 + }
115965 +
115966 + while (missing_fn_head) {
115967 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
115968 +
115969 + cur = missing_fn_head->next;
115970 + free(missing_fn_head);
115971 + missing_fn_head = cur;
115972 + }
115973 +
115974 + return cnodes;
115975 +}
115976 +
115977 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
115978 +{
115979 + gimple phi = get_def_stmt(result);
115980 + unsigned int i, n = gimple_phi_num_args(phi);
115981 +
115982 + pointer_set_insert(visited, phi);
115983 + for (i = 0; i < n; i++) {
115984 + const_tree arg = gimple_phi_arg_def(phi, i);
115985 +
115986 + set_conditions(visited, interesting_conditions, arg);
115987 + }
115988 +}
115989 +
115990 +enum conditions {
115991 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
115992 +};
115993 +
115994 +// Search for constants, cast assignments and binary/ternary assignments
115995 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
115996 +{
115997 + gimple def_stmt = get_def_stmt(lhs);
115998 +
115999 + if (is_gimple_constant(lhs)) {
116000 + interesting_conditions[FROM_CONST] = true;
116001 + return;
116002 + }
116003 +
116004 + if (!def_stmt)
116005 + return;
116006 +
116007 + if (pointer_set_contains(visited, def_stmt))
116008 + return;
116009 +
116010 + switch (gimple_code(def_stmt)) {
116011 + case GIMPLE_CALL:
116012 + if (lhs == gimple_call_lhs(def_stmt))
116013 + interesting_conditions[RET] = true;
116014 + return;
116015 + case GIMPLE_NOP:
116016 + case GIMPLE_ASM:
116017 + return;
116018 + case GIMPLE_PHI:
116019 + interesting_conditions[PHI] = true;
116020 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116021 + case GIMPLE_ASSIGN:
116022 + if (gimple_num_ops(def_stmt) == 2) {
116023 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116024 +
116025 + if (gimple_assign_cast_p(def_stmt))
116026 + interesting_conditions[CAST] = true;
116027 +
116028 + return set_conditions(visited, interesting_conditions, rhs);
116029 + } else {
116030 + interesting_conditions[NOT_UNARY] = true;
116031 + return;
116032 + }
116033 + default:
116034 + debug_gimple_stmt(def_stmt);
116035 + gcc_unreachable();
116036 + }
116037 +}
116038 +
116039 +// determine whether duplication will be necessary or not.
116040 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116041 +{
116042 + struct pointer_set_t *visited;
116043 +
116044 + if (gimple_assign_cast_p(cur_node->first_stmt))
116045 + interesting_conditions[CAST] = true;
116046 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116047 + interesting_conditions[NOT_UNARY] = true;
116048 +
116049 + visited = pointer_set_create();
116050 + set_conditions(visited, interesting_conditions, cur_node->node);
116051 + pointer_set_destroy(visited);
116052 +}
116053 +
116054 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116055 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116056 +{
116057 + gimple assign;
116058 + gimple_stmt_iterator gsi;
116059 +
116060 + // already removed
116061 + if (gimple_bb(asm_stmt) == NULL)
116062 + return;
116063 + gsi = gsi_for_stmt(asm_stmt);
116064 +
116065 + assign = gimple_build_assign(lhs, rhs);
116066 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116067 + SSA_NAME_DEF_STMT(lhs) = assign;
116068 +
116069 + gsi_remove(&gsi, true);
116070 +}
116071 +
116072 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116073 + * stmt is a return otherwise it is the callee function.
116074 + */
116075 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116076 +{
116077 + const_tree fndecl;
116078 +
116079 + if (argnum == 0)
116080 + fndecl = current_function_decl;
116081 + else
116082 + fndecl = gimple_call_fndecl(stmt);
116083 +
116084 + if (fndecl == NULL_TREE)
116085 + return NULL_TREE;
116086 +
116087 + return DECL_ORIGIN(fndecl);
116088 +}
116089 +
116090 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116091 +static bool skip_asm(const_tree arg)
116092 +{
116093 + gimple def_stmt = get_def_stmt(arg);
116094 +
116095 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116096 + return false;
116097 +
116098 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116099 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116100 +}
116101 +
116102 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116103 +{
116104 + gimple phi = get_def_stmt(result);
116105 + unsigned int i, n = gimple_phi_num_args(phi);
116106 +
116107 + pointer_set_insert(visited, phi);
116108 + for (i = 0; i < n; i++) {
116109 + tree arg = gimple_phi_arg_def(phi, i);
116110 +
116111 + walk_use_def(visited, cur_node, arg);
116112 + }
116113 +}
116114 +
116115 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116116 +{
116117 + gimple def_stmt = get_def_stmt(lhs);
116118 + tree rhs1, rhs2;
116119 +
116120 + rhs1 = gimple_assign_rhs1(def_stmt);
116121 + rhs2 = gimple_assign_rhs2(def_stmt);
116122 +
116123 + walk_use_def(visited, cur_node, rhs1);
116124 + walk_use_def(visited, cur_node, rhs2);
116125 +}
116126 +
116127 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116128 +{
116129 + unsigned int i;
116130 + tree element;
116131 + enum tree_code code;
116132 +
116133 + gcc_assert(node != NULL_TREE);
116134 +
116135 + if (is_gimple_constant(node))
116136 + return;
116137 +
116138 + code = TREE_CODE(node);
116139 + if (code == VAR_DECL) {
116140 + node = DECL_ORIGIN(node);
116141 + code = TREE_CODE(node);
116142 + }
116143 +
116144 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116145 + return;
116146 +
116147 +#if BUILDING_GCC_VERSION <= 4007
116148 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116149 +#else
116150 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116151 +#endif
116152 + if (operand_equal_p(node, element, 0))
116153 + return;
116154 + }
116155 +
116156 +#if BUILDING_GCC_VERSION <= 4007
116157 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116158 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116159 +#else
116160 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116161 + vec_safe_push(cur_node->last_nodes, node);
116162 +#endif
116163 +}
116164 +
116165 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116166 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116167 +{
116168 + if (!is_size_overflow_asm(stmt))
116169 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116170 +}
116171 +
116172 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116173 + * and component refs (for checking the intentional_overflow attribute).
116174 + */
116175 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116176 +{
116177 + const_gimple def_stmt;
116178 +
116179 + if (TREE_CODE(lhs) != SSA_NAME) {
116180 + insert_last_node(cur_node, lhs);
116181 + return;
116182 + }
116183 +
116184 + def_stmt = get_def_stmt(lhs);
116185 + if (!def_stmt)
116186 + return;
116187 +
116188 + if (pointer_set_insert(visited, def_stmt))
116189 + return;
116190 +
116191 + switch (gimple_code(def_stmt)) {
116192 + case GIMPLE_NOP:
116193 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116194 + case GIMPLE_ASM:
116195 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116196 + case GIMPLE_CALL: {
116197 + tree fndecl = gimple_call_fndecl(def_stmt);
116198 +
116199 + if (fndecl == NULL_TREE)
116200 + return;
116201 + insert_last_node(cur_node, fndecl);
116202 + return;
116203 + }
116204 + case GIMPLE_PHI:
116205 + return walk_use_def_phi(visited, cur_node, lhs);
116206 + case GIMPLE_ASSIGN:
116207 + switch (gimple_num_ops(def_stmt)) {
116208 + case 2:
116209 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116210 + case 3:
116211 + return walk_use_def_binary(visited, cur_node, lhs);
116212 + }
116213 + default:
116214 + debug_gimple_stmt((gimple)def_stmt);
116215 + error("%s: unknown gimple code", __func__);
116216 + gcc_unreachable();
116217 + }
116218 +}
116219 +
116220 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116221 +static void set_last_nodes(struct interesting_node *cur_node)
116222 +{
116223 + struct pointer_set_t *visited;
116224 +
116225 + visited = pointer_set_create();
116226 + walk_use_def(visited, cur_node, cur_node->node);
116227 + pointer_set_destroy(visited);
116228 +}
116229 +
116230 +enum precond {
116231 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116232 +};
116233 +
116234 +/* 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.
116235 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116236 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116237 + * It skips the possible error codes too.
116238 + */
116239 +static enum precond check_preconditions(struct interesting_node *cur_node)
116240 +{
116241 + bool interesting_conditions[5] = {false, false, false, false, false};
116242 +
116243 + set_last_nodes(cur_node);
116244 +
116245 + check_intentional_attribute_ipa(cur_node);
116246 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116247 + return NO_ATTRIBUTE_SEARCH;
116248 +
116249 + search_interesting_conditions(cur_node, interesting_conditions);
116250 +
116251 + // error code: a phi, unary assign (not cast) and returns only
116252 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116253 + return NO_ATTRIBUTE_SEARCH;
116254 +
116255 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116256 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116257 + return NO_ATTRIBUTE_SEARCH;
116258 +
116259 + // unnecessary overflow check
116260 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116261 + return NO_CHECK_INSERT;
116262 +
116263 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116264 + return NO_CHECK_INSERT;
116265 +
116266 + return NONE;
116267 +}
116268 +
116269 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116270 +{
116271 + const_gimple assign;
116272 + tree orig_type = TREE_TYPE(orig_node);
116273 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116274 +
116275 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116276 + return gimple_assign_lhs(assign);
116277 +}
116278 +
116279 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116280 +{
116281 + void (*set_rhs)(gimple, tree);
116282 + gimple stmt = cur_node->first_stmt;
116283 + const_tree orig_node = cur_node->node;
116284 +
116285 + switch (gimple_code(stmt)) {
116286 + case GIMPLE_RETURN:
116287 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116288 + break;
116289 + case GIMPLE_CALL:
116290 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116291 + break;
116292 + case GIMPLE_ASSIGN:
116293 + switch (cur_node->num) {
116294 + case 1:
116295 + set_rhs = &gimple_assign_set_rhs1;
116296 + break;
116297 + case 2:
116298 + set_rhs = &gimple_assign_set_rhs2;
116299 + break;
116300 +#if BUILDING_GCC_VERSION >= 4006
116301 + case 3:
116302 + set_rhs = &gimple_assign_set_rhs3;
116303 + break;
116304 +#endif
116305 + default:
116306 + gcc_unreachable();
116307 + }
116308 +
116309 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116310 + break;
116311 + default:
116312 + debug_gimple_stmt(stmt);
116313 + gcc_unreachable();
116314 + }
116315 +
116316 + update_stmt(stmt);
116317 +}
116318 +
116319 +static struct visited *create_visited(void)
116320 +{
116321 + struct visited *new_node;
116322 +
116323 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116324 + new_node->stmts = pointer_set_create();
116325 + new_node->my_stmts = pointer_set_create();
116326 + new_node->skip_expr_casts = pointer_set_create();
116327 + new_node->no_cast_check = pointer_set_create();
116328 + return new_node;
116329 +}
116330 +
116331 +static void free_visited(struct visited *visited)
116332 +{
116333 + pointer_set_destroy(visited->stmts);
116334 + pointer_set_destroy(visited->my_stmts);
116335 + pointer_set_destroy(visited->skip_expr_casts);
116336 + pointer_set_destroy(visited->no_cast_check);
116337 +
116338 + free(visited);
116339 +}
116340 +
116341 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116342 + * 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
116343 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116344 + */
116345 +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)
116346 +{
116347 + enum precond ret;
116348 + tree new_node, orig_node = cur_node->node;
116349 +
116350 + ret = check_preconditions(cur_node);
116351 + if (ret == NO_ATTRIBUTE_SEARCH)
116352 + return cnodes;
116353 +
116354 + cnodes = search_overflow_attribute(cnodes, cur_node);
116355 +
116356 + if (ret == NO_CHECK_INSERT)
116357 + return cnodes;
116358 +
116359 + new_node = expand(visited, caller_node, orig_node);
116360 + if (new_node == NULL_TREE)
116361 + return cnodes;
116362 +
116363 + change_orig_node(visited, cur_node, new_node);
116364 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116365 +
116366 + return cnodes;
116367 +}
116368 +
116369 +// Check visited_fns interesting nodes.
116370 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116371 +{
116372 + struct interesting_node *cur;
116373 +
116374 + for (cur = head; cur; cur = cur->next) {
116375 + if (!operand_equal_p(node, cur->node, 0))
116376 + continue;
116377 + if (num != cur->num)
116378 + continue;
116379 + if (first_stmt == cur->first_stmt)
116380 + return true;
116381 + }
116382 + return false;
116383 +}
116384 +
116385 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116386 + 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
116387 + 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
116388 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116389 + num: arg count of a call stmt or 0 when it is a ret
116390 + node: the recursion starts from here, it is a call arg or a return value
116391 + 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.
116392 + intentional_attr_decl: intentional_overflow attribute of the callee function
116393 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116394 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116395 + */
116396 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116397 +{
116398 + struct interesting_node *new_node;
116399 + tree fndecl;
116400 + enum gimple_code code;
116401 +
116402 + gcc_assert(node != NULL_TREE);
116403 + code = gimple_code(first_stmt);
116404 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116405 +
116406 + if (num == CANNOT_FIND_ARG)
116407 + return head;
116408 +
116409 + if (skip_types(node))
116410 + return head;
116411 +
116412 + if (skip_asm(node))
116413 + return head;
116414 +
116415 + if (is_gimple_call(first_stmt))
116416 + fndecl = gimple_call_fndecl(first_stmt);
116417 + else
116418 + fndecl = current_function_decl;
116419 +
116420 + if (fndecl == NULL_TREE)
116421 + return head;
116422 +
116423 + if (is_in_interesting_node(head, first_stmt, node, num))
116424 + return head;
116425 +
116426 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116427 +
116428 + new_node->next = NULL;
116429 + new_node->first_stmt = first_stmt;
116430 +#if BUILDING_GCC_VERSION <= 4007
116431 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116432 +#else
116433 + vec_alloc(new_node->last_nodes, VEC_LEN);
116434 +#endif
116435 + new_node->num = num;
116436 + new_node->node = node;
116437 + new_node->fndecl = fndecl;
116438 + new_node->intentional_attr_decl = MARK_NO;
116439 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116440 + new_node->intentional_mark_from_gimple = asm_stmt;
116441 +
116442 + if (!head)
116443 + return new_node;
116444 +
116445 + new_node->next = head;
116446 + return new_node;
116447 +}
116448 +
116449 +/* 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).
116450 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116451 + */
116452 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116453 +{
116454 + struct next_cgraph_node *cur_node;
116455 + tree ret = gimple_return_retval(stmt);
116456 +
116457 + if (ret == NULL_TREE)
116458 + return head;
116459 +
116460 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116461 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116462 + continue;
116463 + if (cur_node->num == 0)
116464 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116465 + }
116466 +
116467 + return head;
116468 +}
116469 +
116470 +/* 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).
116471 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116472 + */
116473 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116474 +{
116475 + unsigned int argnum;
116476 + tree arg;
116477 + const_tree fndecl;
116478 + struct next_cgraph_node *cur_node;
116479 +
116480 + fndecl = gimple_call_fndecl(stmt);
116481 + if (fndecl == NULL_TREE)
116482 + return head;
116483 +
116484 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116485 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116486 + continue;
116487 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116488 + gcc_assert(argnum != CANNOT_FIND_ARG);
116489 + if (argnum == 0)
116490 + continue;
116491 +
116492 + arg = gimple_call_arg(stmt, argnum - 1);
116493 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116494 + }
116495 +
116496 + return head;
116497 +}
116498 +
116499 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116500 +{
116501 + if (!operand_equal_p(orig_node, node, 0))
116502 + return WRONG_NODE;
116503 + if (skip_types(node))
116504 + return WRONG_NODE;
116505 + return ret_count;
116506 +}
116507 +
116508 +// Get the index of the rhs node in an assignment
116509 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116510 +{
116511 + const_tree rhs1, rhs2;
116512 + unsigned int ret;
116513 +
116514 + gcc_assert(stmt);
116515 + gcc_assert(is_gimple_assign(stmt));
116516 +
116517 + rhs1 = gimple_assign_rhs1(stmt);
116518 + gcc_assert(rhs1 != NULL_TREE);
116519 +
116520 + switch (gimple_num_ops(stmt)) {
116521 + case 2:
116522 + return check_ops(node, rhs1, 1);
116523 + case 3:
116524 + ret = check_ops(node, rhs1, 1);
116525 + if (ret != WRONG_NODE)
116526 + return ret;
116527 +
116528 + rhs2 = gimple_assign_rhs2(stmt);
116529 + gcc_assert(rhs2 != NULL_TREE);
116530 + return check_ops(node, rhs2, 2);
116531 + default:
116532 + gcc_unreachable();
116533 + }
116534 +}
116535 +
116536 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116537 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116538 +{
116539 + unsigned int i;
116540 +
116541 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116542 + return CANNOT_FIND_ARG;
116543 +
116544 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116545 + tree node;
116546 +
116547 + node = gimple_call_arg(stmt, i);
116548 + if (!operand_equal_p(arg, node, 0))
116549 + continue;
116550 + if (!skip_types(node))
116551 + return i + 1;
116552 + }
116553 +
116554 + return CANNOT_FIND_ARG;
116555 +}
116556 +
116557 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116558 + * any of return, call or assignment stmts (because of inlining).
116559 + */
116560 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116561 +{
116562 + use_operand_p use_p;
116563 + imm_use_iterator imm_iter;
116564 + unsigned int argnum;
116565 +
116566 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116567 +
116568 + if (pointer_set_insert(visited, node))
116569 + return head;
116570 +
116571 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116572 + gimple stmt = USE_STMT(use_p);
116573 +
116574 + if (stmt == NULL)
116575 + return head;
116576 + if (is_gimple_debug(stmt))
116577 + continue;
116578 +
116579 + switch (gimple_code(stmt)) {
116580 + case GIMPLE_CALL:
116581 + argnum = find_arg_number_gimple(node, stmt);
116582 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116583 + break;
116584 + case GIMPLE_RETURN:
116585 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116586 + break;
116587 + case GIMPLE_ASSIGN:
116588 + argnum = get_assign_ops_count(stmt, node);
116589 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116590 + break;
116591 + case GIMPLE_PHI: {
116592 + tree result = gimple_phi_result(stmt);
116593 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116594 + break;
116595 + }
116596 + case GIMPLE_ASM:
116597 + if (gimple_asm_noutputs(stmt) != 0)
116598 + break;
116599 + if (!is_size_overflow_asm(stmt))
116600 + break;
116601 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116602 + break;
116603 + case GIMPLE_COND:
116604 + case GIMPLE_SWITCH:
116605 + break;
116606 + default:
116607 + debug_gimple_stmt(stmt);
116608 + gcc_unreachable();
116609 + break;
116610 + }
116611 + }
116612 + return head;
116613 +}
116614 +
116615 +static void remove_size_overflow_asm(gimple stmt)
116616 +{
116617 + gimple_stmt_iterator gsi;
116618 + tree input, output;
116619 +
116620 + if (!is_size_overflow_asm(stmt))
116621 + return;
116622 +
116623 + if (gimple_asm_noutputs(stmt) == 0) {
116624 + gsi = gsi_for_stmt(stmt);
116625 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116626 + gsi_remove(&gsi, true);
116627 + return;
116628 + }
116629 +
116630 + input = gimple_asm_input_op(stmt, 0);
116631 + output = gimple_asm_output_op(stmt, 0);
116632 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116633 +}
116634 +
116635 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116636 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116637 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116638 + */
116639 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116640 +{
116641 + const_tree output;
116642 + struct pointer_set_t *visited;
116643 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116644 +
116645 + if (!is_size_overflow_asm(stmt))
116646 + return head;
116647 +
116648 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116649 + intentional_asm = stmt;
116650 +
116651 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116652 +
116653 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116654 + return head;
116655 +
116656 + if (gimple_asm_noutputs(stmt) == 0) {
116657 + const_tree input;
116658 +
116659 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116660 + return head;
116661 +
116662 + input = gimple_asm_input_op(stmt, 0);
116663 + remove_size_overflow_asm(stmt);
116664 + if (is_gimple_constant(TREE_VALUE(input)))
116665 + return head;
116666 + visited = pointer_set_create();
116667 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116668 + pointer_set_destroy(visited);
116669 + return head;
116670 + }
116671 +
116672 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116673 + remove_size_overflow_asm(stmt);
116674 +
116675 + visited = pointer_set_create();
116676 + output = gimple_asm_output_op(stmt, 0);
116677 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116678 + pointer_set_destroy(visited);
116679 + return head;
116680 +}
116681 +
116682 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116683 + * or a call stmt or a return stmt and store them in the interesting_node list
116684 + */
116685 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116686 +{
116687 + basic_block bb;
116688 + struct interesting_node *head = NULL;
116689 +
116690 + FOR_ALL_BB_FN(bb, cfun) {
116691 + gimple_stmt_iterator gsi;
116692 +
116693 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116694 + enum gimple_code code;
116695 + gimple stmt = gsi_stmt(gsi);
116696 +
116697 + code = gimple_code(stmt);
116698 +
116699 + if (code == GIMPLE_ASM)
116700 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116701 +
116702 + if (!next_node)
116703 + continue;
116704 + if (code == GIMPLE_CALL)
116705 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116706 + if (code == GIMPLE_RETURN)
116707 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116708 + }
116709 + }
116710 + return head;
116711 +}
116712 +
116713 +static void free_interesting_node(struct interesting_node *head)
116714 +{
116715 + struct interesting_node *cur;
116716 +
116717 + while (head) {
116718 + cur = head->next;
116719 +#if BUILDING_GCC_VERSION <= 4007
116720 + VEC_free(tree, gc, head->last_nodes);
116721 +#else
116722 + vec_free(head->last_nodes);
116723 +#endif
116724 + free(head);
116725 + head = cur;
116726 + }
116727 +}
116728 +
116729 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116730 +{
116731 + struct visited_fns *new_visited_fns;
116732 +
116733 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116734 + new_visited_fns->fndecl = cur_node->fndecl;
116735 + new_visited_fns->num = cur_node->num;
116736 + new_visited_fns->first_stmt = cur_node->first_stmt;
116737 + new_visited_fns->next = NULL;
116738 +
116739 + if (!head)
116740 + return new_visited_fns;
116741 +
116742 + new_visited_fns->next = head;
116743 + return new_visited_fns;
116744 +}
116745 +
116746 +/* 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
116747 + * it is a visited_fns function.
116748 + */
116749 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116750 +{
116751 + struct visited_fns *cur;
116752 +
116753 + if (!head)
116754 + return false;
116755 +
116756 + for (cur = head; cur; cur = cur->next) {
116757 + if (cur_node->first_stmt != cur->first_stmt)
116758 + continue;
116759 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116760 + continue;
116761 + if (cur_node->num == cur->num)
116762 + return true;
116763 + }
116764 + return false;
116765 +}
116766 +
116767 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116768 +{
116769 + struct next_cgraph_node *cur;
116770 +
116771 + while (head) {
116772 + cur = head->next;
116773 + free(head);
116774 + head = cur;
116775 + }
116776 +}
116777 +
116778 +static void remove_all_size_overflow_asm(void)
116779 +{
116780 + basic_block bb;
116781 +
116782 + FOR_ALL_BB_FN(bb, cfun) {
116783 + gimple_stmt_iterator si;
116784 +
116785 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116786 + remove_size_overflow_asm(gsi_stmt(si));
116787 + }
116788 +}
116789 +
116790 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116791 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116792 + * the newly collected interesting functions (they are interesting if there is control flow between
116793 + * the interesting stmts and them).
116794 + */
116795 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116796 +{
116797 + struct visited *visited;
116798 + struct interesting_node *head, *cur_node;
116799 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116800 +
116801 + set_current_function_decl(NODE_DECL(node));
116802 + call_count = 0;
116803 +
116804 + head = collect_interesting_stmts(next_node);
116805 +
116806 + visited = create_visited();
116807 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116808 + if (is_visited_fns_function(visited_fns, cur_node))
116809 + continue;
116810 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116811 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116812 + }
116813 +
116814 + free_visited(visited);
116815 + free_interesting_node(head);
116816 + remove_all_size_overflow_asm();
116817 + unset_current_function_decl();
116818 +
116819 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116820 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116821 +
116822 + free_next_cgraph_node(cnodes_head);
116823 + return visited_fns;
116824 +}
116825 +
116826 +static void free_visited_fns(struct visited_fns *head)
116827 +{
116828 + struct visited_fns *cur;
116829 +
116830 + while (head) {
116831 + cur = head->next;
116832 + free(head);
116833 + head = cur;
116834 + }
116835 +}
116836 +
116837 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116838 +unsigned int search_function(void)
116839 +{
116840 + struct cgraph_node *node;
116841 + struct visited_fns *visited_fns = NULL;
116842 +
116843 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116844 + gcc_assert(cgraph_function_flags_ready);
116845 +#if BUILDING_GCC_VERSION <= 4007
116846 + gcc_assert(node->reachable);
116847 +#endif
116848 +
116849 + visited_fns = handle_function(node, NULL, visited_fns);
116850 + }
116851 +
116852 + free_visited_fns(visited_fns);
116853 + return 0;
116854 +}
116855 +
116856 +#if BUILDING_GCC_VERSION >= 4009
116857 +static const struct pass_data insert_size_overflow_check_data = {
116858 +#else
116859 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116860 + .pass = {
116861 +#endif
116862 + .type = SIMPLE_IPA_PASS,
116863 + .name = "size_overflow",
116864 +#if BUILDING_GCC_VERSION >= 4008
116865 + .optinfo_flags = OPTGROUP_NONE,
116866 +#endif
116867 +#if BUILDING_GCC_VERSION >= 4009
116868 + .has_gate = false,
116869 + .has_execute = true,
116870 +#else
116871 + .gate = NULL,
116872 + .execute = search_function,
116873 + .sub = NULL,
116874 + .next = NULL,
116875 + .static_pass_number = 0,
116876 +#endif
116877 + .tv_id = TV_NONE,
116878 + .properties_required = 0,
116879 + .properties_provided = 0,
116880 + .properties_destroyed = 0,
116881 + .todo_flags_start = 0,
116882 + .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,
116883 +#if BUILDING_GCC_VERSION < 4009
116884 + },
116885 + .generate_summary = NULL,
116886 + .write_summary = NULL,
116887 + .read_summary = NULL,
116888 +#if BUILDING_GCC_VERSION >= 4006
116889 + .write_optimization_summary = NULL,
116890 + .read_optimization_summary = NULL,
116891 +#endif
116892 + .stmt_fixup = NULL,
116893 + .function_transform_todo_flags_start = 0,
116894 + .function_transform = NULL,
116895 + .variable_transform = NULL,
116896 +#endif
116897 +};
116898 +
116899 +#if BUILDING_GCC_VERSION >= 4009
116900 +namespace {
116901 +class insert_size_overflow_check : public ipa_opt_pass_d {
116902 +public:
116903 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116904 + unsigned int execute() { return search_function(); }
116905 +};
116906 +}
116907 +#endif
116908 +
116909 +struct opt_pass *make_insert_size_overflow_check(void)
116910 +{
116911 +#if BUILDING_GCC_VERSION >= 4009
116912 + return new insert_size_overflow_check();
116913 +#else
116914 + return &insert_size_overflow_check.pass;
116915 +#endif
116916 +}
116917 +
116918 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116919 new file mode 100644
116920 index 0000000..d71d72a
116921 --- /dev/null
116922 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116923 @@ -0,0 +1,736 @@
116924 +/*
116925 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116926 + * Licensed under the GPL v2, or (at your option) v3
116927 + *
116928 + * Homepage:
116929 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116930 + *
116931 + * Documentation:
116932 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116933 + *
116934 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116935 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116936 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116937 + *
116938 + * Usage:
116939 + * $ make
116940 + * $ make run
116941 + */
116942 +
116943 +#include "gcc-common.h"
116944 +#include "size_overflow.h"
116945 +
116946 +/* Get the param of the intentional_overflow attribute.
116947 + * * 0: MARK_NOT_INTENTIONAL
116948 + * * 1..MAX_PARAM: MARK_YES
116949 + * * -1: MARK_TURN_OFF
116950 + */
116951 +static tree get_attribute_param(const_tree decl)
116952 +{
116953 + const_tree attr;
116954 +
116955 + if (decl == NULL_TREE)
116956 + return NULL_TREE;
116957 +
116958 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116959 + if (!attr || !TREE_VALUE(attr))
116960 + return NULL_TREE;
116961 +
116962 + return TREE_VALUE(attr);
116963 +}
116964 +
116965 +// MARK_TURN_OFF
116966 +bool is_turn_off_intentional_attr(const_tree decl)
116967 +{
116968 + const_tree param_head;
116969 +
116970 + param_head = get_attribute_param(decl);
116971 + if (param_head == NULL_TREE)
116972 + return false;
116973 +
116974 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116975 + return true;
116976 + return false;
116977 +}
116978 +
116979 +// MARK_NOT_INTENTIONAL
116980 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116981 +{
116982 + const_tree param_head;
116983 +
116984 + if (argnum == 0)
116985 + return false;
116986 +
116987 + param_head = get_attribute_param(decl);
116988 + if (param_head == NULL_TREE)
116989 + return false;
116990 +
116991 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116992 + return true;
116993 + return false;
116994 +}
116995 +
116996 +// MARK_YES
116997 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116998 +{
116999 + tree param, param_head;
117000 +
117001 + if (argnum == 0)
117002 + return false;
117003 +
117004 + param_head = get_attribute_param(decl);
117005 + for (param = param_head; param; param = TREE_CHAIN(param))
117006 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117007 + return true;
117008 + return false;
117009 +}
117010 +
117011 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117012 +{
117013 + location_t loc;
117014 +
117015 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117016 + return;
117017 +
117018 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117019 + return;
117020 +
117021 + loc = DECL_SOURCE_LOCATION(decl);
117022 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117023 +}
117024 +
117025 +// Get the field decl of a component ref for intentional_overflow checking
117026 +static const_tree search_field_decl(const_tree comp_ref)
117027 +{
117028 + const_tree field = NULL_TREE;
117029 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
117030 +
117031 + for (i = 0; i < len; i++) {
117032 + field = TREE_OPERAND(comp_ref, i);
117033 + if (TREE_CODE(field) == FIELD_DECL)
117034 + break;
117035 + }
117036 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
117037 + return field;
117038 +}
117039 +
117040 +/* Get the type of the intentional_overflow attribute of a node
117041 + * * MARK_TURN_OFF
117042 + * * MARK_YES
117043 + * * MARK_NO
117044 + * * MARK_NOT_INTENTIONAL
117045 + */
117046 +enum mark get_intentional_attr_type(const_tree node)
117047 +{
117048 + const_tree cur_decl;
117049 +
117050 + if (node == NULL_TREE)
117051 + return MARK_NO;
117052 +
117053 + switch (TREE_CODE(node)) {
117054 + case COMPONENT_REF:
117055 + cur_decl = search_field_decl(node);
117056 + if (is_turn_off_intentional_attr(cur_decl))
117057 + return MARK_TURN_OFF;
117058 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117059 + return MARK_YES;
117060 + break;
117061 + case PARM_DECL: {
117062 + unsigned int argnum;
117063 +
117064 + cur_decl = DECL_ORIGIN(current_function_decl);
117065 + argnum = find_arg_number_tree(node, cur_decl);
117066 + if (argnum == CANNOT_FIND_ARG)
117067 + return MARK_NO;
117068 + if (is_yes_intentional_attr(cur_decl, argnum))
117069 + return MARK_YES;
117070 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117071 + return MARK_NOT_INTENTIONAL;
117072 + break;
117073 + }
117074 + case FUNCTION_DECL:
117075 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117076 + return MARK_TURN_OFF;
117077 + break;
117078 + default:
117079 + break;
117080 + }
117081 + return MARK_NO;
117082 +}
117083 +
117084 +// Search for the intentional_overflow attribute on the last nodes
117085 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117086 +{
117087 + unsigned int i;
117088 + tree last_node;
117089 + enum mark mark = MARK_NO;
117090 +
117091 +#if BUILDING_GCC_VERSION <= 4007
117092 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117093 +#else
117094 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117095 +#endif
117096 + mark = get_intentional_attr_type(last_node);
117097 + if (mark != MARK_NO)
117098 + break;
117099 + }
117100 + return mark;
117101 +}
117102 +
117103 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117104 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117105 + */
117106 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117107 +{
117108 + if (!cur_node->intentional_mark_from_gimple)
117109 + return false;
117110 +
117111 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117112 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117113 + else
117114 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117115 +
117116 + // skip param decls
117117 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117118 + return true;
117119 + return true;
117120 +}
117121 +
117122 +/* Search intentional_overflow attribute on caller and on callee too.
117123 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117124 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117125 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117126 +*/
117127 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117128 +{
117129 + const_tree fndecl;
117130 +
117131 + if (is_intentional_attribute_from_gimple(cur_node))
117132 + return;
117133 +
117134 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117135 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117136 + return;
117137 + }
117138 +
117139 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117140 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117141 + return;
117142 + }
117143 +
117144 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117145 + return;
117146 +
117147 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117148 + if (is_turn_off_intentional_attr(fndecl)) {
117149 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117150 + return;
117151 + }
117152 +
117153 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117154 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117155 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117156 + cur_node->intentional_attr_decl = MARK_YES;
117157 +
117158 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117159 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117160 +}
117161 +
117162 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
117163 +{
117164 + const_tree rhs1, lhs, rhs1_type, lhs_type;
117165 + enum machine_mode lhs_mode, rhs_mode;
117166 + gimple def_stmt = get_def_stmt(no_const_rhs);
117167 +
117168 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117169 + return false;
117170 +
117171 + rhs1 = gimple_assign_rhs1(def_stmt);
117172 + lhs = gimple_assign_lhs(def_stmt);
117173 + rhs1_type = TREE_TYPE(rhs1);
117174 + lhs_type = TREE_TYPE(lhs);
117175 + rhs_mode = TYPE_MODE(rhs1_type);
117176 + lhs_mode = TYPE_MODE(lhs_type);
117177 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
117178 + return false;
117179 +
117180 + return true;
117181 +}
117182 +
117183 +static unsigned int uses_num(tree node)
117184 +{
117185 + imm_use_iterator imm_iter;
117186 + use_operand_p use_p;
117187 + unsigned int num = 0;
117188 +
117189 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117190 + gimple use_stmt = USE_STMT(use_p);
117191 +
117192 + if (use_stmt == NULL)
117193 + return num;
117194 + if (is_gimple_debug(use_stmt))
117195 + continue;
117196 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117197 + continue;
117198 + num++;
117199 + }
117200 + return num;
117201 +}
117202 +
117203 +static bool no_uses(tree node)
117204 +{
117205 + return !uses_num(node);
117206 +}
117207 +
117208 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117209 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117210 +{
117211 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117212 + gimple def_stmt = get_def_stmt(lhs);
117213 +
117214 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117215 + return false;
117216 +
117217 + rhs1 = gimple_assign_rhs1(def_stmt);
117218 + rhs_type = TREE_TYPE(rhs1);
117219 + lhs_type = TREE_TYPE(lhs);
117220 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117221 + return false;
117222 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117223 + return false;
117224 +
117225 + def_stmt = get_def_stmt(rhs1);
117226 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117227 + return false;
117228 +
117229 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117230 + return false;
117231 +
117232 + rhs1 = gimple_assign_rhs1(def_stmt);
117233 + rhs2 = gimple_assign_rhs2(def_stmt);
117234 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117235 + return false;
117236 +
117237 + if (is_gimple_constant(rhs2))
117238 + not_const_rhs = rhs1;
117239 + else
117240 + not_const_rhs = rhs2;
117241 +
117242 + return no_uses(not_const_rhs);
117243 +}
117244 +
117245 +static bool is_lt_signed_type_max(const_tree rhs)
117246 +{
117247 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117248 +
117249 + if (!TYPE_UNSIGNED(type))
117250 + return true;
117251 +
117252 + switch (TYPE_MODE(type)) {
117253 + case QImode:
117254 + new_type = intQI_type_node;
117255 + break;
117256 + case HImode:
117257 + new_type = intHI_type_node;
117258 + break;
117259 + case SImode:
117260 + new_type = intSI_type_node;
117261 + break;
117262 + case DImode:
117263 + new_type = intDI_type_node;
117264 + break;
117265 + default:
117266 + debug_tree((tree)type);
117267 + gcc_unreachable();
117268 + }
117269 +
117270 + type_max = TYPE_MAX_VALUE(new_type);
117271 + if (!tree_int_cst_lt(type_max, rhs))
117272 + return true;
117273 +
117274 + return false;
117275 +}
117276 +
117277 +static bool is_gt_zero(const_tree rhs)
117278 +{
117279 + const_tree type = TREE_TYPE(rhs);
117280 +
117281 + if (TYPE_UNSIGNED(type))
117282 + return true;
117283 +
117284 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117285 + return true;
117286 +
117287 + return false;
117288 +}
117289 +
117290 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117291 +{
117292 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117293 + return false;
117294 + if (!is_gimple_constant(rhs))
117295 + return false;
117296 +
117297 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117298 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117299 + return false;
117300 +
117301 + return true;
117302 +}
117303 +
117304 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117305 +{
117306 + gimple assign;
117307 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117308 + tree origtype = TREE_TYPE(orig_rhs);
117309 +
117310 + gcc_assert(is_gimple_assign(stmt));
117311 +
117312 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117313 + pointer_set_insert(visited->my_stmts, assign);
117314 + return gimple_assign_lhs(assign);
117315 +}
117316 +
117317 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117318 +{
117319 + tree new_rhs, orig_rhs;
117320 + void (*gimple_assign_set_rhs)(gimple, tree);
117321 + tree rhs1 = gimple_assign_rhs1(stmt);
117322 + tree rhs2 = gimple_assign_rhs2(stmt);
117323 + tree lhs = gimple_assign_lhs(stmt);
117324 +
117325 + if (!check_overflow)
117326 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117327 +
117328 + if (change_rhs == NULL_TREE)
117329 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117330 +
117331 + if (new_rhs2 == NULL_TREE) {
117332 + orig_rhs = rhs1;
117333 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117334 + } else {
117335 + orig_rhs = rhs2;
117336 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117337 + }
117338 +
117339 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117340 +
117341 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117342 + gimple_assign_set_rhs(stmt, new_rhs);
117343 + update_stmt(stmt);
117344 +
117345 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117346 +}
117347 +
117348 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117349 +{
117350 + gimple rhs1_def_stmt, rhs2_def_stmt;
117351 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117352 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117353 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117354 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117355 +
117356 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117357 + return false;
117358 +
117359 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117360 +
117361 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117362 + return false;
117363 +
117364 + rhs1_def_stmt = get_def_stmt(rhs1);
117365 + rhs2_def_stmt = get_def_stmt(rhs2);
117366 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117367 + return false;
117368 +
117369 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117370 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117371 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117372 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117373 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117374 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117375 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117376 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117377 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117378 + return false;
117379 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117380 + return false;
117381 +
117382 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117383 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117384 + return true;
117385 +}
117386 +
117387 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117388 +{
117389 + gimple assign;
117390 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117391 + tree type = TREE_TYPE(rhs1);
117392 + tree lhs = create_new_var(type);
117393 +
117394 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117395 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117396 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117397 +
117398 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117399 + update_stmt(assign);
117400 + pointer_set_insert(visited->my_stmts, assign);
117401 + return assign;
117402 +}
117403 +
117404 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117405 +{
117406 + gimple_stmt_iterator gsi;
117407 + gimple cast_stmt;
117408 + tree type = TREE_TYPE(node);
117409 +
117410 + if (types_compatible_p(type, intTI_type_node))
117411 + return node;
117412 +
117413 + gsi = gsi_for_stmt(stmt);
117414 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117415 + pointer_set_insert(visited->my_stmts, cast_stmt);
117416 + return gimple_assign_lhs(cast_stmt);
117417 +}
117418 +
117419 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117420 +{
117421 + tree rhs1, def_stmt_rhs1;
117422 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117423 +
117424 + def_stmt = get_def_stmt(var);
117425 + if (!gimple_assign_cast_p(def_stmt))
117426 + return NULL_TREE;
117427 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117428 +
117429 + rhs1 = gimple_assign_rhs1(def_stmt);
117430 + rhs1_def_stmt = get_def_stmt(rhs1);
117431 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117432 + return rhs1;
117433 +
117434 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117435 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117436 +
117437 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117438 + case GIMPLE_CALL:
117439 + case GIMPLE_NOP:
117440 + case GIMPLE_ASM:
117441 + case GIMPLE_PHI:
117442 + return def_stmt_rhs1;
117443 + case GIMPLE_ASSIGN:
117444 + return rhs1;
117445 + default:
117446 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117447 + gcc_unreachable();
117448 + }
117449 +}
117450 +
117451 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117452 +{
117453 + tree new_rhs1, new_rhs2;
117454 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117455 + gimple assign, stmt = get_def_stmt(lhs);
117456 + tree rhs1 = gimple_assign_rhs1(stmt);
117457 + tree rhs2 = gimple_assign_rhs2(stmt);
117458 +
117459 + if (!is_subtraction_special(visited, stmt))
117460 + return NULL_TREE;
117461 +
117462 + new_rhs1 = expand(visited, caller_node, rhs1);
117463 + new_rhs2 = expand(visited, caller_node, rhs2);
117464 +
117465 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117466 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117467 +
117468 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117469 + return NULL_TREE;
117470 +
117471 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117472 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117473 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117474 + }
117475 +
117476 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117477 + new_lhs = gimple_assign_lhs(assign);
117478 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117479 +
117480 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117481 +}
117482 +
117483 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117484 +{
117485 + const_gimple def_stmt;
117486 +
117487 + if (TREE_CODE(rhs) != SSA_NAME)
117488 + return false;
117489 +
117490 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117491 + return false;
117492 +
117493 + def_stmt = get_def_stmt(rhs);
117494 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117495 + return false;
117496 +
117497 + return true;
117498 +}
117499 +
117500 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117501 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117502 + * fffffff * 16 > signed max -> truncate
117503 + */
117504 +static bool look_for_mult_and_add(const_gimple stmt)
117505 +{
117506 + const_tree res;
117507 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117508 + const_gimple def_stmt;
117509 +
117510 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117511 + return false;
117512 + if (!is_gimple_assign(stmt))
117513 + return false;
117514 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117515 + return false;
117516 +
117517 + rhs1 = gimple_assign_rhs1(stmt);
117518 + rhs2 = gimple_assign_rhs2(stmt);
117519 + if (is_gimple_constant(rhs1)) {
117520 + const_rhs = rhs1;
117521 + def_stmt = get_def_stmt(rhs2);
117522 + } else if (is_gimple_constant(rhs2)) {
117523 + const_rhs = rhs2;
117524 + def_stmt = get_def_stmt(rhs1);
117525 + } else
117526 + return false;
117527 +
117528 + if (!is_gimple_assign(def_stmt))
117529 + return false;
117530 +
117531 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117532 + return false;
117533 +
117534 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117535 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117536 + if (is_gimple_constant(def_rhs1))
117537 + def_const_rhs = def_rhs1;
117538 + else if (is_gimple_constant(def_rhs2))
117539 + def_const_rhs = def_rhs2;
117540 + else
117541 + return false;
117542 +
117543 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117544 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117545 + return false;
117546 + return true;
117547 +}
117548 +
117549 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117550 +{
117551 + const_gimple def_stmt_1, def_stmt_2;
117552 + const_tree rhs1, rhs2;
117553 + bool add_mul_rhs1, add_mul_rhs2;
117554 +
117555 + rhs1 = gimple_assign_rhs1(stmt);
117556 + def_stmt_1 = get_def_stmt(rhs1);
117557 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117558 +
117559 + rhs2 = gimple_assign_rhs2(stmt);
117560 + def_stmt_2 = get_def_stmt(rhs2);
117561 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117562 +
117563 + if (add_mul_rhs1)
117564 + return RHS1_INTENTIONAL_OVERFLOW;
117565 + if (add_mul_rhs2)
117566 + return RHS2_INTENTIONAL_OVERFLOW;
117567 + return NO_INTENTIONAL_OVERFLOW;
117568 +}
117569 +
117570 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117571 +{
117572 + gimple my_stmt;
117573 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117574 +
117575 + gsi_next(&gsi);
117576 + my_stmt = gsi_stmt(gsi);
117577 +
117578 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117579 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117580 +
117581 + return my_stmt;
117582 +}
117583 +
117584 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117585 + * unsigned type cast to signed type, unsigned type: no more uses
117586 + * e.g., lib/vsprintf.c:simple_strtol()
117587 + * _10 = (unsigned long int) _9
117588 + * _11 = -_10;
117589 + * _12 = (long int) _11; (_11_ no more uses)
117590 + */
117591 +static bool is_call_or_cast(gimple stmt)
117592 +{
117593 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117594 +}
117595 +
117596 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117597 +{
117598 + const_tree rhs;
117599 + gimple def_stmt;
117600 +
117601 + if (node == NULL_TREE)
117602 + return true;
117603 + if (is_gimple_constant(node))
117604 + return true;
117605 +
117606 + def_stmt = get_def_stmt(node);
117607 + if (!def_stmt)
117608 + return false;
117609 +
117610 + if (is_call_or_cast(def_stmt))
117611 + return true;
117612 +
117613 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117614 + return false;
117615 + rhs = gimple_assign_rhs1(def_stmt);
117616 + def_stmt = get_def_stmt(rhs);
117617 + if (!def_stmt)
117618 + return false;
117619 + return is_call_or_cast(def_stmt);
117620 +}
117621 +
117622 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117623 +{
117624 + unsigned int use_num;
117625 + gimple so_stmt;
117626 + const_gimple def_stmt;
117627 + const_tree rhs1, rhs2;
117628 + tree rhs = gimple_assign_rhs1(stmt);
117629 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117630 + const_tree rhs_type = TREE_TYPE(rhs);
117631 +
117632 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117633 + return;
117634 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117635 + return;
117636 + use_num = uses_num(rhs);
117637 + if (use_num != 1)
117638 + return;
117639 +
117640 + def_stmt = get_def_stmt(rhs);
117641 + if (!def_stmt)
117642 + return;
117643 + if (!is_gimple_assign(def_stmt))
117644 + return;
117645 +
117646 + rhs1 = gimple_assign_rhs1(def_stmt);
117647 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117648 + return;
117649 +
117650 + rhs2 = gimple_assign_rhs2(def_stmt);
117651 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117652 + return;
117653 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117654 + return;
117655 +
117656 + so_stmt = get_dup_stmt(visited, stmt);
117657 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117658 +}
117659 +
117660 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117661 new file mode 100644
117662 index 0000000..4bddad2
117663 --- /dev/null
117664 +++ b/tools/gcc/size_overflow_plugin/misc.c
117665 @@ -0,0 +1,203 @@
117666 +/*
117667 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117668 + * Licensed under the GPL v2, or (at your option) v3
117669 + *
117670 + * Homepage:
117671 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117672 + *
117673 + * Documentation:
117674 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117675 + *
117676 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117677 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117678 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117679 + *
117680 + * Usage:
117681 + * $ make
117682 + * $ make run
117683 + */
117684 +
117685 +#include "gcc-common.h"
117686 +#include "size_overflow.h"
117687 +
117688 +void set_current_function_decl(tree fndecl)
117689 +{
117690 + gcc_assert(fndecl != NULL_TREE);
117691 +
117692 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117693 + calculate_dominance_info(CDI_DOMINATORS);
117694 + current_function_decl = fndecl;
117695 +}
117696 +
117697 +void unset_current_function_decl(void)
117698 +{
117699 + free_dominance_info(CDI_DOMINATORS);
117700 + pop_cfun();
117701 + current_function_decl = NULL_TREE;
117702 +}
117703 +
117704 +static bool is_bool(const_tree node)
117705 +{
117706 + const_tree type;
117707 +
117708 + if (node == NULL_TREE)
117709 + return false;
117710 +
117711 + type = TREE_TYPE(node);
117712 + if (!INTEGRAL_TYPE_P(type))
117713 + return false;
117714 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117715 + return true;
117716 + if (TYPE_PRECISION(type) == 1)
117717 + return true;
117718 + return false;
117719 +}
117720 +
117721 +bool skip_types(const_tree var)
117722 +{
117723 + tree type;
117724 + enum tree_code code;
117725 +
117726 + if (is_gimple_constant(var))
117727 + return true;
117728 +
117729 + switch (TREE_CODE(var)) {
117730 + case ADDR_EXPR:
117731 +#if BUILDING_GCC_VERSION >= 4006
117732 + case MEM_REF:
117733 +#endif
117734 + case ARRAY_REF:
117735 + case BIT_FIELD_REF:
117736 + case INDIRECT_REF:
117737 + case TARGET_MEM_REF:
117738 + case COMPONENT_REF:
117739 + case VAR_DECL:
117740 + case VIEW_CONVERT_EXPR:
117741 + return true;
117742 + default:
117743 + break;
117744 + }
117745 +
117746 + code = TREE_CODE(var);
117747 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117748 +
117749 + type = TREE_TYPE(var);
117750 + switch (TREE_CODE(type)) {
117751 + case INTEGER_TYPE:
117752 + case ENUMERAL_TYPE:
117753 + return false;
117754 + case BOOLEAN_TYPE:
117755 + return is_bool(var);
117756 + default:
117757 + return true;
117758 + }
117759 +}
117760 +
117761 +gimple get_def_stmt(const_tree node)
117762 +{
117763 + gcc_assert(node != NULL_TREE);
117764 +
117765 + if (skip_types(node))
117766 + return NULL;
117767 +
117768 + if (TREE_CODE(node) != SSA_NAME)
117769 + return NULL;
117770 + return SSA_NAME_DEF_STMT(node);
117771 +}
117772 +
117773 +tree create_new_var(tree type)
117774 +{
117775 + tree new_var = create_tmp_var(type, "cicus");
117776 +
117777 + add_referenced_var(new_var);
117778 + return new_var;
117779 +}
117780 +
117781 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117782 +{
117783 + const_gimple def_stmt = get_def_stmt(rhs);
117784 +
117785 + if (force)
117786 + return false;
117787 +
117788 + if (is_gimple_constant(rhs))
117789 + return false;
117790 +
117791 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117792 + return false;
117793 +
117794 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117795 + return false;
117796 +
117797 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117798 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117799 + return false;
117800 +
117801 + return true;
117802 +}
117803 +
117804 +tree cast_a_tree(tree type, tree var)
117805 +{
117806 + gcc_assert(type != NULL_TREE);
117807 + gcc_assert(var != NULL_TREE);
117808 + gcc_assert(fold_convertible_p(type, var));
117809 +
117810 + return fold_convert(type, var);
117811 +}
117812 +
117813 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117814 +{
117815 + gimple assign, def_stmt;
117816 +
117817 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117818 + gcc_assert(!is_gimple_constant(rhs));
117819 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117820 + gcc_unreachable();
117821 +
117822 + def_stmt = get_def_stmt(rhs);
117823 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117824 + return def_stmt;
117825 +
117826 + if (lhs == CREATE_NEW_VAR)
117827 + lhs = create_new_var(dst_type);
117828 +
117829 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117830 +
117831 + if (!gsi_end_p(*gsi)) {
117832 + location_t loc = gimple_location(gsi_stmt(*gsi));
117833 + gimple_set_location(assign, loc);
117834 + }
117835 +
117836 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117837 +
117838 + if (before)
117839 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117840 + else
117841 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117842 + update_stmt(assign);
117843 + return assign;
117844 +}
117845 +
117846 +bool is_size_overflow_type(const_tree var)
117847 +{
117848 + const char *name;
117849 + const_tree type_name, type;
117850 +
117851 + if (var == NULL_TREE)
117852 + return false;
117853 +
117854 + type = TREE_TYPE(var);
117855 + type_name = TYPE_NAME(type);
117856 + if (type_name == NULL_TREE)
117857 + return false;
117858 +
117859 + if (DECL_P(type_name))
117860 + name = DECL_NAME_POINTER(type_name);
117861 + else
117862 + name = IDENTIFIER_POINTER(type_name);
117863 +
117864 + if (!strncmp(name, "size_overflow_type", 18))
117865 + return true;
117866 + return false;
117867 +}
117868 +
117869 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117870 new file mode 100644
117871 index 0000000..7c9e6d1
117872 --- /dev/null
117873 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117874 @@ -0,0 +1,138 @@
117875 +/*
117876 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117877 + * Licensed under the GPL v2, or (at your option) v3
117878 + *
117879 + * Homepage:
117880 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117881 + *
117882 + * Documentation:
117883 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117884 + *
117885 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117886 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117887 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117888 + *
117889 + * Usage:
117890 + * $ make
117891 + * $ make run
117892 + */
117893 +
117894 +#include "gcc-common.h"
117895 +#include "size_overflow.h"
117896 +
117897 +bool skip_expr_on_double_type(const_gimple stmt)
117898 +{
117899 + enum tree_code code = gimple_assign_rhs_code(stmt);
117900 +
117901 + switch (code) {
117902 + case RSHIFT_EXPR:
117903 + case TRUNC_DIV_EXPR:
117904 + case CEIL_DIV_EXPR:
117905 + case FLOOR_DIV_EXPR:
117906 + case ROUND_DIV_EXPR:
117907 + case EXACT_DIV_EXPR:
117908 + case RDIV_EXPR:
117909 + case TRUNC_MOD_EXPR:
117910 + case CEIL_MOD_EXPR:
117911 + case FLOOR_MOD_EXPR:
117912 + case ROUND_MOD_EXPR:
117913 + return true;
117914 + default:
117915 + return false;
117916 + }
117917 +}
117918 +
117919 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
117920 +{
117921 + const_tree orig_rhs1;
117922 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
117923 + gimple down_cast, up_cast;
117924 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
117925 +
117926 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117927 + down_lhs = gimple_assign_lhs(down_cast);
117928 +
117929 + gsi = gsi_for_stmt(use_stmt);
117930 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117931 + new_lhs = gimple_assign_lhs(up_cast);
117932 +
117933 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
117934 + if (operand_equal_p(orig_rhs1, rhs, 0))
117935 + gimple_assign_set_rhs1(use_stmt, new_lhs);
117936 + else
117937 + gimple_assign_set_rhs2(use_stmt, new_lhs);
117938 + update_stmt(use_stmt);
117939 +
117940 + pointer_set_insert(visited->my_stmts, up_cast);
117941 + pointer_set_insert(visited->my_stmts, down_cast);
117942 + pointer_set_insert(visited->skip_expr_casts, up_cast);
117943 + pointer_set_insert(visited->skip_expr_casts, down_cast);
117944 +}
117945 +
117946 +static tree get_proper_unsigned_half_type(const_tree node)
117947 +{
117948 + tree new_type, type;
117949 +
117950 + gcc_assert(is_size_overflow_type(node));
117951 +
117952 + type = TREE_TYPE(node);
117953 + switch (TYPE_MODE(type)) {
117954 + case HImode:
117955 + new_type = unsigned_intQI_type_node;
117956 + break;
117957 + case SImode:
117958 + new_type = unsigned_intHI_type_node;
117959 + break;
117960 + case DImode:
117961 + new_type = unsigned_intSI_type_node;
117962 + break;
117963 + case TImode:
117964 + new_type = unsigned_intDI_type_node;
117965 + break;
117966 + default:
117967 + gcc_unreachable();
117968 + }
117969 +
117970 + if (TYPE_QUALS(type) != 0)
117971 + return build_qualified_type(new_type, TYPE_QUALS(type));
117972 + return new_type;
117973 +}
117974 +
117975 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
117976 +{
117977 + tree type;
117978 +
117979 + if (rhs == NULL_TREE)
117980 + return;
117981 + if (!is_size_overflow_type(rhs))
117982 + return;
117983 +
117984 + type = get_proper_unsigned_half_type(rhs);
117985 + if (is_gimple_constant(rhs))
117986 + return;
117987 + create_up_and_down_cast(visited, stmt, type, rhs);
117988 +}
117989 +
117990 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
117991 +{
117992 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
117993 + return;
117994 + gcc_assert(is_size_overflow_type(rhs));
117995 + insert_cast_rhs(visited, stmt, rhs);
117996 +}
117997 +
117998 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
117999 +{
118000 + tree rhs1, rhs2;
118001 +
118002 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
118003 + rhs1 = gimple_assign_rhs1(stmt);
118004 + insert_cast(visited, stmt, rhs1);
118005 + }
118006 +
118007 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
118008 + rhs2 = gimple_assign_rhs2(stmt);
118009 + insert_cast(visited, stmt, rhs2);
118010 + }
118011 +}
118012 +
118013 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
118014 new file mode 100644
118015 index 0000000..e5b4e50
118016 --- /dev/null
118017 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
118018 @@ -0,0 +1,127 @@
118019 +#ifndef SIZE_OVERFLOW_H
118020 +#define SIZE_OVERFLOW_H
118021 +
118022 +#define CREATE_NEW_VAR NULL_TREE
118023 +#define CANNOT_FIND_ARG 32
118024 +#define MAX_PARAM 31
118025 +#define BEFORE_STMT true
118026 +#define AFTER_STMT false
118027 +
118028 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
118029 +#define YES_ASM_STR "# size_overflow MARK_YES "
118030 +#define OK_ASM_STR "# size_overflow "
118031 +
118032 +enum mark {
118033 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
118034 +};
118035 +
118036 +enum intentional_overflow_type {
118037 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
118038 +};
118039 +
118040 +struct visited {
118041 + struct pointer_set_t *stmts;
118042 + struct pointer_set_t *my_stmts;
118043 + struct pointer_set_t *skip_expr_casts;
118044 + struct pointer_set_t *no_cast_check;
118045 +};
118046 +
118047 +// size_overflow_plugin.c
118048 +extern tree report_size_overflow_decl;
118049 +extern tree size_overflow_type_HI;
118050 +extern tree size_overflow_type_SI;
118051 +extern tree size_overflow_type_DI;
118052 +extern tree size_overflow_type_TI;
118053 +
118054 +
118055 +// size_overflow_plugin_hash.c
118056 +struct size_overflow_hash {
118057 + const struct size_overflow_hash * const next;
118058 + const char * const name;
118059 + const unsigned int param;
118060 +};
118061 +
118062 +struct interesting_node {
118063 + struct interesting_node *next;
118064 + gimple first_stmt;
118065 + const_tree fndecl;
118066 + tree node;
118067 +#if BUILDING_GCC_VERSION <= 4007
118068 + VEC(tree, gc) *last_nodes;
118069 +#else
118070 + vec<tree, va_gc> *last_nodes;
118071 +#endif
118072 + unsigned int num;
118073 + enum mark intentional_attr_decl;
118074 + enum mark intentional_attr_cur_fndecl;
118075 + gimple intentional_mark_from_gimple;
118076 +};
118077 +
118078 +extern bool is_size_overflow_asm(const_gimple stmt);
118079 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
118080 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
118081 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
118082 +extern bool is_a_return_check(const_tree node);
118083 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
118084 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
118085 +
118086 +
118087 +// size_overflow_debug.c
118088 +extern struct opt_pass *make_dump_pass(void);
118089 +
118090 +
118091 +// intentional_overflow.c
118092 +extern enum mark get_intentional_attr_type(const_tree node);
118093 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
118094 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
118095 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
118096 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
118097 +extern bool is_turn_off_intentional_attr(const_tree decl);
118098 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
118099 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
118100 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
118101 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
118102 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
118103 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
118104 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
118105 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
118106 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
118107 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
118108 +
118109 +
118110 +// insert_size_overflow_check_ipa.c
118111 +extern unsigned int search_function(void);
118112 +extern unsigned int call_count;
118113 +extern struct opt_pass *make_insert_size_overflow_check(void);
118114 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
118115 +
118116 +
118117 +// insert_size_overflow_asm.c
118118 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
118119 +
118120 +
118121 +// misc.c
118122 +extern void set_current_function_decl(tree fndecl);
118123 +extern void unset_current_function_decl(void);
118124 +extern gimple get_def_stmt(const_tree node);
118125 +extern tree create_new_var(tree type);
118126 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
118127 +extern bool skip_types(const_tree var);
118128 +extern tree cast_a_tree(tree type, tree var);
118129 +extern bool is_size_overflow_type(const_tree var);
118130 +
118131 +
118132 +// insert_size_overflow_check_core.c
118133 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
118134 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
118135 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
118136 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
118137 +
118138 +
118139 +// remove_unnecessary_dup.c
118140 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
118141 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
118142 +extern bool skip_expr_on_double_type(const_gimple stmt);
118143 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
118144 +
118145 +#endif
118146 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118147 new file mode 100644
118148 index 0000000..4378111
118149 --- /dev/null
118150 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118151 @@ -0,0 +1,116 @@
118152 +/*
118153 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118154 + * Licensed under the GPL v2, or (at your option) v3
118155 + *
118156 + * Homepage:
118157 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118158 + *
118159 + * Documentation:
118160 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118161 + *
118162 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118163 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118164 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118165 + *
118166 + * Usage:
118167 + * $ make
118168 + * $ make run
118169 + */
118170 +
118171 +#include "gcc-common.h"
118172 +
118173 +static unsigned int dump_functions(void)
118174 +{
118175 + struct cgraph_node *node;
118176 +
118177 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118178 + basic_block bb;
118179 +
118180 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118181 + current_function_decl = NODE_DECL(node);
118182 +
118183 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118184 +
118185 + FOR_ALL_BB_FN(bb, cfun) {
118186 + gimple_stmt_iterator si;
118187 +
118188 + fprintf(stderr, "<bb %u>:\n", bb->index);
118189 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118190 + debug_gimple_stmt(gsi_stmt(si));
118191 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118192 + debug_gimple_stmt(gsi_stmt(si));
118193 + fprintf(stderr, "\n");
118194 + }
118195 +
118196 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118197 +
118198 + pop_cfun();
118199 + current_function_decl = NULL_TREE;
118200 + }
118201 +
118202 + fprintf(stderr, "###############################################################################\n");
118203 +
118204 + return 0;
118205 +}
118206 +
118207 +#if BUILDING_GCC_VERSION >= 4009
118208 +static const struct pass_data dump_pass_data = {
118209 +#else
118210 +static struct ipa_opt_pass_d dump_pass = {
118211 + .pass = {
118212 +#endif
118213 + .type = SIMPLE_IPA_PASS,
118214 + .name = "dump",
118215 +#if BUILDING_GCC_VERSION >= 4008
118216 + .optinfo_flags = OPTGROUP_NONE,
118217 +#endif
118218 +#if BUILDING_GCC_VERSION >= 4009
118219 + .has_gate = false,
118220 + .has_execute = true,
118221 +#else
118222 + .gate = NULL,
118223 + .execute = dump_functions,
118224 + .sub = NULL,
118225 + .next = NULL,
118226 + .static_pass_number = 0,
118227 +#endif
118228 + .tv_id = TV_NONE,
118229 + .properties_required = 0,
118230 + .properties_provided = 0,
118231 + .properties_destroyed = 0,
118232 + .todo_flags_start = 0,
118233 + .todo_flags_finish = 0,
118234 +#if BUILDING_GCC_VERSION < 4009
118235 + },
118236 + .generate_summary = NULL,
118237 + .write_summary = NULL,
118238 + .read_summary = NULL,
118239 +#if BUILDING_GCC_VERSION >= 4006
118240 + .write_optimization_summary = NULL,
118241 + .read_optimization_summary = NULL,
118242 +#endif
118243 + .stmt_fixup = NULL,
118244 + .function_transform_todo_flags_start = 0,
118245 + .function_transform = NULL,
118246 + .variable_transform = NULL,
118247 +#endif
118248 +};
118249 +
118250 +#if BUILDING_GCC_VERSION >= 4009
118251 +namespace {
118252 +class dump_pass : public ipa_opt_pass_d {
118253 +public:
118254 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118255 + unsigned int execute() { return dump_functions(); }
118256 +};
118257 +}
118258 +#endif
118259 +
118260 +struct opt_pass *make_dump_pass(void)
118261 +{
118262 +#if BUILDING_GCC_VERSION >= 4009
118263 + return new dump_pass();
118264 +#else
118265 + return &dump_pass.pass;
118266 +#endif
118267 +}
118268 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118269 new file mode 100644
118270 index 0000000..f2bd55d
118271 --- /dev/null
118272 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118273 @@ -0,0 +1,6031 @@
118274 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118275 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118276 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118277 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118278 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118279 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118280 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118281 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118282 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118283 +load_msg_95 load_msg 2 95 NULL
118284 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118285 +init_q_132 init_q 4 132 NULL
118286 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118287 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118288 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118289 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118290 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118291 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118292 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118293 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118294 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118295 +vpdma_create_desc_list_255 vpdma_create_desc_list 2 255 NULL
118296 +br_port_info_size_268 br_port_info_size 0 268 NULL
118297 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118298 +SYSC_connect_304 SYSC_connect 3 304 NULL
118299 +syslog_print_307 syslog_print 2 307 NULL
118300 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118301 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118302 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118303 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118304 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118305 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118306 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118307 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118308 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118309 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
118310 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118311 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118312 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118313 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118314 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118315 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118316 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118317 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118318 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118319 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118320 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118321 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118322 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118323 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118324 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118325 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118326 +unlink_queued_645 unlink_queued 4 645 NULL
118327 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118328 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118329 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118330 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118331 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118332 +dvb_video_write_754 dvb_video_write 3 754 NULL
118333 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118334 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118335 +if_writecmd_815 if_writecmd 2 815 NULL
118336 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118337 +error_state_read_859 error_state_read 6 859 NULL
118338 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118339 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118340 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118341 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118342 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118343 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118344 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118345 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118346 +readreg_1017 readreg 0-1 1017 NULL
118347 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118348 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118349 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118350 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118351 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118352 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118353 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118354 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118355 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118356 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118357 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118358 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118359 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118360 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118361 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118362 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118363 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118364 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118365 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118366 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118367 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118368 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118369 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118370 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118371 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118372 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118373 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118374 +ffs_1322 ffs 0 1322 NULL
118375 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118376 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118377 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118378 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118379 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118380 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118381 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118382 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118383 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118384 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118385 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118386 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118387 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118388 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118389 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118390 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118391 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118392 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118393 +fpregs_set_1497 fpregs_set 4 1497 NULL
118394 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118395 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118396 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118397 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118398 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118399 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118400 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118401 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118402 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118403 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118404 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118405 +rmap_add_1677 rmap_add 3 1677 NULL
118406 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118407 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118408 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118409 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118410 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118411 +internal_create_group_1733 internal_create_group 0 1733 NULL
118412 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118413 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118414 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118415 +cosa_write_1774 cosa_write 3 1774 NULL
118416 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118417 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118418 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118419 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118420 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118421 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118422 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118423 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118424 +azx_get_position_1927 azx_get_position 0 1927 NULL
118425 +bdev_erase_1933 bdev_erase 3 1933 NULL
118426 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118427 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118428 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118429 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118430 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118431 +qla2xxx_get_vpd_field_1965 qla2xxx_get_vpd_field 4 1965 NULL
118432 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118433 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118434 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118435 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118436 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118437 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118438 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118439 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118440 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118441 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118442 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118443 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118444 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118445 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118446 +audit_expand_2098 audit_expand 0 2098 NULL
118447 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118448 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118449 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118450 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118451 +enable_read_2117 enable_read 3 2117 NULL
118452 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118453 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118454 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118455 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118456 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118457 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118458 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118459 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118460 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118461 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118462 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118463 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118464 +do_update_counters_2259 do_update_counters 4 2259 NULL
118465 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118466 +vpdma_alloc_desc_buf_2278 vpdma_alloc_desc_buf 2 2278 NULL
118467 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118468 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118469 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118470 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118471 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118472 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118473 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118474 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118475 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118476 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118477 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118478 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118479 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118480 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118481 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118482 +raid1_size_2419 raid1_size 0-2 2419 NULL
118483 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118484 +wiphy_new_2482 wiphy_new 2 2482 NULL
118485 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118486 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118487 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118488 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118489 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118490 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118491 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118492 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118493 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118494 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118495 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118496 +slot_bytes_2609 slot_bytes 0 2609 NULL
118497 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118498 +switch_status_2629 switch_status 5 2629 NULL
118499 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118500 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118501 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118502 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118503 +oti6858_write_2692 oti6858_write 4 2692 NULL
118504 +copy_to_iter_iovec_2697 copy_to_iter_iovec 2 2697 NULL
118505 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118506 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118507 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118508 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118509 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118510 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118511 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118512 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118513 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118514 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118515 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118516 +sock_create_2838 sock_create 0 2838 NULL
118517 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118518 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118519 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118520 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118521 +nla_padlen_2883 nla_padlen 1 2883 NULL
118522 +cmm_write_2896 cmm_write 3 2896 NULL
118523 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118524 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118525 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118526 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118527 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118528 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118529 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118530 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118531 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118532 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118533 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118534 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118535 +depth_write_3021 depth_write 3 3021 NULL
118536 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118537 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118538 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118539 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118540 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118541 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118542 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118543 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118544 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118545 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118546 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118547 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118548 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118549 +bio_integrity_intervals_3094 bio_integrity_intervals 0-2 3094 NULL
118550 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118551 +rb_alloc_3102 rb_alloc 1 3102 NULL
118552 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118553 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118554 +print_time_3132 print_time 0 3132 NULL
118555 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118556 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118557 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118558 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118559 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118560 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118561 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118562 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118563 +alloc_context_3194 alloc_context 1 3194 NULL
118564 +dma_init_coherent_memory_3197 dma_init_coherent_memory 3 3197 NULL
118565 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118566 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118567 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118568 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118569 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118570 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118571 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118572 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118573 +key_key_read_3241 key_key_read 3 3241 NULL
118574 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118575 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118576 +cgroup_name_3300 cgroup_name 3 3300 NULL
118577 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118578 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118579 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118580 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118581 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118582 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118583 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118584 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118585 +scnprintf_3360 scnprintf 0-2 3360 NULL
118586 +sr_read_3366 sr_read 3 3366 NULL
118587 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118588 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118589 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118590 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118591 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118592 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118593 +softsynth_write_3455 softsynth_write 3 3455 NULL
118594 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118595 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118596 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118597 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118598 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118599 +SyS_readv_3539 SyS_readv 3 3539 NULL
118600 +nouveau_fuse_create__3546 nouveau_fuse_create_ 4 3546 NULL
118601 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118602 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118603 +evtchn_read_3569 evtchn_read 3 3569 NULL
118604 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118605 +vc_resize_3585 vc_resize 3-2 3585 NULL
118606 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118607 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118608 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118609 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118610 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118611 +fm10k_alloc_q_vector_3638 fm10k_alloc_q_vector 4-6 3638 NULL
118612 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118613 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118614 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118615 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118616 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118617 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118618 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118619 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118620 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118621 +ceph_do_getattr_3838 ceph_do_getattr 0 3838 NULL
118622 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118623 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118624 +get_fd_set_3866 get_fd_set 1 3866 NULL
118625 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118626 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118627 +nvram_write_3894 nvram_write 3 3894 NULL
118628 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118629 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118630 +vcs_write_3910 vcs_write 3 3910 NULL
118631 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118632 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118633 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118634 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118635 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118636 +do_add_counters_3992 do_add_counters 3 3992 NULL
118637 +userspace_status_4004 userspace_status 4 4004 NULL
118638 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118639 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118640 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118641 +blk_end_request_4024 blk_end_request 3 4024 NULL
118642 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118643 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118644 +read_file_queues_4078 read_file_queues 3 4078 NULL
118645 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118646 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118647 +tm6000_read_4151 tm6000_read 3 4151 NULL
118648 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118649 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118650 +get_alua_req_4166 get_alua_req 3 4166 NULL
118651 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118652 +read_file_bool_4180 read_file_bool 3 4180 NULL
118653 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118654 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118655 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118656 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118657 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118658 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118659 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118660 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118661 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118662 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118663 +count_strings_4315 count_strings 0 4315 NULL nohasharray
118664 +cfg80211_inform_bss_4315 cfg80211_inform_bss 9 4315 &count_strings_4315
118665 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118666 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118667 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118668 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118669 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118670 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118671 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118672 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118673 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118674 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118675 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118676 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118677 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118678 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118679 +set_link_security_4502 set_link_security 4 4502 NULL
118680 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118681 +tty_register_device_4544 tty_register_device 2 4544 NULL
118682 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118683 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118684 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118685 +bch_alloc_4593 bch_alloc 1 4593 NULL
118686 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118687 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118688 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118689 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118690 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118691 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118692 +kone_receive_4690 kone_receive 4 4690 NULL
118693 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118694 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118695 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118696 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118697 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118698 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118699 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118700 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118701 +create_subvol_4791 create_subvol 4 4791 NULL
118702 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118703 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118704 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118705 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118706 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118707 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118708 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118709 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118710 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118711 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118712 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118713 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118714 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118715 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118716 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118717 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118718 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118719 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118720 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118721 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118722 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118723 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118724 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118725 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118726 +sound_write_5102 sound_write 3 5102 NULL
118727 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118728 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118729 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118730 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118731 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118732 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118733 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118734 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118735 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118736 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118737 +ipv4_tun_to_nlattr_5261 ipv4_tun_to_nlattr 4 5261 NULL
118738 +dvb_ringbuffer_write_user_5270 dvb_ringbuffer_write_user 3 5270 NULL
118739 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118740 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118741 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118742 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118743 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118744 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118745 +cq_free_res_5355 cq_free_res 5 5355 NULL
118746 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118747 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118748 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118749 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118750 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118751 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118752 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3 5482 NULL
118753 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118754 +tty_write_5494 tty_write 3 5494 NULL
118755 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118756 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118757 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118758 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118759 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118760 +le_readq_5557 le_readq 0 5557 NULL
118761 +inw_5558 inw 0 5558 NULL
118762 +bioset_create_5580 bioset_create 1 5580 NULL
118763 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118764 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118765 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118766 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118767 +get_arg_5694 get_arg 3 5694 NULL
118768 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118769 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118770 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118771 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118772 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118773 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL nohasharray
118774 +ath10k_core_create_5806 ath10k_core_create 1 5806 &skb_copy_datagram_iovec_5806
118775 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118776 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118777 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118778 +setup_req_5848 setup_req 3 5848 NULL
118779 +ria_page_count_5849 ria_page_count 0 5849 NULL
118780 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118781 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118782 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118783 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118784 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118785 +port_show_regs_5904 port_show_regs 3 5904 NULL
118786 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118787 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118788 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118789 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118790 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118791 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118792 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118793 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118794 +SyS_semop_5980 SyS_semop 3 5980 NULL
118795 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118796 +alloc_msg_6072 alloc_msg 1 6072 NULL
118797 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118798 +_random_read_6098 _random_read 3 6098 NULL
118799 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118800 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118801 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118802 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118803 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118804 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118805 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118806 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118807 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118808 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118809 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118810 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118811 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118812 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118813 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118814 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118815 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118816 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118817 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118818 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118819 +serial_port_in_6291 serial_port_in 0 6291 NULL
118820 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118821 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118822 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118823 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118824 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118825 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118826 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118827 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118828 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118829 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118830 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118831 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118832 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118833 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118834 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118835 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118836 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118837 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118838 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118839 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118840 +mei_read_6507 mei_read 3 6507 NULL
118841 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118842 +wdm_read_6549 wdm_read 3 6549 NULL
118843 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118844 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118845 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118846 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118847 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118848 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118849 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118850 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118851 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118852 +mpeg_read_6708 mpeg_read 3 6708 NULL
118853 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118854 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118855 +video_proc_write_6724 video_proc_write 3 6724 NULL
118856 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118857 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
118858 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118859 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118860 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118861 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118862 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118863 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118864 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118865 +rounded_hashtable_size_6802 rounded_hashtable_size 0 6802 NULL
118866 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118867 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118868 +blk_alloc_flush_queue_6839 blk_alloc_flush_queue 3 6839 NULL
118869 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118870 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118871 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118872 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118873 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118874 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118875 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118876 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118877 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118878 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118879 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118880 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
118881 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118882 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118883 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118884 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118885 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118886 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118887 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118888 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118889 +request_key_async_6990 request_key_async 4 6990 NULL
118890 +tpl_write_6998 tpl_write 3 6998 NULL
118891 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118892 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118893 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
118894 +wimax_msg_7030 wimax_msg 4 7030 NULL
118895 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
118896 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
118897 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
118898 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
118899 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
118900 +event_enable_read_7074 event_enable_read 3 7074 NULL
118901 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
118902 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
118903 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
118904 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
118905 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
118906 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
118907 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
118908 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
118909 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
118910 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
118911 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
118912 +get_string_7302 get_string 0 7302 NULL
118913 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
118914 +mgmt_control_7349 mgmt_control 3 7349 NULL
118915 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
118916 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
118917 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
118918 +hweight_long_7388 hweight_long 0-1 7388 NULL
118919 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
118920 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
118921 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
118922 +readb_7401 readb 0 7401 NULL
118923 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
118924 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
118925 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
118926 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
118927 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
118928 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
118929 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
118930 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
118931 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
118932 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
118933 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
118934 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
118935 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
118936 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
118937 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
118938 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
118939 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
118940 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
118941 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
118942 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
118943 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
118944 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
118945 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
118946 +dev_write_7708 dev_write 3 7708 NULL
118947 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
118948 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
118949 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
118950 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
118951 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
118952 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
118953 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
118954 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
118955 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
118956 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
118957 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
118958 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
118959 +config_desc_7878 config_desc 0 7878 NULL
118960 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
118961 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
118962 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
118963 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
118964 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
118965 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
118966 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
118967 +vcs_read_8017 vcs_read 3 8017 NULL
118968 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
118969 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
118970 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
118971 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
118972 +venus_lookup_8121 venus_lookup 4 8121 NULL
118973 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
118974 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
118975 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
118976 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
118977 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
118978 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
118979 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
118980 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
118981 +play_iframe_8219 play_iframe 3 8219 NULL
118982 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
118983 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
118984 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
118985 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
118986 +init_cdev_8274 init_cdev 1 8274 NULL
118987 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
118988 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
118989 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
118990 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
118991 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
118992 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
118993 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
118994 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
118995 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
118996 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
118997 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
118998 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
118999 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
119000 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
119001 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
119002 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
119003 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
119004 +dev_config_8506 dev_config 3 8506 NULL
119005 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
119006 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
119007 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
119008 +user_on_off_8552 user_on_off 2 8552 NULL
119009 +profile_remove_8556 profile_remove 3 8556 NULL
119010 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
119011 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
119012 +tower_write_8580 tower_write 3 8580 NULL
119013 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
119014 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
119015 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
119016 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
119017 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
119018 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
119019 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
119020 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
119021 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
119022 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
119023 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
119024 +arcfb_write_8702 arcfb_write 3 8702 NULL
119025 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
119026 +init_header_8703 init_header 0 8703 &i_size_read_8703
119027 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
119028 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
119029 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
119030 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
119031 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
119032 +iov_iter_zero_8748 iov_iter_zero 1 8748 NULL
119033 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
119034 +compound_order_8750 compound_order 0 8750 NULL
119035 +cfg80211_inform_bss_width_8754 cfg80211_inform_bss_width 10 8754 NULL
119036 +yurex_write_8761 yurex_write 3 8761 NULL
119037 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
119038 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
119039 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
119040 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
119041 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
119042 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
119043 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
119044 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
119045 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
119046 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
119047 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
119048 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
119049 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
119050 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
119051 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
119052 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
119053 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
119054 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
119055 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
119056 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
119057 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
119058 +write_file_ani_8918 write_file_ani 3 8918 NULL
119059 +layout_commit_8926 layout_commit 3 8926 NULL
119060 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
119061 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
119062 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
119063 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
119064 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
119065 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
119066 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
119067 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
119068 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
119069 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
119070 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
119071 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
119072 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
119073 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
119074 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
119075 +nla_put_9042 nla_put 3 9042 NULL
119076 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
119077 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
119078 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
119079 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
119080 +create_queues_9088 create_queues 2-3 9088 NULL
119081 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
119082 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
119083 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
119084 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
119085 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
119086 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
119087 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
119088 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
119089 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
119090 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
119091 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
119092 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
119093 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
119094 +card_send_command_9215 card_send_command 3 9215 NULL
119095 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
119096 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
119097 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
119098 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
119099 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
119100 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
119101 +flakey_status_9274 flakey_status 5 9274 NULL
119102 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
119103 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
119104 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
119105 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
119106 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
119107 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
119108 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
119109 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
119110 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
119111 +read_9397 read 3 9397 NULL
119112 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
119113 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
119114 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
119115 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
119116 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
119117 +get_registers_9470 get_registers 4 9470 NULL nohasharray
119118 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
119119 +crypt_status_9492 crypt_status 5 9492 NULL
119120 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
119121 +lp_write_9511 lp_write 3 9511 NULL
119122 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
119123 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
119124 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
119125 +read_file_dma_9530 read_file_dma 3 9530 NULL
119126 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
119127 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
119128 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
119129 +fw_node_create_9559 fw_node_create 2 9559 NULL
119130 +kobj_map_9566 kobj_map 2-3 9566 NULL
119131 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
119132 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
119133 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
119134 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
119135 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
119136 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
119137 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
119138 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
119139 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
119140 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
119141 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
119142 +dns_query_9676 dns_query 3 9676 NULL
119143 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
119144 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
119145 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
119146 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
119147 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
119148 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
119149 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
119150 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
119151 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
119152 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
119153 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
119154 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
119155 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
119156 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
119157 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
119158 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
119159 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
119160 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
119161 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
119162 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
119163 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
119164 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
119165 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
119166 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
119167 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
119168 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
119169 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
119170 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
119171 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
119172 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
119173 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
119174 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
119175 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
119176 +read_file_misc_9948 read_file_misc 3 9948 NULL
119177 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
119178 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
119179 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
119180 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
119181 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
119182 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
119183 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
119184 +asymmetric_key_generate_id_10064 asymmetric_key_generate_id 2-4 10064 NULL
119185 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
119186 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
119187 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
119188 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
119189 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
119190 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
119191 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
119192 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
119193 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
119194 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
119195 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
119196 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
119197 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
119198 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
119199 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
119200 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
119201 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
119202 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
119203 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
119204 +read_emulate_10310 read_emulate 2-4 10310 NULL
119205 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
119206 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
119207 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
119208 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
119209 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
119210 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
119211 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
119212 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
119213 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
119214 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
119215 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
119216 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
119217 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
119218 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
119219 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
119220 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
119221 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
119222 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
119223 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119224 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119225 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119226 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119227 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119228 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119229 +otp_read_10594 otp_read 2-4-5 10594 NULL
119230 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119231 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119232 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119233 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119234 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119235 +parport_write_10669 parport_write 0 10669 NULL
119236 +edge_write_10692 edge_write 4 10692 NULL
119237 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119238 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119239 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119240 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119241 +spi_sync_10731 spi_sync 0 10731 NULL
119242 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119243 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119244 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119245 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119246 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119247 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119248 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119249 +ttm_dma_page_pool_free_10796 ttm_dma_page_pool_free 2-0 10796 NULL
119250 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119251 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119252 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119253 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119254 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119255 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119256 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119257 +get_scq_10897 get_scq 2 10897 NULL
119258 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119259 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119260 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119261 +kobject_add_10919 kobject_add 0 10919 NULL
119262 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119263 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119264 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119265 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119266 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119267 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119268 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119269 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119270 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119271 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL nohasharray
119272 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 &insert_inline_extent_backref_11063
119273 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
119274 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119275 +count_argc_11083 count_argc 0 11083 NULL
119276 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119277 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119278 +tc90522_master_xfer_11119 tc90522_master_xfer 3 11119 NULL
119279 +page_offset_11120 page_offset 0 11120 NULL
119280 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119281 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119282 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119283 +copy_from_iter_iovec_11196 copy_from_iter_iovec 2 11196 NULL
119284 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119285 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119286 +of_irq_count_11253 of_irq_count 0 11253 NULL
119287 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119288 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119289 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119290 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119291 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119292 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119293 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119294 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119295 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119296 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119297 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119298 +next_segment_11330 next_segment 0-2-1 11330 NULL
119299 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119300 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119301 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119302 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119303 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119304 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119305 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119306 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119307 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119308 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119309 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119310 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119311 +str_to_user_11411 str_to_user 2 11411 NULL
119312 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119313 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119314 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119315 +trace_options_read_11419 trace_options_read 3 11419 NULL
119316 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119317 +bttv_read_11432 bttv_read 3 11432 NULL
119318 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119319 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119320 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119321 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119322 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119323 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119324 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119325 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119326 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119327 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119328 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119329 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119330 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119331 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119332 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119333 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119334 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119335 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119336 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119337 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119338 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119339 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119340 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119341 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119342 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119343 +split_11691 split 2 11691 NULL
119344 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119345 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119346 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119347 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119348 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119349 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119350 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119351 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119352 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119353 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119354 +umc_device_register_11824 umc_device_register 0 11824 NULL
119355 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119356 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119357 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119358 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119359 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
119360 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119361 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119362 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119363 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119364 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119365 +ti_write_11916 ti_write 4 11916 NULL
119366 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119367 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119368 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119369 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119370 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119371 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119372 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119373 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119374 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119375 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119376 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119377 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119378 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119379 +set_powered_12129 set_powered 4 12129 NULL
119380 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119381 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119382 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119383 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119384 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119385 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119386 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119387 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119388 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119389 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119390 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119391 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119392 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119393 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119394 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119395 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119396 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119397 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119398 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119399 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119400 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119401 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119402 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119403 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119404 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119405 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119406 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119407 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119408 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119409 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119410 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119411 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119412 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119413 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119414 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119415 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119416 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119417 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119418 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119419 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119420 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119421 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119422 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119423 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119424 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119425 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119426 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119427 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119428 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119429 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119430 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119431 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119432 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119433 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119434 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119435 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119436 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119437 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119438 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119439 +ivtv_write_12721 ivtv_write 3 12721 NULL
119440 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119441 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119442 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119443 +listxattr_12769 listxattr 3 12769 NULL
119444 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119445 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119446 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119447 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119448 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119449 +spidev_sync_12842 spidev_sync 0 12842 NULL
119450 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119451 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119452 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119453 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119454 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119455 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119456 +bm_status_write_12964 bm_status_write 3 12964 NULL
119457 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119458 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119459 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119460 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119461 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119462 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119463 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119464 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119465 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119466 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119467 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119468 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119469 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119470 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119471 +blk_update_request_13146 blk_update_request 3 13146 NULL
119472 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119473 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119474 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119475 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119476 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119477 +comedi_read_13199 comedi_read 3 13199 NULL
119478 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119479 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119480 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119481 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119482 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119483 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119484 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119485 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119486 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119487 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119488 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119489 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119490 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119491 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119492 +sd_major_13294 sd_major 0-1 13294 NULL
119493 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119494 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119495 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119496 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119497 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119498 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119499 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119500 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119501 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119502 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119503 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119504 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119505 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119506 +data_read_13494 data_read 3 13494 NULL nohasharray
119507 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119508 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119509 +core_status_13515 core_status 4 13515 NULL
119510 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119511 +bm_init_13529 bm_init 2 13529 NULL
119512 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119513 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119514 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119515 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119516 +cache_write_13589 cache_write 3 13589 NULL
119517 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119518 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119519 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119520 +packet_snd_13634 packet_snd 3 13634 NULL
119521 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119522 +cache_downcall_13666 cache_downcall 3 13666 NULL
119523 +usb_get_string_13693 usb_get_string 0 13693 NULL
119524 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119525 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119526 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119527 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119528 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119529 +alloc_indirect_13783 alloc_indirect 1 13783 NULL
119530 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119531 +random_read_13815 random_read 3 13815 NULL
119532 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119533 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119534 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119535 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119536 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119537 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119538 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119539 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119540 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119541 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119542 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119543 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119544 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119545 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119546 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119547 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119548 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119549 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119550 +qcam_read_13977 qcam_read 3 13977 NULL
119551 +dsp_read_13980 dsp_read 2 13980 NULL
119552 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119553 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119554 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119555 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119556 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119557 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119558 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119559 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119560 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119561 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119562 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119563 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119564 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119565 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119566 +em_canid_change_14150 em_canid_change 3 14150 NULL
119567 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119568 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119569 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119570 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119571 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119572 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119573 +alloc_async_14208 alloc_async 1 14208 NULL
119574 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119575 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119576 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119577 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119578 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119579 +rr_status_14293 rr_status 5 14293 NULL
119580 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119581 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119582 +oo_objects_14319 oo_objects 0 14319 NULL
119583 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119584 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119585 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119586 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119587 +lowpan_read_14369 lowpan_read 3 14369 NULL
119588 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119589 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119590 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119591 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119592 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119593 +block_size_14443 block_size 0 14443 NULL
119594 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119595 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119596 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119597 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119598 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119599 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119600 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119601 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119602 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119603 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119604 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119605 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119606 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119607 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119608 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119609 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119610 +dbJoin_14644 dbJoin 0 14644 NULL
119611 +profile_replace_14652 profile_replace 3 14652 NULL
119612 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119613 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119614 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119615 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119616 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119617 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119618 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119619 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119620 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119621 +vfd_write_14717 vfd_write 3 14717 NULL
119622 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119623 +raid1_resize_14740 raid1_resize 2 14740 NULL
119624 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119625 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119626 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119627 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119628 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119629 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119630 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119631 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119632 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119633 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119634 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119635 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119636 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119637 +lcd_write_14857 lcd_write 3 14857 NULL
119638 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119639 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119640 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119641 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119642 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119643 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119644 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119645 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119646 +queue_cnt_14951 queue_cnt 0 14951 NULL
119647 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119648 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119649 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119650 +setkey_14987 setkey 3 14987 NULL nohasharray
119651 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119652 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119653 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119654 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119655 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119656 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119657 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119658 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119659 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119660 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119661 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119662 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119663 +start_port_15124 start_port 0 15124 NULL
119664 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119665 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119666 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119667 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119668 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119669 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119670 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119671 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119672 +simple_strtol_15273 simple_strtol 0 15273 NULL
119673 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119674 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119675 +ioread16_15342 ioread16 0 15342 NULL
119676 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119677 +blkdev_readpages_15357 blkdev_readpages 4 15357 NULL
119678 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119679 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119680 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119681 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119682 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119683 +get_modalias_15406 get_modalias 2 15406 NULL
119684 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119685 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119686 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119687 +memweight_15450 memweight 2 15450 NULL
119688 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119689 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119690 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119691 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119692 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119693 +persistent_status_15574 persistent_status 4 15574 NULL
119694 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119695 +vme_user_write_15587 vme_user_write 3 15587 NULL
119696 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119697 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119698 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119699 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119700 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119701 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119702 +fs_path_add_15648 fs_path_add 3 15648 NULL
119703 +xsd_read_15653 xsd_read 3 15653 NULL
119704 +unix_bind_15668 unix_bind 3 15668 NULL
119705 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119706 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119707 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119708 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119709 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119710 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119711 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119712 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119713 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119714 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119715 +table_size_15851 table_size 0-1-2 15851 NULL
119716 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119717 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119718 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119719 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119720 +power_read_15939 power_read 3 15939 NULL
119721 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119722 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119723 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119724 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119725 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119726 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119727 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119728 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119729 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119730 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119731 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119732 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119733 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119734 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119735 +fsm_init_16134 fsm_init 2 16134 NULL
119736 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119737 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119738 +mapping_level_16188 mapping_level 2-0 16188 NULL
119739 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119740 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119741 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119742 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119743 +create_table_16213 create_table 2 16213 NULL
119744 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119745 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119746 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119747 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119748 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119749 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119750 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119751 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119752 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119753 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119754 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119755 +account_16283 account 0-4-2 16283 NULL nohasharray
119756 +mirror_status_16283 mirror_status 5 16283 &account_16283
119757 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119758 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119759 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119760 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119761 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119762 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119763 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119764 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119765 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119766 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119767 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119768 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119769 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119770 +cmdline_store_16442 cmdline_store 4 16442 NULL
119771 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119772 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119773 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119774 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119775 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119776 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119777 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119778 +raid10_resize_16537 raid10_resize 2 16537 NULL
119779 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119780 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119781 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119782 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119783 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119784 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119785 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119786 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119787 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119788 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119789 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119790 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119791 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119792 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119793 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119794 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119795 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119796 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119797 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119798 +st_write_16874 st_write 3 16874 NULL
119799 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119800 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119801 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119802 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119803 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119804 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119805 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119806 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119807 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119808 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119809 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119810 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119811 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119812 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119813 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119814 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119815 +entry_length_17093 entry_length 0 17093 NULL
119816 +write_mem_17114 write_mem 3 17114 NULL
119817 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119818 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119819 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119820 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119821 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119822 +sep_read_17161 sep_read 3 17161 NULL
119823 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119824 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119825 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119826 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119827 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119828 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119829 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119830 +sync_request_17208 sync_request 2 17208 NULL
119831 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119832 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119833 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119834 +alloc_ep_17269 alloc_ep 1 17269 NULL
119835 +pg_read_17276 pg_read 3 17276 NULL
119836 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119837 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119838 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119839 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119840 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119841 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119842 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119843 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119844 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119845 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119846 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119847 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119848 +copy_from_iter_17433 copy_from_iter 2 17433 NULL
119849 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119850 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119851 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119852 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119853 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119854 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119855 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119856 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119857 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119858 +qp_free_res_17541 qp_free_res 5 17541 NULL
119859 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119860 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119861 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119862 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119863 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119864 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119865 +osst_execute_17607 osst_execute 7-6 17607 NULL
119866 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119867 +dma_map_page_17628 dma_map_page 0 17628 NULL
119868 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119869 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119870 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119871 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119872 +venus_rename_17707 venus_rename 4-5 17707 NULL
119873 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119874 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119875 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119876 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119877 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119878 +_iwl_dbgfs_set_nic_temperature_write_17804 _iwl_dbgfs_set_nic_temperature_write 3 17804 NULL
119879 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119880 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119881 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119882 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119883 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119884 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119885 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119886 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119887 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119888 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119889 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119890 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119891 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119892 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119893 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119894 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119895 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119896 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119897 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119898 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119899 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119900 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119901 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119902 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119903 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119904 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
119905 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
119906 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
119907 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
119908 +fpregs_get_18066 fpregs_get 4 18066 NULL
119909 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
119910 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
119911 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
119912 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
119913 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
119914 +svc_getnl_18120 svc_getnl 0 18120 NULL
119915 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
119916 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
119917 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
119918 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
119919 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
119920 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
119921 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
119922 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
119923 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
119924 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
119925 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
119926 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
119927 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
119928 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
119929 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
119930 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
119931 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
119932 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
119933 +um_idi_write_18293 um_idi_write 3 18293 NULL
119934 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
119935 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
119936 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
119937 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
119938 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
119939 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
119940 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
119941 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
119942 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
119943 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
119944 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
119945 +ep_io_18367 ep_io 0 18367 NULL
119946 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
119947 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
119948 +ci_role_write_18388 ci_role_write 3 18388 NULL
119949 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
119950 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
119951 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
119952 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
119953 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
119954 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
119955 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
119956 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
119957 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
119958 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
119959 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
119960 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
119961 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
119962 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
119963 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
119964 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
119965 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
119966 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
119967 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
119968 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
119969 +debug_output_18575 debug_output 3 18575 NULL
119970 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
119971 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
119972 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
119973 +from_buffer_18625 from_buffer 3 18625 NULL
119974 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
119975 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
119976 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
119977 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
119978 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
119979 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
119980 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
119981 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
119982 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
119983 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
119984 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
119985 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
119986 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
119987 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
119988 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
119989 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
119990 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
119991 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
119992 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
119993 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
119994 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
119995 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
119996 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
119997 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
119998 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
119999 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
120000 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
120001 +xfs_buf_read_uncached_18922 xfs_buf_read_uncached 3 18922 NULL
120002 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
120003 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
120004 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
120005 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
120006 +huge_page_size_19008 huge_page_size 0 19008 NULL
120007 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
120008 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
120009 +revalidate_19043 revalidate 2 19043 NULL
120010 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
120011 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
120012 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
120013 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
120014 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
120015 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
120016 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
120017 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
120018 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
120019 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
120020 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
120021 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
120022 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
120023 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
120024 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
120025 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
120026 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
120027 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
120028 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
120029 +ucma_query_19260 ucma_query 4 19260 NULL
120030 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
120031 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
120032 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
120033 +qc_capture_19298 qc_capture 3 19298 NULL
120034 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
120035 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
120036 +debug_read_19322 debug_read 3 19322 NULL
120037 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
120038 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
120039 +closure_sub_19359 closure_sub 2 19359 NULL
120040 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
120041 +read_zero_19366 read_zero 3 19366 NULL
120042 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
120043 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
120044 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
120045 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
120046 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
120047 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
120048 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
120049 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
120050 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
120051 +sky2_read16_19475 sky2_read16 0 19475 NULL
120052 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
120053 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
120054 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
120055 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
120056 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
120057 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
120058 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
120059 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
120060 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
120061 +nfsd_read_19568 nfsd_read 5 19568 NULL
120062 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
120063 +bm_status_read_19583 bm_status_read 3 19583 NULL
120064 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
120065 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
120066 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
120067 +parser_init_19651 parser_init 2 19651 NULL
120068 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
120069 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
120070 +read_reg_19723 read_reg 0 19723 NULL
120071 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
120072 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
120073 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
120074 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
120075 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
120076 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
120077 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
120078 +readhscx_19769 readhscx 0 19769 NULL
120079 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
120080 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
120081 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
120082 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
120083 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
120084 +__nla_put_19857 __nla_put 3 19857 NULL
120085 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
120086 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
120087 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
120088 +mangle_name_19923 mangle_name 0 19923 NULL
120089 +tipc_sk_show_19928 tipc_sk_show 3-0 19928 NULL
120090 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
120091 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
120092 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
120093 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
120094 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
120095 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
120096 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
120097 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
120098 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
120099 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
120100 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
120101 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
120102 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
120103 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
120104 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
120105 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
120106 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
120107 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
120108 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
120109 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
120110 +target_message_20072 target_message 2 20072 NULL
120111 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
120112 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
120113 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
120114 +team_options_register_20091 team_options_register 3 20091 NULL
120115 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
120116 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
120117 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
120118 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
120119 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
120120 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
120121 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
120122 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
120123 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
120124 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
120125 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
120126 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
120127 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
120128 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
120129 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
120130 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
120131 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
120132 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
120133 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
120134 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
120135 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
120136 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
120137 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
120138 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
120139 +read_buf_20469 read_buf 2 20469 NULL
120140 +bio_trim_20472 bio_trim 2 20472 NULL
120141 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
120142 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
120143 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
120144 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
120145 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
120146 +venus_create_20555 venus_create 4 20555 NULL
120147 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
120148 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
120149 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
120150 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
120151 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
120152 +lirc_write_20604 lirc_write 3 20604 NULL
120153 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
120154 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
120155 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
120156 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
120157 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
120158 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
120159 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
120160 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
120161 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
120162 +cpumask_size_20683 cpumask_size 0 20683 NULL
120163 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
120164 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
120165 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
120166 +__maestro_read_20700 __maestro_read 0 20700 NULL
120167 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
120168 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
120169 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
120170 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
120171 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
120172 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
120173 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
120174 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
120175 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
120176 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
120177 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
120178 +edid_write_20797 edid_write 3 20797 NULL
120179 +lowpan_write_20800 lowpan_write 3 20800 NULL
120180 +strndup_user_20819 strndup_user 2 20819 NULL
120181 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
120182 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
120183 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
120184 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
120185 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
120186 +get_name_20855 get_name 4 20855 NULL
120187 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
120188 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
120189 +srq_free_res_20868 srq_free_res 5 20868 NULL
120190 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
120191 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
120192 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
120193 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
120194 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
120195 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
120196 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
120197 +htable_bits_20933 htable_bits 0 20933 NULL
120198 +cfg80211_rx_assoc_resp_20934 cfg80211_rx_assoc_resp 4 20934 NULL
120199 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
120200 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
120201 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
120202 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
120203 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
120204 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
120205 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
120206 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
120207 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
120208 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
120209 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
120210 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
120211 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
120212 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
120213 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
120214 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
120215 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
120216 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
120217 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
120218 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
120219 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
120220 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
120221 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
120222 +bioset_create_nobvec_21180 bioset_create_nobvec 1 21180 NULL
120223 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
120224 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
120225 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
120226 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
120227 +input_ff_create_21240 input_ff_create 2 21240 NULL
120228 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
120229 +fru_length_21257 fru_length 0 21257 NULL
120230 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
120231 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
120232 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
120233 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
120234 +add_res_range_21310 add_res_range 4 21310 NULL
120235 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
120236 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
120237 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
120238 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
120239 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
120240 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
120241 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
120242 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
120243 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
120244 +insert_ptr_21386 insert_ptr 6 21386 NULL
120245 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
120246 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
120247 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
120248 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120249 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120250 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120251 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120252 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120253 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120254 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120255 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120256 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120257 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120258 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120259 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120260 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120261 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120262 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120263 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120264 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
120265 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120266 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120267 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120268 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120269 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL nohasharray
120270 +proc_maps_open_21687 proc_maps_open 4 21687 &rtllib_alloc_txb_21687
120271 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120272 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120273 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120274 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120275 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120276 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120277 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120278 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120279 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120280 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120281 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120282 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120283 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
120284 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120285 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120286 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120287 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL nohasharray
120288 +nvme_submit_sync_cmd_21911 nvme_submit_sync_cmd 0 21911 &dbAllocCtl_21911
120289 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120290 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120291 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120292 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120293 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120294 +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
120295 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120296 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120297 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120298 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120299 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120300 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120301 +mem_rw_22085 mem_rw 3 22085 NULL
120302 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120303 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120304 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120305 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120306 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120307 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120308 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120309 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120310 +mem_write_22232 mem_write 3 22232 NULL
120311 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120312 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120313 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120314 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120315 +add_res_tree_22263 add_res_tree 7 22263 NULL
120316 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120317 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120318 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120319 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120320 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120321 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120322 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
120323 +atomic_read_22342 atomic_read 0 22342 NULL
120324 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120325 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120326 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120327 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120328 +zoran_write_22404 zoran_write 3 22404 NULL
120329 +queue_reply_22416 queue_reply 3 22416 NULL
120330 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120331 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120332 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120333 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120334 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL nohasharray
120335 +video_write_22490 video_write 3 22490 &qib_user_sdma_alloc_header_22490
120336 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120337 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120338 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120339 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2 22549 NULL
120340 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120341 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120342 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120343 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120344 +snapshot_read_22601 snapshot_read 3 22601 NULL
120345 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120346 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120347 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120348 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120349 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120350 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
120351 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120352 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120353 +reg_umr_22686 reg_umr 5 22686 NULL
120354 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120355 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120356 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120357 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120358 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120359 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120360 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120361 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120362 +print_frame_22769 print_frame 0 22769 NULL
120363 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120364 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120365 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120366 +create_attr_set_22861 create_attr_set 1 22861 NULL
120367 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120368 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120369 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120370 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120371 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120372 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120373 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120374 +__set_xattr_22923 __set_xattr 0 22923 NULL
120375 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120376 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120377 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120378 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120379 +vme_get_size_22964 vme_get_size 0 22964 NULL
120380 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120381 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120382 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120383 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120384 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120385 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120386 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
120387 +st_status_23032 st_status 5 23032 NULL
120388 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120389 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
120390 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120391 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120392 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120393 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120394 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120395 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120396 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120397 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120398 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120399 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120400 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120401 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120402 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120403 +__clear_user_23118 __clear_user 0-2 23118 NULL
120404 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120405 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120406 +read_file_ani_23161 read_file_ani 3 23161 NULL
120407 +usblp_write_23178 usblp_write 3 23178 NULL
120408 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120409 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120410 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120411 +mcryptd_alloc_instance_23221 mcryptd_alloc_instance 2-3 23221 NULL
120412 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120413 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120414 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120415 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120416 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120417 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120418 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120419 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120420 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120421 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120422 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120423 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120424 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120425 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120426 +page_readlink_23346 page_readlink 3 23346 NULL
120427 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120428 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120429 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120430 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120431 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120432 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120433 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120434 +linear_conf_23485 linear_conf 2 23485 NULL
120435 +event_filter_read_23494 event_filter_read 3 23494 NULL
120436 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120437 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120438 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120439 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120440 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120441 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120442 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120443 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120444 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120445 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120446 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120447 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120448 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120449 +sInW_23663 sInW 0 23663 NULL
120450 +SyS_connect_23669 SyS_connect 3 23669 NULL
120451 +cx18_read_23699 cx18_read 3 23699 NULL
120452 +at_get_23708 at_get 0 23708 NULL
120453 +get_conn_info_23723 get_conn_info 4 23723 NULL
120454 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120455 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120456 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120457 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120458 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120459 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120460 +map_write_23795 map_write 3 23795 NULL
120461 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120462 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120463 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120464 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120465 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120466 +p54_init_common_23850 p54_init_common 1 23850 NULL
120467 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120468 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120469 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120470 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120471 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120472 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120473 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120474 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120475 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120476 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120477 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120478 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120479 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120480 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120481 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120482 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120483 +xfs_zero_file_space_24000 xfs_zero_file_space 2-3 24000 NULL
120484 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120485 +give_pages_24021 give_pages 3 24021 NULL
120486 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120487 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120488 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120489 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120490 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120491 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120492 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120493 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120494 +lov_brw_24122 lov_brw 4 24122 NULL
120495 +mpu401_read_24126 mpu401_read 3 24126 NULL
120496 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120497 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120498 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120499 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120500 +adu_read_24177 adu_read 3 24177 NULL
120501 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120502 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120503 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120504 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
120505 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120506 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120507 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120508 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120509 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120510 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120511 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120512 +thin_status_24278 thin_status 5 24278 NULL
120513 +msg_size_24288 msg_size 0 24288 NULL
120514 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120515 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120516 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120517 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120518 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120519 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120520 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120521 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120522 +igetword_24373 igetword 0 24373 NULL
120523 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120524 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120525 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120526 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120527 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
120528 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120529 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120530 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120531 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120532 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120533 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120534 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120535 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120536 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120537 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120538 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120539 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120540 +ttm_page_pool_free_24486 ttm_page_pool_free 2-0 24486 NULL
120541 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120542 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120543 +pd_video_read_24510 pd_video_read 3 24510 NULL
120544 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120545 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120546 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120547 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120548 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120549 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120550 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120551 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605 nohasharray
120552 +i915_error_state_buf_init_24605 i915_error_state_buf_init 3 24605 &lov_alloc_memmd_24605
120553 +SyS_poll_24620 SyS_poll 2 24620 NULL
120554 +context_alloc_24645 context_alloc 3 24645 NULL
120555 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120556 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120557 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120558 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120559 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120560 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120561 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120562 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120563 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120564 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120565 +cache_read_24790 cache_read 3 24790 NULL
120566 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120567 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120568 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120569 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120570 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120571 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120572 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120573 +queues_read_24877 queues_read 3 24877 NULL
120574 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120575 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120576 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120577 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120578 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120579 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120580 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120581 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL nohasharray
120582 +ath10k_fw_crash_dump_read_24987 ath10k_fw_crash_dump_read 3 24987 &llc_ui_sendmsg_24987
120583 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120584 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120585 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120586 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120587 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120588 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120589 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120590 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120591 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120592 +do_add_page_to_bio_25071 do_add_page_to_bio 2 25071 NULL
120593 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120594 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120595 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120596 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120597 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120598 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120599 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120600 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120601 +stripe_status_25259 stripe_status 5 25259 NULL
120602 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120603 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120604 +vfs_writev_25278 vfs_writev 3 25278 NULL
120605 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120606 +cx25821_write_frame_25315 cx25821_write_frame 3 25315 NULL
120607 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120608 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120609 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120610 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120611 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120612 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120613 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120614 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120615 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120616 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120617 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120618 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120619 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120620 +sb_permission_25523 sb_permission 0 25523 NULL
120621 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120622 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120623 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120624 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120625 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120626 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120627 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120628 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120629 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120630 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120631 +__direct_map_25647 __direct_map 6-5 25647 NULL
120632 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120633 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120634 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120635 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120636 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120637 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120638 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120639 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120640 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120641 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120642 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120643 +sg_read_25799 sg_read 3 25799 NULL
120644 +system_enable_read_25815 system_enable_read 3 25815 NULL
120645 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120646 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120647 +parport_read_25855 parport_read 0 25855 NULL
120648 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120649 +key_attr_size_25865 key_attr_size 0 25865 NULL
120650 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120651 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120652 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120653 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120654 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120655 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120656 +rcname_read_25919 rcname_read 3 25919 NULL
120657 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120658 +key_flags_read_25931 key_flags_read 3 25931 NULL
120659 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120660 +flush_25957 flush 2 25957 NULL
120661 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120662 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120663 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120664 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120665 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120666 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120667 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120668 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120669 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120670 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120671 +read_sb_page_26119 read_sb_page 5 26119 NULL
120672 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120673 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120674 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120675 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120676 +disk_devt_26180 disk_devt 0 26180 NULL
120677 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120678 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120679 +mce_write_26201 mce_write 3 26201 NULL
120680 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120681 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120682 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120683 +nlm_end_grace_read_26234 nlm_end_grace_read 3 26234 NULL
120684 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120685 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120686 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120687 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120688 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120689 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120690 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120691 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120692 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120693 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120694 +ntty_write_26404 ntty_write 3 26404 NULL
120695 +firmware_store_26408 firmware_store 4 26408 NULL
120696 +pagemap_read_26441 pagemap_read 3 26441 NULL
120697 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120698 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120699 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120700 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120701 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL nohasharray
120702 +msi_verify_entries_26490 msi_verify_entries 0 26490 &dvb_ca_en50221_io_ioctl_26490
120703 +read_vmcore_26501 read_vmcore 3 26501 NULL
120704 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120705 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120706 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120707 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120708 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120709 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120710 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120711 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120712 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120713 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120714 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120715 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120716 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120717 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120718 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120719 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120720 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120721 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120722 +bos_desc_26752 bos_desc 0 26752 NULL
120723 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120724 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120725 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120726 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120727 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120728 +smk_write_load_26829 smk_write_load 3 26829 NULL
120729 +snd_pcm_action_mutex_26832 snd_pcm_action_mutex 0 26832 NULL
120730 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120731 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120732 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120733 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120734 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120735 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120736 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120737 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120738 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120739 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120740 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120741 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120742 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120743 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120744 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120745 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120746 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120747 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120748 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120749 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120750 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120751 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120752 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120753 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120754 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120755 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120756 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120757 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120758 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120759 +pms_capture_27142 pms_capture 4 27142 NULL
120760 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120761 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120762 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120763 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120764 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120765 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120766 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120767 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120768 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120769 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120770 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120771 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120772 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120773 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120774 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120775 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120776 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120777 +seq_read_27411 seq_read 3 27411 NULL
120778 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120779 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120780 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120781 +cypress_write_27423 cypress_write 4 27423 NULL
120782 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120783 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120784 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120785 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120786 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120787 +garmin_read_process_27509 garmin_read_process 3 27509 NULL nohasharray
120788 +mcryptd_hash_setkey_27509 mcryptd_hash_setkey 3 27509 &garmin_read_process_27509
120789 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120790 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120791 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120792 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120793 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120794 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120795 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120796 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120797 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120798 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120799 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120800 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120801 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120802 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120803 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120804 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120805 +evm_write_key_27715 evm_write_key 3 27715 NULL
120806 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120807 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120808 +load_scode_27738 load_scode 2 27738 NULL
120809 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120810 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120811 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120812 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120813 +SyS_readv_27804 SyS_readv 3 27804 NULL
120814 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120815 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120816 +init_header_complete_27833 init_header_complete 0 27833 NULL
120817 +read_profile_27859 read_profile 3 27859 NULL
120818 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120819 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120820 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120821 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120822 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120823 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120824 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120825 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120826 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120827 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120828 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120829 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120830 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120831 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120832 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120833 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120834 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120835 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120836 +pool_status_28055 pool_status 5 28055 NULL
120837 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120838 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120839 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120840 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120841 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120842 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120843 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120844 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120845 +video_read_28148 video_read 3 28148 NULL
120846 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120847 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120848 +vread_28173 vread 0-3 28173 NULL
120849 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120850 +counter_free_res_28187 counter_free_res 5 28187 NULL
120851 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120852 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120853 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120854 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120855 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120856 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120857 +usemap_size_28281 usemap_size 0 28281 NULL
120858 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120859 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120860 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120861 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120862 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120863 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120864 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120865 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120866 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120867 +snapshot_write_28351 snapshot_write 3 28351 NULL
120868 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120869 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120870 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120871 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120872 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120873 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120874 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120875 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120876 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120877 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120878 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120879 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120880 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120881 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120882 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120883 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120884 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120885 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120886 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120887 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120888 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120889 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120890 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120891 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120892 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120893 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120894 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120895 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120896 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120897 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120898 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120899 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120900 +iwl_dbgfs_nic_temp_read_28662 iwl_dbgfs_nic_temp_read 3 28662 NULL
120901 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120902 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120903 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120904 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
120905 +spi_execute_28736 spi_execute 5 28736 NULL
120906 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
120907 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
120908 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
120909 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
120910 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
120911 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
120912 +sel_write_member_28800 sel_write_member 3 28800 NULL
120913 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
120914 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
120915 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
120916 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
120917 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
120918 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
120919 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
120920 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
120921 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
120922 +push_rx_28939 push_rx 3 28939 NULL
120923 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
120924 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
120925 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
120926 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
120927 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
120928 +bin_uuid_28999 bin_uuid 3 28999 NULL
120929 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
120930 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
120931 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
120932 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
120933 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
120934 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
120935 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
120936 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
120937 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
120938 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
120939 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
120940 +snprintf_29125 snprintf 0 29125 NULL
120941 +iov_shorten_29130 iov_shorten 0 29130 NULL
120942 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
120943 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
120944 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
120945 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
120946 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
120947 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
120948 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
120949 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
120950 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
120951 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
120952 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
120953 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
120954 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
120955 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
120956 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
120957 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
120958 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
120959 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
120960 +tun_put_user_29337 tun_put_user 5 29337 NULL
120961 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
120962 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
120963 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
120964 +mempool_create_29437 mempool_create 1 29437 NULL
120965 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
120966 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
120967 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
120968 +memcg_update_cache_params_29465 memcg_update_cache_params 2 29465 NULL
120969 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
120970 +do_register_entry_29478 do_register_entry 4 29478 NULL
120971 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
120972 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
120973 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
120974 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
120975 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
120976 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
120977 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
120978 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
120979 +ftrace_write_29551 ftrace_write 3 29551 NULL
120980 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
120981 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
120982 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
120983 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
120984 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
120985 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
120986 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
120987 +slots_per_page_29601 slots_per_page 0 29601 NULL
120988 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
120989 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
120990 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
120991 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
120992 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
120993 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
120994 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
120995 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
120996 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
120997 +probes_write_29711 probes_write 3 29711 NULL
120998 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
120999 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
121000 +std_nic_write_29752 std_nic_write 3 29752 NULL
121001 +static_key_count_29771 static_key_count 0 29771 NULL
121002 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
121003 +dbAlloc_29794 dbAlloc 0 29794 NULL
121004 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
121005 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
121006 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
121007 +count_partial_29850 count_partial 0 29850 NULL
121008 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
121009 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
121010 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
121011 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
121012 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
121013 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
121014 +write_file_queue_29922 write_file_queue 3 29922 NULL
121015 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
121016 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
121017 +zero_iovec_29955 zero_iovec 1 29955 NULL
121018 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
121019 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
121020 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
121021 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
121022 +drp_wmove_30043 drp_wmove 4 30043 NULL
121023 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
121024 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
121025 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
121026 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
121027 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
121028 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
121029 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
121030 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
121031 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
121032 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
121033 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
121034 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
121035 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
121036 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
121037 +SyS_semop_30227 SyS_semop 3 30227 NULL
121038 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
121039 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
121040 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
121041 +compat_readv_30273 compat_readv 3 30273 NULL
121042 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
121043 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
121044 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
121045 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
121046 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
121047 +i8254_read_30330 i8254_read 0 30330 NULL
121048 +resource_from_user_30341 resource_from_user 3 30341 NULL
121049 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
121050 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
121051 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
121052 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
121053 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
121054 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
121055 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
121056 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
121057 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
121058 +enable_write_30456 enable_write 3 30456 NULL
121059 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
121060 +urandom_read_30462 urandom_read 3 30462 NULL
121061 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
121062 +adu_write_30487 adu_write 3 30487 NULL
121063 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
121064 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
121065 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
121066 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
121067 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
121068 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
121069 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL nohasharray
121070 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 &xfs_sb_version_hasftype_30559
121071 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
121072 +set_le_30581 set_le 4 30581 NULL
121073 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
121074 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
121075 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
121076 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
121077 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
121078 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
121079 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
121080 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
121081 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
121082 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
121083 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
121084 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
121085 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
121086 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
121087 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
121088 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
121089 +snapshot_status_30744 snapshot_status 5 30744 NULL
121090 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
121091 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
121092 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
121093 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
121094 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
121095 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
121096 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
121097 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
121098 +cfg80211_rx_mgmt_30844 cfg80211_rx_mgmt 5 30844 NULL
121099 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
121100 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
121101 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
121102 +copy_to_iter_30901 copy_to_iter 2 30901 NULL
121103 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
121104 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
121105 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
121106 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
121107 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
121108 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
121109 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
121110 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
121111 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
121112 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
121113 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
121114 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
121115 +depth_read_31112 depth_read 3 31112 NULL
121116 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
121117 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
121118 +size_inside_page_31141 size_inside_page 0 31141 NULL
121119 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
121120 +nvme_set_features_31169 nvme_set_features 0 31169 NULL
121121 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
121122 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
121123 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
121124 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
121125 +__read_reg_31216 __read_reg 0 31216 NULL
121126 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
121127 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
121128 +cyy_readb_31240 cyy_readb 0 31240 NULL
121129 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
121130 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
121131 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
121132 +iwl_dbgfs_set_nic_temperature_read_31300 iwl_dbgfs_set_nic_temperature_read 3 31300 NULL
121133 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
121134 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
121135 +command_file_write_31318 command_file_write 3 31318 NULL
121136 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
121137 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
121138 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
121139 +outlen_write_31358 outlen_write 3 31358 NULL
121140 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
121141 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
121142 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
121143 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
121144 +inb_31388 inb 0 31388 NULL
121145 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
121146 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
121147 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
121148 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
121149 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
121150 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
121151 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
121152 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
121153 +alg_setkey_31485 alg_setkey 3 31485 NULL
121154 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
121155 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
121156 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
121157 +hidraw_write_31536 hidraw_write 3 31536 NULL
121158 +usbvision_read_31555 usbvision_read 3 31555 NULL
121159 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
121160 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
121161 +osst_write_31581 osst_write 3 31581 NULL
121162 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
121163 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
121164 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
121165 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
121166 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
121167 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
121168 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
121169 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
121170 +__lgread_31668 __lgread 4 31668 NULL
121171 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
121172 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
121173 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
121174 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
121175 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
121176 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
121177 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
121178 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
121179 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
121180 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
121181 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
121182 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
121183 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
121184 +get_count_order_31800 get_count_order 0 31800 NULL
121185 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
121186 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
121187 +data_write_31805 data_write 3 31805 NULL
121188 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
121189 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
121190 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
121191 +clone_bio_31854 clone_bio 4-3 31854 NULL
121192 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
121193 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
121194 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
121195 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
121196 +xattr_permission_31907 xattr_permission 0 31907 NULL
121197 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
121198 +new_dir_31919 new_dir 3 31919 NULL
121199 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
121200 +era_status_31934 era_status 5 31934 NULL
121201 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
121202 +read_mem_31942 read_mem 3 31942 NULL
121203 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
121204 +vb2_write_31948 vb2_write 3 31948 NULL
121205 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
121206 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
121207 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
121208 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
121209 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
121210 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
121211 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
121212 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
121213 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
121214 +calc_hmac_32010 calc_hmac 3 32010 NULL
121215 +aead_len_32021 aead_len 0 32021 NULL
121216 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
121217 +stk_read_32038 stk_read 3 32038 NULL
121218 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
121219 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
121220 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
121221 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
121222 +bio_alloc_32095 bio_alloc 2 32095 NULL
121223 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
121224 +wil_read_file_recovery_32104 wil_read_file_recovery 3 32104 NULL
121225 +disk_status_32120 disk_status 4 32120 NULL
121226 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
121227 +venus_link_32165 venus_link 5 32165 NULL
121228 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
121229 +do_writepages_32173 do_writepages 0 32173 NULL
121230 +del_ptr_32197 del_ptr 4 32197 NULL
121231 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
121232 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
121233 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
121234 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
121235 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
121236 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
121237 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
121238 +SyS_select_32319 SyS_select 1 32319 NULL
121239 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
121240 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
121241 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
121242 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
121243 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
121244 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
121245 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
121246 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
121247 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
121248 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
121249 +cache_status_32462 cache_status 5 32462 NULL
121250 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
121251 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
121252 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
121253 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
121254 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
121255 +disconnect_32521 disconnect 4 32521 NULL
121256 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
121257 +ilo_read_32531 ilo_read 3 32531 NULL
121258 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
121259 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
121260 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
121261 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
121262 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
121263 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
121264 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
121265 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
121266 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
121267 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
121268 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
121269 +kvmalloc_32646 kvmalloc 1 32646 NULL
121270 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
121271 +generic_readlink_32654 generic_readlink 3 32654 NULL
121272 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
121273 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
121274 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
121275 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
121276 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
121277 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
121278 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
121279 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
121280 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
121281 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
121282 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
121283 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
121284 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
121285 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
121286 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
121287 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
121288 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
121289 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
121290 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
121291 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121292 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121293 +compat_filldir_32999 compat_filldir 3 32999 NULL
121294 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121295 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121296 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121297 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121298 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121299 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121300 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121301 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121302 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121303 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121304 +alloc_tio_33077 alloc_tio 3 33077 NULL
121305 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121306 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121307 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121308 +SyS_poll_33152 SyS_poll 2 33152 NULL
121309 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121310 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121311 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121312 +pp_read_33210 pp_read 3 33210 NULL
121313 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121314 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121315 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121316 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121317 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121318 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121319 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121320 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121321 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121322 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121323 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121324 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121325 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121326 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121327 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121328 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121329 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121330 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121331 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121332 +message_stats_list_33440 message_stats_list 5 33440 NULL
121333 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121334 +create_entry_33479 create_entry 2 33479 NULL
121335 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121336 +res_counter_read_33499 res_counter_read 4 33499 NULL
121337 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121338 +fb_read_33506 fb_read 3 33506 NULL
121339 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121340 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121341 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121342 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121343 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121344 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121345 +count_subheaders_33591 count_subheaders 0 33591 NULL
121346 +scsi_execute_33596 scsi_execute 5 33596 NULL
121347 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121348 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121349 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121350 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121351 +stride_page_count_33641 stride_page_count 2 33641 NULL
121352 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121353 +inw_p_33668 inw_p 0 33668 NULL
121354 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121355 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121356 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121357 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121358 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121359 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121360 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121361 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121362 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121363 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121364 +hashtab_create_33769 hashtab_create 3 33769 NULL
121365 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121366 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121367 +filter_write_33819 filter_write 3 33819 NULL
121368 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121369 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121370 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121371 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121372 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121373 +get_user_pages_33908 get_user_pages 0 33908 NULL
121374 +sg_nents_33909 sg_nents 0 33909 NULL
121375 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121376 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121377 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121378 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121379 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121380 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121381 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121382 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121383 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121384 +ppp_write_34034 ppp_write 3 34034 NULL
121385 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121386 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121387 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121388 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121389 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121390 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121391 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121392 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121393 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121394 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121395 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121396 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121397 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL nohasharray
121398 +rbd_osd_req_create_34206 rbd_osd_req_create 3 34206 &rsi_debug_zone_write_34206
121399 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121400 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121401 +device_private_init_34279 device_private_init 0 34279 NULL
121402 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121403 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121404 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121405 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121406 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121407 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121408 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121409 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121410 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121411 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121412 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121413 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121414 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121415 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121416 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121417 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121418 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121419 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121420 +security_socket_create_34439 security_socket_create 0 34439 NULL
121421 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121422 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121423 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121424 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121425 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121426 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121427 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121428 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121429 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121430 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121431 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121432 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121433 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121434 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121435 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121436 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121437 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121438 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121439 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121440 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121441 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121442 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121443 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121444 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121445 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121446 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121447 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121448 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121449 +port_print_34704 port_print 3 34704 NULL
121450 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121451 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121452 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121453 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121454 +bootmode_store_34762 bootmode_store 4 34762 NULL
121455 +device_add_34766 device_add 0 34766 NULL
121456 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121457 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121458 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121459 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121460 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121461 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121462 +file_page_index_34820 file_page_index 0-2 34820 NULL
121463 +bio_segments_34832 bio_segments 0 34832 NULL
121464 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121465 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121466 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121467 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121468 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121469 +msg_print_text_34889 msg_print_text 0 34889 NULL
121470 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121471 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121472 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121473 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121474 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121475 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121476 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121477 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121478 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121479 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121480 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121481 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121482 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121483 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121484 +proc_setgroups_write_35039 proc_setgroups_write 3 35039 NULL
121485 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121486 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121487 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121488 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121489 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121490 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121491 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121492 +message_stats_print_35158 message_stats_print 6 35158 NULL
121493 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121494 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121495 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121496 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121497 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121498 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121499 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121500 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121501 +set_fd_set_35249 set_fd_set 1 35249 NULL
121502 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121503 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121504 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121505 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121506 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121507 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL nohasharray
121508 +nvkm_notify_init_35283 nvkm_notify_init 7 35283 &isr_rx_rdys_read_35283
121509 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121510 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121511 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121512 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121513 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121514 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121515 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121516 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121517 +read_kmem_35372 read_kmem 3 35372 NULL
121518 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121519 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121520 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121521 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121522 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121523 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121524 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121525 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121526 +async_setkey_35521 async_setkey 3 35521 NULL
121527 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121528 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121529 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121530 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121531 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121532 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121533 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121534 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121535 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121536 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121537 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121538 +kernel_readv_35617 kernel_readv 3 35617 NULL
121539 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121540 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121541 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121542 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121543 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121544 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121545 +md_super_write_35703 md_super_write 4 35703 NULL
121546 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121547 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121548 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121549 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121550 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121551 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121552 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121553 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121554 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121555 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121556 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121557 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121558 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121559 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121560 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121561 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121562 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121563 +acl_alloc_35979 acl_alloc 1 35979 NULL
121564 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121565 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121566 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121567 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121568 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121569 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121570 +account_shadowed_36048 account_shadowed 2 36048 NULL
121571 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121572 +write_emulate_36065 write_emulate 2-4 36065 NULL
121573 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121574 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121575 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121576 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121577 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121578 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121579 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121580 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121581 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121582 +twl_set_36154 twl_set 2 36154 NULL
121583 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121584 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121585 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121586 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121587 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121588 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121589 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121590 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121591 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121592 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121593 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121594 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121595 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121596 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121597 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121598 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121599 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121600 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121601 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121602 +lc_create_36332 lc_create 4 36332 NULL
121603 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121604 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121605 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121606 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121607 +to_sector_36361 to_sector 0-1 36361 NULL
121608 +tunables_read_36385 tunables_read 3 36385 NULL
121609 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121610 +sierra_write_36402 sierra_write 4 36402 NULL
121611 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121612 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121613 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121614 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121615 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121616 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121617 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121618 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121619 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121620 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121621 +cmd_loop_36491 cmd_loop 0 36491 NULL
121622 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121623 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121624 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121625 +get_param_l_36518 get_param_l 0 36518 NULL
121626 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121627 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121628 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121629 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121630 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121631 +__erst_read_36579 __erst_read 0 36579 NULL
121632 +put_cmsg_36589 put_cmsg 4 36589 NULL
121633 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121634 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121635 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121636 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121637 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121638 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121639 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121640 +xillybus_read_36678 xillybus_read 3 36678 NULL
121641 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121642 +path_getxattr_36717 path_getxattr 4 36717 NULL
121643 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121644 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121645 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121646 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121647 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121648 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121649 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121650 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121651 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121652 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121653 +cm_write_36858 cm_write 3 36858 NULL
121654 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121655 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121656 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121657 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121658 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121659 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121660 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121661 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121662 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121663 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121664 +setxattr_37006 setxattr 4 37006 NULL
121665 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121666 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121667 +command_file_read_37038 command_file_read 3 37038 NULL
121668 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121669 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121670 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121671 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121672 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121673 +parse_command_37079 parse_command 2 37079 NULL
121674 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121675 +tun_get_user_37094 tun_get_user 5 37094 NULL
121676 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121677 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121678 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121679 +msg_word_37164 msg_word 0 37164 NULL
121680 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121681 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121682 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121683 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121684 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121685 +__do_replace_37227 __do_replace 5 37227 NULL
121686 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121687 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121688 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121689 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121690 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121691 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121692 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121693 +tipc_send_37315 tipc_send 3 37315 NULL
121694 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121695 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121696 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121697 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121698 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121699 +seek_firmware_37372 seek_firmware 2 37372 NULL
121700 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121701 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121702 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121703 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121704 +fru_alloc_37442 fru_alloc 1 37442 NULL
121705 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121706 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121707 +get_est_timing_37484 get_est_timing 0 37484 NULL
121708 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121709 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121710 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121711 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121712 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121713 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121714 +hdr_size_37536 hdr_size 0 37536 NULL
121715 +extent_map_end_37550 extent_map_end 0 37550 NULL
121716 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121717 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121718 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121719 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121720 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121721 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121722 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121723 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121724 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121725 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121726 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121727 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121728 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121729 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121730 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121731 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121732 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121733 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121734 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121735 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121736 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121737 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121738 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121739 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121740 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121741 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121742 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121743 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121744 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121745 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121746 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121747 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121748 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121749 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121750 +write_file_bool_37957 write_file_bool 3 37957 NULL
121751 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121752 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121753 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121754 +vfs_readv_38011 vfs_readv 3 38011 NULL
121755 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121756 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121757 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121758 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121759 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121760 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121761 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121762 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121763 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121764 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121765 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121766 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121767 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121768 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121769 +ep0_read_38095 ep0_read 3 38095 NULL
121770 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121771 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121772 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121773 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121774 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121775 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121776 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121777 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121778 +cdev_add_38176 cdev_add 2-3 38176 NULL
121779 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121780 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121781 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121782 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121783 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121784 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121785 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121786 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121787 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121788 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121789 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121790 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121791 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121792 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121793 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121794 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121795 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121796 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121797 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121798 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121799 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121800 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121801 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121802 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121803 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121804 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121805 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121806 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121807 +dev_names_read_38509 dev_names_read 3 38509 NULL
121808 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121809 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121810 +set_queue_count_38519 set_queue_count 0 38519 NULL
121811 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121812 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121813 +kuc_len_38557 kuc_len 0-1 38557 NULL
121814 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121815 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121816 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121817 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121818 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121819 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121820 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121821 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121822 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121823 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121824 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121825 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121826 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121827 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121828 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121829 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121830 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121831 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121832 +udf_readpages_38761 udf_readpages 4 38761 NULL
121833 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121834 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121835 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121836 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121837 +err_decode_38804 err_decode 2 38804 NULL
121838 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121839 +direct_entry_38836 direct_entry 3 38836 NULL
121840 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121841 +interfaces_38859 interfaces 2 38859 NULL
121842 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121843 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121844 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121845 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121846 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121847 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121848 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121849 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121850 +get_nodes_39012 get_nodes 3 39012 NULL
121851 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121852 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121853 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121854 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121855 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121856 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121857 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121858 +ea_foreach_39133 ea_foreach 0 39133 NULL
121859 +generic_permission_39150 generic_permission 0 39150 NULL
121860 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121861 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121862 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121863 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121864 +mlx4_en_create_tx_ring_39179 mlx4_en_create_tx_ring 4 39179 NULL
121865 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121866 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121867 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121868 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121869 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121870 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121871 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121872 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121873 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121874 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121875 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121876 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121877 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121878 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121879 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121880 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121881 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121882 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121883 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121884 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121885 +__send_to_port_39386 __send_to_port 3 39386 NULL
121886 +user_power_read_39414 user_power_read 3 39414 NULL
121887 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121888 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121889 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121890 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121891 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121892 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121893 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121894 +int_proc_write_39542 int_proc_write 3 39542 NULL
121895 +pp_write_39554 pp_write 3 39554 NULL
121896 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121897 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121898 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121899 +ext_depth_39607 ext_depth 0 39607 NULL
121900 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121901 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121902 +sdio_readb_39618 sdio_readb 0 39618 NULL
121903 +set_dev_class_39645 set_dev_class 4 39645 NULL
121904 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
121905 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
121906 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
121907 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
121908 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
121909 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
121910 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
121911 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
121912 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
121913 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
121914 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
121915 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
121916 +pkt_add_39897 pkt_add 3 39897 NULL
121917 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
121918 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
121919 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
121920 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
121921 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
121922 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
121923 +__spi_async_39932 __spi_async 0 39932 NULL
121924 +__get_order_39935 __get_order 0 39935 NULL
121925 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
121926 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
121927 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
121928 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
121929 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
121930 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
121931 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
121932 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
121933 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
121934 +server_name2svname_39998 server_name2svname 4 39998 NULL
121935 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
121936 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
121937 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
121938 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
121939 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
121940 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
121941 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
121942 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
121943 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
121944 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
121945 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
121946 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL nohasharray
121947 +kvm_mmu_notifier_clear_flush_young_40143 kvm_mmu_notifier_clear_flush_young 3-4 40143 &ath10k_write_simulate_fw_crash_40143
121948 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
121949 +pt_write_40159 pt_write 3 40159 NULL
121950 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
121951 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
121952 +allocate_probes_40204 allocate_probes 1 40204 NULL
121953 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
121954 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
121955 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
121956 +osst_read_40237 osst_read 3 40237 NULL
121957 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
121958 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
121959 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
121960 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
121961 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
121962 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
121963 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
121964 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
121965 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
121966 +SyS_bind_40303 SyS_bind 3 40303 NULL
121967 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
121968 +mmio_read_40348 mmio_read 4 40348 NULL
121969 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
121970 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
121971 +get_chars_40373 get_chars 3 40373 NULL
121972 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
121973 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
121974 +repair_io_failure_40452 repair_io_failure 4-3 40452 NULL
121975 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
121976 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
121977 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
121978 +SyS_writev_40467 SyS_writev 3 40467 NULL
121979 +SyS_select_40473 SyS_select 1 40473 NULL
121980 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
121981 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
121982 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
121983 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
121984 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
121985 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
121986 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
121987 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
121988 +bl_alloc_init_bio_40569 bl_alloc_init_bio 1 40569 NULL
121989 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
121990 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
121991 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
121992 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
121993 +fops_read_40672 fops_read 3 40672 NULL
121994 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
121995 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
121996 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
121997 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
121998 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
121999 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
122000 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
122001 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
122002 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
122003 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
122004 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
122005 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
122006 +card_send_command_40757 card_send_command 3 40757 NULL
122007 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
122008 +pg_write_40766 pg_write 3 40766 NULL
122009 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
122010 +show_list_40775 show_list 3-0 40775 NULL
122011 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
122012 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
122013 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
122014 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
122015 +add_action_40811 add_action 4 40811 NULL
122016 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
122017 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
122018 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
122019 +read_file_queue_40895 read_file_queue 3 40895 NULL
122020 +waiters_read_40902 waiters_read 3 40902 NULL
122021 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
122022 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
122023 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
122024 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
122025 +path_listxattr_40949 path_listxattr 3 40949 NULL
122026 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
122027 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
122028 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
122029 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
122030 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
122031 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
122032 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
122033 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
122034 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
122035 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
122036 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
122037 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
122038 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
122039 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
122040 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
122041 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
122042 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
122043 +dma_attach_41094 dma_attach 5-6 41094 NULL
122044 +nl80211_send_mlme_event_41099 nl80211_send_mlme_event 4 41099 NULL
122045 +provide_user_output_41105 provide_user_output 3 41105 NULL
122046 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
122047 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
122048 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
122049 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
122050 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
122051 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
122052 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
122053 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
122054 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
122055 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
122056 +erst_read_41260 erst_read 0 41260 NULL
122057 +alloc_context_41283 alloc_context 1 41283 NULL
122058 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
122059 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
122060 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
122061 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
122062 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
122063 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
122064 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
122065 +kmp_init_41373 kmp_init 2 41373 NULL
122066 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
122067 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
122068 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
122069 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
122070 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
122071 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
122072 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
122073 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
122074 +se_io_cb_41461 se_io_cb 3 41461 NULL
122075 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
122076 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
122077 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
122078 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
122079 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
122080 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
122081 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
122082 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
122083 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
122084 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
122085 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
122086 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
122087 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
122088 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
122089 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
122090 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
122091 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
122092 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
122093 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
122094 +a2mp_send_41615 a2mp_send 4 41615 NULL
122095 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
122096 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
122097 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
122098 +get_std_timing_41654 get_std_timing 0 41654 NULL
122099 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
122100 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
122101 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
122102 +connector_write_41709 connector_write 3 41709 NULL
122103 +fillonedir_41746 fillonedir 3 41746 NULL
122104 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
122105 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
122106 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
122107 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
122108 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
122109 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
122110 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
122111 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
122112 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
122113 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
122114 +pci_map_single_41869 pci_map_single 0 41869 NULL
122115 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
122116 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
122117 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
122118 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
122119 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
122120 +read_gssp_41947 read_gssp 3 41947 NULL
122121 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
122122 +portnames_read_41958 portnames_read 3 41958 NULL
122123 +dst_mtu_41969 dst_mtu 0 41969 NULL
122124 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
122125 +pool_allocate_42012 pool_allocate 3 42012 NULL
122126 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
122127 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
122128 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
122129 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
122130 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
122131 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
122132 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
122133 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
122134 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
122135 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
122136 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
122137 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
122138 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
122139 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
122140 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
122141 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
122142 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
122143 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
122144 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
122145 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
122146 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
122147 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
122148 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
122149 +find_last_bit_42260 find_last_bit 0 42260 NULL
122150 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
122151 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
122152 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
122153 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
122154 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
122155 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
122156 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
122157 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
122158 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
122159 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
122160 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
122161 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
122162 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
122163 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
122164 +krng_get_random_42420 krng_get_random 3 42420 NULL
122165 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
122166 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
122167 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
122168 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
122169 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
122170 +kuc_free_42455 kuc_free 2 42455 NULL
122171 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
122172 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
122173 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
122174 +bypass_write_42498 bypass_write 3 42498 NULL
122175 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
122176 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
122177 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
122178 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
122179 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
122180 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
122181 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
122182 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
122183 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
122184 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
122185 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
122186 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
122187 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
122188 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL nohasharray
122189 +num_controllers_42644 num_controllers 0 42644 &parport_pc_compat_write_block_pio_42644
122190 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
122191 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
122192 +vb2_read_42703 vb2_read 3 42703 NULL
122193 +read_status_42722 read_status 0 42722 NULL
122194 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
122195 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
122196 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
122197 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
122198 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
122199 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
122200 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
122201 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
122202 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
122203 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
122204 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
122205 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
122206 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
122207 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
122208 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
122209 +set_arg_42824 set_arg 3 42824 NULL
122210 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
122211 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
122212 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
122213 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
122214 +hd_end_request_42904 hd_end_request 2 42904 NULL
122215 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
122216 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
122217 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
122218 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2 42971 NULL
122219 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
122220 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
122221 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
122222 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
122223 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
122224 +__bioset_create_43059 __bioset_create 1 43059 NULL
122225 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
122226 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
122227 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
122228 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
122229 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
122230 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
122231 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
122232 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
122233 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
122234 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
122235 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
122236 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
122237 +uio_write_43202 uio_write 3 43202 NULL
122238 +iso_callback_43208 iso_callback 3 43208 NULL
122239 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
122240 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
122241 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
122242 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
122243 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
122244 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
122245 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
122246 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
122247 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
122248 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
122249 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
122250 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
122251 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
122252 +xenfb_write_43412 xenfb_write 3 43412 NULL
122253 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
122254 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
122255 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
122256 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
122257 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
122258 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
122259 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
122260 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
122261 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
122262 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
122263 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
122264 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
122265 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
122266 +read_events_43534 read_events 3 43534 NULL
122267 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
122268 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
122269 +request_resource_43548 request_resource 0 43548 NULL
122270 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
122271 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
122272 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
122273 +proc_read_43614 proc_read 3 43614 NULL
122274 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
122275 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
122276 +random_write_43656 random_write 3 43656 NULL
122277 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
122278 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
122279 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
122280 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
122281 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
122282 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
122283 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
122284 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
122285 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
122286 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
122287 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
122288 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
122289 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
122290 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
122291 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
122292 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
122293 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
122294 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
122295 +read_flush_43851 read_flush 3 43851 NULL
122296 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
122297 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
122298 +SendString_43928 SendString 3 43928 NULL
122299 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
122300 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
122301 +nla_reserve_43984 nla_reserve 3 43984 NULL
122302 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
122303 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
122304 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
122305 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
122306 +emit_flags_44006 emit_flags 4-3 44006 NULL
122307 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
122308 +fru_strlen_44046 fru_strlen 0 44046 NULL
122309 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
122310 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
122311 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
122312 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
122313 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
122314 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
122315 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
122316 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
122317 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
122318 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122319 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122320 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122321 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122322 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122323 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122324 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122325 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122326 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122327 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122328 +device_create_file_44285 device_create_file 0 44285 NULL
122329 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122330 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122331 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122332 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122333 +rs_init_44327 rs_init 1 44327 NULL
122334 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122335 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122336 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122337 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122338 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122339 +strlcpy_44400 strlcpy 3 44400 NULL
122340 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122341 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122342 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122343 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122344 +write_file_debug_44476 write_file_debug 3 44476 NULL
122345 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122346 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122347 +bio_advance_44496 bio_advance 2 44496 NULL
122348 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122349 +ac_register_board_44504 ac_register_board 3 44504 NULL
122350 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122351 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122352 +spidev_write_44510 spidev_write 3 44510 NULL
122353 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122354 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122355 +comm_write_44537 comm_write 3 44537 NULL
122356 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122357 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122358 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122359 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122360 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122361 +mpi_resize_44674 mpi_resize 2 44674 NULL
122362 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122363 +ts_read_44687 ts_read 3 44687 NULL
122364 +write_file_spectral_bins_44696 write_file_spectral_bins 3 44696 NULL
122365 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122366 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122367 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122368 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122369 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122370 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122371 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122372 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122373 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
122374 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122375 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122376 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122377 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122378 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122379 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122380 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122381 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122382 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122383 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122384 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122385 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122386 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122387 +sisusb_write_44834 sisusb_write 3 44834 NULL
122388 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122389 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122390 +copydesc_user_44855 copydesc_user 3 44855 NULL
122391 +set_advertising_44870 set_advertising 4 44870 NULL
122392 +init_rs_44873 init_rs 1 44873 NULL
122393 +skb_availroom_44883 skb_availroom 0 44883 NULL
122394 +do_tty_write_44896 do_tty_write 5 44896 NULL
122395 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122396 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122397 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122398 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122399 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122400 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122401 +sel_write_user_45060 sel_write_user 3 45060 NULL
122402 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122403 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122404 +snd_card_new_45104 snd_card_new 5 45104 NULL
122405 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122406 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122407 +usbdev_read_45114 usbdev_read 3 45114 NULL
122408 +send_to_tty_45141 send_to_tty 3 45141 NULL
122409 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122410 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122411 +device_write_45156 device_write 3 45156 NULL nohasharray
122412 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
122413 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122414 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122415 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122416 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122417 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122418 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122419 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122420 +event_enable_write_45238 event_enable_write 3 45238 NULL
122421 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122422 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122423 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122424 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122425 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122426 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122427 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122428 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122429 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122430 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122431 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122432 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122433 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122434 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122435 +__node_remap_45458 __node_remap 4 45458 NULL
122436 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122437 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122438 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122439 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122440 +copy_macs_45534 copy_macs 4 45534 NULL
122441 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122442 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122443 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122444 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122445 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122446 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122447 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122448 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122449 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122450 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122451 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122452 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122453 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122454 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122455 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122456 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122457 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122458 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122459 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122460 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122461 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122462 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122463 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122464 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122465 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122466 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122467 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122468 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122469 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122470 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122471 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122472 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122473 +isdn_write_45863 isdn_write 3 45863 NULL
122474 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122475 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122476 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122477 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122478 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122479 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122480 +alloc_mr_45935 alloc_mr 1 45935 NULL
122481 +copy_to_45969 copy_to 3 45969 NULL
122482 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122483 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122484 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122485 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122486 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122487 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122488 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122489 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122490 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122491 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122492 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122493 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122494 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122495 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122496 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122497 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122498 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122499 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122500 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122501 +fq_resize_46195 fq_resize 2 46195 NULL
122502 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122503 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122504 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122505 +dsp_write_46218 dsp_write 2 46218 NULL
122506 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122507 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122508 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122509 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122510 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122511 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122512 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122513 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122514 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122515 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122516 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122517 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122518 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122519 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122520 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122521 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122522 +filldir64_46469 filldir64 3 46469 NULL
122523 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122524 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122525 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122526 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122527 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122528 +nlm_end_grace_write_46517 nlm_end_grace_write 3 46517 NULL
122529 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122530 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122531 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122532 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122533 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122534 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122535 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122536 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122537 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122538 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122539 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122540 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122541 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122542 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122543 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122544 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122545 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122546 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122547 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122548 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122549 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122550 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122551 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122552 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122553 +readreg_46845 readreg 0 46845 NULL
122554 +spi_async_46857 spi_async 0 46857 NULL
122555 +vsnprintf_46863 vsnprintf 0 46863 NULL
122556 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122557 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122558 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122559 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122560 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122561 +alloc_cmdid_46904 alloc_cmdid 0 46904 NULL
122562 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122563 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122564 +fb_write_46924 fb_write 3 46924 NULL
122565 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122566 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122567 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122568 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122569 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122570 +strlcat_46985 strlcat 3 46985 NULL
122571 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122572 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122573 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122574 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122575 +fs_path_len_47060 fs_path_len 0 47060 NULL
122576 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122577 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122578 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122579 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122580 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122581 +mousedev_read_47123 mousedev_read 3 47123 NULL
122582 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122583 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122584 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122585 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122586 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122587 +options_write_47243 options_write 3 47243 NULL
122588 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122589 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122590 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122591 +vsnprintf_47291 vsnprintf 0 47291 NULL
122592 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122593 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122594 +virtqueue_add_47306 virtqueue_add 3 47306 NULL
122595 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122596 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122597 +nvme_submit_admin_cmd_47357 nvme_submit_admin_cmd 0 47357 NULL
122598 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122599 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122600 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122601 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122602 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122603 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122604 +nametbl_list_47391 nametbl_list 2 47391 NULL
122605 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122606 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122607 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122608 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122609 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122610 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122611 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122612 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122613 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122614 +newpart_47485 newpart 6-4 47485 NULL
122615 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122616 +core_sys_select_47494 core_sys_select 1 47494 NULL
122617 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122618 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122619 +unlink_simple_47506 unlink_simple 3 47506 NULL
122620 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122621 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122622 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122623 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122624 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122625 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122626 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122627 +read_ldt_47570 read_ldt 2 47570 NULL
122628 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122629 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122630 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122631 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122632 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122633 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122634 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122635 +get_size_47644 get_size 1-2 47644 NULL
122636 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122637 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122638 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122639 +save_microcode_47717 save_microcode 3 47717 NULL
122640 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122641 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122642 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122643 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122644 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122645 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122646 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122647 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122648 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122649 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122650 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122651 +lov_packmd_47810 lov_packmd 0 47810 NULL
122652 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122653 +read_file_spectral_bins_47829 read_file_spectral_bins 3 47829 NULL
122654 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122655 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122656 +vhci_read_47878 vhci_read 3 47878 NULL
122657 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122658 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122659 +comedi_write_47926 comedi_write 3 47926 NULL
122660 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122661 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
122662 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122663 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122664 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122665 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122666 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122667 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122668 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122669 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122670 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122671 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122672 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122673 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122674 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122675 +disc_write_48070 disc_write 3 48070 NULL
122676 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122677 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122678 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122679 +load_firmware_48128 load_firmware 2 48128 NULL
122680 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122681 +set_discoverable_48141 set_discoverable 4 48141 NULL
122682 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122683 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122684 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122685 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122686 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122687 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122688 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122689 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122690 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122691 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122692 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122693 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122694 +read_file_recv_48232 read_file_recv 3 48232 NULL
122695 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122696 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122697 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122698 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122699 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122700 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122701 +trace_options_write_48275 trace_options_write 3 48275 NULL
122702 +send_set_info_48288 send_set_info 7 48288 NULL
122703 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122704 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122705 +hash_setkey_48310 hash_setkey 3 48310 NULL
122706 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122707 +skb_add_data_48363 skb_add_data 3 48363 NULL
122708 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122709 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122710 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122711 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122712 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122713 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122714 +print_filtered_48442 print_filtered 2-0 48442 NULL
122715 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122716 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122717 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122718 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122719 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122720 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122721 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122722 +send_control_msg_48498 send_control_msg 6 48498 NULL
122723 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122724 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122725 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122726 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122727 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122728 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122729 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122730 +llog_data_len_48607 llog_data_len 1 48607 NULL
122731 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122732 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122733 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122734 +mtd_read_48655 mtd_read 0 48655 NULL
122735 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122736 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122737 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122738 +altera_drscan_48698 altera_drscan 2 48698 NULL
122739 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122740 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122741 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122742 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122743 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122744 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122745 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122746 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122747 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122748 +azx_get_position_48841 azx_get_position 0 48841 NULL
122749 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122750 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122751 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122752 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122753 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122754 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122755 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122756 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122757 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122758 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122759 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122760 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122761 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122762 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122763 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122764 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122765 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122766 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122767 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122768 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122769 +transient_status_49027 transient_status 4 49027 NULL
122770 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122771 +scsi_register_49094 scsi_register 2 49094 NULL
122772 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122773 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122774 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122775 +pt_read_49136 pt_read 3 49136 NULL nohasharray
122776 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
122777 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122778 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122779 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122780 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122781 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122782 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122783 +print_queue_49191 print_queue 0-4 49191 NULL
122784 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122785 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122786 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122787 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122788 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122789 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122790 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122791 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122792 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122793 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122794 +uio_read_49300 uio_read 3 49300 NULL
122795 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122796 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122797 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122798 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122799 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122800 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122801 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122802 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122803 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122804 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122805 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122806 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122807 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122808 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122809 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122810 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122811 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122812 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122813 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122814 +smk_write_access_49561 smk_write_access 3 49561 NULL
122815 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122816 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122817 +readfifo_49583 readfifo 1 49583 NULL
122818 +tap_write_49595 tap_write 3 49595 NULL
122819 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122820 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122821 +heap_init_49617 heap_init 2 49617 NULL
122822 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122823 +port_fops_read_49626 port_fops_read 3 49626 NULL
122824 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122825 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122826 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122827 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122828 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122829 +write_pool_49718 write_pool 3 49718 NULL
122830 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122831 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122832 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122833 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122834 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122835 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122836 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122837 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122838 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122839 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122840 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122841 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122842 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122843 +add_uuid_49831 add_uuid 4 49831 NULL
122844 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122845 +twl4030_write_49846 twl4030_write 2 49846 NULL
122846 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122847 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122848 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122849 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122850 +osc_brw_49896 osc_brw 4 49896 NULL
122851 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122852 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122853 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122854 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122855 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122856 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122857 +isdn_read_50021 isdn_read 3 50021 NULL
122858 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122859 +xlog_recovery_process_trans_50028 xlog_recovery_process_trans 4 50028 NULL
122860 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122861 +ioread8_50049 ioread8 0 50049 NULL
122862 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122863 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122864 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122865 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122866 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122867 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122868 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122869 +read_file_slot_50111 read_file_slot 3 50111 NULL
122870 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122871 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122872 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122873 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122874 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122875 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122876 +odev_update_50169 odev_update 2 50169 NULL
122877 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122878 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122879 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122880 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122881 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122882 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122883 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122884 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122885 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122886 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122887 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122888 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122889 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122890 +do_launder_page_50329 do_launder_page 0 50329 NULL
122891 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122892 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122893 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122894 +tpm_read_50344 tpm_read 3 50344 NULL
122895 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122896 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122897 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122898 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122899 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122900 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122901 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122902 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122903 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122904 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
122905 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
122906 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
122907 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
122908 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
122909 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
122910 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
122911 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
122912 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
122913 +fat_readpages_50582 fat_readpages 4 50582 NULL
122914 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
122915 +xillybus_write_50605 xillybus_write 3 50605 NULL
122916 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
122917 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
122918 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
122919 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
122920 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
122921 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
122922 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
122923 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
122924 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
122925 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
122926 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
122927 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
122928 +tpm_write_50798 tpm_write 3 50798 NULL
122929 +tun_do_read_50800 tun_do_read 4 50800 NULL
122930 +write_flush_50803 write_flush 3 50803 NULL
122931 +dvb_play_50814 dvb_play 3 50814 NULL
122932 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
122933 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
122934 +SetArea_50835 SetArea 4 50835 NULL
122935 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
122936 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
122937 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
122938 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
122939 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
122940 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
122941 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
122942 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
122943 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
122944 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
122945 +show_device_status_50947 show_device_status 0 50947 NULL
122946 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
122947 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
122948 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
122949 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
122950 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
122951 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
122952 +timeout_write_50991 timeout_write 3 50991 NULL
122953 +proc_write_51003 proc_write 3 51003 NULL
122954 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
122955 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
122956 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
122957 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
122958 +dump_midi_51040 dump_midi 3 51040 NULL
122959 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
122960 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
122961 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
122962 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
122963 +rsc_mgr_init_51067 rsc_mgr_init 3 51067 NULL
122964 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
122965 +__ipv4_tun_to_nlattr_51095 __ipv4_tun_to_nlattr 4 51095 NULL
122966 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
122967 +ti_recv_51110 ti_recv 3 51110 NULL
122968 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
122969 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
122970 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
122971 +i40evf_acquire_msix_vectors_51190 i40evf_acquire_msix_vectors 2 51190 NULL
122972 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
122973 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
122974 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
122975 +drm_property_create_51239 drm_property_create 4 51239 NULL
122976 +st_read_51251 st_read 3 51251 NULL
122977 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
122978 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
122979 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
122980 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
122981 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
122982 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
122983 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
122984 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
122985 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
122986 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
122987 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
122988 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
122989 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
122990 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
122991 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
122992 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
122993 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
122994 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
122995 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
122996 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
122997 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
122998 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
122999 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
123000 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
123001 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
123002 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
123003 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
123004 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
123005 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
123006 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
123007 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
123008 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
123009 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
123010 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
123011 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
123012 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
123013 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
123014 +sel_write_access_51704 sel_write_access 3 51704 NULL
123015 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
123016 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
123017 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
123018 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
123019 +str_read_51731 str_read 4 51731 NULL
123020 +cm4040_read_51732 cm4040_read 3 51732 NULL
123021 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
123022 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
123023 +if_write_51756 if_write 3 51756 NULL
123024 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
123025 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
123026 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
123027 +ioread32_51847 ioread32 0 51847 NULL nohasharray
123028 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
123029 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
123030 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
123031 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
123032 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
123033 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
123034 +user_read_51881 user_read 3 51881 NULL
123035 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
123036 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
123037 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
123038 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
123039 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
123040 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
123041 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
123042 +get_clock_info_51952 get_clock_info 4 51952 NULL
123043 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
123044 +get_zone_51981 get_zone 0-1 51981 NULL
123045 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
123046 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
123047 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
123048 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
123049 +rdmalt_52022 rdmalt 0 52022 NULL
123050 +override_release_52032 override_release 2 52032 NULL
123051 +end_port_52042 end_port 0 52042 NULL
123052 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
123053 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
123054 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
123055 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
123056 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
123057 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
123058 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
123059 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
123060 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
123061 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
123062 +retry_count_read_52129 retry_count_read 3 52129 NULL
123063 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
123064 +sub_alloc_52140 sub_alloc 0 52140 NULL
123065 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
123066 +htable_size_52148 htable_size 0-1 52148 NULL
123067 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
123068 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
123069 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
123070 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
123071 +print_prefix_52176 print_prefix 0 52176 NULL
123072 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
123073 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
123074 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
123075 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
123076 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
123077 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
123078 +shrink_slab_52261 shrink_slab 2 52261 NULL
123079 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
123080 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
123081 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
123082 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
123083 +read_file_reset_52310 read_file_reset 3 52310 NULL
123084 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
123085 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
123086 +hwflags_read_52318 hwflags_read 3 52318 NULL
123087 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
123088 +hur_len_52339 hur_len 0 52339 NULL
123089 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
123090 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
123091 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
123092 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
123093 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
123094 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
123095 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
123096 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
123097 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
123098 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
123099 +delay_status_52431 delay_status 5 52431 NULL
123100 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
123101 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
123102 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
123103 +bt_alloc_52457 bt_alloc 2 52457 NULL
123104 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
123105 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
123106 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
123107 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
123108 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
123109 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
123110 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
123111 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
123112 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
123113 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
123114 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
123115 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
123116 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
123117 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
123118 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
123119 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
123120 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
123121 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
123122 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
123123 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
123124 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
123125 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
123126 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
123127 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
123128 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
123129 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
123130 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
123131 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
123132 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
123133 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
123134 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
123135 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
123136 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
123137 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
123138 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
123139 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
123140 +twlreg_write_52880 twlreg_write 3 52880 NULL
123141 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
123142 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
123143 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
123144 +copy_from_iter_bvec_52912 copy_from_iter_bvec 0-2 52912 NULL
123145 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
123146 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
123147 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
123148 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
123149 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
123150 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
123151 +num_node_state_52989 num_node_state 0 52989 NULL
123152 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
123153 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
123154 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
123155 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
123156 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
123157 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
123158 +fimc_get_alpha_mask_53057 fimc_get_alpha_mask 0 53057 NULL
123159 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
123160 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
123161 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
123162 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
123163 +ath10k_mac_create_53118 ath10k_mac_create 1 53118 NULL
123164 +verity_status_53120 verity_status 5 53120 NULL
123165 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
123166 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
123167 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
123168 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
123169 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
123170 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
123171 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
123172 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
123173 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
123174 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
123175 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
123176 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
123177 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
123178 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
123179 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
123180 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
123181 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
123182 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
123183 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
123184 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
123185 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
123186 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
123187 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
123188 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
123189 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
123190 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
123191 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
123192 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
123193 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
123194 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
123195 +check_acl_53512 check_acl 0 53512 NULL nohasharray
123196 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
123197 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
123198 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
123199 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
123200 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
123201 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
123202 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
123203 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
123204 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
123205 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
123206 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
123207 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
123208 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
123209 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
123210 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
123211 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
123212 +wdm_write_53735 wdm_write 3 53735 NULL
123213 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
123214 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
123215 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
123216 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
123217 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
123218 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
123219 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
123220 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
123221 +setup_data_read_53822 setup_data_read 3 53822 NULL
123222 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
123223 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
123224 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
123225 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
123226 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
123227 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
123228 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
123229 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
123230 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
123231 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
123232 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
123233 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
123234 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
123235 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
123236 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
123237 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
123238 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
123239 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
123240 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
123241 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
123242 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
123243 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
123244 +strn_len_54122 strn_len 0 54122 NULL
123245 +isku_receive_54130 isku_receive 4 54130 NULL
123246 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
123247 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
123248 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
123249 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
123250 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
123251 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
123252 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
123253 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
123254 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
123255 +reada_add_block_54247 reada_add_block 2 54247 NULL
123256 +write_file_spec_scan_ctl_54248 write_file_spec_scan_ctl 3 54248 NULL
123257 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
123258 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
123259 +audio_write_54261 audio_write 4 54261 NULL nohasharray
123260 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
123261 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
123262 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
123263 +sizeof_long_54276 sizeof_long 0 54276 NULL
123264 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
123265 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
123266 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
123267 +sprintf_54306 sprintf 0 54306 NULL
123268 +path_setxattr_54308 path_setxattr 4 54308 NULL
123269 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
123270 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
123271 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
123272 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
123273 +readlink_copy_54366 readlink_copy 2 54366 NULL
123274 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
123275 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
123276 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
123277 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
123278 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
123279 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL nohasharray
123280 +hash_mac4_expire_54392 hash_mac4_expire 4 54392 &iwl_dbgfs_power_save_status_read_54392
123281 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
123282 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
123283 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
123284 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
123285 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
123286 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
123287 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
123288 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
123289 +viacam_read_54526 viacam_read 3 54526 NULL
123290 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
123291 +setsockopt_54539 setsockopt 5 54539 NULL
123292 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
123293 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
123294 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
123295 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
123296 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
123297 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
123298 +port_fops_write_54627 port_fops_write 3 54627 NULL
123299 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
123300 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
123301 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
123302 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
123303 +simple_alloc_urb_54661 simple_alloc_urb 3 54661 NULL
123304 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
123305 +bus_add_device_54665 bus_add_device 0 54665 NULL
123306 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
123307 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
123308 +evm_read_key_54674 evm_read_key 3 54674 NULL
123309 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
123310 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
123311 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
123312 +kzalloc_54740 kzalloc 1 54740 NULL
123313 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
123314 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
123315 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
123316 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
123317 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
123318 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
123319 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
123320 +nfsd_write_54809 nfsd_write 6 54809 NULL
123321 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
123322 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
123323 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
123324 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
123325 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
123326 +write_rio_54837 write_rio 3 54837 NULL
123327 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
123328 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
123329 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
123330 +printer_read_54851 printer_read 3 54851 NULL
123331 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
123332 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
123333 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
123334 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
123335 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
123336 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
123337 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
123338 +add_port_54941 add_port 2 54941 NULL
123339 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
123340 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
123341 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
123342 +c4_add_card_54968 c4_add_card 3 54968 NULL
123343 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
123344 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123345 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123346 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123347 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123348 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123349 +read_dma_55086 read_dma 3 55086 NULL
123350 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123351 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123352 +filldir_55137 filldir 3 55137 NULL
123353 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123354 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123355 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123356 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123357 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123358 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123359 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123360 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123361 +mlx4_load_one_55213 mlx4_load_one 3 55213 NULL
123362 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123363 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123364 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123365 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123366 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123367 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123368 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123369 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123370 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123371 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123372 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123373 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123374 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123375 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123376 +vme_user_read_55338 vme_user_read 3 55338 NULL
123377 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123378 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123379 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123380 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123381 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123382 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123383 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123384 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123385 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123386 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123387 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123388 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123389 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123390 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123391 +ea_get_55522 ea_get 3-0 55522 NULL
123392 +buffer_size_55534 buffer_size 0 55534 NULL
123393 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123394 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123395 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123396 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123397 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123398 +add_partition_55588 add_partition 2 55588 NULL
123399 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123400 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123401 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123402 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123403 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123404 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123405 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123406 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123407 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123408 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123409 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123410 +get_info_55681 get_info 3 55681 NULL
123411 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123412 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123413 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123414 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123415 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123416 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123417 +set_local_name_55757 set_local_name 4 55757 NULL
123418 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123419 +strlen_55778 strlen 0 55778 NULL
123420 +set_spte_55783 set_spte 4-5 55783 NULL
123421 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123422 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123423 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123424 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123425 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123426 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123427 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123428 +hsc_write_55875 hsc_write 3 55875 NULL
123429 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123430 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123431 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123432 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123433 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123434 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123435 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123436 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123437 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123438 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123439 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123440 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123441 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123442 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123443 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123444 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123445 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123446 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123447 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123448 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123449 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123450 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123451 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123452 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123453 +fd_copyin_56247 fd_copyin 3 56247 NULL
123454 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123455 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123456 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123457 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123458 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123459 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123460 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123461 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123462 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123463 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123464 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123465 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123466 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123467 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123468 +dev_read_56369 dev_read 3 56369 NULL
123469 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123470 +lnet_ping_56378 lnet_ping 4 56378 NULL
123471 +write_gssp_56404 write_gssp 3 56404 NULL
123472 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123473 +store_msg_56417 store_msg 3 56417 NULL
123474 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123475 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL nohasharray
123476 +nvme_submit_cmd_56426 nvme_submit_cmd 0 56426 &l2cap_segment_le_sdu_56426
123477 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123478 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123479 +fl_create_56435 fl_create 5 56435 NULL
123480 +gnttab_map_56439 gnttab_map 2 56439 NULL
123481 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123482 +set_connectable_56458 set_connectable 4 56458 NULL
123483 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123484 +putused_user_56467 putused_user 3 56467 NULL
123485 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123486 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123487 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123488 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123489 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123490 +init_map_ip_56508 init_map_ip 5 56508 NULL
123491 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123492 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123493 +ip_options_get_56538 ip_options_get 4 56538 NULL
123494 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123495 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123496 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123497 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123498 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123499 +event_filter_write_56609 event_filter_write 3 56609 NULL
123500 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123501 +gather_array_56641 gather_array 3 56641 NULL
123502 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123503 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123504 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123505 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123506 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123507 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123508 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123509 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123510 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123511 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123512 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123513 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123514 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123515 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123516 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123517 +do_syslog_56807 do_syslog 3 56807 NULL
123518 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123519 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123520 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123521 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123522 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123523 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123524 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123525 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123526 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123527 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123528 +strcspn_56913 strcspn 0 56913 NULL
123529 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123530 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123531 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123532 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123533 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123534 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123535 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123536 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123537 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123538 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123539 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123540 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123541 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123542 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123543 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123544 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123545 +altera_get_note_57099 altera_get_note 6 57099 NULL
123546 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123547 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123548 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123549 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123550 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123551 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123552 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123553 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123554 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123555 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123556 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123557 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123558 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123559 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123560 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123561 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123562 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123563 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123564 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123565 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123566 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123567 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123568 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123569 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123570 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123571 +write_file_regval_57313 write_file_regval 3 57313 NULL
123572 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123573 +usblp_read_57342 usblp_read 3 57342 NULL
123574 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123575 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123576 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123577 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123578 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123579 +read_file_blob_57406 read_file_blob 3 57406 NULL
123580 +enclosure_register_57412 enclosure_register 3 57412 NULL
123581 +read_file_eeprom_57428 read_file_eeprom 3 57428 NULL
123582 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123583 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123584 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123585 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123586 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123587 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123588 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123589 +skb_headlen_57501 skb_headlen 0 57501 NULL
123590 +copy_in_user_57502 copy_in_user 3 57502 NULL
123591 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123592 +init_tag_map_57515 init_tag_map 3 57515 NULL
123593 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123594 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123595 +cmm_read_57520 cmm_read 3 57520 NULL
123596 +inode_permission_57531 inode_permission 0 57531 NULL
123597 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123598 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123599 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123600 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123601 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123602 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123603 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123604 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123605 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123606 +copy_to_iter_bvec_57604 copy_to_iter_bvec 0-2 57604 NULL
123607 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123608 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123609 +mem_read_57631 mem_read 3 57631 NULL
123610 +r3964_write_57662 r3964_write 4 57662 NULL
123611 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123612 +__lgwrite_57669 __lgwrite 4 57669 NULL
123613 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123614 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123615 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123616 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123617 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123618 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123619 +ld2_57794 ld2 0 57794 NULL
123620 +ivtv_read_57796 ivtv_read 3 57796 NULL
123621 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123622 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123623 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123624 +flash_read_57843 flash_read 3 57843 NULL
123625 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123626 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123627 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123628 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123629 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123630 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123631 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123632 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123633 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123634 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123635 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123636 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123637 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123638 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123639 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123640 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123641 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123642 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123643 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123644 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123645 +mce_async_out_58056 mce_async_out 3 58056 NULL
123646 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123647 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123648 +cm4040_write_58079 cm4040_write 3 58079 NULL
123649 +savemem_58129 savemem 3 58129 NULL
123650 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123651 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123652 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123653 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123654 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123655 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123656 +read_file_debug_58256 read_file_debug 3 58256 NULL
123657 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123658 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123659 +profile_load_58267 profile_load 3 58267 NULL
123660 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123661 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123662 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123663 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123664 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123665 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123666 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123667 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123668 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123669 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123670 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123671 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123672 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123673 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123674 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123675 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123676 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123677 +capabilities_read_58457 capabilities_read 3 58457 NULL
123678 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123679 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123680 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123681 +nv_rd08_58472 nv_rd08 0 58472 NULL
123682 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123683 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123684 +dw_spi_show_regs_58486 dw_spi_show_regs 3 58486 NULL
123685 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123686 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123687 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123688 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123689 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123690 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123691 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123692 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123693 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123694 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123695 +xip_file_read_58592 xip_file_read 3 58592 NULL
123696 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123697 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123698 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123699 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123700 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123701 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123702 +find_zero_58685 find_zero 0-1 58685 NULL
123703 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123704 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123705 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123706 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123707 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123708 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123709 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123710 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123711 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123712 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123713 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123714 +ep_read_58813 ep_read 3 58813 NULL
123715 +command_write_58841 command_write 3 58841 NULL
123716 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123717 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123718 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123719 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123720 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123721 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123722 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123723 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123724 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123725 +init_list_set_59005 init_list_set 3 59005 NULL
123726 +ep_write_59008 ep_write 3 59008 NULL
123727 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123728 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123729 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123730 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123731 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123732 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123733 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123734 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123735 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123736 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123737 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123738 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123739 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123740 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123741 +ksize_59176 ksize 0 59176 NULL
123742 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123743 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123744 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123745 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123746 +dt3155_read_59226 dt3155_read 3 59226 NULL
123747 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123748 +nla_len_59258 nla_len 0 59258 NULL
123749 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123750 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123751 +fd_copyout_59323 fd_copyout 3 59323 NULL
123752 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123753 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123754 +__map_request_59350 __map_request 0 59350 NULL
123755 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123756 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123757 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123758 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123759 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123760 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123761 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123762 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123763 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123764 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123765 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123766 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123767 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123768 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123769 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL
123770 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123771 +tunables_write_59563 tunables_write 3 59563 NULL
123772 +bio_split_59564 bio_split 2 59564 NULL
123773 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123774 +write_pbl_59583 write_pbl 4 59583 NULL
123775 +memdup_user_59590 memdup_user 2 59590 NULL
123776 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123777 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123778 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123779 +mtrr_write_59622 mtrr_write 3 59622 NULL
123780 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123781 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123782 +hidraw_read_59650 hidraw_read 3 59650 NULL
123783 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123784 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123785 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123786 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123787 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123788 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123789 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123790 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123791 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123792 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123793 +strnlen_59746 strnlen 0 59746 NULL
123794 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123795 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123796 +venus_remove_59781 venus_remove 4 59781 NULL
123797 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123798 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123799 +ipw_write_59807 ipw_write 3 59807 NULL
123800 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123801 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123802 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123803 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123804 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123805 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123806 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123807 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123808 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123809 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123810 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123811 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123812 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123813 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123814 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123815 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123816 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123817 +copy_items_60009 copy_items 7 60009 NULL
123818 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123819 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123820 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123821 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123822 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123823 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123824 +vcs_size_60050 vcs_size 0 60050 NULL
123825 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123826 +compat_writev_60063 compat_writev 3 60063 NULL
123827 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123828 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123829 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123830 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123831 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123832 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123833 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123834 +pcpu_need_to_extend_60133 pcpu_need_to_extend 0 60133 NULL
123835 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123836 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123837 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123838 +init_state_60165 init_state 2 60165 NULL
123839 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123840 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123841 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123842 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL nohasharray
123843 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 &rx_rx_tkip_replays_read_60193
123844 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123845 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123846 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123847 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123848 +printer_write_60276 printer_write 3 60276 NULL
123849 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123850 +getDataLength_60301 getDataLength 0 60301 NULL
123851 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123852 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123853 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123854 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123855 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123856 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123857 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123858 +driver_names_read_60399 driver_names_read 3 60399 NULL
123859 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123860 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123861 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123862 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123863 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123864 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123865 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123866 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123867 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123868 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123869 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123870 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123871 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123872 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123873 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123874 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123875 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123876 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123877 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123878 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123879 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123880 +raid_status_60755 raid_status 5 60755 NULL
123881 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123882 +opticon_write_60775 opticon_write 4 60775 NULL
123883 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123884 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123885 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123886 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123887 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123888 +generic_writepages_60871 generic_writepages 0 60871 NULL
123889 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123890 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123891 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123892 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123893 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123894 +pti_char_write_60960 pti_char_write 3 60960 NULL
123895 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123896 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123897 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123898 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123899 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123900 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123901 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123902 +read_file_ackto_61037 read_file_ackto 3 61037 NULL
123903 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123904 +symtab_init_61050 symtab_init 2 61050 NULL
123905 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
123906 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
123907 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
123908 +get_derived_key_61100 get_derived_key 4 61100 NULL
123909 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
123910 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
123911 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
123912 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
123913 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
123914 +pair_device_61175 pair_device 4 61175 NULL nohasharray
123915 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
123916 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
123917 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
123918 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
123919 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
123920 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
123921 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
123922 +kvm_age_hva_61267 kvm_age_hva 2-3 61267 NULL
123923 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
123924 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
123925 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
123926 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
123927 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
123928 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
123929 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
123930 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
123931 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
123932 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
123933 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
123934 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
123935 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
123936 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
123937 +wil_write_file_recovery_61354 wil_write_file_recovery 3 61354 NULL
123938 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
123939 +system_enable_write_61396 system_enable_write 3 61396 NULL
123940 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
123941 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
123942 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
123943 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
123944 +erst_errno_61526 erst_errno 0 61526 NULL
123945 +proc_write_device_61541 proc_write_device 3 61541 NULL
123946 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
123947 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
123948 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
123949 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
123950 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
123951 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
123952 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
123953 +seq_open_private_61589 seq_open_private 3 61589 NULL
123954 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
123955 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
123956 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
123957 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
123958 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
123959 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
123960 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
123961 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
123962 +resize_stripes_61650 resize_stripes 2 61650 NULL
123963 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
123964 +insert_one_name_61668 insert_one_name 7 61668 NULL
123965 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
123966 +lock_loop_61681 lock_loop 1 61681 NULL
123967 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
123968 +filter_read_61692 filter_read 3 61692 NULL
123969 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
123970 +iov_length_61716 iov_length 0 61716 NULL
123971 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
123972 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
123973 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
123974 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
123975 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
123976 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
123977 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
123978 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
123979 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
123980 +__skb_flow_dissect_61855 __skb_flow_dissect 5 61855 NULL
123981 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
123982 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
123983 +get_fw_name_61874 get_fw_name 3 61874 NULL
123984 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
123985 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
123986 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
123987 +kernfs_name_61910 kernfs_name 3 61910 NULL
123988 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
123989 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
123990 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
123991 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
123992 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
123993 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
123994 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
123995 +fix_read_error_61965 fix_read_error 4 61965 NULL
123996 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
123997 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
123998 +cow_file_range_61979 cow_file_range 3 61979 NULL
123999 +dequeue_event_62000 dequeue_event 3 62000 NULL
124000 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
124001 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
124002 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
124003 +SYSC_select_62024 SYSC_select 1 62024 NULL
124004 +comedi_write_array_to_buffer_62032 comedi_write_array_to_buffer 3 62032 NULL
124005 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
124006 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
124007 +do_pselect_62061 do_pselect 1 62061 NULL
124008 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
124009 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
124010 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
124011 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
124012 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
124013 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
124014 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
124015 +ql_status_62135 ql_status 5 62135 NULL nohasharray
124016 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
124017 +video_usercopy_62151 video_usercopy 2 62151 NULL
124018 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
124019 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
124020 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
124021 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
124022 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
124023 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
124024 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
124025 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
124026 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
124027 +get_random_int_62279 get_random_int 0 62279 NULL
124028 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
124029 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
124030 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
124031 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
124032 +subseq_list_62332 subseq_list 3-0 62332 NULL
124033 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
124034 +flash_write_62354 flash_write 3 62354 NULL
124035 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
124036 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
124037 +altera_irscan_62396 altera_irscan 2 62396 NULL
124038 +set_ssp_62411 set_ssp 4 62411 NULL
124039 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
124040 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
124041 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
124042 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
124043 +debugfs_read_62535 debugfs_read 3 62535 NULL
124044 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
124045 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
124046 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
124047 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
124048 +get_subdir_62581 get_subdir 3 62581 NULL
124049 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
124050 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
124051 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
124052 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
124053 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
124054 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
124055 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
124056 +rdm_62719 rdm 0 62719 NULL
124057 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
124058 +key_replays_read_62746 key_replays_read 3 62746 NULL
124059 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
124060 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
124061 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
124062 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
124063 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
124064 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
124065 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
124066 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
124067 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
124068 +__add_action_62798 __add_action 4 62798 NULL
124069 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
124070 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
124071 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
124072 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
124073 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
124074 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
124075 +aoechr_write_62883 aoechr_write 3 62883 NULL
124076 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
124077 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
124078 +getdqbuf_62908 getdqbuf 1 62908 NULL
124079 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
124080 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
124081 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
124082 +hwdep_read_62992 hwdep_read 3 62992 NULL
124083 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
124084 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
124085 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
124086 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
124087 +unlink1_63059 unlink1 3 63059 NULL
124088 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
124089 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
124090 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
124091 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
124092 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
124093 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
124094 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
124095 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
124096 +vme_master_read_63221 vme_master_read 0 63221 NULL
124097 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
124098 +ptp_read_63251 ptp_read 4 63251 NULL
124099 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
124100 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
124101 +raid5_resize_63306 raid5_resize 2 63306 NULL
124102 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
124103 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
124104 +proc_info_read_63344 proc_info_read 3 63344 NULL
124105 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
124106 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
124107 +idmouse_read_63374 idmouse_read 3 63374 NULL
124108 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
124109 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
124110 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
124111 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
124112 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
124113 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
124114 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
124115 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
124116 +read_kcore_63488 read_kcore 3 63488 NULL
124117 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
124118 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
124119 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
124120 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
124121 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
124122 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
124123 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
124124 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
124125 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
124126 +write_debug_level_63613 write_debug_level 3 63613 NULL
124127 +__spi_validate_63618 __spi_validate 0 63618 NULL
124128 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
124129 +hid_report_len_63637 hid_report_len 0 63637 NULL
124130 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
124131 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
124132 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
124133 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
124134 +vbi_read_63673 vbi_read 3 63673 NULL
124135 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
124136 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
124137 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
124138 +ntb_debugfs_read_63728 ntb_debugfs_read 3 63728 NULL
124139 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
124140 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
124141 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
124142 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
124143 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
124144 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
124145 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
124146 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
124147 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
124148 +sel_write_load_63830 sel_write_load 3 63830 NULL
124149 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
124150 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
124151 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
124152 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
124153 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
124154 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
124155 +__team_options_register_63941 __team_options_register 3 63941 NULL
124156 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
124157 +set_bredr_63975 set_bredr 4 63975 NULL
124158 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
124159 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
124160 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
124161 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
124162 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
124163 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
124164 +nl80211_send_rx_assoc_64040 nl80211_send_rx_assoc 4 64040 NULL
124165 +__sock_create_64069 __sock_create 0 64069 NULL
124166 +get_u8_64076 get_u8 0 64076 NULL
124167 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
124168 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
124169 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
124170 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
124171 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
124172 +to_bytes_64103 to_bytes 0-1 64103 NULL
124173 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
124174 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
124175 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
124176 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
124177 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
124178 +init_bch_64130 init_bch 1-2 64130 NULL
124179 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
124180 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
124181 +number_of_tds_64156 number_of_tds 0 64156 NULL
124182 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
124183 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
124184 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
124185 +read_pulse_64227 read_pulse 0-3 64227 NULL
124186 +ea_len_64229 ea_len 0 64229 NULL
124187 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
124188 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
124189 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
124190 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
124191 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
124192 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
124193 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
124194 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
124195 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
124196 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
124197 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
124198 +ts_write_64336 ts_write 3 64336 NULL
124199 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
124200 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
124201 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
124202 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
124203 +reg_create_64372 reg_create 5 64372 NULL nohasharray
124204 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
124205 +ilo_write_64378 ilo_write 3 64378 NULL
124206 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
124207 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
124208 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
124209 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
124210 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
124211 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
124212 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
124213 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
124214 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
124215 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
124216 +single_open_size_64483 single_open_size 4 64483 NULL
124217 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
124218 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
124219 +remove_uuid_64505 remove_uuid 4 64505 NULL
124220 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
124221 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
124222 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
124223 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
124224 +SyS_bind_64544 SyS_bind 3 64544 NULL
124225 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
124226 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
124227 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
124228 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
124229 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
124230 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
124231 +do_erase_64574 do_erase 4 64574 NULL
124232 +fanotify_write_64623 fanotify_write 3 64623 NULL
124233 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
124234 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
124235 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
124236 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
124237 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
124238 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
124239 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
124240 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
124241 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
124242 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
124243 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
124244 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
124245 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
124246 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
124247 +hwdep_write_64776 hwdep_write 3 64776 NULL
124248 +message_for_md_64777 message_for_md 5 64777 NULL
124249 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
124250 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
124251 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
124252 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
124253 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
124254 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
124255 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
124256 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
124257 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
124258 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
124259 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
124260 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
124261 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
124262 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
124263 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
124264 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
124265 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
124266 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
124267 +insert_dent_65034 insert_dent 7 65034 NULL
124268 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
124269 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
124270 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
124271 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
124272 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
124273 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
124274 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
124275 +usbtest_alloc_urb_65115 usbtest_alloc_urb 3-5 65115 NULL
124276 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
124277 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
124278 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
124279 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
124280 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
124281 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
124282 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
124283 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
124284 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
124285 +get_var_len_65304 get_var_len 0 65304 NULL
124286 +unpack_array_65318 unpack_array 0 65318 NULL
124287 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
124288 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
124289 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
124290 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
124291 +SyS_writev_65372 SyS_writev 3 65372 NULL
124292 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
124293 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
124294 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
124295 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
124296 +device_add_groups_65423 device_add_groups 0 65423 NULL
124297 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
124298 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
124299 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
124300 +clear_user_65470 clear_user 2 65470 NULL
124301 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
124302 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
124303 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
124304 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
124305 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124306 new file mode 100644
124307 index 0000000..560cd7b
124308 --- /dev/null
124309 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124310 @@ -0,0 +1,92 @@
124311 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
124312 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
124313 +mappedread_2627 mappedread 2 2627 NULL
124314 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
124315 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
124316 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
124317 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
124318 +dmu_write_6048 dmu_write 4-3 6048 NULL
124319 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
124320 +update_pages_6225 update_pages 2-3 6225 NULL
124321 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
124322 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
124323 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
124324 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
124325 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
124326 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
124327 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
124328 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
124329 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
124330 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
124331 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
124332 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
124333 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
124334 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
124335 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
124336 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
124337 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
124338 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
124339 +uiocopy_18680 uiocopy 2 18680 NULL
124340 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
124341 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
124342 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
124343 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
124344 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
124345 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
124346 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
124347 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
124348 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
124349 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
124350 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
124351 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
124352 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
124353 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
124354 +splat_write_30943 splat_write 3 30943 NULL
124355 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
124356 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
124357 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
124358 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
124359 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
124360 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
124361 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
124362 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
124363 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
124364 +copyinstr_36980 copyinstr 3 36980 NULL
124365 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
124366 +splat_read_38116 splat_read 3 38116 NULL
124367 +sa_setup_38756 sa_setup 4 38756 NULL
124368 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
124369 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
124370 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
124371 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
124372 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
124373 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124374 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124375 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124376 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124377 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124378 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124379 +kcopy_write_43683 kcopy_write 3 43683 NULL
124380 +uiomove_44355 uiomove 2 44355 NULL
124381 +dmu_read_44418 dmu_read 4-3 44418 NULL
124382 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124383 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124384 +copyin_45945 copyin 3 45945 NULL
124385 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124386 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124387 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124388 +spa_history_write_49650 spa_history_write 3 49650 NULL
124389 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124390 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124391 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124392 +copyout_51409 copyout 3 51409 NULL
124393 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124394 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124395 +get_nvlist_56685 get_nvlist 2 56685 NULL
124396 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124397 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124398 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124399 +zpios_write_61823 zpios_write 3 61823 NULL
124400 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124401 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124402 +zpios_read_64734 zpios_read 3 64734 NULL
124403 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124404 new file mode 100644
124405 index 0000000..95f7abd
124406 --- /dev/null
124407 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124408 @@ -0,0 +1,259 @@
124409 +/*
124410 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124411 + * Licensed under the GPL v2, or (at your option) v3
124412 + *
124413 + * Homepage:
124414 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124415 + *
124416 + * Documentation:
124417 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124418 + *
124419 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124420 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124421 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124422 + *
124423 + * Usage:
124424 + * $ make
124425 + * $ make run
124426 + */
124427 +
124428 +#include "gcc-common.h"
124429 +#include "size_overflow.h"
124430 +
124431 +int plugin_is_GPL_compatible;
124432 +
124433 +tree report_size_overflow_decl;
124434 +
124435 +tree size_overflow_type_HI;
124436 +tree size_overflow_type_SI;
124437 +tree size_overflow_type_DI;
124438 +tree size_overflow_type_TI;
124439 +
124440 +static struct plugin_info size_overflow_plugin_info = {
124441 + .version = "20140725",
124442 + .help = "no-size-overflow\tturn off size overflow checking\n",
124443 +};
124444 +
124445 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124446 +{
124447 + unsigned int arg_count;
124448 + enum tree_code code = TREE_CODE(*node);
124449 +
124450 + switch (code) {
124451 + case FUNCTION_DECL:
124452 + arg_count = type_num_arguments(TREE_TYPE(*node));
124453 + break;
124454 + case FUNCTION_TYPE:
124455 + case METHOD_TYPE:
124456 + arg_count = type_num_arguments(*node);
124457 + break;
124458 + default:
124459 + *no_add_attrs = true;
124460 + error("%s: %qE attribute only applies to functions", __func__, name);
124461 + return NULL_TREE;
124462 + }
124463 +
124464 + for (; args; args = TREE_CHAIN(args)) {
124465 + tree position = TREE_VALUE(args);
124466 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124467 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124468 + *no_add_attrs = true;
124469 + }
124470 + }
124471 + return NULL_TREE;
124472 +}
124473 +
124474 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124475 +{
124476 + unsigned int arg_count;
124477 + enum tree_code code = TREE_CODE(*node);
124478 +
124479 + switch (code) {
124480 + case FUNCTION_DECL:
124481 + arg_count = type_num_arguments(TREE_TYPE(*node));
124482 + break;
124483 + case FUNCTION_TYPE:
124484 + case METHOD_TYPE:
124485 + arg_count = type_num_arguments(*node);
124486 + break;
124487 + case FIELD_DECL:
124488 + return NULL_TREE;
124489 + default:
124490 + *no_add_attrs = true;
124491 + error("%qE attribute only applies to functions", name);
124492 + return NULL_TREE;
124493 + }
124494 +
124495 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124496 + return NULL_TREE;
124497 +
124498 + for (; args; args = TREE_CHAIN(args)) {
124499 + tree position = TREE_VALUE(args);
124500 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124501 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124502 + *no_add_attrs = true;
124503 + }
124504 + }
124505 + return NULL_TREE;
124506 +}
124507 +
124508 +static struct attribute_spec size_overflow_attr = {
124509 + .name = "size_overflow",
124510 + .min_length = 1,
124511 + .max_length = -1,
124512 + .decl_required = true,
124513 + .type_required = false,
124514 + .function_type_required = false,
124515 + .handler = handle_size_overflow_attribute,
124516 +#if BUILDING_GCC_VERSION >= 4007
124517 + .affects_type_identity = false
124518 +#endif
124519 +};
124520 +
124521 +static struct attribute_spec intentional_overflow_attr = {
124522 + .name = "intentional_overflow",
124523 + .min_length = 1,
124524 + .max_length = -1,
124525 + .decl_required = true,
124526 + .type_required = false,
124527 + .function_type_required = false,
124528 + .handler = handle_intentional_overflow_attribute,
124529 +#if BUILDING_GCC_VERSION >= 4007
124530 + .affects_type_identity = false
124531 +#endif
124532 +};
124533 +
124534 +static void register_attributes(void __unused *event_data, void __unused *data)
124535 +{
124536 + register_attribute(&size_overflow_attr);
124537 + register_attribute(&intentional_overflow_attr);
124538 +}
124539 +
124540 +static tree create_typedef(tree type, const char* ident)
124541 +{
124542 + tree new_type, decl;
124543 +
124544 + new_type = build_variant_type_copy(type);
124545 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124546 + DECL_ORIGINAL_TYPE(decl) = type;
124547 + TYPE_NAME(new_type) = decl;
124548 + return new_type;
124549 +}
124550 +
124551 +// Create the noreturn report_size_overflow() function decl.
124552 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124553 +{
124554 + tree const_char_ptr_type_node;
124555 + tree fntype;
124556 +
124557 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124558 +
124559 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124560 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124561 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124562 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124563 +
124564 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124565 + fntype = build_function_type_list(void_type_node,
124566 + const_char_ptr_type_node,
124567 + unsigned_type_node,
124568 + const_char_ptr_type_node,
124569 + const_char_ptr_type_node,
124570 + NULL_TREE);
124571 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124572 +
124573 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124574 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124575 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124576 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124577 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124578 +}
124579 +
124580 +
124581 +extern struct gimple_opt_pass pass_dce;
124582 +
124583 +static struct opt_pass *make_dce_pass(void)
124584 +{
124585 +#if BUILDING_GCC_VERSION >= 4009
124586 + return make_pass_dce(g);
124587 +#else
124588 + return &pass_dce.pass;
124589 +#endif
124590 +}
124591 +
124592 +
124593 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124594 +{
124595 + int i;
124596 + const char * const plugin_name = plugin_info->base_name;
124597 + const int argc = plugin_info->argc;
124598 + const struct plugin_argument * const argv = plugin_info->argv;
124599 + bool enable = true;
124600 + struct register_pass_info insert_size_overflow_asm_pass_info;
124601 + struct register_pass_info __unused dump_before_pass_info;
124602 + struct register_pass_info __unused dump_after_pass_info;
124603 + struct register_pass_info insert_size_overflow_check_info;
124604 + struct register_pass_info dce_pass_info;
124605 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124606 + {
124607 + .base = &report_size_overflow_decl,
124608 + .nelt = 1,
124609 + .stride = sizeof(report_size_overflow_decl),
124610 + .cb = &gt_ggc_mx_tree_node,
124611 + .pchw = &gt_pch_nx_tree_node
124612 + },
124613 + LAST_GGC_ROOT_TAB
124614 + };
124615 +
124616 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124617 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124618 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124619 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124620 +
124621 + dump_before_pass_info.pass = make_dump_pass();
124622 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124623 + dump_before_pass_info.ref_pass_instance_number = 1;
124624 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124625 +
124626 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124627 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124628 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124629 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124630 +
124631 + dump_after_pass_info.pass = make_dump_pass();
124632 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124633 + dump_after_pass_info.ref_pass_instance_number = 1;
124634 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124635 +
124636 + dce_pass_info.pass = make_dce_pass();
124637 + dce_pass_info.reference_pass_name = "vrp";
124638 + dce_pass_info.ref_pass_instance_number = 1;
124639 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124640 +
124641 + if (!plugin_default_version_check(version, &gcc_version)) {
124642 + error(G_("incompatible gcc/plugin versions"));
124643 + return 1;
124644 + }
124645 +
124646 + for (i = 0; i < argc; ++i) {
124647 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124648 + enable = false;
124649 + continue;
124650 + }
124651 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124652 + }
124653 +
124654 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124655 + if (enable) {
124656 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124657 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124658 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124659 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124660 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124661 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124662 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124663 + }
124664 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124665 +
124666 + return 0;
124667 +}
124668 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124669 new file mode 100644
124670 index 0000000..0888f6c
124671 --- /dev/null
124672 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124673 @@ -0,0 +1,364 @@
124674 +/*
124675 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124676 + * Licensed under the GPL v2, or (at your option) v3
124677 + *
124678 + * Homepage:
124679 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124680 + *
124681 + * Documentation:
124682 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124683 + *
124684 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124685 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124686 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124687 + *
124688 + * Usage:
124689 + * $ make
124690 + * $ make run
124691 + */
124692 +
124693 +#include "gcc-common.h"
124694 +#include "size_overflow.h"
124695 +
124696 +#include "size_overflow_hash.h"
124697 +#include "size_overflow_hash_aux.h"
124698 +
124699 +#define CODES_LIMIT 32
124700 +
124701 +static unsigned char get_tree_code(const_tree type)
124702 +{
124703 + switch (TREE_CODE(type)) {
124704 + case ARRAY_TYPE:
124705 + return 0;
124706 + case BOOLEAN_TYPE:
124707 + return 1;
124708 + case ENUMERAL_TYPE:
124709 + return 2;
124710 + case FUNCTION_TYPE:
124711 + return 3;
124712 + case INTEGER_TYPE:
124713 + return 4;
124714 + case POINTER_TYPE:
124715 + return 5;
124716 + case RECORD_TYPE:
124717 + return 6;
124718 + case UNION_TYPE:
124719 + return 7;
124720 + case VOID_TYPE:
124721 + return 8;
124722 + case REAL_TYPE:
124723 + return 9;
124724 + case VECTOR_TYPE:
124725 + return 10;
124726 + case REFERENCE_TYPE:
124727 + return 11;
124728 + case OFFSET_TYPE:
124729 + return 12;
124730 + case COMPLEX_TYPE:
124731 + return 13;
124732 + default:
124733 + debug_tree((tree)type);
124734 + gcc_unreachable();
124735 + }
124736 +}
124737 +
124738 +struct function_hash {
124739 + size_t tree_codes_len;
124740 + unsigned char tree_codes[CODES_LIMIT];
124741 + const_tree fndecl;
124742 + unsigned int hash;
124743 +};
124744 +
124745 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124746 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124747 +{
124748 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124749 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124750 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124751 +
124752 + unsigned int m = 0x57559429;
124753 + unsigned int n = 0x5052acdb;
124754 + const unsigned int *key4 = (const unsigned int *)key;
124755 + unsigned int h = len;
124756 + unsigned int k = len + seed + n;
124757 + unsigned long long p;
124758 +
124759 + while (len >= 8) {
124760 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124761 + len -= 8;
124762 + }
124763 + if (len >= 4) {
124764 + cwmixb(key4[0]) key4 += 1;
124765 + len -= 4;
124766 + }
124767 + if (len)
124768 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124769 + cwmixb(h ^ (k + n));
124770 + return k ^ h;
124771 +
124772 +#undef cwfold
124773 +#undef cwmixa
124774 +#undef cwmixb
124775 +}
124776 +
124777 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124778 +{
124779 + unsigned int fn, codes, seed = 0;
124780 +
124781 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124782 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124783 +
124784 + fn_hash_data->hash = fn ^ codes;
124785 +}
124786 +
124787 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124788 +{
124789 + gcc_assert(type != NULL_TREE);
124790 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124791 +
124792 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124793 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124794 + fn_hash_data->tree_codes_len++;
124795 + type = TREE_TYPE(type);
124796 + }
124797 +}
124798 +
124799 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124800 +{
124801 + const_tree result;
124802 +
124803 + gcc_assert(node != NULL_TREE);
124804 +
124805 + if (DECL_P(node)) {
124806 + result = DECL_RESULT(node);
124807 + if (result != NULL_TREE)
124808 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124809 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124810 + }
124811 +
124812 + gcc_assert(TYPE_P(node));
124813 +
124814 + if (TREE_CODE(node) == FUNCTION_TYPE)
124815 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124816 +
124817 + return set_node_codes(node, fn_hash_data);
124818 +}
124819 +
124820 +static void set_function_codes(struct function_hash *fn_hash_data)
124821 +{
124822 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124823 + enum tree_code code = TREE_CODE(type);
124824 +
124825 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124826 +
124827 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124828 +
124829 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124830 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124831 +}
124832 +
124833 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124834 +{
124835 + while (entry) {
124836 + if (!strcmp(entry->name, func_name))
124837 + return entry;
124838 + entry = entry->next;
124839 + }
124840 + return NULL;
124841 +}
124842 +
124843 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124844 +{
124845 + const struct size_overflow_hash *entry;
124846 + struct function_hash fn_hash_data;
124847 + const char *func_name;
124848 +
124849 + // skip builtins __builtin_constant_p
124850 + if (DECL_BUILT_IN(fndecl))
124851 + return NULL;
124852 +
124853 + fn_hash_data.fndecl = fndecl;
124854 + fn_hash_data.tree_codes_len = 0;
124855 +
124856 + set_function_codes(&fn_hash_data);
124857 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124858 +
124859 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124860 + set_hash(func_name, &fn_hash_data);
124861 +
124862 + entry = size_overflow_hash[fn_hash_data.hash];
124863 + entry = get_proper_hash_chain(entry, func_name);
124864 + if (entry)
124865 + return entry;
124866 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124867 + return get_proper_hash_chain(entry, func_name);
124868 +}
124869 +
124870 +static void print_missing_msg(const_tree func, unsigned int argnum)
124871 +{
124872 + location_t loc;
124873 + const char *curfunc;
124874 + struct function_hash fn_hash_data;
124875 +
124876 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124877 + fn_hash_data.tree_codes_len = 0;
124878 +
124879 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124880 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124881 +
124882 + set_function_codes(&fn_hash_data);
124883 + set_hash(curfunc, &fn_hash_data);
124884 +
124885 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124886 +}
124887 +
124888 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124889 +{
124890 + tree var;
124891 + unsigned int argnum = 1;
124892 +
124893 + if (TREE_CODE(arg) == SSA_NAME)
124894 + arg = SSA_NAME_VAR(arg);
124895 +
124896 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124897 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124898 + continue;
124899 + if (!skip_types(var))
124900 + return argnum;
124901 + }
124902 +
124903 + return CANNOT_FIND_ARG;
124904 +}
124905 +
124906 +static const char *get_asm_string(const_gimple stmt)
124907 +{
124908 + if (!stmt)
124909 + return NULL;
124910 + if (gimple_code(stmt) != GIMPLE_ASM)
124911 + return NULL;
124912 +
124913 + return gimple_asm_string(stmt);
124914 +}
124915 +
124916 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
124917 +{
124918 + const char *str;
124919 +
124920 + str = get_asm_string(stmt);
124921 + if (!str)
124922 + return false;
124923 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
124924 +}
124925 +
124926 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
124927 +{
124928 + const char *str;
124929 +
124930 + str = get_asm_string(stmt);
124931 + if (!str)
124932 + return false;
124933 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
124934 +}
124935 +
124936 +bool is_size_overflow_asm(const_gimple stmt)
124937 +{
124938 + const char *str;
124939 +
124940 + str = get_asm_string(stmt);
124941 + if (!str)
124942 + return false;
124943 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
124944 +}
124945 +
124946 +bool is_a_return_check(const_tree node)
124947 +{
124948 + if (TREE_CODE(node) == FUNCTION_DECL)
124949 + return true;
124950 +
124951 + gcc_assert(TREE_CODE(node) == PARM_DECL);
124952 + return false;
124953 +}
124954 +
124955 +// Get the argnum of a function decl, if node is a return then the argnum is 0
124956 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
124957 +{
124958 + if (is_a_return_check(node))
124959 + return 0;
124960 + else
124961 + return find_arg_number_tree(node, orig_fndecl);
124962 +}
124963 +
124964 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
124965 +{
124966 + const struct size_overflow_hash *hash;
124967 + unsigned int new_argnum;
124968 + tree arg;
124969 + const_tree origarg;
124970 +
124971 + if (argnum == 0)
124972 + return argnum;
124973 +
124974 + hash = get_function_hash(fndecl);
124975 + if (hash && hash->param & (1U << argnum))
124976 + return argnum;
124977 +
124978 + if (DECL_EXTERNAL(fndecl))
124979 + return argnum;
124980 +
124981 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
124982 + argnum--;
124983 + while (origarg && argnum) {
124984 + origarg = TREE_CHAIN(origarg);
124985 + argnum--;
124986 + }
124987 + gcc_assert(argnum == 0);
124988 + gcc_assert(origarg != NULL_TREE);
124989 +
124990 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
124991 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
124992 + return new_argnum;
124993 +
124994 + return CANNOT_FIND_ARG;
124995 +}
124996 +
124997 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
124998 +{
124999 + const struct size_overflow_hash *hash;
125000 +
125001 + hash = get_function_hash(fndecl);
125002 + if (hash && (hash->param & (1U << num)))
125003 + return true;
125004 + return false;
125005 +}
125006 +
125007 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
125008 + * If the function is missing everywhere then print the missing message into stderr.
125009 + */
125010 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
125011 +{
125012 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
125013 +#if BUILDING_GCC_VERSION >= 4008
125014 + case BUILT_IN_BSWAP16:
125015 +#endif
125016 + case BUILT_IN_BSWAP32:
125017 + case BUILT_IN_BSWAP64:
125018 + case BUILT_IN_EXPECT:
125019 + case BUILT_IN_MEMCMP:
125020 + return false;
125021 + default:
125022 + break;
125023 + }
125024 +
125025 + // skip test.c
125026 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
125027 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
125028 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
125029 + }
125030 +
125031 + if (is_in_hash_table(orig_fndecl, num))
125032 + return false;
125033 +
125034 + print_missing_msg(orig_fndecl, num);
125035 + return true;
125036 +}
125037 +
125038 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
125039 new file mode 100644
125040 index 0000000..924652b
125041 --- /dev/null
125042 +++ b/tools/gcc/stackleak_plugin.c
125043 @@ -0,0 +1,395 @@
125044 +/*
125045 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
125046 + * Licensed under the GPL v2
125047 + *
125048 + * Note: the choice of the license means that the compilation process is
125049 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125050 + * but for the kernel it doesn't matter since it doesn't link against
125051 + * any of the gcc libraries
125052 + *
125053 + * gcc plugin to help implement various PaX features
125054 + *
125055 + * - track lowest stack pointer
125056 + *
125057 + * TODO:
125058 + * - initialize all local variables
125059 + *
125060 + * BUGS:
125061 + * - none known
125062 + */
125063 +
125064 +#include "gcc-common.h"
125065 +
125066 +int plugin_is_GPL_compatible;
125067 +
125068 +static int track_frame_size = -1;
125069 +static const char track_function[] = "pax_track_stack";
125070 +static const char check_function[] = "pax_check_alloca";
125071 +static tree track_function_decl, check_function_decl;
125072 +static bool init_locals;
125073 +
125074 +static struct plugin_info stackleak_plugin_info = {
125075 + .version = "201408011900",
125076 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
125077 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
125078 +};
125079 +
125080 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
125081 +{
125082 + gimple check_alloca;
125083 + tree alloca_size;
125084 +
125085 + // insert call to void pax_check_alloca(unsigned long size)
125086 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
125087 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
125088 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
125089 +}
125090 +
125091 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
125092 +{
125093 + gimple track_stack;
125094 +
125095 + // insert call to void pax_track_stack(void)
125096 + track_stack = gimple_build_call(track_function_decl, 0);
125097 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
125098 +}
125099 +
125100 +static bool is_alloca(gimple stmt)
125101 +{
125102 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
125103 + return true;
125104 +
125105 +#if BUILDING_GCC_VERSION >= 4007
125106 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
125107 + return true;
125108 +#endif
125109 +
125110 + return false;
125111 +}
125112 +
125113 +static unsigned int execute_stackleak_tree_instrument(void)
125114 +{
125115 + basic_block bb, entry_bb;
125116 + bool prologue_instrumented = false, is_leaf = true;
125117 +
125118 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
125119 +
125120 + // 1. loop through BBs and GIMPLE statements
125121 + FOR_EACH_BB_FN(bb, cfun) {
125122 + gimple_stmt_iterator gsi;
125123 +
125124 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125125 + gimple stmt;
125126 +
125127 + stmt = gsi_stmt(gsi);
125128 +
125129 + if (is_gimple_call(stmt))
125130 + is_leaf = false;
125131 +
125132 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
125133 + if (!is_alloca(stmt))
125134 + continue;
125135 +
125136 + // 2. insert stack overflow check before each __builtin_alloca call
125137 + stackleak_check_alloca(&gsi);
125138 +
125139 + // 3. insert track call after each __builtin_alloca call
125140 + stackleak_add_instrumentation(&gsi);
125141 + if (bb == entry_bb)
125142 + prologue_instrumented = true;
125143 + }
125144 + }
125145 +
125146 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
125147 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
125148 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
125149 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
125150 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
125151 + return 0;
125152 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
125153 + return 0;
125154 +
125155 + // 4. insert track call at the beginning
125156 + if (!prologue_instrumented) {
125157 + gimple_stmt_iterator gsi;
125158 +
125159 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125160 + if (dom_info_available_p(CDI_DOMINATORS))
125161 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125162 + gsi = gsi_start_bb(bb);
125163 + stackleak_add_instrumentation(&gsi);
125164 + }
125165 +
125166 + return 0;
125167 +}
125168 +
125169 +static unsigned int execute_stackleak_final(void)
125170 +{
125171 + rtx insn, next;
125172 +
125173 + if (cfun->calls_alloca)
125174 + return 0;
125175 +
125176 + // keep calls only if function frame is big enough
125177 + if (get_frame_size() >= track_frame_size)
125178 + return 0;
125179 +
125180 + // 1. find pax_track_stack calls
125181 + for (insn = get_insns(); insn; insn = next) {
125182 + // 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))
125183 + rtx body;
125184 +
125185 + next = NEXT_INSN(insn);
125186 + if (!CALL_P(insn))
125187 + continue;
125188 + body = PATTERN(insn);
125189 + if (GET_CODE(body) != CALL)
125190 + continue;
125191 + body = XEXP(body, 0);
125192 + if (GET_CODE(body) != MEM)
125193 + continue;
125194 + body = XEXP(body, 0);
125195 + if (GET_CODE(body) != SYMBOL_REF)
125196 + continue;
125197 +// if (strcmp(XSTR(body, 0), track_function))
125198 + if (SYMBOL_REF_DECL(body) != track_function_decl)
125199 + continue;
125200 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125201 + // 2. delete call
125202 + delete_insn_and_edges(insn);
125203 +#if BUILDING_GCC_VERSION >= 4007
125204 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
125205 + insn = next;
125206 + next = NEXT_INSN(insn);
125207 + delete_insn_and_edges(insn);
125208 + }
125209 +#endif
125210 + }
125211 +
125212 +// print_simple_rtl(stderr, get_insns());
125213 +// print_rtl(stderr, get_insns());
125214 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125215 +
125216 + return 0;
125217 +}
125218 +
125219 +static bool gate_stackleak_track_stack(void)
125220 +{
125221 + tree section;
125222 +
125223 + if (ix86_cmodel != CM_KERNEL)
125224 + return false;
125225 +
125226 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
125227 + if (section && TREE_VALUE(section)) {
125228 + section = TREE_VALUE(TREE_VALUE(section));
125229 +
125230 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
125231 + return false;
125232 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
125233 + return false;
125234 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
125235 + return false;
125236 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
125237 + return false;
125238 + }
125239 +
125240 + return track_frame_size >= 0;
125241 +}
125242 +
125243 +static void stackleak_start_unit(void *gcc_data, void *user_data)
125244 +{
125245 + tree fntype;
125246 +
125247 + // void pax_track_stack(void)
125248 + fntype = build_function_type_list(void_type_node, NULL_TREE);
125249 + track_function_decl = build_fn_decl(track_function, fntype);
125250 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
125251 + TREE_PUBLIC(track_function_decl) = 1;
125252 + DECL_EXTERNAL(track_function_decl) = 1;
125253 + DECL_ARTIFICIAL(track_function_decl) = 1;
125254 +
125255 + // void pax_check_alloca(unsigned long)
125256 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
125257 + check_function_decl = build_fn_decl(check_function, fntype);
125258 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
125259 + TREE_PUBLIC(check_function_decl) = 1;
125260 + DECL_EXTERNAL(check_function_decl) = 1;
125261 + DECL_ARTIFICIAL(check_function_decl) = 1;
125262 +}
125263 +
125264 +#if BUILDING_GCC_VERSION >= 4009
125265 +static const struct pass_data stackleak_tree_instrument_pass_data = {
125266 +#else
125267 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
125268 + .pass = {
125269 +#endif
125270 + .type = GIMPLE_PASS,
125271 + .name = "stackleak_tree_instrument",
125272 +#if BUILDING_GCC_VERSION >= 4008
125273 + .optinfo_flags = OPTGROUP_NONE,
125274 +#endif
125275 +#if BUILDING_GCC_VERSION >= 4009
125276 + .has_gate = true,
125277 + .has_execute = true,
125278 +#else
125279 + .gate = gate_stackleak_track_stack,
125280 + .execute = execute_stackleak_tree_instrument,
125281 + .sub = NULL,
125282 + .next = NULL,
125283 + .static_pass_number = 0,
125284 +#endif
125285 + .tv_id = TV_NONE,
125286 + .properties_required = PROP_gimple_leh | PROP_cfg,
125287 + .properties_provided = 0,
125288 + .properties_destroyed = 0,
125289 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
125290 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
125291 +#if BUILDING_GCC_VERSION < 4009
125292 + }
125293 +#endif
125294 +};
125295 +
125296 +#if BUILDING_GCC_VERSION >= 4009
125297 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
125298 +#else
125299 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
125300 + .pass = {
125301 +#endif
125302 + .type = RTL_PASS,
125303 + .name = "stackleak_final",
125304 +#if BUILDING_GCC_VERSION >= 4008
125305 + .optinfo_flags = OPTGROUP_NONE,
125306 +#endif
125307 +#if BUILDING_GCC_VERSION >= 4009
125308 + .has_gate = true,
125309 + .has_execute = true,
125310 +#else
125311 + .gate = gate_stackleak_track_stack,
125312 + .execute = execute_stackleak_final,
125313 + .sub = NULL,
125314 + .next = NULL,
125315 + .static_pass_number = 0,
125316 +#endif
125317 + .tv_id = TV_NONE,
125318 + .properties_required = 0,
125319 + .properties_provided = 0,
125320 + .properties_destroyed = 0,
125321 + .todo_flags_start = 0,
125322 + .todo_flags_finish = TODO_dump_func
125323 +#if BUILDING_GCC_VERSION < 4009
125324 + }
125325 +#endif
125326 +};
125327 +
125328 +#if BUILDING_GCC_VERSION >= 4009
125329 +namespace {
125330 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
125331 +public:
125332 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
125333 + bool gate() { return gate_stackleak_track_stack(); }
125334 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
125335 +};
125336 +
125337 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
125338 +public:
125339 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
125340 + bool gate() { return gate_stackleak_track_stack(); }
125341 + unsigned int execute() { return execute_stackleak_final(); }
125342 +};
125343 +}
125344 +
125345 +static opt_pass *make_stackleak_tree_instrument_pass(void)
125346 +{
125347 + return new stackleak_tree_instrument_pass();
125348 +}
125349 +
125350 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
125351 +{
125352 + return new stackleak_final_rtl_opt_pass();
125353 +}
125354 +#else
125355 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
125356 +{
125357 + return &stackleak_tree_instrument_pass.pass;
125358 +}
125359 +
125360 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
125361 +{
125362 + return &stackleak_final_rtl_opt_pass.pass;
125363 +}
125364 +#endif
125365 +
125366 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125367 +{
125368 + const char * const plugin_name = plugin_info->base_name;
125369 + const int argc = plugin_info->argc;
125370 + const struct plugin_argument * const argv = plugin_info->argv;
125371 + int i;
125372 + struct register_pass_info stackleak_tree_instrument_pass_info;
125373 + struct register_pass_info stackleak_final_pass_info;
125374 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125375 + {
125376 + .base = &track_function_decl,
125377 + .nelt = 1,
125378 + .stride = sizeof(track_function_decl),
125379 + .cb = &gt_ggc_mx_tree_node,
125380 + .pchw = &gt_pch_nx_tree_node
125381 + },
125382 + {
125383 + .base = &check_function_decl,
125384 + .nelt = 1,
125385 + .stride = sizeof(check_function_decl),
125386 + .cb = &gt_ggc_mx_tree_node,
125387 + .pchw = &gt_pch_nx_tree_node
125388 + },
125389 + LAST_GGC_ROOT_TAB
125390 + };
125391 +
125392 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125393 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125394 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125395 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125396 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125397 +
125398 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125399 + stackleak_final_pass_info.reference_pass_name = "final";
125400 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125401 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125402 +
125403 + if (!plugin_default_version_check(version, &gcc_version)) {
125404 + error(G_("incompatible gcc/plugin versions"));
125405 + return 1;
125406 + }
125407 +
125408 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125409 +
125410 + for (i = 0; i < argc; ++i) {
125411 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125412 + if (!argv[i].value) {
125413 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125414 + continue;
125415 + }
125416 + track_frame_size = atoi(argv[i].value);
125417 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125418 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125419 + continue;
125420 + }
125421 + if (!strcmp(argv[i].key, "initialize-locals")) {
125422 + if (argv[i].value) {
125423 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125424 + continue;
125425 + }
125426 + init_locals = true;
125427 + continue;
125428 + }
125429 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125430 + }
125431 +
125432 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125433 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125434 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125435 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125436 +
125437 + return 0;
125438 +}
125439 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125440 new file mode 100644
125441 index 0000000..4ee2231
125442 --- /dev/null
125443 +++ b/tools/gcc/structleak_plugin.c
125444 @@ -0,0 +1,274 @@
125445 +/*
125446 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125447 + * Licensed under the GPL v2
125448 + *
125449 + * Note: the choice of the license means that the compilation process is
125450 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125451 + * but for the kernel it doesn't matter since it doesn't link against
125452 + * any of the gcc libraries
125453 + *
125454 + * gcc plugin to forcibly initialize certain local variables that could
125455 + * otherwise leak kernel stack to userland if they aren't properly initialized
125456 + * by later code
125457 + *
125458 + * Homepage: http://pax.grsecurity.net/
125459 + *
125460 + * Usage:
125461 + * $ # for 4.5/4.6/C based 4.7
125462 + * $ 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
125463 + * $ # for C++ based 4.7/4.8+
125464 + * $ 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
125465 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125466 + *
125467 + * TODO: eliminate redundant initializers
125468 + * increase type coverage
125469 + */
125470 +
125471 +#include "gcc-common.h"
125472 +
125473 +// unused C type flag in all versions 4.5-4.9
125474 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125475 +
125476 +int plugin_is_GPL_compatible;
125477 +
125478 +static struct plugin_info structleak_plugin_info = {
125479 + .version = "201401260140",
125480 + .help = "disable\tdo not activate plugin\n",
125481 +};
125482 +
125483 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125484 +{
125485 + *no_add_attrs = true;
125486 +
125487 + // check for types? for now accept everything linux has to offer
125488 + if (TREE_CODE(*node) != FIELD_DECL)
125489 + return NULL_TREE;
125490 +
125491 + *no_add_attrs = false;
125492 + return NULL_TREE;
125493 +}
125494 +
125495 +static struct attribute_spec user_attr = {
125496 + .name = "user",
125497 + .min_length = 0,
125498 + .max_length = 0,
125499 + .decl_required = false,
125500 + .type_required = false,
125501 + .function_type_required = false,
125502 + .handler = handle_user_attribute,
125503 +#if BUILDING_GCC_VERSION >= 4007
125504 + .affects_type_identity = true
125505 +#endif
125506 +};
125507 +
125508 +static void register_attributes(void *event_data, void *data)
125509 +{
125510 + register_attribute(&user_attr);
125511 +// register_attribute(&force_attr);
125512 +}
125513 +
125514 +static tree get_field_type(tree field)
125515 +{
125516 + return strip_array_types(TREE_TYPE(field));
125517 +}
125518 +
125519 +static bool is_userspace_type(tree type)
125520 +{
125521 + tree field;
125522 +
125523 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125524 + tree fieldtype = get_field_type(field);
125525 + enum tree_code code = TREE_CODE(fieldtype);
125526 +
125527 + if (code == RECORD_TYPE || code == UNION_TYPE)
125528 + if (is_userspace_type(fieldtype))
125529 + return true;
125530 +
125531 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125532 + return true;
125533 + }
125534 + return false;
125535 +}
125536 +
125537 +static void finish_type(void *event_data, void *data)
125538 +{
125539 + tree type = (tree)event_data;
125540 +
125541 + if (TYPE_USERSPACE(type))
125542 + return;
125543 +
125544 + if (is_userspace_type(type))
125545 + TYPE_USERSPACE(type) = 1;
125546 +}
125547 +
125548 +static void initialize(tree var)
125549 +{
125550 + basic_block bb;
125551 + gimple_stmt_iterator gsi;
125552 + tree initializer;
125553 + gimple init_stmt;
125554 +
125555 + // this is the original entry bb before the forced split
125556 + // TODO: check further BBs in case more splits occured before us
125557 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125558 +
125559 + // first check if the variable is already initialized, warn otherwise
125560 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125561 + gimple stmt = gsi_stmt(gsi);
125562 + tree rhs1;
125563 +
125564 + // we're looking for an assignment of a single rhs...
125565 + if (!gimple_assign_single_p(stmt))
125566 + continue;
125567 + rhs1 = gimple_assign_rhs1(stmt);
125568 +#if BUILDING_GCC_VERSION >= 4007
125569 + // ... of a non-clobbering expression...
125570 + if (TREE_CLOBBER_P(rhs1))
125571 + continue;
125572 +#endif
125573 + // ... to our variable...
125574 + if (gimple_get_lhs(stmt) != var)
125575 + continue;
125576 + // if it's an initializer then we're good
125577 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125578 + return;
125579 + }
125580 +
125581 + // these aren't the 0days you're looking for
125582 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125583 +
125584 + // build the initializer expression
125585 + initializer = build_constructor(TREE_TYPE(var), NULL);
125586 +
125587 + // build the initializer stmt
125588 + init_stmt = gimple_build_assign(var, initializer);
125589 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125590 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125591 + update_stmt(init_stmt);
125592 +}
125593 +
125594 +static unsigned int handle_function(void)
125595 +{
125596 + basic_block bb;
125597 + unsigned int ret = 0;
125598 + tree var;
125599 + unsigned int i;
125600 +
125601 + // split the first bb where we can put the forced initializers
125602 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125603 + if (dom_info_available_p(CDI_DOMINATORS))
125604 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125605 +
125606 + // enumarate all local variables and forcibly initialize our targets
125607 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125608 + tree type = TREE_TYPE(var);
125609 +
125610 + gcc_assert(DECL_P(var));
125611 + if (!auto_var_in_fn_p(var, current_function_decl))
125612 + continue;
125613 +
125614 + // only care about structure types
125615 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125616 + continue;
125617 +
125618 + // if the type is of interest, examine the variable
125619 + if (TYPE_USERSPACE(type))
125620 + initialize(var);
125621 + }
125622 +
125623 + return ret;
125624 +}
125625 +
125626 +#if BUILDING_GCC_VERSION >= 4009
125627 +static const struct pass_data structleak_pass_data = {
125628 +#else
125629 +static struct gimple_opt_pass structleak_pass = {
125630 + .pass = {
125631 +#endif
125632 + .type = GIMPLE_PASS,
125633 + .name = "structleak",
125634 +#if BUILDING_GCC_VERSION >= 4008
125635 + .optinfo_flags = OPTGROUP_NONE,
125636 +#endif
125637 +#if BUILDING_GCC_VERSION >= 4009
125638 + .has_gate = false,
125639 + .has_execute = true,
125640 +#else
125641 + .gate = NULL,
125642 + .execute = handle_function,
125643 + .sub = NULL,
125644 + .next = NULL,
125645 + .static_pass_number = 0,
125646 +#endif
125647 + .tv_id = TV_NONE,
125648 + .properties_required = PROP_cfg,
125649 + .properties_provided = 0,
125650 + .properties_destroyed = 0,
125651 + .todo_flags_start = 0,
125652 + .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
125653 +#if BUILDING_GCC_VERSION < 4009
125654 + }
125655 +#endif
125656 +};
125657 +
125658 +#if BUILDING_GCC_VERSION >= 4009
125659 +namespace {
125660 +class structleak_pass : public gimple_opt_pass {
125661 +public:
125662 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125663 + unsigned int execute() { return handle_function(); }
125664 +};
125665 +}
125666 +
125667 +static opt_pass *make_structleak_pass(void)
125668 +{
125669 + return new structleak_pass();
125670 +}
125671 +#else
125672 +static struct opt_pass *make_structleak_pass(void)
125673 +{
125674 + return &structleak_pass.pass;
125675 +}
125676 +#endif
125677 +
125678 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125679 +{
125680 + int i;
125681 + const char * const plugin_name = plugin_info->base_name;
125682 + const int argc = plugin_info->argc;
125683 + const struct plugin_argument * const argv = plugin_info->argv;
125684 + bool enable = true;
125685 + struct register_pass_info structleak_pass_info;
125686 +
125687 + structleak_pass_info.pass = make_structleak_pass();
125688 + structleak_pass_info.reference_pass_name = "ssa";
125689 + structleak_pass_info.ref_pass_instance_number = 1;
125690 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125691 +
125692 + if (!plugin_default_version_check(version, &gcc_version)) {
125693 + error(G_("incompatible gcc/plugin versions"));
125694 + return 1;
125695 + }
125696 +
125697 + if (strcmp(lang_hooks.name, "GNU C")) {
125698 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125699 + enable = false;
125700 + }
125701 +
125702 + for (i = 0; i < argc; ++i) {
125703 + if (!strcmp(argv[i].key, "disable")) {
125704 + enable = false;
125705 + continue;
125706 + }
125707 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125708 + }
125709 +
125710 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125711 + if (enable) {
125712 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125713 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125714 + }
125715 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125716 +
125717 + return 0;
125718 +}
125719 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125720 index 88461f0..6fb70a0 100644
125721 --- a/tools/include/linux/compiler.h
125722 +++ b/tools/include/linux/compiler.h
125723 @@ -35,6 +35,14 @@
125724 # define unlikely(x) __builtin_expect(!!(x), 0)
125725 #endif
125726
125727 +#ifndef __size_overflow
125728 +# define __size_overflow(...)
125729 +#endif
125730 +
125731 +#ifndef __intentional_overflow
125732 +# define __intentional_overflow(...)
125733 +#endif
125734 +
125735 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125736
125737 #endif /* _TOOLS_LINUX_COMPILER_H */
125738 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125739 index 36c08b1..87c72d1 100644
125740 --- a/tools/lib/api/Makefile
125741 +++ b/tools/lib/api/Makefile
125742 @@ -21,7 +21,7 @@ LIB_OBJS += $(OUTPUT)fd/array.o
125743
125744 LIBFILE = libapikfs.a
125745
125746 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125747 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125748 EXTLIBS = -lelf -lpthread -lrt -lm
125749 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125750 ALL_LDFLAGS = $(LDFLAGS)
125751 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125752 index 6789d788..4afd019e 100644
125753 --- a/tools/perf/util/include/asm/alternative-asm.h
125754 +++ b/tools/perf/util/include/asm/alternative-asm.h
125755 @@ -5,4 +5,7 @@
125756
125757 #define altinstruction_entry #
125758
125759 + .macro pax_force_retaddr rip=0, reload=0
125760 + .endm
125761 +
125762 #endif
125763 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125764 index 0a578fe..b81f62d 100644
125765 --- a/tools/virtio/linux/uaccess.h
125766 +++ b/tools/virtio/linux/uaccess.h
125767 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125768 ({ \
125769 typeof(ptr) __pu_ptr = (ptr); \
125770 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125771 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125772 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125773 0; \
125774 })
125775
125776 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125777 index 3cee7b1..29cb7d8 100644
125778 --- a/virt/kvm/kvm_main.c
125779 +++ b/virt/kvm/kvm_main.c
125780 @@ -78,12 +78,17 @@ LIST_HEAD(vm_list);
125781
125782 static cpumask_var_t cpus_hardware_enabled;
125783 static int kvm_usage_count = 0;
125784 -static atomic_t hardware_enable_failed;
125785 +static atomic_unchecked_t hardware_enable_failed;
125786
125787 struct kmem_cache *kvm_vcpu_cache;
125788 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125789
125790 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125791 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125792 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125793 +static struct preempt_ops kvm_preempt_ops = {
125794 + .sched_in = kvm_sched_in,
125795 + .sched_out = kvm_sched_out,
125796 +};
125797
125798 struct dentry *kvm_debugfs_dir;
125799
125800 @@ -786,7 +791,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125801 /* We can read the guest memory with __xxx_user() later on. */
125802 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125803 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125804 - !access_ok(VERIFY_WRITE,
125805 + !access_ok_noprefault(VERIFY_WRITE,
125806 (void __user *)(unsigned long)mem->userspace_addr,
125807 mem->memory_size)))
125808 goto out;
125809 @@ -1690,9 +1695,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125810
125811 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125812 {
125813 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125814 + int r;
125815 + unsigned long addr;
125816
125817 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125818 + addr = gfn_to_hva(kvm, gfn);
125819 + if (kvm_is_error_hva(addr))
125820 + return -EFAULT;
125821 + r = __clear_user((void __user *)addr + offset, len);
125822 + if (r)
125823 + return -EFAULT;
125824 + mark_page_dirty(kvm, gfn);
125825 + return 0;
125826 }
125827 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125828
125829 @@ -1941,7 +1954,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125830 return 0;
125831 }
125832
125833 -static struct file_operations kvm_vcpu_fops = {
125834 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125835 .release = kvm_vcpu_release,
125836 .unlocked_ioctl = kvm_vcpu_ioctl,
125837 #ifdef CONFIG_COMPAT
125838 @@ -2650,7 +2663,7 @@ out:
125839 }
125840 #endif
125841
125842 -static struct file_operations kvm_vm_fops = {
125843 +static file_operations_no_const kvm_vm_fops __read_only = {
125844 .release = kvm_vm_release,
125845 .unlocked_ioctl = kvm_vm_ioctl,
125846 #ifdef CONFIG_COMPAT
125847 @@ -2721,7 +2734,7 @@ out:
125848 return r;
125849 }
125850
125851 -static struct file_operations kvm_chardev_ops = {
125852 +static file_operations_no_const kvm_chardev_ops __read_only = {
125853 .unlocked_ioctl = kvm_dev_ioctl,
125854 .compat_ioctl = kvm_dev_ioctl,
125855 .llseek = noop_llseek,
125856 @@ -2747,7 +2760,7 @@ static void hardware_enable_nolock(void *junk)
125857
125858 if (r) {
125859 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125860 - atomic_inc(&hardware_enable_failed);
125861 + atomic_inc_unchecked(&hardware_enable_failed);
125862 printk(KERN_INFO "kvm: enabling virtualization on "
125863 "CPU%d failed\n", cpu);
125864 }
125865 @@ -2803,10 +2816,10 @@ static int hardware_enable_all(void)
125866
125867 kvm_usage_count++;
125868 if (kvm_usage_count == 1) {
125869 - atomic_set(&hardware_enable_failed, 0);
125870 + atomic_set_unchecked(&hardware_enable_failed, 0);
125871 on_each_cpu(hardware_enable_nolock, NULL, 1);
125872
125873 - if (atomic_read(&hardware_enable_failed)) {
125874 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125875 hardware_disable_all_nolock();
125876 r = -EBUSY;
125877 }
125878 @@ -3213,7 +3226,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125879 kvm_arch_vcpu_put(vcpu);
125880 }
125881
125882 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125883 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125884 struct module *module)
125885 {
125886 int r;
125887 @@ -3260,7 +3273,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125888 if (!vcpu_align)
125889 vcpu_align = __alignof__(struct kvm_vcpu);
125890 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125891 - 0, NULL);
125892 + SLAB_USERCOPY, NULL);
125893 if (!kvm_vcpu_cache) {
125894 r = -ENOMEM;
125895 goto out_free_3;
125896 @@ -3270,9 +3283,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125897 if (r)
125898 goto out_free;
125899
125900 + pax_open_kernel();
125901 kvm_chardev_ops.owner = module;
125902 kvm_vm_fops.owner = module;
125903 kvm_vcpu_fops.owner = module;
125904 + pax_close_kernel();
125905
125906 r = misc_register(&kvm_dev);
125907 if (r) {
125908 @@ -3282,9 +3297,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125909
125910 register_syscore_ops(&kvm_syscore_ops);
125911
125912 - kvm_preempt_ops.sched_in = kvm_sched_in;
125913 - kvm_preempt_ops.sched_out = kvm_sched_out;
125914 -
125915 r = kvm_init_debug();
125916 if (r) {
125917 printk(KERN_ERR "kvm: create debugfs files failed\n");